Sha256: 3491496bfe4414cf7046673f91a62906229cbad4fc23e7329da584d65335ef83
Contents?: true
Size: 1.12 KB
Versions: 9
Compression:
Stored size: 1.12 KB
Contents
require 'spec_helper' describe EdgeRider::ToIdQuery do describe '#to_id_query' do it 'should simplify a scope to a IN query that selects IDs' do Forum.create!(:id => 1, :name => 'Name 1') Forum.create!(:id => 2, :name => 'Name 2') Forum.create!(:id => 3, :name => 'Name 2') scope = Forum.scoped(:conditions => { :name => 'Name 2' }) scope.to_id_query.to_sql.should =~ EdgeRider::Development.selects_star_with_conditions_pattern('forums', /`forums`\.`id` IN \(2,\s*3\)/) end it 'should resolve and lose any JOINs' do Forum.create!(:id => 1, :name => 'A') Forum.create!(:id => 2, :name => 'B') Forum.create!(:id => 3, :name => 'A') Topic.create!(:id => 100, :forum_id => 1) Topic.create!(:id => 101, :forum_id => 1) Topic.create!(:id => 102, :forum_id => 2) Topic.create!(:id => 103, :forum_id => 3) scope = Topic.scoped(:joins => :forum, :conditions => 'forums.name = "A"') scope.to_id_query.to_sql.should =~ EdgeRider::Development.selects_star_with_conditions_pattern('topics', /`topics`\.`id` IN \(100,\s*101,\s*103\)/) end end end
Version data entries
9 entries across 9 versions & 1 rubygems