Skip to content

Instantly share code, notes, and snippets.

@3dd13
Created January 7, 2011 07:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3dd13/769213 to your computer and use it in GitHub Desktop.
Save 3dd13/769213 to your computer and use it in GitHub Desktop.
sharing on functional test refactoring with code block. cleaner and more readable.
test "not allow to update state after account reconciliation" do
# get fixture
account = accounts(:fresh)
# submit and expect no errors
post :waive_fee, :id => account.id
assert_nil flash[:error]
post :add_fee, :id => account.id
assert_nil flash[:error]
post :increase_limit, :id => account.id
assert_nil flash[:error]
# reconcile and lock it
account.reconcile!
# submit and expect errors
post :waive_fee, :id => account.id
assert_equal "This account is reconciled. not allow to modify", flash[:error]
post :add_fee, :id => account.id
assert_equal "This account is reconciled. not allow to modify", flash[:error]
post :increase_limit, :id => account.id
assert_equal "This account is reconciled. not allow to modify", flash[:error]
end
test "not allow to update state after account reconciliation" do
account = accounts(:fresh)
[:waive_fee, :add_fee, :increase_limit].each do |update_method|
post update_method, :id => account.id
assert_nil flash[:error]
end
account.reconcile!
# submit and expect errors
[:waive_fee, :add_fee, :increase_limit].each do |update_method|
post update_method, :id => account.id
assert_equal "This account is reconciled. not allow to modify", flash[:error]
end
end
test "not allow to update after account reconciliation" do
account = accounts(:fresh)
submit_update_methods(account) do
assert_nil flash[:error]
end
reversal.reconcile!
submit_update_methods(account) do
assert_equal "This account is reconciled. not allow to modify", flash[:error]
end
end
def submit_update_methods(reversal)
[:waive_fee, :add_fee, :increase_limit].each do |update_method|
post update_method, :id => account.id
yield
end
end
test "not allow to update after account reconciliation" do
account = accounts(:fresh)
submit_update_methods(account) { assert_nil flash[:error] }
account.reconcile!
submit_update_methods(account) { assert_equal "This account is reconciled. not allow to modify", flash[:error] }
end
private
def submit_update_methods(account)
[:waive_fee, :add_fee, :increase_limit].each do |update_method|
post update_method, :id => account.id
yield
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment