Module: CommonLib::ActiveSupportExtension::TestCase::ClassMethods
- Defined in:
- lib/common_lib/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
-
#model_name_without_test ⇒ Object
I left no description.
Instance Method Details
#assert_requires_complete_date(*attr_names) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/common_lib/active_support_extension/test_case.rb', line 128 def assert_requires_complete_date(*attr_names) = attr_names. model = [:model] || model_name_without_test attr_names.each do |attr_name| test "#{brand}should require a complete date for #{attr_name}" do object = model.constantize.new object.send("#{attr_name}=", "Sept 11, 2001") object.valid? # could be, but probably isn't assert !object.errors.matching?(attr_name,'is not a complete date'), "Expected #{attr_name}:is NOT not a complete date, but only got " << object.errors..to_sentence object = model.constantize.new object.send("#{attr_name}=", "Sept 2001") assert !object.valid? assert object.errors.matching?(attr_name,'is not a complete date'), "Expected #{attr_name}:is not a complete date, but only got " << object.errors..to_sentence object = model.constantize.new object.send("#{attr_name}=", "9/2001") assert !object.valid? assert object.errors.matching?(attr_name,'is not a complete date') "Expected #{attr_name}:is not a complete date, but only got " << object.errors..to_sentence end end end |
#assert_requires_past_date(*attr_names) ⇒ Object
What? No assert_requires_absence method??? Its usually conditional so would be pretty pointless
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/common_lib/active_support_extension/test_case.rb', line 45 def assert_requires_past_date(*attr_names) = { :allow_today => true } .update(attr_names.) model = [:model] || model_name_without_test attr_names.each do |attr_name| if [:allow_today] test "#{brand}should allow #{attr_name} to be today" do object = model.constantize.new object.send("#{attr_name}=", Date.current) object.valid? # could be, but probably isn't assert !object.errors.matching?(attr_name, 'is in the future and must be in the past'), "Expected #{attr_name}:is NOT not a past date, but only got " << object.errors..to_sentence end else test "#{brand}should NOT allow #{attr_name} to be today" do object = model.constantize.new object.send("#{attr_name}=", Date.current) assert !object.valid? assert object.errors.matching?(attr_name, 'is in the future and must be in the past'), "Expected #{attr_name}:is not a past date, but only got " << object.errors..to_sentence end end test "#{brand}should require Date #{attr_name} be in the past" do object = model.constantize.new object.send("#{attr_name}=", Date.yesterday) object.valid? # could be, but probably isn't assert !object.errors.matching?(attr_name, 'is in the future and must be in the past'), "Expected #{attr_name}:is NOT not a past date, but only got " << object.errors..to_sentence object = model.constantize.new object.send("#{attr_name}=", Date.tomorrow) assert !object.valid? assert object.errors.matching?(attr_name, 'is in the future and must be in the past'), "Expected #{attr_name}:is not a past date, but only got " << object.errors..to_sentence end # doesn't seem to actually compare as a DateTime test "#{brand}should require DateTime #{attr_name} be in the past" do object = model.constantize.new object.send("#{attr_name}=", (DateTime.current - 1.day)) object.valid? # could be, but probably isn't assert !object.errors.matching?(attr_name, 'is in the future and must be in the past'), "Expected #{attr_name}:is NOT not a past date, but only got " << object.errors..to_sentence object = model.constantize.new object.send("#{attr_name}=", (DateTime.current + 1.day)) assert !object.valid? assert object.errors.matching?(attr_name, 'is in the future and must be in the past'), "Expected #{attr_name}:is not a past date, but only got " << object.errors..to_sentence end test "#{brand}should require ActiveSupport::TimeWithZone #{attr_name} be in the past" do object = model.constantize.new object.send("#{attr_name}=", (Time.zone.now - 1.day)) object.valid? # could be, but probably isn't assert !object.errors.matching?(attr_name, 'is in the future and must be in the past'), "Expected #{attr_name}:is NOT not a past date, but only got " << object.errors..to_sentence object = model.constantize.new object.send("#{attr_name}=", (Time.zone.now + 1.day)) assert !object.valid? assert object.errors.matching?(attr_name, 'is in the future and must be in the past'), "Expected #{attr_name}:is not a past date, but only got " << object.errors..to_sentence end end end |
#assert_should_act_as_list(*args) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/common_lib/active_support_extension/test_case.rb', line 19 def assert_should_act_as_list(*args) = args. scope = [:scope] test "#{brand}should act as list" do object = create_object first_position = object.position assert first_position > 0 attrs = {} Array(scope).each do |attr| attrs[attr.to_sym] = object.send(attr) end if scope object = create_object(attrs) assert_equal ( first_position + 1 ), object.position object = create_object(attrs) assert_equal ( first_position + 2 ), object.position end end |
#model_name_without_test ⇒ Object
I left no description
15 16 17 |
# File 'lib/common_lib/active_support_extension/test_case.rb', line 15 def model_name_without_test self.name.demodulize.sub(/Test$/,'') end |