fix for bug 123

This commit is contained in:
McClain Looney 2010-08-17 09:33:11 -05:00
parent a566ea0f4f
commit 3d7742ea43
2 changed files with 25 additions and 10 deletions

View File

@ -34,17 +34,22 @@ module CanCan
end
end
# Returns a hash of conditions, pluralizing the table names
def tableized_conditions
if @conditions
@conditions.inject({}) do |tableized_conditions, (name, value)|
name = name.to_s.tableize.to_sym if value.kind_of? Hash
def tableized_conditions(c=nil)
conditions = c || @conditions
if conditions
conditions.inject({}) do |tableized_conditions, (name, value)|
if value.kind_of? Hash
name = name.to_s.tableize.to_sym
value = tableized_conditions(value)
end
tableized_conditions[name] = value
tableized_conditions
end
end
end
def only_block?
conditions_empty? && !@block.nil?
end

View File

@ -30,6 +30,16 @@ describe CanCan::CanDefinition do
@conditions[:foo] = {:bar => {1 => 2}}
@can.associations_hash.should == {:foo => {:bar => {}}}
end
it "should tableize correctly for absurdly complex permissions" do
@conditions[:unit] = {:property=>{:landlord=>{:weasle_id=>560}}}
@conditions[:test] = 1
@can.tableized_conditions.should == {:units => {:properties => {:landlords=>{:weasle_id=>560}}}, :test => 1}
end
it "should tableize correctly for complex permissions" do
@conditions[:unit] = {:property=>{:landlord_id=>560}}
@conditions[:test] = 1
@can.tableized_conditions.should == {:units => {:properties => {:landlord_id=>560}}, :test => 1}
end
it "should return table names in conditions for association joins" do
@conditions[:foo] = {:bar => 1}