Sha256: 126b9fc0f205baa4b4a56b0c3f90c562bfbbad40e2d6338b242c6146183ba049

Contents?: true

Size: 1.78 KB

Versions: 24

Compression:

Stored size: 1.78 KB

Contents

require File.join(File.dirname(__FILE__), 'spec_helper')

describe 'proxying to the found data' do
  before do
    TestModel.extended_models.each { |model| model.last_find = {} }
  end

  describe 'calling first and last on a filter result' do
    before do
      Blog.all.each { |b| b.destroy }
      @blog = Class.new(Blog)
      @blog.named_filter(:by_name) do
        order(:name)
      end
      @blog1 = @blog.create(:name => 'a')
      @blog2 = @blog.create(:name => 'b')
      @blog3 = @blog.create(:name => 'c')
    end
    
    it 'should return the first element in the result correctly' do
      @blog.by_name.first.should == @blog1
    end

    it 'should return the last element in the result correctly' do
      @blog.by_name.last.should == @blog3
    end

    it 'should proxy arguments through' do
      @blog.by_name.first(:conditions => ['name = ?', 'b']).should == @blog2
    end

    it 'should evaluate whether the returned scope is empty correctly' do
      @blog.by_name.empty?.should == false
      Blog.all.each { |b| b.destroy }
      @blog.by_name.empty?.should == true
    end

    it 'should do the right thing for any?' do
      @blog.by_name.any? { |b| b.name == 'b' }.should == true
      @blog.by_name.any? { |b| b.name == 'd' }.should == false
      @blog.by_name.any?.should == true
    end
  end

  describe 'calling reject! on a filter result' do
    before do
      Blog.all.each { |b| b.destroy }
      @blog = Class.new(Blog)
      @blog.named_filter(:by_name) do
        order(:name)
      end
      @blog1 = @blog.create
      @blog2 = @blog.create
    end

    it 'should remove the rejected items from the list' do
      items = @blog.by_name
      items.size.should == 2
      items.reject! { |i| true } # should reject them all
      items.size.should == 0
    end
  end
end

Version data entries

24 entries across 24 versions & 3 rubygems

Version Path
aub-record_filter-0.8.0 spec/proxying_spec.rb
aub-record_filter-0.9.0 spec/proxying_spec.rb
aub-record_filter-0.9.1 spec/proxying_spec.rb
aub-record_filter-0.9.10 spec/proxying_spec.rb
aub-record_filter-0.9.11 spec/proxying_spec.rb
aub-record_filter-0.9.12 spec/proxying_spec.rb
aub-record_filter-0.9.2 spec/proxying_spec.rb
aub-record_filter-0.9.3 spec/proxying_spec.rb
aub-record_filter-0.9.4 spec/proxying_spec.rb
aub-record_filter-0.9.5 spec/proxying_spec.rb
aub-record_filter-0.9.6 spec/proxying_spec.rb
aub-record_filter-0.9.7 spec/proxying_spec.rb
aub-record_filter-0.9.8 spec/proxying_spec.rb
aub-record_filter-0.9.9 spec/proxying_spec.rb
outoftime-record_filter-0.6.0 spec/proxying_spec.rb
outoftime-record_filter-0.8.0 spec/proxying_spec.rb
record_filter-1.0.1 spec/proxying_spec.rb
record_filter-1.0.0 spec/proxying_spec.rb
record_filter-0.9.17 spec/proxying_spec.rb
record_filter-0.9.16 spec/proxying_spec.rb