Created
June 12, 2009 08:03
-
-
Save kematzy/128509 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
### NOTE!! Store this file in the | |
# | |
# github.com/datamapper/dm-more/tree/next # Next branch | |
# | | |
# |--> dm-is-list/spec/integration | |
require 'pathname' | |
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper' | |
require Pathname(__FILE__).dirname.expand_path.parent.parent.parent / 'dm-is-tree' / 'lib' / 'dm-is-tree' / 'is' / 'tree.rb' | |
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES | |
describe 'DataMapper::Is::List' do | |
class Album | |
include DataMapper::Resource | |
property :id, Serial | |
property :parent_id, Integer, :default => 0 | |
property :name, String | |
is :list, :scope => [:parent_id] #, :order => [:position] | |
is :tree, :order => [:parent_id, :position] | |
end | |
before :each do | |
Album.auto_migrate! | |
Album.create(:name => 'Album1') | |
Album.create(:name => 'Album2') | |
Album.create(:name => 'Album3') | |
Album.create(:name => 'Album4') | |
@album5 = Album.create(:name => 'Album5') | |
end | |
describe 'Strange behaviour with reference objects' do | |
it 'this test fails with mismatch on the position of Album.get(5)' do | |
DataMapper.repository(:default) do |repos| | |
album5 = Album.get(5) | |
album5.position.should == 5 | |
album5.position.should == @album5.position | |
@album5.update(:position => 20) | |
@album5.position.should == 20 | |
Album.all.map{ |a| [a.id, a.position] }.should == [ [1, 1], [2, 2], [3, 3], [4, 4], [5, 20] ] | |
end | |
end | |
it 'this test passes because I do a reload of the temporary "album5" variable' do | |
DataMapper.repository(:default) do |repos| | |
album5 = Album.get(5) | |
album5.position.should == 5 | |
album5.position.should == @album5.position | |
@album5.update(:position => 20) | |
@album5.position.should == 20 | |
album5.position.should == 5 | |
album5.reload | |
Album.all.map{ |a| [a.id, a.position] }.should == [ [1, 1], [2, 2], [3, 3], [4, 4], [5, 20] ] | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment