Class: VersionedTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- VersionedTest
- Defined in:
- vendor/plugins/acts_as_versioned/test/versioned_test.rb
Instance Method Summary
- - (Object) assert_page_title(p, i, version_field = :version)
- - (Object) test_association_options
- - (Object) test_find_version
- - (Object) test_find_versions
- - (Object) test_has_many_through
- - (Object) test_has_many_through_with_custom_association
- - (Object) test_lock_version_works_with_versioning
- - (Object) test_referential_integrity
- - (Object) test_rollback_fails_with_invalid_revision
- - (Object) test_rollback_with_version_class
- - (Object) test_rollback_with_version_class_with_options
- - (Object) test_rollback_with_version_number
- - (Object) test_rollback_with_version_number_with_options
- - (Object) test_rollback_with_version_number_with_sti
- - (Object) test_saves_versioned_copy
- - (Object) test_saves_versioned_copy_with_options
- - (Object) test_saves_versioned_copy_with_sti
- - (Object) test_saves_without_revision
- - (Object) test_should_find_earliest_version
- - (Object) test_should_find_latest_version
- - (Object) test_should_find_next_version
- - (Object) test_should_find_previous_version
- - (Object) test_should_find_version_count
- - (Object) test_special_methods
- - (Object) test_track_altered_attributes
- - (Object) test_track_altered_attributes_default_value
- - (Object) test_unaltered_attributes
- - (Object) test_unchanged_string_attributes
- - (Object) test_version_if_condition
- - (Object) test_version_if_condition2
- - (Object) test_version_if_condition_with_block
- - (Object) test_version_max_limit
- - (Object) test_version_no_limit
- - (Object) test_version_order
- - (Object) test_versioned_class
- - (Object) test_versioned_class_name
- - (Object) test_versioned_records_should_belong_to_parent
- - (Object) test_with_sequence
Instance Method Details
- (Object) assert_page_title(p, i, version_field = :version)
239 240 241 242 243 244 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 239 def assert_page_title(p, i, version_field = :version) p.title = "title#{i}" p.save assert_equal "title#{i}", p.title assert_equal (i+4), p.send(version_field) end |
- (Object) test_association_options
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 288 def association = Page.reflect_on_association(:versions) = association. assert_equal :delete_all, [:dependent] assert_equal 'version', [:order] association = Widget.reflect_on_association(:versions) = association. assert_equal :nullify, [:dependent] assert_equal 'version desc', [:order] assert_equal 'widget_id', [:foreign_key] = Widget.create! :name => 'new widget' assert_equal 1, Widget.count assert_equal 1, Widget.versioned_class.count .destroy assert_equal 0, Widget.count assert_equal 1, Widget.versioned_class.count end |
- (Object) test_find_version
254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 254 def test_find_version assert_equal page_versions(:welcome_1), Page.find_version(pages(:welcome).id, 23) assert_equal page_versions(:welcome_2), Page.find_version(pages(:welcome).id, 24) assert_equal pages(:welcome), Page.find_version(pages(:welcome).id) assert_equal page_versions(:welcome_1), pages(:welcome).find_version(23) assert_equal page_versions(:welcome_2), pages(:welcome).find_version(24) assert_equal pages(:welcome), pages(:welcome).find_version assert_raise(ActiveRecord::RecordNotFound) { Page.find_version(pages(:welcome).id, 1) } assert_raise(ActiveRecord::RecordNotFound) { Page.find_version(0, 23) } end |
- (Object) test_find_versions
246 247 248 249 250 251 252 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 246 def test_find_versions assert_equal 2, locked_pages(:welcome).versions.size assert_equal 1, locked_pages(:welcome).versions.find(:all, :conditions => ['title LIKE ?', '%weblog%']).length assert_equal 2, locked_pages(:welcome).versions.find(:all, :conditions => ['title LIKE ?', '%web%']).length assert_equal 0, locked_pages(:thinking).versions.find(:all, :conditions => ['title LIKE ?', '%web%']).length assert_equal 2, locked_pages(:welcome).versions.length end |
- (Object) test_has_many_through
274 275 276 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 274 def test_has_many_through assert_equal [(:caged), (:mly)], pages(:welcome). end |
- (Object) test_has_many_through_with_custom_association
278 279 280 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 278 def test_has_many_through_with_custom_association assert_equal [(:caged), (:mly)], pages(:welcome).revisors end |
- (Object) test_lock_version_works_with_versioning
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 116 def test_lock_version_works_with_versioning p = locked_pages(:thinking) p2 = LockedPage.find(p.id) p.title = 'fresh title' p.save assert_equal 2, p.versions.size # limit! assert_raises(ActiveRecord::StaleObjectError) do p2.title = 'stale title' p2.save end end |
- (Object) test_referential_integrity
282 283 284 285 286 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 282 def test_referential_integrity pages(:welcome).destroy assert_equal 0, Page.count assert_equal 0, Page::Version.count end |
- (Object) test_rollback_fails_with_invalid_revision
67 68 69 70 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 67 def test_rollback_fails_with_invalid_revision p = locked_pages(:welcome) assert !p.revert_to!(locked_pages(:thinking)) end |
- (Object) test_rollback_with_version_class
57 58 59 60 61 62 63 64 65 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 57 def test_rollback_with_version_class p = pages(:welcome) assert_equal 24, p.version assert_equal 'Welcome to the weblog', p.title assert p.revert_to!(p.versions.first), "Couldn't revert to 23" assert_equal 23, p.version assert_equal 'Welcome to the weblg', p.title end |
- (Object) test_rollback_with_version_class_with_options
89 90 91 92 93 94 95 96 97 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 89 def p = locked_pages(:welcome) assert_equal 'Welcome to the weblog', p.title assert_equal 'LockedPage', p.versions.first.version_type assert p.revert_to!(p.versions.first), "Couldn't revert to 1" assert_equal 'Welcome to the weblg', p.title assert_equal 'LockedPage', p.versions.first.version_type end |
- (Object) test_rollback_with_version_number
30 31 32 33 34 35 36 37 38 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 30 def test_rollback_with_version_number p = pages(:welcome) assert_equal 24, p.version assert_equal 'Welcome to the weblog', p.title assert p.revert_to!(p.versions.first.version), "Couldn't revert to 23" assert_equal 23, p.version assert_equal 'Welcome to the weblg', p.title end |
- (Object) test_rollback_with_version_number_with_options
79 80 81 82 83 84 85 86 87 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 79 def p = locked_pages(:welcome) assert_equal 'Welcome to the weblog', p.title assert_equal 'LockedPage', p.versions.first.version_type assert p.revert_to!(p.versions.first.version), "Couldn't revert to 23" assert_equal 'Welcome to the weblg', p.title assert_equal 'LockedPage', p.versions.first.version_type end |
- (Object) test_rollback_with_version_number_with_sti
107 108 109 110 111 112 113 114 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 107 def test_rollback_with_version_number_with_sti p = locked_pages(:thinking) assert_equal 'So I was thinking', p.title assert p.revert_to!(p.versions.first.version), "Couldn't revert to 1" assert_equal 'So I was thinking!!!', p.title assert_equal 'SpecialLockedPage', p.versions.first.version_type end |
- (Object) test_saves_versioned_copy
9 10 11 12 13 14 15 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 9 def test_saves_versioned_copy p = Page.create! :title => 'first title', :body => 'first body' assert !p.new_record? assert_equal 1, p.versions.size assert_equal 1, p.version assert_instance_of Page.versioned_class, p.versions.first end |
- (Object) test_saves_versioned_copy_with_options
72 73 74 75 76 77 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 72 def p = LockedPage.create! :title => 'first title' assert !p.new_record? assert_equal 1, p.versions.size assert_instance_of LockedPage.versioned_class, p.versions.first end |
- (Object) test_saves_versioned_copy_with_sti
99 100 101 102 103 104 105 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 99 def test_saves_versioned_copy_with_sti p = SpecialLockedPage.create! :title => 'first title' assert !p.new_record? assert_equal 1, p.versions.size assert_instance_of LockedPage.versioned_class, p.versions.first assert_equal 'SpecialLockedPage', p.versions.first.version_type end |
- (Object) test_saves_without_revision
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 17 def test_saves_without_revision p = pages(:welcome) old_versions = p.versions.count p.save_without_revision p.without_revision do p.update_attributes :title => 'changed' end assert_equal old_versions, p.versions.count end |
- (Object) test_should_find_earliest_version
324 325 326 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 324 def test_should_find_earliest_version assert_equal page_versions(:welcome_1), pages(:welcome).versions.earliest end |
- (Object) test_should_find_latest_version
328 329 330 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 328 def test_should_find_latest_version assert_equal page_versions(:welcome_2), pages(:welcome).versions.latest end |
- (Object) test_should_find_next_version
337 338 339 340 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 337 def test_should_find_next_version assert_equal page_versions(:welcome_2), page_versions(:welcome_1).next assert_equal page_versions(:welcome_2), pages(:welcome).versions.after(page_versions(:welcome_1)) end |
- (Object) test_should_find_previous_version
332 333 334 335 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 332 def test_should_find_previous_version assert_equal page_versions(:welcome_1), page_versions(:welcome_2).previous assert_equal page_versions(:welcome_1), pages(:welcome).versions.before(page_versions(:welcome_2)) end |
- (Object) test_should_find_version_count
342 343 344 345 346 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 342 def test_should_find_version_count assert_equal 24, pages(:welcome).versions_count assert_equal 24, page_versions(:welcome_1).versions_count assert_equal 24, page_versions(:welcome_2).versions_count end |
- (Object) test_special_methods
50 51 52 53 54 55 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 50 def test_special_methods assert_nothing_raised { pages(:welcome).feeling_good? } assert_nothing_raised { pages(:welcome).versions.first.feeling_good? } assert_nothing_raised { locked_pages(:welcome).hello_world } assert_nothing_raised { locked_pages(:welcome).versions.first.hello_world } end |
- (Object) test_track_altered_attributes
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 215 def test_track_altered_attributes p = LockedPage.create! :title => "title" assert_equal 1, p.lock_version assert_equal 1, p.versions(true).size p.title = 'title' assert !p.save_version? p.save assert_equal 2, p.lock_version # still increments version because of optimistic locking assert_equal 1, p.versions(true).size p.title = 'updated title' assert p.save_version? p.save assert_equal 3, p.lock_version assert_equal 1, p.versions(true).size # version 1 deleted p.title = 'updated title!' assert p.save_version? p.save assert_equal 4, p.lock_version assert_equal 2, p.versions(true).size # version 1 deleted end |
- (Object) test_track_altered_attributes_default_value
204 205 206 207 208 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 204 def test_track_altered_attributes_default_value assert !Page.track_altered_attributes assert LockedPage.track_altered_attributes assert SpecialLockedPage.track_altered_attributes end |
- (Object) test_unaltered_attributes
314 315 316 317 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 314 def test_unaltered_attributes landmarks(:washington).attributes = landmarks(:washington).attributes.except("id") assert !landmarks(:washington).changed? end |
- (Object) test_unchanged_string_attributes
319 320 321 322 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 319 def test_unchanged_string_attributes landmarks(:washington).attributes = landmarks(:washington).attributes.except("id").inject({}) { |params, (key, value)| params.update(key => value.to_s) } assert !landmarks(:washington).changed? end |
- (Object) test_version_if_condition
130 131 132 133 134 135 136 137 138 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 130 def test_version_if_condition p = Page.create! :title => "title" assert_equal 1, p.version Page.feeling_good = false p.save assert_equal 1, p.version Page.feeling_good = true end |
- (Object) test_version_if_condition2
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 140 def test_version_if_condition2 # set new if condition Page.class_eval do def new_feeling_good() title[0..0] == 'a'; end alias_method :old_feeling_good, :feeling_good? alias_method :feeling_good?, :new_feeling_good end p = Page.create! :title => "title" assert_equal 1, p.version # version does not increment assert_equal 1, p.versions(true).size p.update_attributes(:title => 'new title') assert_equal 1, p.version # version does not increment assert_equal 1, p.versions(true).size p.update_attributes(:title => 'a title') assert_equal 2, p.version assert_equal 2, p.versions(true).size # reset original if condition Page.class_eval { alias_method :feeling_good?, :old_feeling_good } end |
- (Object) test_version_if_condition_with_block
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 164 def test_version_if_condition_with_block # set new if condition old_condition = Page.version_condition Page.version_condition = Proc.new { |page| page.title[0..0] == 'b' } p = Page.create! :title => "title" assert_equal 1, p.version # version does not increment assert_equal 1, p.versions(true).size p.update_attributes(:title => 'a title') assert_equal 1, p.version # version does not increment assert_equal 1, p.versions(true).size p.update_attributes(:title => 'b title') assert_equal 2, p.version assert_equal 2, p.versions(true).size # reset original if condition Page.version_condition = old_condition end |
- (Object) test_version_max_limit
194 195 196 197 198 199 200 201 202 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 194 def test_version_max_limit p = LockedPage.create! :title => "title" p.update_attributes(:title => "title1") p.update_attributes(:title => "title2") 5.times do |i| assert_page_title p, i, :lock_version assert p.versions(true).size <= 2, "locked version can only store 2 versions" end end |
- (Object) test_version_no_limit
185 186 187 188 189 190 191 192 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 185 def test_version_no_limit p = Page.create! :title => "title", :body => 'first body' p.save p.save 5.times do |i| assert_page_title p, i end end |
- (Object) test_version_order
210 211 212 213 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 210 def test_version_order assert_equal 23, pages(:welcome).versions.first.version assert_equal 24, pages(:welcome).versions.last.version end |
- (Object) test_versioned_class
45 46 47 48 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 45 def test_versioned_class assert_equal Page::Version, Page.versioned_class assert_equal LockedPage::LockedPageRevision, LockedPage.versioned_class end |
- (Object) test_versioned_class_name
40 41 42 43 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 40 def test_versioned_class_name assert_equal 'Version', Page.versioned_class_name assert_equal 'LockedPageRevision', LockedPage.versioned_class_name end |
- (Object) test_versioned_records_should_belong_to_parent
308 309 310 311 312 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 308 def test_versioned_records_should_belong_to_parent page = pages(:welcome) page_version = page.versions.last assert_equal page, page_version.page end |
- (Object) test_with_sequence
267 268 269 270 271 272 |
# File 'vendor/plugins/acts_as_versioned/test/versioned_test.rb', line 267 def test_with_sequence assert_equal 'widgets_seq', Widget.versioned_class.sequence_name 3.times { Widget.create! :name => 'new widget' } assert_equal 3, Widget.count assert_equal 3, Widget.versioned_class.count end |