Module: RailsExtension::ActiveSupportExtension::TestCase::ClassMethods
- Defined in:
- lib/rails_extension/active_support_extension/test_case.rb
Instance Method Summary collapse
- #assert_requires_complete_date(*attr_names) ⇒ Object
-
#assert_requires_past_date(*attr_names) ⇒ Object
What? No assert_requires_absence method??? Its usually conditional so would be pretty pointless.
- #assert_should_act_as_list(*args) ⇒ Object
-
#st_model_name ⇒ Object
I don’t like this quick and dirty name.
- #test_with_verbosity(name, &block) ⇒ Object
Instance Method Details
#assert_requires_complete_date(*attr_names) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/rails_extension/active_support_extension/test_case.rb', line 107 def assert_requires_complete_date(*attr_names) attr_names.each do |attr_name| test "should require a complete date for #{attr_name}" do # # # What? No successful test? # # assert_difference( "#{model_name}.count", 0 ) do object = create_object( attr_name => "Sept 2010") assert object.errors.on_attr_and_type(attr_name,:not_complete_date) end assert_difference( "#{model_name}.count", 0 ) do object = create_object( attr_name => "9/2010") assert object.errors.on_attr_and_type(attr_name,:not_complete_date) end end end end |
#assert_requires_past_date(*attr_names) ⇒ Object
What? No assert_requires_absence method??? Its usually conditional so would be pretty pointless
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rails_extension/active_support_extension/test_case.rb', line 93 def assert_requires_past_date(*attr_names) attr_names.each do |attr_name| test "should require #{attr_name} be in the past" do # can't assert difference of 1 as may be other errors object = create_object( attr_name => Chronic.parse('yesterday')) assert !object.errors.on_attr_and_type(attr_name,:not_past_date) assert_difference( "#{model_name}.count", 0 ) do object = create_object( attr_name => Chronic.parse('tomorrow')) assert object.errors.on_attr_and_type(attr_name,:not_past_date) end end end end |
#assert_should_act_as_list(*args) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rails_extension/active_support_extension/test_case.rb', line 61 def assert_should_act_as_list(*args) = args. scope = [:scope] test "#{brand}should act as list" do model = create_object.class.name model.constantize.destroy_all object = create_object assert_equal 1, object.position attrs = {} Array(scope).each do |attr| attrs[attr.to_sym] = object.send(attr) end if scope object = create_object(attrs) assert_equal 2, object.position # gotta be a relative test as there may already # by existing objects (unless I destroy them) assert_difference("#{model}.last.position",1) do create_object(attrs) end end end |
#st_model_name ⇒ Object
I don’t like this quick and dirty name
37 38 39 |
# File 'lib/rails_extension/active_support_extension/test_case.rb', line 37 def st_model_name self.name.demodulize.sub(/Test$/,'') end |
#test_with_verbosity(name, &block) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rails_extension/active_support_extension/test_case.rb', line 41 def test_with_verbosity(name,&block) test_without_verbosity(name,&block) test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym define_method("_#{test_name}_with_verbosity") do print "\n#{self.class.name.gsub(/Test$/,'').titleize} #{name}: " send("_#{test_name}_without_verbosity") end # # can't do this. # alias_method_chain test_name, :verbosity # end up with 2 methods that begin # with 'test_' so they both get run # alias_method "_#{test_name}_without_verbosity".to_sym, test_name alias_method test_name, "_#{test_name}_with_verbosity".to_sym end |