Class: PermalinkFuTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- PermalinkFuTest
- Defined in:
- lib/permalink_fu/test/permalink_fu_test.rb
Constant Summary collapse
- @@samples =
{ 'This IS a Tripped out title!!.!1 (well/ not really)' => 'this-is-a-tripped-out-title1-well-not-really', '////// meph1sto r0x ! \\\\\\' => 'meph1sto-r0x', 'āčēģīķļņū' => 'acegiklnu', '中文測試 chinese text' => 'zhong-wen-ce-shi-chinese-text', 'fööbär' => 'foobar' }
- @@extra =
{ 'some-)()()-ExtRa!/// .data==?> to \/\/test' => 'some-extra-data-to-test' }
Instance Method Summary collapse
- #test_basemodel ⇒ Object
- #test_multiple_attribute_permalink ⇒ Object
- #test_set_new_permalink_attributes_on_sub_class ⇒ Object
- #test_should_abide_by_if_method_condition ⇒ Object
- #test_should_abide_by_if_proc_condition ⇒ Object
- #test_should_abide_by_if_string_condition ⇒ Object
- #test_should_abide_by_unless_method_condition ⇒ Object
- #test_should_abide_by_unless_proc_condition ⇒ Object
- #test_should_abide_by_unless_string_condition ⇒ Object
- #test_should_allow_override_of_permalink_method ⇒ Object
- #test_should_assign_a_random_permalink_if_the_title_has_no_permalinkable_characters ⇒ Object
- #test_should_assign_a_random_permalink_if_the_title_is_nil ⇒ Object
- #test_should_check_itself_for_unique_permalink_if_permalink_field_changed ⇒ Object
- #test_should_common_permalink_if_unique_is_false ⇒ Object
- #test_should_create_permalink_from_attribute_not_attribute_accessor ⇒ Object
- #test_should_create_unique_permalink ⇒ Object
- #test_should_create_unique_permalink_when_assigned_directly ⇒ Object
- #test_should_create_unique_scoped_permalink ⇒ Object
- #test_should_escape_activerecord_model ⇒ Object
- #test_should_escape_activerecord_model_with_existing_permalink ⇒ Object
- #test_should_escape_permalinks ⇒ Object
- #test_should_limit_permalink ⇒ Object
- #test_should_limit_unique_permalink ⇒ Object
- #test_should_not_check_itself_for_unique_permalink_if_permalink_field_not_changed ⇒ Object
- #test_should_not_check_itself_for_unique_permalink_if_unchanged ⇒ Object
- #test_should_not_inherit_permalink_attributes ⇒ Object
- #test_should_not_update_permalink_if_already_set_even_if_title_changed ⇒ Object
- #test_should_not_update_permalink_unless_field_changed ⇒ Object
- #test_should_not_update_permalink_without_update_set_even_if_field_changed ⇒ Object
- #test_should_update_permalink_every_time_the_title_is_changed ⇒ Object
- #test_should_update_permalink_if_changed_method_does_not_exist ⇒ Object
- #test_should_update_permalink_if_the_existing_permalink_is_blank ⇒ Object
- #test_should_update_permalink_if_the_existing_permalink_is_nil ⇒ Object
- #test_should_update_permalink_the_first_time_the_title_is_set ⇒ Object
- #test_should_work_correctly_for_scoped_fields_with_nil_value ⇒ Object
Instance Method Details
#test_basemodel ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 21 def test_basemodel @m = BaseModel.new assert @m.valid? assert_equal @m.id, nil assert_equal @m.title, nil assert_equal @m.permalink, nil assert_equal @m.extra, nil assert_equal @m.foo, nil end |
#test_multiple_attribute_permalink ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 76 def test_multiple_attribute_permalink @m = MockModelExtra.new @@samples.each do |from, to| @@extra.each do |from_extra, to_extra| @m.title = from; @m.extra = from_extra; @m.permalink = nil assert @m.valid? assert_equal "#{to}-#{to_extra}", @m.permalink end end end |
#test_set_new_permalink_attributes_on_sub_class ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 31 def test_set_new_permalink_attributes_on_sub_class @m = ClassModel.new @m.title = 'foo' @m.extra = 'bar' assert @m.valid? assert_equal @m.permalink, 'foo' @m = SubClassHasPermalinkModel.new @m.title = 'foo' @m.extra = 'bar' assert @m.valid? assert_equal @m.permalink, 'foo-bar' end |
#test_should_abide_by_if_method_condition ⇒ Object
185 186 187 188 189 190 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 185 def test_should_abide_by_if_method_condition @m = IfMethodConditionModel.new @m.title = 'dont make me a permalink' assert @m.valid? assert_nil @m.permalink end |
#test_should_abide_by_if_proc_condition ⇒ Object
178 179 180 181 182 183 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 178 def test_should_abide_by_if_proc_condition @m = IfProcConditionModel.new @m.title = 'dont make me a permalink' assert @m.valid? assert_nil @m.permalink end |
#test_should_abide_by_if_string_condition ⇒ Object
192 193 194 195 196 197 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 192 def test_should_abide_by_if_string_condition @m = IfStringConditionModel.new @m.title = 'dont make me a permalink' assert @m.valid? assert_nil @m.permalink end |
#test_should_abide_by_unless_method_condition ⇒ Object
206 207 208 209 210 211 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 206 def test_should_abide_by_unless_method_condition @m = UnlessMethodConditionModel.new @m.title = 'make me a permalink' assert @m.valid? assert_not_nil @m.permalink end |
#test_should_abide_by_unless_proc_condition ⇒ Object
199 200 201 202 203 204 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 199 def test_should_abide_by_unless_proc_condition @m = UnlessProcConditionModel.new @m.title = 'make me a permalink' assert @m.valid? assert_not_nil @m.permalink end |
#test_should_abide_by_unless_string_condition ⇒ Object
213 214 215 216 217 218 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 213 def test_should_abide_by_unless_string_condition @m = UnlessStringConditionModel.new @m.title = 'make me a permalink' assert @m.valid? assert_not_nil @m.permalink end |
#test_should_allow_override_of_permalink_method ⇒ Object
220 221 222 223 224 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 220 def test_should_allow_override_of_permalink_method @m = OverrideModel.new @m[:permalink] = 'the permalink' assert_not_equal @m.permalink, @m[:permalink] end |
#test_should_assign_a_random_permalink_if_the_title_has_no_permalinkable_characters ⇒ Object
280 281 282 283 284 285 286 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 280 def test_should_assign_a_random_permalink_if_the_title_has_no_permalinkable_characters @m = NoChangeModel.new @m.title = '////' assert @m.valid? assert_not_nil @m[:permalink] assert @m[:permalink].size > 0 end |
#test_should_assign_a_random_permalink_if_the_title_is_nil ⇒ Object
272 273 274 275 276 277 278 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 272 def test_should_assign_a_random_permalink_if_the_title_is_nil @m = NoChangeModel.new @m.title = nil assert @m.valid? assert_not_nil @m[:permalink] assert @m[:permalink].size > 0 end |
#test_should_check_itself_for_unique_permalink_if_permalink_field_changed ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 129 def test_should_check_itself_for_unique_permalink_if_permalink_field_changed @m = PermalinkChangeableMockModel.new @m.permalink_will_change! @m.permalink = 'foo' assert @m.valid? assert_equal 'foo-2', @m.permalink end |
#test_should_common_permalink_if_unique_is_false ⇒ Object
111 112 113 114 115 116 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 111 def test_should_common_permalink_if_unique_is_false @m = CommonMockModel.new @m.permalink = 'foo' assert @m.valid? assert_equal 'foo', @m.permalink end |
#test_should_create_permalink_from_attribute_not_attribute_accessor ⇒ Object
226 227 228 229 230 231 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 226 def test_should_create_permalink_from_attribute_not_attribute_accessor @m = OverrideModel.new @m.title = 'the permalink' assert @m.valid? assert_equal 'the-permalink', @m[:permalink] end |
#test_should_create_unique_permalink ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 87 def test_should_create_unique_permalink @m = MockModel.new @m.title = 'foo' assert @m.valid? assert_equal 'foo-2', @m.permalink @m.title = 'bar' @m.permalink = nil assert @m.valid? assert_equal 'bar-3', @m.permalink end |
#test_should_create_unique_permalink_when_assigned_directly ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 99 def test_should_create_unique_permalink_when_assigned_directly @m = MockModel.new @m.permalink = 'foo' assert @m.valid? assert_equal 'foo-2', @m.permalink # should always check itself for uniqueness when not respond_to?(:permalink_changed?) @m.permalink = 'bar' assert @m.valid? assert_equal 'bar-3', @m.permalink end |
#test_should_create_unique_scoped_permalink ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 144 def test_should_create_unique_scoped_permalink @m = ScopedModel.new @m.permalink = 'foo' assert @m.valid? assert_equal 'foo-2', @m.permalink @m.foo = 5 @m.permalink = 'foo' assert @m.valid? assert_equal 'foo', @m.permalink end |
#test_should_escape_activerecord_model ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 58 def test_should_escape_activerecord_model @m = MockModel.new @@samples.each do |from, to| @m.title = from; @m.permalink = nil assert @m.valid? assert_equal to, @m.permalink end end |
#test_should_escape_activerecord_model_with_existing_permalink ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 67 def test_should_escape_activerecord_model_with_existing_permalink @m = MockModel.new @@samples.each do |from, to| @m.title = 'whatever'; @m.permalink = from assert @m.valid? assert_equal to, @m.permalink end end |
#test_should_escape_permalinks ⇒ Object
52 53 54 55 56 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 52 def test_should_escape_permalinks @@samples.each do |from, to| assert_equal to, PermalinkFu.escape(from) end end |
#test_should_limit_permalink ⇒ Object
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 156 def test_should_limit_permalink @old = MockModel.columns_hash['permalink'].instance_variable_get(:@limit) MockModel.columns_hash['permalink'].instance_variable_set(:@limit, 2) @m = MockModel.new @m.title = 'BOO' assert @m.valid? assert_equal 'bo', @m.permalink ensure MockModel.columns_hash['permalink'].instance_variable_set(:@limit, @old) end |
#test_should_limit_unique_permalink ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 167 def test_should_limit_unique_permalink @old = MockModel.columns_hash['permalink'].instance_variable_get(:@limit) MockModel.columns_hash['permalink'].instance_variable_set(:@limit, 3) @m = MockModel.new @m.title = 'foo' assert @m.valid? assert_equal 'f-2', @m.permalink ensure MockModel.columns_hash['permalink'].instance_variable_set(:@limit, @old) end |
#test_should_not_check_itself_for_unique_permalink_if_permalink_field_not_changed ⇒ Object
137 138 139 140 141 142 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 137 def test_should_not_check_itself_for_unique_permalink_if_permalink_field_not_changed @m = PermalinkChangeableMockModel.new @m.permalink = 'foo' assert @m.valid? assert_equal 'foo', @m.permalink end |
#test_should_not_check_itself_for_unique_permalink_if_unchanged ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 118 def test_should_not_check_itself_for_unique_permalink_if_unchanged @m = MockModel.new @m.id = 2 @m.permalink = 'bar-2' @m.instance_eval do @changed_attributes = {} end assert @m.valid? assert_equal 'bar-2', @m.permalink end |
#test_should_not_inherit_permalink_attributes ⇒ Object
45 46 47 48 49 50 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 45 def test_should_not_inherit_permalink_attributes @m = SubClassNoPermalinkModel.new @m.title = 'foo' assert @m.valid? assert_equal @m.permalink, nil end |
#test_should_not_update_permalink_if_already_set_even_if_title_changed ⇒ Object
298 299 300 301 302 303 304 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 298 def test_should_not_update_permalink_if_already_set_even_if_title_changed @m = ChangedWithoutUpdateModel.new @m.permalink = "old permalink" @m.title = "new title" assert @m.valid? assert_equal "old-permalink", @m[:permalink] end |
#test_should_not_update_permalink_unless_field_changed ⇒ Object
233 234 235 236 237 238 239 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 233 def test_should_not_update_permalink_unless_field_changed @m = NoChangeModel.new @m.title = 'the permalink' @m.permalink = 'unchanged' assert @m.valid? assert_equal 'unchanged', @m[:permalink] end |
#test_should_not_update_permalink_without_update_set_even_if_field_changed ⇒ Object
241 242 243 244 245 246 247 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 241 def test_should_not_update_permalink_without_update_set_even_if_field_changed @m = ChangedWithoutUpdateModel.new @m.title = 'the permalink' @m.permalink = 'unchanged' assert @m.valid? assert_equal 'unchanged', @m[:permalink] end |
#test_should_update_permalink_every_time_the_title_is_changed ⇒ Object
306 307 308 309 310 311 312 313 314 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 306 def test_should_update_permalink_every_time_the_title_is_changed @m = ChangedWithUpdateModel.new @m.title = "old title" assert @m.valid? assert_equal "old-title", @m[:permalink] @m.title = "new title" assert @m.valid? assert_equal "new-title", @m[:permalink] end |
#test_should_update_permalink_if_changed_method_does_not_exist ⇒ Object
249 250 251 252 253 254 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 249 def test_should_update_permalink_if_changed_method_does_not_exist @m = OverrideModel.new @m.title = 'the permalink' assert @m.valid? assert_equal 'the-permalink', @m[:permalink] end |
#test_should_update_permalink_if_the_existing_permalink_is_blank ⇒ Object
264 265 266 267 268 269 270 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 264 def test_should_update_permalink_if_the_existing_permalink_is_blank @m = NoChangeModel.new @m.title = 'the permalink' @m.permalink = '' assert @m.valid? assert_equal 'the-permalink', @m[:permalink] end |
#test_should_update_permalink_if_the_existing_permalink_is_nil ⇒ Object
256 257 258 259 260 261 262 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 256 def test_should_update_permalink_if_the_existing_permalink_is_nil @m = NoChangeModel.new @m.title = 'the permalink' @m.permalink = nil assert @m.valid? assert_equal 'the-permalink', @m[:permalink] end |
#test_should_update_permalink_the_first_time_the_title_is_set ⇒ Object
288 289 290 291 292 293 294 295 296 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 288 def test_should_update_permalink_the_first_time_the_title_is_set @m = ChangedWithoutUpdateModel.new @m.title = "old title" assert @m.valid? assert_equal "old-title", @m[:permalink] @m.title = "new title" assert @m.valid? assert_equal "old-title", @m[:permalink] end |
#test_should_work_correctly_for_scoped_fields_with_nil_value ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/permalink_fu/test/permalink_fu_test.rb', line 316 def test_should_work_correctly_for_scoped_fields_with_nil_value s1 = ScopedModelForNilScope.new s1.title = 'ack' s1.foo = 3 assert s1.valid? assert_equal 'ack', s1.permalink s2 = ScopedModelForNilScope.new s2.title = 'ack' s2.foo = nil assert s2.valid? assert_equal 'ack-2', s2.permalink end |