Skip to content

Commit 460166c

Browse files
committed
improved audit log tests (fixture usage, param coverage)
1 parent 439df8f commit 460166c

2 files changed

Lines changed: 36 additions & 5 deletions

File tree

test/controllers/admin_controller_test.rb

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,26 @@ class AdminControllerTest < ActionController::TestCase
174174

175175
test 'audit log should work with filter params' do
176176
sign_in users(:admin)
177-
get :audit_logs, params: { log_type: 'admin_audit', event_type: 'setting_update', from: '2025-04-13',
178-
to: '2025-04-13' }
179-
assert_response(:success)
180-
assert_not_nil assigns(:logs)
177+
178+
log_types = audit_logs.map(&:log_type)
179+
180+
log_types.each do |type|
181+
try_audit_logs(log_type: type)
182+
@logs = assigns(:logs)
183+
assert_response(:success)
184+
assert_not_nil @logs
185+
assert(@logs.all? { |l| l.log_type == type })
186+
end
187+
188+
event_types = audit_logs.map(&:event_type)
189+
190+
event_types.each do |type|
191+
try_audit_logs(event_type: type)
192+
@logs = assigns(:logs)
193+
assert_response(:success)
194+
assert_not_nil @logs
195+
assert(@logs.all? { |l| l.event_type == type })
196+
end
181197
end
182198

183199
test 'hellban should correctly block the user' do
@@ -203,6 +219,10 @@ class AdminControllerTest < ActionController::TestCase
203219

204220
private
205221

222+
def try_audit_logs(**params)
223+
get :audit_logs, params: params
224+
end
225+
206226
def try_hellban_user(user)
207227
post :hellban, params: { id: user.id }
208228
end

test/fixtures/audit_logs.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
22

3-
admin_log:
3+
site_setting_update_log:
44
community: sample
55
log_type: admin_audit
66
event_type: setting_update
77
related_type: SiteSetting
88
related: one
99
user: admin
1010
comment: some words
11+
12+
vote_rate_limit_log:
13+
community: sample
14+
log_type: rate_limit_log
15+
event_type: vote
16+
related_type: Post
17+
related: question_one
18+
user: standard_user
19+
comment: >
20+
limit: 10
21+
vote: 1

0 commit comments

Comments
 (0)