Sha256: 511d2a9bcc24df4b3038278a0059475f7f25657dcaf7f2c58693be84a068be10

Contents?: true

Size: 1.28 KB

Versions: 23

Compression:

Stored size: 1.28 KB

Contents

require File.expand_path("../../spec_helper", __FILE__)

describe "Querying with an ad-hoc scope" do
  before do
    User.all(:name => "Fred").each { |u| u.destroy }
    @users = (1..10).map { User.create(:name => "Fred") }
  end

  it "can return all the objects matching the scope" do
    User.scope(:name => "Fred").all.should == @users
  end

  it "can return the first object matching the scope" do
    User.scope(:name => "Fred").first.should == User.first(:name => "Fred")
  end

  it "can paginate over the matching objects" do
    found = User.scope(:name => "Fred").paginate(:per_page! => 5)
    found.should == User.paginate(:name => "Fred", :per_page! => 5)
  end

  it "can build an object at scope" do
    User.scope(:name => "Fred", :limit! => 5).build.name.should == "Fred"
  end

  it "supports overriding parameters when building" do
    scope = User.scope(:name => "Fred", :limit! => 5)
    scope.build(:name => "Joe").name.should == "Joe"
  end

  it "can create an object at scope" do
    user = User.scope(:name => "Joe").create
    user.should_not be_new_record
    user.name.should == "Joe"
  end

  it "supports overriding parameters when creating" do
    user = User.scope(:name => "Joe").create(:name => "Fred")
    user.should_not be_new_record
    user.name.should == "Fred"
  end
end

Version data entries

23 entries across 23 versions & 7 rubygems

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