Skip to content

Commit 0c53da4

Browse files
committed
Autoformat with Rufo
1 parent cc6e620 commit 0c53da4

15 files changed

Lines changed: 213 additions & 185 deletions

app/controllers/alchemy/confirmations_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# frozen_string_literal: true
2+
13
module Alchemy
24
class ConfirmationsController < ::Devise::ConfirmationsController
3-
helper 'Alchemy::Pages'
5+
helper "Alchemy::Pages"
46

57
private
68

app/controllers/alchemy/passwords_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# frozen_string_literal: true
2+
13
module Alchemy
24
class PasswordsController < ::Devise::PasswordsController
3-
helper 'Alchemy::Pages'
5+
helper "Alchemy::Pages"
46

57
private
68

app/controllers/alchemy/sessions_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# frozen_string_literal: true
2+
13
module Alchemy
24
class SessionsController < ::Devise::SessionsController
3-
helper 'Alchemy::Pages'
5+
helper "Alchemy::Pages"
46

57
private
68

app/models/alchemy/user.rb

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
require 'devise/orm/active_record'
2-
require 'userstamp'
1+
# frozen_string_literal: true
2+
3+
require "devise/orm/active_record"
4+
require "userstamp"
35

46
module Alchemy
57
class User < ActiveRecord::Base
@@ -12,7 +14,7 @@ class User < ActiveRecord::Base
1214
:password,
1315
:password_confirmation,
1416
:send_credentials,
15-
:tag_list
17+
:tag_list,
1618
]
1719

1820
devise *Alchemy.devise_modules
@@ -29,9 +31,9 @@ class User < ActiveRecord::Base
2931
# Unlock all locked pages before destroy.
3032
before_destroy :unlock_pages!
3133

32-
scope :admins, -> { where(arel_table[:alchemy_roles].matches('%admin%')) }
33-
scope :logged_in, -> { where('last_request_at > ?', logged_in_timeout.seconds.ago) }
34-
scope :logged_out, -> { where('last_request_at is NULL or last_request_at <= ?', logged_in_timeout.seconds.ago) }
34+
scope :admins, -> { where(arel_table[:alchemy_roles].matches("%admin%")) }
35+
scope :logged_in, -> { where("last_request_at > ?", logged_in_timeout.seconds.ago) }
36+
scope :logged_out, -> { where("last_request_at is NULL or last_request_at <= ?", logged_in_timeout.seconds.ago) }
3537

3638
ROLES = Config.get(:user_roles)
3739

@@ -51,10 +53,7 @@ def logged_in_timeout
5153
def search(query)
5254
query = "%#{query.downcase}%"
5355

54-
where arel_table[:login].lower.matches(query)
55-
.or arel_table[:email].lower.matches(query)
56-
.or arel_table[:firstname].lower.matches(query)
57-
.or arel_table[:lastname].lower.matches(query)
56+
where arel_table[:login].lower.matches(query).or arel_table[:email].lower.matches(query).or arel_table[:firstname].lower.matches(query).or arel_table[:lastname].lower.matches(query)
5857
end
5958
end
6059

@@ -67,12 +66,12 @@ def role
6766
end
6867

6968
def alchemy_roles
70-
read_attribute(:alchemy_roles).split(' ')
69+
read_attribute(:alchemy_roles).split(" ")
7170
end
7271

7372
def alchemy_roles=(roles_string)
7473
if roles_string.is_a? Array
75-
write_attribute(:alchemy_roles, roles_string.join(' '))
74+
write_attribute(:alchemy_roles, roles_string.join(" "))
7675
elsif roles_string.is_a? String
7776
write_attribute(:alchemy_roles, roles_string)
7877
end
@@ -84,8 +83,9 @@ def add_role(role)
8483

8584
# Returns true if the user ahs admin role
8685
def is_admin?
87-
has_role? 'admin'
86+
has_role? "admin"
8887
end
88+
8989
alias_method :admin?, :is_admin?
9090

9191
# Returns true if the user has the given role.
@@ -105,6 +105,7 @@ def unlock_pages!
105105
def pages_locked_by_me
106106
Page.locked_by(self).order(:updated_at)
107107
end
108+
108109
alias_method :locked_pages, :pages_locked_by_me
109110

110111
# Returns the firstname and lastname as a string
@@ -118,11 +119,12 @@ def fullname(options = {})
118119
if lastname.blank? && firstname.blank?
119120
login
120121
else
121-
options = {:flipped => false}.merge(options)
122+
options = { :flipped => false }.merge(options)
122123
fullname = options[:flipped] ? "#{lastname}, #{firstname}" : "#{firstname} #{lastname}"
123124
fullname.squeeze(" ").strip
124125
end
125126
end
127+
126128
alias_method :name, :fullname
127129
alias_method :alchemy_display_name, :fullname
128130

@@ -150,7 +152,7 @@ def store_request_time!
150152
# Delivers a welcome mail depending from user's role.
151153
#
152154
def deliver_welcome_mail
153-
if has_role?('author') || has_role?('editor') || has_role?('admin')
155+
if has_role?("author") || has_role?("editor") || has_role?("admin")
154156
Notifications.alchemy_user_created(self).deliver_later
155157
else
156158
Notifications.member_created(self).deliver_later
@@ -159,7 +161,7 @@ def deliver_welcome_mail
159161

160162
# Overwritten to send a different email to members
161163
def send_reset_password_instructions_notification(token)
162-
if has_role?('member')
164+
if has_role?("member")
163165
send_devise_notification(:member_reset_password_instructions, token, {})
164166
else
165167
send_devise_notification(:reset_password_instructions, token, {})

config/routes.rb

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1+
# frozen_string_literal: true
2+
13
Alchemy::Engine.routes.draw do
24
if Alchemy::Devise.enable_user_accounts?
35
devise_for :user,
4-
class_name: 'Alchemy::User',
6+
class_name: "Alchemy::User",
57
singular: :user,
68
skip: :all,
79
controllers: {
8-
registrations: Alchemy::Devise.registrations_enabled? ? 'alchemy/accounts' : nil,
9-
confirmations: Alchemy::Devise.confirmations_enabled? ? 'alchemy/confirmations' : nil,
10-
sessions: 'alchemy/sessions',
11-
passwords: 'alchemy/passwords'
10+
registrations: Alchemy::Devise.registrations_enabled? ? "alchemy/accounts" : nil,
11+
confirmations: Alchemy::Devise.confirmations_enabled? ? "alchemy/confirmations" : nil,
12+
sessions: "alchemy/sessions",
13+
passwords: "alchemy/passwords",
1214
},
1315
path: :account,
1416
router_name: :alchemy
1517

1618
scope :account do
1719
devise_scope :user do
18-
get '/login' => 'sessions#new'
19-
post '/login' => 'sessions#create'
20-
match '/logout' => 'sessions#destroy', via: Devise.sign_out_via
20+
get "/login" => "sessions#new"
21+
post "/login" => "sessions#create"
22+
match "/logout" => "sessions#destroy", via: Devise.sign_out_via
2123

2224
if Alchemy::Devise.confirmations_enabled?
2325
resource :confirmation, only: %i[new create show]
@@ -33,37 +35,36 @@
3335

3436
namespace :admin, {
3537
path: Alchemy.admin_path,
36-
constraints: Alchemy.admin_constraints
38+
constraints: Alchemy.admin_constraints,
3739
} do
38-
3940
devise_for :user,
40-
class_name: 'Alchemy::User',
41+
class_name: "Alchemy::User",
4142
singular: :user,
4243
skip: :all,
4344
controllers: {
44-
sessions: 'alchemy/admin/user_sessions',
45-
passwords: 'alchemy/admin/passwords'
45+
sessions: "alchemy/admin/user_sessions",
46+
passwords: "alchemy/admin/passwords",
4647
},
4748
router_name: :alchemy
4849

4950
devise_scope :user do
50-
get '/dashboard' => 'dashboard#index',
51+
get "/dashboard" => "dashboard#index",
5152
:as => :user_root
52-
get '/signup' => 'users#signup',
53+
get "/signup" => "users#signup",
5354
:as => :signup
54-
get '/login' => 'user_sessions#new',
55+
get "/login" => "user_sessions#new",
5556
:as => :login
56-
post '/login' => 'user_sessions#create'
57-
match '/logout' => 'user_sessions#destroy',
57+
post "/login" => "user_sessions#create"
58+
match "/logout" => "user_sessions#destroy",
5859
:as => :logout, via: Devise.sign_out_via
5960

60-
get '/passwords' => 'passwords#new',
61+
get "/passwords" => "passwords#new",
6162
:as => :new_password
62-
get '/passwords/:id/edit/:reset_password_token' => 'passwords#edit',
63+
get "/passwords/:id/edit/:reset_password_token" => "passwords#edit",
6364
:as => :edit_password
64-
post '/passwords' => 'passwords#create',
65+
post "/passwords" => "passwords#create",
6566
:as => :reset_password
66-
patch '/passwords' => 'passwords#update',
67+
patch "/passwords" => "passwords#update",
6768
:as => :update_password
6869
end
6970

spec/controllers/accounts_controller_spec.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,45 @@
1-
require 'rails_helper'
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
24

35
describe Alchemy::AccountsController do
46
routes { Alchemy::Engine.routes }
57

6-
context 'with user accounts enabled' do
8+
context "with user accounts enabled" do
79
before do
810
allow(Alchemy::Devise).to receive(:enable_user_accounts?) { true }
911
Rails.application.reload_routes!
1012
@request.env["devise.mapping"] = Devise.mappings[:user]
1113
end
1214

13-
describe '#show' do
15+
describe "#show" do
1416
let(:user) { create(:alchemy_member_user) }
1517

16-
context 'with authorized user' do
18+
context "with authorized user" do
1719
before { authorize_user(user) }
1820

1921
render_views
2022

21-
it 'shows account' do
23+
it "shows account" do
2224
get :show
2325
is_expected.to render_template(:show)
2426
end
2527
end
2628

27-
context 'with unauthorized user' do
28-
it 'redirects to login' do
29+
context "with unauthorized user" do
30+
it "redirects to login" do
2931
get :show
3032
is_expected.to redirect_to(login_path)
3133
end
3234

33-
it 'stores current location' do
35+
it "stores current location" do
3436
get :show
3537
expect(session[:user_return_to]).to eq(account_path)
3638
end
3739

38-
it 'shows warning message' do
40+
it "shows warning message" do
3941
get :show
40-
expect(flash[:warning]).to eq I18n.t(:unauthenticated, scope: 'devise.failure')
42+
expect(flash[:warning]).to eq I18n.t(:unauthenticated, scope: "devise.failure")
4143
end
4244
end
4345
end

spec/controllers/confirmations_controller_spec.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
require 'rails_helper'
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
24

35
describe Alchemy::ConfirmationsController do
46
routes { Alchemy::Engine.routes }
57

6-
context 'with user accounts enabled' do
8+
context "with user accounts enabled" do
79
before do
810
allow(Alchemy::Devise).to receive(:enable_user_accounts?) { true }
911
end
1012

11-
context 'with confirmations enabled' do
12-
let(:user) { double(email: 'mail@example.com') }
13+
context "with confirmations enabled" do
14+
let(:user) { double(email: "mail@example.com") }
1315

1416
before do
1517
allow(Alchemy::Devise).to receive(:confirmations_enabled?) { true }
@@ -18,25 +20,25 @@
1820
expect(Alchemy::User).to receive(:send_confirmation_instructions) { user }
1921
end
2022

21-
describe '#create' do
22-
context 'with valid params' do
23+
describe "#create" do
24+
context "with valid params" do
2325
before do
2426
expect(user).to receive(:errors) { [] }
2527
end
2628

2729
it "redirects to account" do
28-
post :create, params: {user: {email: user.email}}
30+
post :create, params: { user: { email: user.email } }
2931
expect(response).to redirect_to(login_path)
3032
end
3133
end
3234

33-
context 'without valid params' do
35+
context "without valid params" do
3436
before do
35-
expect(user).to receive(:errors).twice { ['Email not found'] }
37+
expect(user).to receive(:errors).twice { ["Email not found"] }
3638
end
3739

3840
it "renders form" do
39-
post :create, params: {user: {email: 'not@found'}}
41+
post :create, params: { user: { email: "not@found" } }
4042
is_expected.to render_template(:new)
4143
end
4244
end

spec/controllers/passwords_controller_spec.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
require 'rails_helper'
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
24

35
describe Alchemy::PasswordsController do
46
routes { Alchemy::Engine.routes }
57

6-
context 'with user accounts enabled' do
8+
context "with user accounts enabled" do
79
before(:all) do
810
Alchemy::Devise.enable_user_accounts = true
911
Rails.application.reload_routes!
@@ -15,17 +17,17 @@
1517

1618
let!(:user) { create(:alchemy_user) }
1719

18-
describe '#create' do
19-
context 'with valid params' do
20+
describe "#create" do
21+
context "with valid params" do
2022
it "redirects to login" do
21-
post :create, params: {user: {email: user.email}}
23+
post :create, params: { user: { email: user.email } }
2224
expect(response).to redirect_to(login_path)
2325
end
2426
end
2527

26-
context 'without valid params' do
28+
context "without valid params" do
2729
it "renders form" do
28-
post :create, params: {user: {email: 'not@found'}}
30+
post :create, params: { user: { email: "not@found" } }
2931
is_expected.to render_template(:new)
3032
end
3133
end

0 commit comments

Comments
 (0)