removing extra white space at end of lines
This commit is contained in:
@@ -15,7 +15,7 @@ describe CanCan::Ability do
|
||||
it "should not have permission to do something it doesn't know about" do
|
||||
@ability.can?(:foodfight, String).should be_false
|
||||
end
|
||||
|
||||
|
||||
it "should pass true to `can?` when non false/nil is returned in block" do
|
||||
@ability.can :read, :all
|
||||
@ability.can :read, Symbol do |sym|
|
||||
@@ -23,7 +23,7 @@ describe CanCan::Ability do
|
||||
end
|
||||
@ability.can?(:read, :some_symbol).should == true
|
||||
end
|
||||
|
||||
|
||||
it "should pass to previous can definition, if block returns false or nil" do
|
||||
@ability.can :read, Symbol
|
||||
@ability.can :read, Integer do |i|
|
||||
@@ -151,7 +151,7 @@ describe CanCan::Ability do
|
||||
@ability.can?(:read, 3).should be_true
|
||||
@ability.can?(:read, 123).should be_false
|
||||
end
|
||||
|
||||
|
||||
it "should pass to previous can definition, if block returns false or nil" do
|
||||
#same as previous
|
||||
@ability.can :read, :all
|
||||
@@ -162,9 +162,9 @@ describe CanCan::Ability do
|
||||
@ability.can?(:read, 3).should be_true
|
||||
@ability.can?(:read, 8).should be_false
|
||||
@ability.can?(:read, 123).should be_true
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
it "should always return `false` for single cannot definition" do
|
||||
@ability.cannot :read, Integer do |int|
|
||||
int > 10 ? nil : ( int > 5 )
|
||||
@@ -174,7 +174,7 @@ describe CanCan::Ability do
|
||||
@ability.can?(:read, 8).should be_false
|
||||
@ability.can?(:read, 123).should be_false
|
||||
end
|
||||
|
||||
|
||||
it "should pass to previous cannot definition, if block returns false or nil" do
|
||||
@ability.cannot :read, :all
|
||||
@ability.can :read, Integer do |int|
|
||||
@@ -238,7 +238,7 @@ describe CanCan::Ability do
|
||||
@ability.can?(:read, [[1, 2, 3]]).should be_true
|
||||
@ability.can?(:read, [[4, 5, 6]]).should be_false
|
||||
end
|
||||
|
||||
|
||||
it "should has eated cheezburger" do
|
||||
lambda {
|
||||
@ability.can? :has, :cheezburger
|
||||
|
||||
@@ -25,11 +25,11 @@ describe CanCan::ActiveRecordAdditions do
|
||||
stub(@model_class).scoped(:conditions => {:foos => {:bar => 1}}, :joins => [:foo]) { :found_records }
|
||||
@model_class.accessible_by(@ability).should == :found_records
|
||||
end
|
||||
|
||||
|
||||
it "should merge association joins and sanitize conditions" do
|
||||
@ability.can :read, @model_class, :foo => {:bar => 1}
|
||||
@ability.can :read, @model_class, :too => {:car => 1, :far => {:bar => 1}}
|
||||
|
||||
|
||||
condition_variants = [
|
||||
'(toos.far.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)'
|
||||
@@ -38,7 +38,7 @@ describe CanCan::ActiveRecordAdditions do
|
||||
[:foo, {:too => [:far]}],
|
||||
[{:too => [:far]}, :foo]
|
||||
]
|
||||
|
||||
|
||||
condition_variants.each do |condition|
|
||||
joins_variants.each do |joins|
|
||||
stub(@model_class).scoped( :conditions => condition, :joins => joins ) { :found_records }
|
||||
|
||||
@@ -5,68 +5,68 @@ describe CanCan::Query do
|
||||
@ability = Object.new
|
||||
@ability.extend(CanCan::Ability)
|
||||
end
|
||||
|
||||
|
||||
it "should have false conditions if no abilities match" do
|
||||
@ability.query(:destroy, Person).conditions.should == "true=false"
|
||||
end
|
||||
|
||||
|
||||
it "should return hash for single `can` definition" do
|
||||
@ability.can :read, Person, :blocked => false, :user_id => 1
|
||||
@ability.query(:read, Person).conditions.should == { :blocked => false, :user_id => 1 }
|
||||
end
|
||||
|
||||
|
||||
it "should merge multiple can definitions into single SQL string joining with OR" do
|
||||
@ability.can :read, Person, :blocked => false
|
||||
@ability.can :read, Person, :admin => true
|
||||
@ability.query(:read, Person).conditions.should == "(admin=true) OR (blocked=false)"
|
||||
end
|
||||
|
||||
|
||||
it "should merge multiple can definitions into single SQL string joining with OR and AND" do
|
||||
@ability.can :read, Person, :blocked => false, :active => true
|
||||
@ability.can :read, Person, :admin => true
|
||||
@ability.query(:read, Person).conditions.should orderlessly_match("(blocked=false AND active=true) OR (admin=true)")
|
||||
end
|
||||
|
||||
|
||||
it "should merge multiple can definitions into single SQL string joining with OR and AND" do
|
||||
@ability.can :read, Person, :blocked => false, :active => true
|
||||
@ability.can :read, Person, :admin => true
|
||||
@ability.query(:read, Person).conditions.should orderlessly_match("(blocked=false AND active=true) OR (admin=true)")
|
||||
end
|
||||
|
||||
|
||||
it "should return false conditions for cannot clause" do
|
||||
@ability.cannot :read, Person
|
||||
@ability.query(:read, Person).conditions.should == "true=false"
|
||||
end
|
||||
|
||||
|
||||
it "should return SQL for single `can` definition in front of default `cannot` condition" do
|
||||
@ability.cannot :read, Person
|
||||
@ability.can :read, Person, :blocked => false, :user_id => 1
|
||||
@ability.query(:read, Person).conditions.should orderlessly_match("blocked=false AND user_id=1")
|
||||
end
|
||||
|
||||
|
||||
it "should return true condition for single `can` definition in front of default `can` condition" do
|
||||
@ability.can :read, Person
|
||||
@ability.can :read, Person, :blocked => false, :user_id => 1
|
||||
@ability.query(:read, Person).conditions.should == 'true=true'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it "should return false condition for single `cannot` definition" do
|
||||
@ability.cannot :read, Person, :blocked => true, :user_id => 1
|
||||
@ability.query(:read, Person).conditions.should == 'true=false'
|
||||
end
|
||||
|
||||
|
||||
it "should return `false condition` for single `cannot` definition in front of default `cannot` condition" do
|
||||
@ability.cannot :read, Person
|
||||
@ability.cannot :read, Person, :blocked => true, :user_id => 1
|
||||
@ability.query(:read, Person).conditions.should == 'true=false'
|
||||
end
|
||||
|
||||
|
||||
it "should return `not (sql)` for single `cannot` definition in front of default `can` condition" do
|
||||
@ability.can :read, Person
|
||||
@ability.cannot :read, Person, :blocked => true, :user_id => 1
|
||||
@ability.query(:read, Person).conditions.should orderlessly_match("not (blocked=true AND user_id=1)")
|
||||
end
|
||||
|
||||
|
||||
it "should return appropriate sql conditions in complex case" do
|
||||
@ability.can :read, Person
|
||||
@ability.can :manage, Person, :id => 1
|
||||
@@ -76,29 +76,29 @@ describe CanCan::Query do
|
||||
@ability.query(:manage, Person).conditions.should == {:id=>1}
|
||||
@ability.query(:read, Person).conditions.should == 'true=true'
|
||||
end
|
||||
|
||||
|
||||
it "should have nil joins if no can definitions" do
|
||||
@ability.query(:read, Person).joins.should be_nil
|
||||
end
|
||||
|
||||
|
||||
it "should have nil joins if no nested hashes specified in conditions" do
|
||||
@ability.can :read, Person, :blocked => false
|
||||
@ability.can :read, Person, :admin => true
|
||||
@ability.query(:read, Person).joins.should be_nil
|
||||
end
|
||||
|
||||
|
||||
it "should merge separate joins into a single array" do
|
||||
@ability.can :read, Person, :project => { :blocked => false }
|
||||
@ability.can :read, Person, :company => { :admin => true }
|
||||
@ability.query(:read, Person).joins.inspect.should orderlessly_match([:company, :project].inspect)
|
||||
end
|
||||
|
||||
|
||||
it "should merge same joins into a single array" do
|
||||
@ability.can :read, Person, :project => { :blocked => false }
|
||||
@ability.can :read, Person, :project => { :admin => true }
|
||||
@ability.query(:read, Person).joins.should == [:project]
|
||||
end
|
||||
|
||||
|
||||
it "should merge complex, nested joins" do
|
||||
@ability.can :read, Person, :project => { :bar => {:test => true} }, :company => { :bar => {:test => true} }
|
||||
@ability.can :read, Person, :project => { :foo => {:bar => true}, :bar => {:zip => :zap} }
|
||||
|
||||
@@ -23,14 +23,14 @@ end
|
||||
class Person
|
||||
def self.sanitize_sql(hash_cond)
|
||||
case hash_cond
|
||||
when Hash
|
||||
when Hash
|
||||
sanitize_hash(hash_cond).join(' AND ')
|
||||
when Array
|
||||
hash_cond.shift.gsub('?'){"#{hash_cond.shift.inspect}"}
|
||||
when String then hash_cond
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.sanitize_hash(hash)
|
||||
hash.map do |name, value|
|
||||
if Hash === value
|
||||
|
||||
Reference in New Issue
Block a user