Added test at the service level, to see how well madeleine copes with errors. Looks like it does cope with them.
This commit is contained in:
parent
cb1d8ed54f
commit
5c8b738238
|
@ -15,6 +15,7 @@ class Page
|
||||||
end
|
end
|
||||||
|
|
||||||
def revise(content, created_at, author)
|
def revise(content, created_at, author)
|
||||||
|
|
||||||
if not @revisions.empty? and content == @revisions.last.content
|
if not @revisions.empty? and content == @revisions.last.content
|
||||||
raise Instiki::ValidationError.new(
|
raise Instiki::ValidationError.new(
|
||||||
"You have tried to save page '#{name}' without changing its content")
|
"You have tried to save page '#{name}' without changing its content")
|
||||||
|
|
|
@ -37,27 +37,66 @@ class WikiServiceTest < Test::Unit::TestCase
|
||||||
'state of any object, and therefore should not be logged by Madeleine!',
|
'state of any object, and therefore should not be logged by Madeleine!',
|
||||||
Time.now, 'AlexeyVerkhovsky'
|
Time.now, 'AlexeyVerkhovsky'
|
||||||
|
|
||||||
assert_doesnt_change_state :authenticate, 'pswd'
|
assert_doesnt_change_state_or_log :authenticate, 'pswd'
|
||||||
assert_doesnt_change_state :read_page, 'instiki', 'TestReadOnlyOperations'
|
assert_doesnt_change_state_or_log :read_page, 'instiki', 'TestReadOnlyOperations'
|
||||||
assert_doesnt_change_state :setup?
|
assert_doesnt_change_state_or_log :setup?
|
||||||
assert_doesnt_change_state :webs
|
assert_doesnt_change_state_or_log :webs
|
||||||
|
|
||||||
@s.write_page 'instiki', 'FirstPage', "Electric shocks, I love 'em",
|
@s.write_page 'instiki', 'FirstPage', "Electric shocks, I love 'em",
|
||||||
Time.now, 'DavidHeinemeierHansson'
|
Time.now, 'DavidHeinemeierHansson'
|
||||||
assert_equal "Electric shocks, I love 'em", @s.read_page('instiki', 'FirstPage').content
|
assert_equal "Electric shocks, I love 'em", @s.read_page('instiki', 'FirstPage').content
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_aborted_transaction
|
||||||
|
@s.write_page 'instiki', 'FirstPage', "Electric shocks, I love 'em",
|
||||||
|
10.minutes.ago, 'DavidHeinemeierHansson'
|
||||||
|
|
||||||
def assert_doesnt_change_state(method, *args)
|
assert_doesnt_change_state('revise_page with unchanged content') {
|
||||||
|
begin
|
||||||
|
@s.revise_page 'instiki', 'FirstPage', "Electric shocks, I love 'em",
|
||||||
|
Time.now, 'DavidHeinemeierHansson'
|
||||||
|
fail 'Expected Instiki::ValidationError not raised'
|
||||||
|
rescue Instiki::ValidationError
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# Checks that a method call or a block doesn;t change the persisted state of the wiki
|
||||||
|
# Usage:
|
||||||
|
# assert_doesnt_change_state :read_page, 'instiki', 'TestReadOnlyOperations'
|
||||||
|
# or
|
||||||
|
# assert_doesnt_change_state {|wiki| wiki.webs}
|
||||||
|
|
||||||
|
def assert_doesnt_change_state(method, *args, &block)
|
||||||
|
_assert_doesnt_change_state(including_command_log = false, method, *args, &block)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Same as assert_doesnt_change_state, but also asserts that no vommand log is generated
|
||||||
|
def assert_doesnt_change_state_or_log(method, *args, &block)
|
||||||
|
_assert_doesnt_change_state(including_command_log = true, method, *args, &block)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def _assert_doesnt_change_state(including_log, method, *args)
|
||||||
WikiService.snapshot
|
WikiService.snapshot
|
||||||
last_snapshot_before = File.read(Dir[RAILS_ROOT + 'storage/test/*.snapshot'].last)
|
last_snapshot_before = File.read(Dir[RAILS_ROOT + 'storage/test/*.snapshot'].last)
|
||||||
|
|
||||||
@s.send(method, *args)
|
if block_given?
|
||||||
|
yield @s
|
||||||
|
else
|
||||||
|
@s.send(method, *args)
|
||||||
|
end
|
||||||
|
|
||||||
|
if including_log
|
||||||
|
command_logs = Dir[RAILS_ROOT + 'storage/test/*.command_log']
|
||||||
|
assert command_logs.empty?, "Calls to #{method} should not be logged"
|
||||||
|
end
|
||||||
|
|
||||||
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)
|
last_snapshot_after = File.read(Dir[RAILS_ROOT + 'storage/test/*.snapshot'].last)
|
||||||
assert last_snapshot_before == last_snapshot_after,
|
assert last_snapshot_before == last_snapshot_after,
|
||||||
'Calls to #{method} should not change the state of any persisted object'
|
'Calls to #{method} should not change the state of any persisted object'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue