This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

refactoring example for dan

git-svn-id: https://svn.thoughtbot.com/plugins/when/trunk@313 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
  • Loading branch information...
1 parent d4621e4 commit ee264f7e414c0726bcda4fb5276d0515559c1adb tsaleh committed Feb 12, 2008
Showing with 9 additions and 11 deletions.
  1. +9 −11 test/callbacks_test.rb
View
@@ -15,21 +15,19 @@ def setup
destroy_callbacks = ['before_destroy', 'after_destroy']
unique_callbacks = ['after_find', 'after_initialize']
- conditions = ['lambda {|company| company.callback_flag == true}']
+ conditions = [ lambda {|company| company.callback_flag == true}, :flag? ]
src = ''
conditions.each do |condition|
basic_callbacks.each do |callback|
+ define_method "test_#{callback}_with_if_condition_which_returns_true_should_change_company_name" do
+ Company.send(callback.to_sym, :change_name, { :if => condition })
+ company = Company.new :name => 'thoughtbot', :callback_flag => true
+ assert company.save
+ assert_equal 'new name', company.name
+ end
+
src << <<-END;
- def test_#{callback}_with_if_condition_which_returns_true_should_change_company_name
- Company.class_eval do
- #{callback} :change_name, :if => #{condition}
- end
- company = Company.new :name => 'thoughtbot', :callback_flag => true
- assert company.save
- assert_equal 'new name', company.name
- end
-
def test_#{callback}_with_if_condition_which_returns_false_should_not_change_company_name
Company.class_eval do
#{callback} :change_name, :if => #{condition}
@@ -194,4 +192,4 @@ def teardown
end
end
-end
+end

0 comments on commit ee264f7

Please sign in to comment.