aboutsummaryrefslogblamecommitdiffstats
path: root/spec/active_relation/unit/predicates/relation_inclusion_spec.rb
blob: 0ac7ccb6e222fcf9290eab1cc8aa9d990252a16a (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                                                                          
 







                                        
  




                                                                                                                 
       
  

                                            
                                                                             
                                                      
          
         


       
require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')

module ActiveRelation
  describe RelationInclusion do
    before do
      foo = Table.new(:foo)
      @relation1 = foo.project(foo[:id])
      @relation2 = Table.new(:bar)
      @attribute = @relation1[:id]
    end
  
    describe RelationInclusion, '==' do    
      it "obtains if attribute1 and attribute2 are identical" do
        RelationInclusion.new(@attribute, @relation1).should == RelationInclusion.new(@attribute, @relation1)
        RelationInclusion.new(@attribute, @relation1).should_not == RelationInclusion.new(@attribute, @relation2)
      end
    end
  
    describe RelationInclusion, '#to_sql' do
      it "manufactures subselect sql" do
        RelationInclusion.new(@attribute, @relation1).to_sql.should be_like("
          `foo`.`id` IN (SELECT `foo`.`id` FROM `foo`)
        ")
      end
    end
  end
end