Sha256: 18f7af001eeed64ffee451b34419aa0ec53bf0abc182acc3ccb961ddf75143f1

Contents?: true

Size: 1.82 KB

Versions: 18

Compression:

Stored size: 1.82 KB

Contents

require File.expand_path("../../spec_helper", __FILE__)
require 'active_support/duration'
require 'active_support/core_ext/integer'
require 'active_support/core_ext/time'
require 'active_support/core_ext/object'
require 'active_support/core_ext/numeric'

describe "Finding multiple objects by id" do
  before do
    @user_one = User.new
    @user_two = User.new
    @user_one.save
    @user_two.save
    @users    = User.all(:id => [@user_one.id, @user_two.id])
  end

  it "finds the objects in the database" do
    @users.length.should == 2
    @users.should include(@user_one)
    @users.should include(@user_two)
  end

  describe "when no objects are found" do
    it "returns an empty array" do
      User.all(:id => [9999, 12345, 999]).should == []
    end
  end

  describe "when one object is found, but others aren't" do
    it "returns the found objects" do
      User.all(:id => [@user_one.id, 12345]).should == [@user_one]
    end
  end
end

describe "Limiting a query" do
  before do
    10.times { User.new(:name => "Stewie").save }
    @results = User.all(:name => "Stewie", :limit! => 5)
  end

  it "returns the number of results you asked for" do
    @results.length.should == 5
  end
end

describe "limiting a query with offset" do
  before do
    @objects = (0..10).map do |i| 
      User.new(:name => "Joe", :created_at => i.minutes.from_now).tap do |u|
        u.save
      end
    end
  end

  after { @objects.each { |o| o.destroy } }

  it "returns results starting from the offset to hte limit" do
    User.all(:name    => "Joe", 
             :offset! => 2, 
             :limit!  => 2,
             :order!  => :created_at.desc).should == @objects.reverse.slice(2, 2)
  end
end

describe "all with only order" do
  it "queries the index" do
    Address.create
      Address.all(:order! => :created_at.desc, :limit! => 5)
  end
end

Version data entries

18 entries across 18 versions & 7 rubygems

Version Path
ihoka-friendly-0.8.0.pre spec/integration/finder_spec.rb
ihoka-friendly-0.7.1.2 spec/integration/finder_spec.rb
ihoka-friendly-0.7.1.1 spec/integration/finder_spec.rb
ihoka-friendly-0.7.1 spec/integration/finder_spec.rb
ihoka-friendly-0.7.0 spec/integration/finder_spec.rb
friendly-0.6.0 spec/integration/finder_spec.rb
honkster-friendly-0.5.3 spec/integration/finder_spec.rb
honkster-friendly-0.5.2 spec/integration/finder_spec.rb
honkster-friendly-0.5.1 spec/integration/finder_spec.rb
wayne-friendly-0.5.1 spec/integration/finder_spec.rb
wego-friendly-0.5.1 spec/integration/finder_spec.rb
arunthampi-friendly-0.5.1 spec/integration/finder_spec.rb
friendly_postgres-0.5.1 spec/integration/finder_spec.rb
friendly-0.5.1 spec/integration/finder_spec.rb
friendly-0.5.0 spec/integration/finder_spec.rb
friendly_postgres-0.4.5 spec/integration/finder_spec.rb
friendly-0.4.5 spec/integration/finder_spec.rb
friendly-0.4.4 spec/integration/finder_spec.rb