Created
November 18, 2009 21:34
-
-
Save comeara/238283 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "test/unit" | |
require "rubygems" | |
gem "activerecord", :version => "2.3.4" | |
require "active_record" | |
ActiveRecord::Base.establish_connection( | |
:adapter => "sqlite3", | |
:dbfile => ":memory:" | |
) | |
ActiveRecord::Schema.define do | |
create_table :albums do |table| | |
table.string :title | |
table.integer :artist_id | |
end | |
create_table :artists do |table| | |
table.string :name | |
end | |
end | |
class Album < ActiveRecord::Base | |
belongs_to :artist | |
end | |
class Artist < ActiveRecord::Base | |
has_many :albums | |
end | |
class DirtyAssociationTest < Test::Unit::TestCase | |
def test_changed_includes_new_record_assignments | |
album = Album.create! :title => "Give Up the Ghost" | |
album.artist = Artist.new :name => "Brandi Carlile" | |
assert album.changes.any? | |
end | |
def test_changed_includes_persistent_record_assignments | |
album = Album.create! :title => "Give Up the Ghost" | |
album.artist = Artist.create! :name => "Brandi Carlile" | |
assert album.changes.any? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment