spec/public/collection_spec.rb in dm-ambition-1.0.0 vs spec/public/collection_spec.rb in dm-ambition-1.1.0.rc1

- old
+ new

@@ -16,36 +16,101 @@ property :id, Serial property :name, String property :admin, Boolean, :default => false end - if DataMapper.respond_to?(:auto_migrate!) - DataMapper.auto_migrate! - end + @model = User end - before :all do - @repository = DataMapper.repository(:default) - @model = User - @query = DataMapper::Query.new(@repository, @model) + supported_by :all do + before :all do + @query = DataMapper::Query.new(@repository, @model) - @user = @model.create(:name => 'Dan Kubb', :admin => true) - @other = @model.create(:name => 'Sam Smoot') + @user = @model.create(:name => 'Dan Kubb', :admin => true) + @other = @model.create(:name => 'Sam Smoot') - @subject = @model.all(@query) - @subject.to_a if loaded - end + @subject = @model.all(@query) + @subject.to_a if loaded + end - it_should_behave_like 'it has public filter methods' + it_should_behave_like 'it has public filter methods' - unless loaded || Gem::Version.new(DataMapper::VERSION) < Gem::Version.new('0.10') - [ :select, :find_all ].each do |method| - describe "##{method}", '(unloaded)' do - describe 'when matching resource prepended' do + unless loaded + [ :select, :find_all ].each do |method| + describe "##{method}", '(unloaded)' do + context 'when matching resource prepended' do + before :all do + @other.update(:admin => true) + @subject.unshift(@other) + @return = @subject.send(method) { |u| u.admin == true } + end + + it 'should return a Collection' do + @return.should be_kind_of(DataMapper::Collection) + end + + it 'should not return self' do + @return.should_not equal(@subject) + end + + it 'should not be a kicker' do + @return.should_not be_loaded + end + + it 'should return expected values' do + @return.should == [ @other, @user ] + end + + it 'should include the exact prepended resource' do + @return.first.should equal(@other) + end + + it "should return the same as Array##{method}" do + @return.should == @subject.to_a.send(method) { |u| u.admin == true } + end + end + + context 'when matching resource appended' do + before :all do + @other.update(:admin => true) + @subject << @other + @return = @subject.send(method) { |u| u.admin == true } + end + + it 'should return a Collection' do + @return.should be_kind_of(DataMapper::Collection) + end + + it 'should not return self' do + @return.should_not equal(@subject) + end + + it 'should not be a kicker' do + @return.should_not be_loaded + end + + it 'should return expected values' do + @return.should == [ @user, @other ] + end + + it 'should include the exact appended resource' do + @return.last.should equal(@other) + end + + it "should return the same as Array##{method}" do + @return.should == @subject.to_a.send(method) { |u| u.admin == true } + end + end + end + end + + describe '#reject', '(unloaded)' do + context 'when matching resource prepended' do before :all do + @other.update(:admin => true) @subject.unshift(@other) - @return = @subject.send(method) { |u| u.admin == true } + @return = @subject.reject { |u| u.admin != true } end it 'should return a Collection' do @return.should be_kind_of(DataMapper::Collection) end @@ -57,18 +122,27 @@ it 'should not be a kicker' do @return.should_not be_loaded end it 'should return expected values' do - @return.should == [ @user ] + @return.should == [ @other, @user ] end + + it 'should include the exact prepended resource' do + @return.first.should equal(@other) + end + + it 'should return the same as Array#reject' do + @return.should == @subject.to_a.reject { |u| u.admin != true } + end end - describe 'when matching resource appended' do + context 'when matching resource appended' do before :all do + @other.update(:admin => true) @subject << @other - @return = @subject.send(method) { |u| u.admin == true } + @return = @subject.reject { |u| u.admin != true } end it 'should return a Collection' do @return.should be_kind_of(DataMapper::Collection) end @@ -80,59 +154,19 @@ it 'should not be a kicker' do @return.should_not be_loaded end it 'should return expected values' do - @return.should == [ @user ] + @return.should == [ @user, @other ] end - end - end - end - describe '#reject', '(unloaded)' do - describe 'when matching resource prepended' do - before :all do - @subject.unshift(@other) - @return = @subject.reject { |u| u.admin != true } - end + it 'should include the exact appended resource' do + @return.last.should equal(@other) + end - it 'should return a Collection' do - @return.should be_kind_of(DataMapper::Collection) - end - - it 'should not return self' do - @return.should_not equal(@subject) - end - - it 'should not be a kicker' do - @return.should_not be_loaded - end - - it 'should return expected values' do - @return.should == [ @user ] - end - end - - describe 'when matching resource appended' do - before :all do - @subject << @other - @return = @subject.reject { |u| u.admin != true } - end - - it 'should return a Collection' do - @return.should be_kind_of(DataMapper::Collection) - end - - it 'should not return self' do - @return.should_not equal(@subject) - end - - it 'should not be a kicker' do - @return.should_not be_loaded - end - - it 'should return expected values' do - @return.should == [ @user ] + it 'should return the same as Array#reject' do + @return.should == @subject.to_a.reject { |u| u.admin != true } + end end end end end end