0
@@ -370,6 +370,70 @@ describe "DataMapper::Resource" do
0
earth.orbit_period.should == 365.26
0
+ describe "#reload_attributes" do
0
+ it 'should call collection.reload if not a new record' do
0
+ planet = Planet.new(:name => 'Omicron Persei VIII')
0
+ planet.stub!(:new_record?).and_return(false)
0
+ collection = mock('collection')
0
+ collection.should_receive(:reload).with(:fields => [:name]).once
0
+ planet.stub!(:collection).and_return(collection)
0
+ planet.reload_attributes(:name)
0
+ it 'should not call collection.reload if no attributes are provided to reload' do
0
+ planet = Planet.new(:name => 'Omicron Persei VIII')
0
+ planet.stub!(:new_record?).and_return(false)
0
+ collection = mock('collection')
0
+ collection.should_not_receive(:reload)
0
+ planet.stub!(:collection).and_return(collection)
0
+ planet.reload_attributes
0
+ it 'should not call collection.reload if the record is new' do
0
+ planet = Planet.new(:name => 'Omicron Persei VIII')
0
+ planet.should_not_receive(:collection)
0
+ planet.reload_attributes(:name)
0
+ it 'should call #reload_attributes with the currently loaded attributes' do
0
+ planet = Planet.new(:name => 'Omicron Persei VIII', :age => 1)
0
+ planet.stub!(:new_record?).and_return(false)
0
+ planet.should_receive(:reload_attributes).with(:name, :age).once
0
+ it 'should call #reload on the parent and child associations' do
0
+ planet = Planet.new(:name => 'Omicron Persei VIII', :age => 1)
0
+ planet.stub!(:new_record?).and_return(false)
0
+ child_association = mock('child assoc')
0
+ child_association.should_receive(:reload).once.and_return(true)
0
+ parent_association = mock('parent assoc')
0
+ parent_association.should_receive(:reload).once.and_return(true)
0
+ planet.stub!(:child_associations).and_return([child_association])
0
+ planet.stub!(:parent_associations).and_return([parent_association])
0
+ planet.stub!(:reload_attributes).and_return(planet)
0
+ it 'should not do anything if the record is new' do
0
+ planet = Planet.new(:name => 'Omicron Persei VIII', :age => 1)
0
+ planet.should_not_receive(:reload_attributes)
0
describe "anonymity" do
0
it "should require a default storage name and accept a block" do
0
pluto = DataMapper::Resource.new("planets") do
Comments
No one has commented yet.