Skip to content

Commit a726a24

Browse files
tungleduyxyzoc-kyle
authored andcommitted
Added new rubocop extensions
1 parent c833d05 commit a726a24

6 files changed

Lines changed: 45 additions & 69 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -112,61 +112,7 @@ jobs:
112112
if: ${{ matrix.docker-compose-file == 'docker-compose.ci.postgresql.yml' }}
113113
run: |
114114
curl https://raw.githubusercontent.com/killbill/killbill-email-notifications-plugin/master/src/main/resources/ddl.sql | psql -h 127.0.0.1 -U postgres -p 5432 -d killbill
115-
- name: Install plugin
116-
run: |
117-
curl --connect-timeout 10 --max-time 30 -v \
118-
-X POST \
119-
-u admin:password \
120-
-H 'Content-Type: application/json' \
121-
-H 'X-Killbill-CreatedBy: GitHub' \
122-
-d '{
123-
"nodeCommandProperties": [
124-
{
125-
"key": "pluginKey",
126-
"value": "email-notifications"
127-
}
128-
],
129-
"nodeCommandType": "INSTALL_PLUGIN",
130-
"isSystemCommandType": "true"
131-
}' \
132-
"http://${KB_ADDRESS}:${KB_PORT}/1.0/kb/nodesInfo"
133-
134-
sudo snap install yq
135-
136-
count=0
137-
until [[ "$(curl -s -uadmin:password http://${KB_ADDRESS}:${KB_PORT}/1.0/kb/nodesInfo | jq -r '.[].pluginsInfo[] | select(.pluginKey == "email-notifications").state')" == "STOPPED" ]]; do
138-
if [[ "$count" == "180" ]]; then
139-
exit 64
140-
fi
141-
count=$(( count + 1 ))
142-
sleep 1
143-
done
144-
145-
curl --connect-timeout 10 --max-time 30 -v \
146-
-X POST \
147-
-u admin:password \
148-
-H 'Content-Type: application/json' \
149-
-H 'X-Killbill-CreatedBy: GitHub' \
150-
-d '{
151-
"nodeCommandProperties": [
152-
{
153-
"key": "pluginKey",
154-
"value": "email-notifications"
155-
}
156-
],
157-
"nodeCommandType": "START_PLUGIN",
158-
"isSystemCommandType": "true"
159-
}' \
160-
"http://${KB_ADDRESS}:${KB_PORT}/1.0/kb/nodesInfo"
161-
162-
count=0
163-
until [[ "$(curl -s -uadmin:password http://${KB_ADDRESS}:${KB_PORT}/1.0/kb/nodesInfo | jq -r '.[].pluginsInfo[] | select(.pluginKey == "email-notifications").state')" == "RUNNING" ]]; do
164-
if [[ "$count" == "180" ]]; then
165-
exit 65
166-
fi
167-
count=$(( count + 1 ))
168-
sleep 1
169-
done
115+
170116
- name: Run tests
171117
env:
172118
DB_ADAPTER: ${{ matrix.database-adapter }}

.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.1
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)