fixing broken spec and minor improvements to tableized_conditions method
This commit is contained in:
parent
3d7742ea43
commit
e893e12260
|
@ -34,22 +34,17 @@ module CanCan
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def tableized_conditions(c=nil)
|
def tableized_conditions(conditions = @conditions)
|
||||||
conditions = c || @conditions
|
conditions.inject({}) do |result_hash, (name, value)|
|
||||||
if conditions
|
if value.kind_of? Hash
|
||||||
conditions.inject({}) do |tableized_conditions, (name, value)|
|
name = name.to_s.tableize.to_sym
|
||||||
if value.kind_of? Hash
|
value = tableized_conditions(value)
|
||||||
name = name.to_s.tableize.to_sym
|
|
||||||
value = tableized_conditions(value)
|
|
||||||
end
|
|
||||||
tableized_conditions[name] = value
|
|
||||||
tableized_conditions
|
|
||||||
end
|
end
|
||||||
|
result_hash[name] = value
|
||||||
|
result_hash
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def only_block?
|
def only_block?
|
||||||
conditions_empty? && !@block.nil?
|
conditions_empty? && !@block.nil?
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,8 +31,8 @@ describe CanCan::ActiveRecordAdditions do
|
||||||
@ability.can :read, @model_class, :too => {:car => 1, :far => {:bar => 1}}
|
@ability.can :read, @model_class, :too => {:car => 1, :far => {:bar => 1}}
|
||||||
|
|
||||||
condition_variants = [
|
condition_variants = [
|
||||||
'(toos.far.bar=1 AND toos.car=1) OR (foos.bar=1)', # faked sql sanitizer is stupid ;-)
|
'(toos.fars.bar=1 AND toos.car=1) OR (foos.bar=1)', # faked sql sanitizer is stupid ;-)
|
||||||
'(toos.car=1 AND toos.far.bar=1) OR (foos.bar=1)'
|
'(toos.car=1 AND toos.fars.bar=1) OR (foos.bar=1)'
|
||||||
]
|
]
|
||||||
joins_variants = [
|
joins_variants = [
|
||||||
[:foo, {:too => [:far]}],
|
[:foo, {:too => [:far]}],
|
||||||
|
|
|
@ -30,11 +30,13 @@ describe CanCan::CanDefinition do
|
||||||
@conditions[:foo] = {:bar => {1 => 2}}
|
@conditions[:foo] = {:bar => {1 => 2}}
|
||||||
@can.associations_hash.should == {:foo => {:bar => {}}}
|
@can.associations_hash.should == {:foo => {:bar => {}}}
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should tableize correctly for absurdly complex permissions" do
|
it "should tableize correctly for absurdly complex permissions" do
|
||||||
@conditions[:unit] = {:property=>{:landlord=>{:weasle_id=>560}}}
|
@conditions[:unit] = {:property=>{:landlord=>{:weasle_id=>560}}}
|
||||||
@conditions[:test] = 1
|
@conditions[:test] = 1
|
||||||
@can.tableized_conditions.should == {:units => {:properties => {:landlords=>{:weasle_id=>560}}}, :test => 1}
|
@can.tableized_conditions.should == {:units => {:properties => {:landlords=>{:weasle_id=>560}}}, :test => 1}
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should tableize correctly for complex permissions" do
|
it "should tableize correctly for complex permissions" do
|
||||||
@conditions[:unit] = {:property=>{:landlord_id=>560}}
|
@conditions[:unit] = {:property=>{:landlord_id=>560}}
|
||||||
@conditions[:test] = 1
|
@conditions[:test] = 1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user