can accept array for sql sanitizing in conditions
This commit is contained in:
		
							parent
							
								
									b473d8827f
								
							
						
					
					
						commit
						9c0346b90b
					
				@ -302,7 +302,8 @@ module CanCan
 | 
				
			|||||||
      can_definitions.each do |can_definition|
 | 
					      can_definitions.each do |can_definition|
 | 
				
			||||||
        merge_association_joins(joins, can_definition.association_joins || [])
 | 
					        merge_association_joins(joins, can_definition.association_joins || [])
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
      clear_association_joins(joins)
 | 
					      joins = clear_association_joins(joins)
 | 
				
			||||||
 | 
					      joins unless joins.empty?
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    def merge_association_joins(what, with)
 | 
					    def merge_association_joins(what, with)
 | 
				
			||||||
 | 
				
			|||||||
@ -270,6 +270,21 @@ describe CanCan::Ability do
 | 
				
			|||||||
    @ability.sql_conditions(:read, SqlSanitizer).should == 'true=true'
 | 
					    @ability.sql_conditions(:read, SqlSanitizer).should == 'true=true'
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					  it "should accept array condition for use in sql" do
 | 
				
			||||||
 | 
					    @ability.can :read, SqlSanitizer, ["user_id = ?", 1]
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    @ability.sql_conditions(:read, SqlSanitizer).should == ['user_id = ?', 1]
 | 
				
			||||||
 | 
					    @ability.association_joins(:read, SqlSanitizer).should be_nil
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  it "should accept array condition for use in sql and do sanitizing in complex conditions" do
 | 
				
			||||||
 | 
					    @ability.cannot :read, SqlSanitizer
 | 
				
			||||||
 | 
					    @ability.can :read, SqlSanitizer, ["user_id = ?", 1]
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    @ability.sql_conditions(:read, SqlSanitizer).should == 'user_id = 1'
 | 
				
			||||||
 | 
					    @ability.association_joins(:read, SqlSanitizer).should be_nil
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  it "should has eated cheezburger" do
 | 
					  it "should has eated cheezburger" do
 | 
				
			||||||
    lambda {
 | 
					    lambda {
 | 
				
			||||||
      @ability.can? :has, :cheezburger
 | 
					      @ability.can? :has, :cheezburger
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user