Non-mutating operations should not be logged.
This commit is contained in:
parent
621b79db55
commit
da3c060c89
2 changed files with 51 additions and 6 deletions
|
@ -14,6 +14,7 @@ class WikiServiceTest < Test::Unit::TestCase
|
|||
FileUtils.rm(Dir[RAILS_ROOT + 'storage/test/*.zip'])
|
||||
FileUtils.rm(Dir[RAILS_ROOT + 'storage/test/*.pdf'])
|
||||
@@cleaned_storage = true
|
||||
WikiService.instance.setup('pswd', 'Wiki', 'wiki')
|
||||
end
|
||||
|
||||
def setup
|
||||
|
@ -30,4 +31,33 @@ class WikiServiceTest < Test::Unit::TestCase
|
|||
Time.now, 'DavidHeinemeierHansson'
|
||||
assert_equal "Electric shocks, I love 'em", @s.read_page('instiki', 'FirstPage').content
|
||||
end
|
||||
|
||||
def test_read_only_operations
|
||||
@s.write_page 'instiki', 'TestReadOnlyOperations', 'Read only operations dont change the' +
|
||||
'state of any object, and therefore should not be logged by Madeleine!',
|
||||
Time.now, 'AlexeyVerkhovsky'
|
||||
|
||||
assert_doesnt_change_state :authenticate, 'pswd'
|
||||
assert_doesnt_change_state :read_page, 'instiki', 'TestReadOnlyOperations'
|
||||
assert_doesnt_change_state :setup?
|
||||
assert_doesnt_change_state :webs
|
||||
|
||||
@s.write_page 'instiki', 'FirstPage', "Electric shocks, I love 'em",
|
||||
Time.now, 'DavidHeinemeierHansson'
|
||||
assert_equal "Electric shocks, I love 'em", @s.read_page('instiki', 'FirstPage').content
|
||||
end
|
||||
|
||||
|
||||
def assert_doesnt_change_state(method, *args)
|
||||
WikiService.snapshot
|
||||
last_snapshot_before = File.read(Dir[RAILS_ROOT + 'storage/test/*.snapshot'].last)
|
||||
|
||||
@s.send(method, *args)
|
||||
|
||||
command_logs = Dir[RAILS_ROOT + 'storage/test/*.command_log']
|
||||
assert command_logs.empty?, "Calls to #{method} should not be logged"
|
||||
last_snapshot_after = File.read(Dir[RAILS_ROOT + 'storage/test/*.snapshot'].last)
|
||||
assert last_snapshot_before == last_snapshot_after,
|
||||
'Calls to #{method} should not change the state of any persisted object'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue