Sha256: 86183f203f6ab121df5677bd11950ac7f2536cea8458ab943b813805f39b85f6

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

require File.dirname(__FILE__) + '/helper'

context "Limit" do
  setup do
    @sql = User.select { |m| m.name == 'jon' }
  end

  specify "first" do
    conditions = { :conditions => "users.`name` = 'jon'", :limit => '1' }
    User.expects(:find).with(:first, conditions)
    @sql.first
  end

  specify "first with argument" do
    conditions = { :conditions => "users.`name` = 'jon'", :limit => '5' }
    User.expects(:find).with(:all, conditions)
    @sql.first(5)
  end

  specify "[] with one element" do
    conditions = { :conditions => "users.`name` = 'jon'", :limit => '10, 1' }
    User.expects(:find).with(:all, conditions)
    @sql[10]
  end
  
  specify "[] with two elements" do
    conditions = { :conditions => "users.`name` = 'jon'", :limit => '10, 20' }
    User.expects(:find).with(:all, conditions)
    @sql[10, 20]
  end
  
  specify "slice is an alias of []" do
    conditions = { :conditions => "users.`name` = 'jon'", :limit => '10, 20' }
    User.expects(:find).with(:all, conditions)
    @sql.slice(10, 20)
  end
  
  specify "[] with range" do
    conditions = { :conditions => "users.`name` = 'jon'", :limit => '10, 10' }
    User.expects(:find).with(:all, conditions)
    @sql[10..20]
  end
end

Version data entries

4 entries across 2 versions & 1 rubygems

Version Path
ambition-0.1.3 ./test/limit_test.rb
ambition-0.1.3 test/limit_test.rb
ambition-0.1.4 ./test/limit_test.rb
ambition-0.1.4 test/limit_test.rb