Sha256: 32a76adef00ccc2f41b561592a44b5b0185e72967d8df11e3a9be2e94934fff0
Contents?: true
Size: 1.73 KB
Versions: 1
Compression:
Stored size: 1.73 KB
Contents
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper.rb") describe 'has_one relationships' do before :all do Redis.new.flushall Ampere.connect # These are used by the has_one/belongs_to example below class Car < Ampere::Model field :make field :model field :year has_one :engine end class Engine < Ampere::Model field :displacement field :cylinders field :configuration belongs_to :car end @car = Car.create :make => "Lamborghini", :model => "Countach", :year => "1974" @engine = Engine.create :displacement => "5167", :cylinders => "12", :configuration => "V" end ### it 'can store a relationship to one model instance from another using an attr_accessor' do @car.engine_id = @engine.id @car.save @car.reload @engine.reload @car.engine_id.should == @engine.id @car.engine.should == @engine @car.engine_id = nil @car.save @car.engine.should be_nil end it 'can store a relationship to one model instance from another using custom accessor methods' do @car.engine = @engine @car.save @car.reload @engine.reload @car.engine_id.should == @engine.id @car.engine.should == @engine @car.engine_id = nil @car.save @car.engine.should be_nil end it 'can delete the object related to it in a has_one relationship' do @car.engine = @engine @car.engine.destroy @car.reload @car.engine.should be_nil Engine.find(@engine.id).should be_nil end ### after :all do Ampere.disconnect Redis.new.flushall end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ampere-0.1.0 | spec/models/relationships/has_one_spec.rb |