Class: PermanentRecordsTest
- Inherits:
-
ActiveSupport::TestCase
- Object
- ActiveSupport::TestCase
- PermanentRecordsTest
- Defined in:
- test/permanent_records_test.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #teardown ⇒ Object
- #test_deleted_returns_true_for_deleted_records ⇒ Object
- #test_dependent_non_permanent_records_should_be_destroyed ⇒ Object
- #test_dependent_permanent_records_should_be_marked_as_deleted ⇒ Object
- #test_dependent_permanent_records_should_be_revived_when_parent_is_revived ⇒ Object
- #test_destroy_returns_record_with_modified_attributes ⇒ Object
- #test_destroy_should_ignore_other_parameters ⇒ Object
- #test_destroy_should_not_really_remove_the_record ⇒ Object
- #test_destroy_should_recognize_a_force_parameter ⇒ Object
- #test_destroy_should_return_the_record ⇒ Object
- #test_destroy_should_save_deleted_at_attribute ⇒ Object
- #test_destroy_should_set_deleted_at_attribute ⇒ Object
- #test_models_without_a_deleted_at_column_should_destroy_as_normal ⇒ Object
- #test_old_dependent_permanent_records_should_not_be_revived ⇒ Object
- #test_revive_and_destroy_should_be_chainable ⇒ Object
- #test_revive_should_make_deleted_return_false ⇒ Object
- #test_revive_should_return_the_record ⇒ Object
- #test_revive_should_unfreeze_record ⇒ Object
- #test_revive_should_unset_deleted_at ⇒ Object
- #test_with_counting_on_deleted_limits_scope_to_count_deleted_records ⇒ Object
- #test_with_counting_on_not_deleted_limits_scope_to_count_not_deleted_records ⇒ Object
- #test_with_deleted_limits_scope_to_deleted_records ⇒ Object
- #test_with_not_deleted_limits_scope_to_not_deleted_records ⇒ Object
Instance Method Details
#setup ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'test/permanent_records_test.rb', line 9 def setup super Muskrat.delete_all @active = Muskrat.create!(:name => 'Wakko') @deleted = Muskrat.create!(:name => 'Yakko', :deleted_at => 4.days.ago) @the_girl = Muskrat.create!(:name => 'Dot') Kitty.delete_all @kitty = Kitty.create!(:name => 'Meow Meow') @hole = Hole.create(:number => 14) @hole.muskrats.create(:name => "Active Muskrat") @hole.muskrats.create(:name => "Deleted Muskrat", :deleted_at => 5.days.ago) @mole = @hole.moles.create(:name => "Grabowski") end |
#teardown ⇒ Object
23 24 25 |
# File 'test/permanent_records_test.rb', line 23 def teardown setup end |
#test_deleted_returns_true_for_deleted_records ⇒ Object
69 70 71 |
# File 'test/permanent_records_test.rb', line 69 def test_deleted_returns_true_for_deleted_records assert @deleted.deleted? end |
#test_dependent_non_permanent_records_should_be_destroyed ⇒ Object
104 105 106 107 108 109 110 |
# File 'test/permanent_records_test.rb', line 104 def test_dependent_non_permanent_records_should_be_destroyed assert @hole.is_permanent? assert !@hole.moles.first.is_permanent? assert_difference "Mole.count", -1 do @hole.destroy end end |
#test_dependent_permanent_records_should_be_marked_as_deleted ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'test/permanent_records_test.rb', line 112 def test_dependent_permanent_records_should_be_marked_as_deleted assert @hole.is_permanent? assert @hole.muskrats.first.is_permanent? assert_no_difference "Muskrat.count" do @hole.destroy end assert @hole.muskrats.first.deleted? end |
#test_dependent_permanent_records_should_be_revived_when_parent_is_revived ⇒ Object
121 122 123 124 125 126 127 |
# File 'test/permanent_records_test.rb', line 121 def test_dependent_permanent_records_should_be_revived_when_parent_is_revived assert @hole.is_permanent? @hole.destroy assert @hole.muskrats.find_by_name("Active Muskrat").deleted? @hole.revive assert !@hole.muskrats.find_by_name("Active Muskrat").deleted? end |
#test_destroy_returns_record_with_modified_attributes ⇒ Object
73 74 75 |
# File 'test/permanent_records_test.rb', line 73 def test_destroy_returns_record_with_modified_attributes assert @active.destroy.deleted? end |
#test_destroy_should_ignore_other_parameters ⇒ Object
53 54 55 |
# File 'test/permanent_records_test.rb', line 53 def test_destroy_should_ignore_other_parameters assert Muskrat.find(@active.destroy(:hula_dancer).id) end |
#test_destroy_should_not_really_remove_the_record ⇒ Object
45 46 47 |
# File 'test/permanent_records_test.rb', line 45 def test_destroy_should_not_really_remove_the_record assert Muskrat.find(@active.destroy.id) end |
#test_destroy_should_recognize_a_force_parameter ⇒ Object
49 50 51 |
# File 'test/permanent_records_test.rb', line 49 def test_destroy_should_recognize_a_force_parameter assert_raises(ActiveRecord::RecordNotFound) { @active.destroy(:force).reload } end |
#test_destroy_should_return_the_record ⇒ Object
27 28 29 30 |
# File 'test/permanent_records_test.rb', line 27 def test_destroy_should_return_the_record muskrat = @active assert_equal muskrat, muskrat.destroy end |
#test_destroy_should_save_deleted_at_attribute ⇒ Object
41 42 43 |
# File 'test/permanent_records_test.rb', line 41 def test_destroy_should_save_deleted_at_attribute assert Muskrat.find(@active.destroy.id).deleted_at end |
#test_destroy_should_set_deleted_at_attribute ⇒ Object
37 38 39 |
# File 'test/permanent_records_test.rb', line 37 def test_destroy_should_set_deleted_at_attribute assert @active.destroy.deleted_at end |
#test_models_without_a_deleted_at_column_should_destroy_as_normal ⇒ Object
100 101 102 |
# File 'test/permanent_records_test.rb', line 100 def test_models_without_a_deleted_at_column_should_destroy_as_normal assert_raises(ActiveRecord::RecordNotFound) {@kitty.destroy.reload} end |
#test_old_dependent_permanent_records_should_not_be_revived ⇒ Object
129 130 131 132 133 134 135 |
# File 'test/permanent_records_test.rb', line 129 def test_old_dependent_permanent_records_should_not_be_revived assert @hole.is_permanent? @hole.destroy assert @hole.muskrats.find_by_name("Deleted Muskrat").deleted? @hole.revive assert @hole.muskrats.find_by_name("Deleted Muskrat").deleted? end |
#test_revive_and_destroy_should_be_chainable ⇒ Object
77 78 79 80 |
# File 'test/permanent_records_test.rb', line 77 def test_revive_and_destroy_should_be_chainable assert @active.destroy.revive.destroy.destroy.revive.revive.destroy.deleted? assert !@deleted.destroy.revive.revive.destroy.destroy.revive.deleted? end |
#test_revive_should_make_deleted_return_false ⇒ Object
65 66 67 |
# File 'test/permanent_records_test.rb', line 65 def test_revive_should_make_deleted_return_false assert !@deleted.revive.deleted? end |
#test_revive_should_return_the_record ⇒ Object
32 33 34 35 |
# File 'test/permanent_records_test.rb', line 32 def test_revive_should_return_the_record muskrat = @deleted assert_equal muskrat, muskrat.revive end |
#test_revive_should_unfreeze_record ⇒ Object
57 58 59 |
# File 'test/permanent_records_test.rb', line 57 def test_revive_should_unfreeze_record assert !@deleted.revive.frozen? end |
#test_revive_should_unset_deleted_at ⇒ Object
61 62 63 |
# File 'test/permanent_records_test.rb', line 61 def test_revive_should_unset_deleted_at assert !@deleted.revive.deleted_at end |
#test_with_counting_on_deleted_limits_scope_to_count_deleted_records ⇒ Object
82 83 84 85 |
# File 'test/permanent_records_test.rb', line 82 def test_with_counting_on_deleted_limits_scope_to_count_deleted_records assert_equal Muskrat.deleted.length, Muskrat.deleted.count end |
#test_with_counting_on_not_deleted_limits_scope_to_count_not_deleted_records ⇒ Object
87 88 89 90 |
# File 'test/permanent_records_test.rb', line 87 def test_with_counting_on_not_deleted_limits_scope_to_count_not_deleted_records assert_equal Muskrat.not_deleted.length, Muskrat.not_deleted.count end |
#test_with_deleted_limits_scope_to_deleted_records ⇒ Object
92 93 94 |
# File 'test/permanent_records_test.rb', line 92 def test_with_deleted_limits_scope_to_deleted_records assert Muskrat.deleted.all?(&:deleted?) end |
#test_with_not_deleted_limits_scope_to_not_deleted_records ⇒ Object
96 97 98 |
# File 'test/permanent_records_test.rb', line 96 def test_with_not_deleted_limits_scope_to_not_deleted_records assert !Muskrat.not_deleted.any?(&:deleted?) end |