Created
January 7, 2011 07:04
-
-
Save 3dd13/769213 to your computer and use it in GitHub Desktop.
sharing on functional test refactoring with code block. cleaner and more readable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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