Sha256: 49d8a90000ecdfcd8559cbd78b2e631b033180525c83fc7115130bc18b83891a
Contents?: true
Size: 1.83 KB
Versions: 1
Compression:
Stored size: 1.83 KB
Contents
require 'helper' describe 'Enhanced Finder Methods' do after do User.destroy_all end describe '.all' do it 'extracts the non-where scopes and applies' do test_sql = User.all(:limit! => 1, :offset! => 2, :order! => :name, :age => 10).to_sql expected_sql = User.where(:age => 10).limit(1).offset(2).order(:name).to_sql test_sql.must_be_like expected_sql end it 'finds implicit joins by reflection' do test_sql = User.all(:records => { :name => 'test' }).to_sql expected_sql = User.joins(:records).where(:records => { :name => 'test' }).to_sql test_sql.must_be_like expected_sql end end describe '.first' do it 'calls #first on .all' do expected = User.create(:age => 10) User.create(:age => 11) User.first(:age => 10).must_equal expected end end describe '.count' do it 'calls #count on .all' do User.create(:age => 10) User.create(:age => 11) User.count(:age => 10).must_equal 1 end end describe 'hash contains :conditions' do before do @expected = User.create(:name => 'test') @user = User.create(:name => 'no test') end describe 'with conditions' do it 'falls back for .all' do User.all(:conditions => "name = 'test'").must_equal [@expected] end it 'falls back for .first' do User.first(:conditions => "name = 'test'").must_equal @expected end it 'falls back for .count' do User.count(:conditions => "name = 'test'").must_equal 1 end end describe 'without conditions' do it 'falls back for .all' do User.all.must_equal [@expected, @user] end it 'falls back for .first' do User.first.must_equal @expected end it 'falls back for .count' do User.count.must_equal 2 end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
better_ar-0.0.6 | test/test_finder_methods.rb |