Sha256: 267f8e1bc6eccc7fd84d90f32a570abc6ada962d81deb14ebd39e8fe3424c97f
Contents?: true
Size: 1.19 KB
Versions: 3
Compression:
Stored size: 1.19 KB
Contents
require 'test_helper' class DirtyAssociationsTest < ActiveSupport::TestCase test "setting has_many association adds object to changes" do foo = FactoryGirl.create(:foo) refute bar.foo_ids_changed? bar.foos = [ foo ] assert_equal [ foo ], bar.foos assert bar.foo_ids_changed? end test "setting has_many association ids adds association to changes" do foo = FactoryGirl.create(:foo) refute bar.foo_ids_changed? bar.foo_ids = [ foo.id ] assert_equal [ foo.id ], bar.foo_ids assert bar.foo_ids_changed? end test "changes reset by save" do bar.foos = [ FactoryGirl.create(:foo) ] assert bar.foo_ids_changed? bar.save refute bar.foo_ids_changed? end test "has_many association appears in previous_changes after save" do refute bar.foo_ids_previously_changed? bar.foos = [ FactoryGirl.create(:foo) ] refute bar.foo_ids_previously_changed? bar.save assert bar.foo_ids_previously_changed? bar.save refute bar.foo_ids_previously_changed? end private def bar unless @bar foo = FactoryGirl.create(:foo) @bar = FactoryGirl.create(:bar, :foo_ids => [ foo.id ]) @bar.save end @bar end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dirty_associations-0.2.1 | test/dirty_associations_test.rb |
dirty_associations-0.2.0 | test/dirty_associations_test.rb |
dirty_associations-0.1.0 | test/dirty_associations_test.rb |