raise an error when trying to make a rule with both hash conditions and a block - closes #269
This commit is contained in:
		
							parent
							
								
									f9b181af05
								
							
						
					
					
						commit
						0de43c445b
					
				| @ -11,6 +11,7 @@ module CanCan | |||||||
|     # and subject respectively (such as :read, @project). The third argument is a hash |     # and subject respectively (such as :read, @project). The third argument is a hash | ||||||
|     # of conditions and the last one is the block passed to the "can" call. |     # of conditions and the last one is the block passed to the "can" call. | ||||||
|     def initialize(base_behavior, action, subject, conditions, block) |     def initialize(base_behavior, action, subject, conditions, block) | ||||||
|  |       raise Error, "You are not able to supply a block with a hash of conditions in #{action} #{subject} ability. Use either one." if conditions.kind_of?(Hash) && !block.nil? | ||||||
|       @match_all = action.nil? && subject.nil? |       @match_all = action.nil? && subject.nil? | ||||||
|       @base_behavior = base_behavior |       @base_behavior = base_behavior | ||||||
|       @actions = [action].flatten |       @actions = [action].flatten | ||||||
|  | |||||||
| @ -357,6 +357,14 @@ describe CanCan::Ability do | |||||||
|     @ability.model_adapter(model_class, :read).should == :adapter_instance |     @ability.model_adapter(model_class, :read).should == :adapter_instance | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  |   it "should raise an error when attempting to use a block with a hash condition since it's not likely what they want" do | ||||||
|  |     lambda { | ||||||
|  |       @ability.can :read, Array, :published => true do | ||||||
|  |         false | ||||||
|  |       end | ||||||
|  |     }.should raise_error(CanCan::Error, "You are not able to supply a block with a hash of conditions in read Array ability. Use either one.") | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|   describe "unauthorized message" do |   describe "unauthorized message" do | ||||||
|     after(:each) do |     after(:each) do | ||||||
|       I18n.backend = nil |       I18n.backend = nil | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Ryan Bates
						Ryan Bates