Skip to content

Commit a05ed82

Browse files
committed
Autoformat with Rufo
1 parent 84c40ee commit a05ed82

17 files changed

Lines changed: 228 additions & 197 deletions

app/controllers/alchemy/accounts_controller.rb

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

57
def show
68
authorize! :show, current_alchemy_user
@@ -11,7 +13,7 @@ def show
1113

1214
def permission_denied(*)
1315
store_location_for(:user, account_path)
14-
flash[:warning] = t(:unauthenticated, scope: 'devise.failure')
16+
flash[:warning] = t(:unauthenticated, scope: "devise.failure")
1517
redirect_to alchemy.login_path
1618
end
1719
end

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/mailers/alchemy/notifications.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
# frozen_string_literal: true
2+
13
module Alchemy
24
class Notifications < ::Devise::Mailer
3-
4-
default(from: Config.get(:mailer)['mail_from'])
5+
default(from: Config.get(:mailer)["mail_from"])
56

67
def member_created(user)
78
@user = user
89

910
mail(
1011
to: user.email,
11-
subject: Alchemy.t("Your user credentials")
12+
subject: Alchemy.t("Your user credentials"),
1213
)
1314
end
1415

@@ -17,34 +18,34 @@ def alchemy_user_created(user)
1718
@url = admin_url
1819
mail(
1920
to: user.email,
20-
subject: Alchemy.t("Your Alchemy Login")
21+
subject: Alchemy.t("Your Alchemy Login"),
2122
)
2223
end
2324

24-
def member_reset_password_instructions(user, token, opts={})
25+
def member_reset_password_instructions(user, token, _opts = {})
2526
@user = user
2627
@token = token
2728
mail(
2829
to: user.email,
29-
subject: Alchemy.t("Reset password instructions")
30+
subject: Alchemy.t("Reset password instructions"),
3031
)
3132
end
3233

33-
def reset_password_instructions(user, token, opts={})
34+
def reset_password_instructions(user, token, _opts = {})
3435
@user = user
3536
@token = token
3637
mail(
3738
to: user.email,
38-
subject: Alchemy.t("Reset password instructions")
39+
subject: Alchemy.t("Reset password instructions"),
3940
)
4041
end
4142

42-
def confirmation_instructions(user, token, opts={})
43+
def confirmation_instructions(user, token, _opts = {})
4344
@user = user
4445
@token = token
4546
mail(
4647
to: user.email,
47-
subject: Alchemy.t("Account confirmation instructions")
48+
subject: Alchemy.t("Account confirmation instructions"),
4849
)
4950
end
5051
end

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

0 commit comments

Comments
 (0)