Skip to content

Commit 05c22df

Browse files
committed
Added new rubocop extensions
1 parent c833d05 commit 05c22df

5 files changed

Lines changed: 44 additions & 14 deletions

File tree

.rubocop.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
require:
2+
- rubocop-performance
3+
- rubocop-rails
4+
- rubocop-thread_safety
5+
16
inherit_mode:
27
merge:
38
- Exclude
@@ -8,6 +13,7 @@ AllCops:
813
- 'app/controllers/kenui/engine_controller.rb' # Too much magic going on
914
NewCops: enable
1015
SuggestExtensions: false
16+
TargetRubyVersion: 3.2
1117

1218
Gemspec/RequiredRubyVersion:
1319
Enabled: false
@@ -51,3 +57,24 @@ Style/Documentation:
5157

5258
Style/EmptyElse:
5359
EnforcedStyle: empty
60+
61+
# Rails cops
62+
Rails:
63+
Enabled: true
64+
65+
Rails/I18nLocaleTexts:
66+
Enabled: false
67+
68+
Rails/SkipsModelValidations:
69+
Enabled: false
70+
71+
# Performance cops
72+
Performance:
73+
Enabled: true
74+
75+
# Thread Safety cops
76+
ThreadSafety:
77+
Enabled: true
78+
79+
ThreadSafety/ClassAndModuleAttributes:
80+
Enabled: false

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ group :development do
2424
gem 'puma'
2525
gem 'rake'
2626
gem 'rubocop'
27+
gem 'rubocop-performance'
28+
gem 'rubocop-rails'
29+
gem 'rubocop-thread_safety'
2730
gem 'simplecov'
2831
gem 'sprockets-rails'
2932
end

app/controllers/kenui/email_notifications_controller.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def pagination
2727
events = ''
2828
unless email_notifications_configuration.first.is_a?(FalseClass)
2929
configuration = email_notifications_configuration.select { |event| event[:kbAccountId] == row.account_id }
30-
events = configuration.map { |event| event[:eventType] }.join(', ')
30+
events = configuration.pluck(:eventType).join(', ')
3131
end
3232

3333
data << [
@@ -37,20 +37,20 @@ def pagination
3737
view_context.link_to('Edit'.html_safe,
3838
'#configureEmailNotification',
3939
data: { name: row.name, account_id: row.account_id,
40-
events: events, bs_toggle: 'modal', target: '#configureEmailNotification' })
40+
events:, bs_toggle: 'modal', target: '#configureEmailNotification' })
4141
]
4242
end
4343

4444
respond_to do |format|
45-
format.json { render json: { data: data, recordsTotal: record_total, recordsFiltered: record_total } }
45+
format.json { render json: { data:, recordsTotal: record_total, recordsFiltered: record_total } }
4646
end
4747
end
4848

4949
def events_to_consider
5050
data = Kenui::EmailNotificationService.get_events_to_consider(options_for_klient)
5151

5252
respond_to do |format|
53-
format.json { render json: { data: data } }
53+
format.json { render json: { data: } }
5454
end
5555
end
5656

@@ -59,14 +59,14 @@ def configuration
5959
data = Kenui::EmailNotificationService.get_configuration_per_account(account_id, options_for_klient)
6060

6161
respond_to do |format|
62-
format.json { render json: { data: data } }
62+
format.json { render json: { data: } }
6363
end
6464
end
6565

6666
def set_configuration
6767
configuration = params.require(:configuration)
6868

69-
event_types = Array(configuration[:event_types]).reject(&:blank?)
69+
event_types = Array(configuration[:event_types]).compact_blank
7070

7171
is_success, message = Kenui::EmailNotificationService.set_configuration_per_account(configuration[:account_id],
7272
event_types,

config/routes.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
resources :email_notifications, only: [:index]
77

88
scope '/email_notifications' do
9-
match '/pagination' => 'email_notifications#pagination', :via => :get, :as => 'email_notification_pagination'
10-
match '/configuration' => 'email_notifications#configuration', :via => :get, :as => 'email_notifications_get_configuration'
11-
match '/configuration' => 'email_notifications#set_configuration', :via => :post, :as => 'email_notifications_configuration'
12-
match '/events_to_consider' => 'email_notifications#events_to_consider', :via => :get, :as => 'email_notification_events_to_consider'
9+
get '/pagination' => 'email_notifications#pagination', :as => 'email_notification_pagination'
10+
get '/configuration' => 'email_notifications#configuration', :as => 'email_notifications_get_configuration'
11+
post '/configuration' => 'email_notifications#set_configuration', :as => 'email_notifications_configuration'
12+
get '/events_to_consider' => 'email_notifications#events_to_consider', :as => 'email_notification_events_to_consider'
1313
end
1414
end

test/controllers/kenui/email_notifications_controller_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ class EmailNotificationsControllerTest < ActionDispatch::IntegrationTest
1313

1414
test 'should set configuration' do
1515
account_id = SecureRandom.uuid.to_s
16-
configuration = { account_id: account_id,
16+
configuration = { account_id:,
1717
event_types: %w[INVOICE_NOTIFICATION INVOICE_CREATION] }
1818

19-
post email_notifications_configuration_path, params: { configuration: configuration }
19+
post email_notifications_configuration_path, params: { configuration: }
2020
follow_redirect!
2121
assert_equal email_notifications_path, path
2222
assert_equal "Email notifications for account #{account_id} was successfully updated", flash[:notice]
2323

24-
get email_notifications_get_configuration_path, as: :json, params: { account_id: account_id }
24+
get email_notifications_get_configuration_path, as: :json, params: { account_id: }
2525
assert_response :success
26-
json = JSON.parse(response.body)
26+
json = response.parsed_body
2727
assert_equal(2, json['data'].size)
2828
assert_equal(account_id, json['data'][0]['kbAccountId'])
2929
end

0 commit comments

Comments
 (0)