Skip to content

Instantly share code, notes, and snippets.

@comeara
Created November 18, 2009 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save comeara/238283 to your computer and use it in GitHub Desktop.
Save comeara/238283 to your computer and use it in GitHub Desktop.
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