Skip to content

Commit ed2018c

Browse files
committed
Fix linter issues
1 parent df7eec0 commit ed2018c

File tree

3 files changed

+52
-26
lines changed

3 files changed

+52
-26
lines changed

app/controllers/admin/admins_controller.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Admin::AdminsController < Comfy::Admin::BaseController
24
before_action :build_admin, only: [:new, :create]
35
before_action :load_admin, only: [:show, :edit, :update, :destroy]
@@ -20,25 +22,25 @@ def edit
2022

2123
def create
2224
@admin.save!
23-
flash[:success] = "Admin created"
25+
flash[:success] = t(".admin_created_successfully")
2426
redirect_to action: :show, id: @admin
2527
rescue ActiveRecord::RecordInvalid
26-
flash.now[:danger] = "Failed to create Admin"
28+
flash.now[:danger] = t(".admin_creation_failed")
2729
render action: :new
2830
end
2931

3032
def update
3133
@admin.update!(admin_params)
32-
flash[:success] = "Admin updated"
34+
flash[:success] = t(".admin_updated_successfully")
3335
redirect_to action: :show, id: @admin
3436
rescue ActiveRecord::RecordInvalid
35-
flash.now[:danger] = "Failed to update Admin"
37+
flash.now[:danger] = t(".admin_update_failed")
3638
render action: :edit
3739
end
3840

3941
def destroy
4042
@admin.destroy
41-
flash[:success] = "Admin deleted"
43+
flash[:success] = t(".admin_deleted_successfully")
4244
redirect_to action: :index
4345
end
4446

@@ -51,7 +53,7 @@ def build_admin
5153
def load_admin
5254
@admin = Admin.find(params[:id])
5355
rescue ActiveRecord::RecordNotFound
54-
flash[:danger] = "Admin not found"
56+
flash[:danger] = t("admin.admins.admin_not_found")
5557
redirect_to action: :index
5658
end
5759

config/locales/en.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,14 @@
3131

3232
en:
3333
hello: "Hello world"
34+
admin:
35+
admins:
36+
admin_not_found: "Admin not found"
37+
create:
38+
admin_created_successfully: "Admin created successfully"
39+
admin_creation_failed: "Admin creation failed"
40+
update:
41+
admin_updated_successfully: "Admin updated successfully"
42+
admin_update_failed: "Admin update failed"
43+
destroy:
44+
admin_deleted_successfully: "Admin deleted successfully"
Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
require_relative '../../test_helper'
1+
# frozen_string_literal: true
22

3-
class Admin::AdminsControllerTest < ActionDispatch::IntegrationTest
3+
require_relative "../../test_helper"
44

5+
class Admin::AdminsControllerTest < ActionDispatch::IntegrationTest
56
setup do
67
@admin = admins(:default)
78
end
@@ -11,38 +12,42 @@ class Admin::AdminsControllerTest < ActionDispatch::IntegrationTest
1112
# Move this to test_helper.rb
1213
def r(verb, path, options = {})
1314
headers = options[:headers] || {}
14-
headers['HTTP_AUTHORIZATION'] =
15+
headers["HTTP_AUTHORIZATION"] =
1516
ActionController::HttpAuthentication::Basic.encode_credentials(
1617
ComfortableMexicanSofa::AccessControl::AdminAuthentication.username,
1718
ComfortableMexicanSofa::AccessControl::AdminAuthentication.password
1819
)
19-
options.merge!(headers: headers)
20+
options[:headers] = headers
2021
send(verb, path, options)
2122
end
2223

2324
def test_get_index
2425
r :get, admin_admins_path
26+
2527
assert_response :success
2628
assert assigns(:admins)
2729
assert_template :index
2830
end
2931

3032
def test_get_show
3133
r :get, admin_admin_path(@admin)
34+
3235
assert_response :success
3336
assert assigns(:admin)
3437
assert_template :show
3538
end
3639

3740
def test_get_show_failure
38-
r :get, admin_admin_path('invalid')
41+
r :get, admin_admin_path("invalid")
42+
3943
assert_response :redirect
4044
assert_redirected_to action: :index
41-
assert_equal 'Admin not found', flash[:danger]
45+
assert_equal "Admin not found", flash[:danger]
4246
end
4347

4448
def test_get_new
4549
r :get, new_admin_admin_path
50+
4651
assert_response :success
4752
assert assigns(:admin)
4853
assert_template :new
@@ -51,61 +56,69 @@ def test_get_new
5156

5257
def test_get_edit
5358
r :get, edit_admin_admin_path(@admin)
59+
5460
assert_response :success
5561
assert assigns(:admin)
5662
assert_template :edit
5763
assert_select "form[action='/admin/admins/#{@admin.id}']"
5864
end
5965

6066
def test_creation
61-
assert_difference 'Admin.count' do
67+
assert_difference "Admin.count" do
6268
r :post, admin_admins_path, params: {admin: {
63-
name: 'test name',
69+
name: "test name"
6470
}}
6571
admin = Admin.last
72+
6673
assert_response :redirect
6774
assert_redirected_to action: :show, id: admin
68-
assert_equal 'Admin created', flash[:success]
75+
assert_equal "Admin created", flash[:success]
6976
end
7077
end
7178

7279
def test_creation_failure
73-
assert_no_difference 'Admin.count' do
74-
r :post, admin_admins_path, params: {admin: { }}
80+
assert_no_difference "Admin.count" do
81+
r :post, admin_admins_path, params: {admin: {}}
82+
7583
assert_response :success
7684
assert_template :new
77-
assert_equal 'Failed to create Admin', flash[:danger]
85+
assert_equal "Failed to create Admin", flash[:danger]
7886
end
7987
end
8088

8189
def test_update
8290
r :put, admin_admin_path(@admin), params: {admin: {
83-
name: 'Updated'
91+
name: "Updated"
8492
}}
93+
8594
assert_response :redirect
8695
assert_redirected_to action: :show, id: @admin
87-
assert_equal 'Admin updated', flash[:success]
96+
assert_equal "Admin updated", flash[:success]
8897
@admin.reload
89-
assert_equal 'Updated', @admin.name
98+
99+
assert_equal "Updated", @admin.name
90100
end
91101

92102
def test_update_failure
93103
r :put, admin_admin_path(@admin), params: {admin: {
94-
name: ''
104+
name: ""
95105
}}
106+
96107
assert_response :success
97108
assert_template :edit
98-
assert_equal 'Failed to update Admin', flash[:danger]
109+
assert_equal "Failed to update Admin", flash[:danger]
99110
@admin.reload
100-
refute_equal '', @admin.name
111+
112+
assert_not_equal "", @admin.name
101113
end
102114

103115
def test_destroy
104-
assert_difference 'Admin.count', -1 do
116+
assert_difference "Admin.count", -1 do
105117
r :delete, admin_admin_path(@admin)
118+
106119
assert_response :redirect
107120
assert_redirected_to action: :index
108-
assert_equal 'Admin deleted', flash[:success]
121+
assert_equal "Admin deleted", flash[:success]
109122
end
110123
end
111124
end

0 commit comments

Comments
 (0)