cancan 1.3.4 → 1.4.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,101 +7,101 @@ describe CanCan::Query do
7
7
  end
8
8
 
9
9
  it "should have false conditions if no abilities match" do
10
- @ability.query(:destroy, Person).conditions.should == "true=false"
10
+ @ability.query(:destroy, Project).conditions.should == "true=false"
11
11
  end
12
12
 
13
13
  it "should return hash for single `can` definition" do
14
- @ability.can :read, Person, :blocked => false, :user_id => 1
15
- @ability.query(:read, Person).conditions.should == { :blocked => false, :user_id => 1 }
14
+ @ability.can :read, Project, :blocked => false, :user_id => 1
15
+ @ability.query(:read, Project).conditions.should == { :blocked => false, :user_id => 1 }
16
16
  end
17
17
 
18
18
  it "should merge multiple can definitions into single SQL string joining with OR" do
19
- @ability.can :read, Person, :blocked => false
20
- @ability.can :read, Person, :admin => true
21
- @ability.query(:read, Person).conditions.should == "(admin=true) OR (blocked=false)"
19
+ @ability.can :read, Project, :blocked => false
20
+ @ability.can :read, Project, :admin => true
21
+ @ability.query(:read, Project).conditions.should == "(admin=true) OR (blocked=false)"
22
22
  end
23
23
 
24
24
  it "should merge multiple can definitions into single SQL string joining with OR and AND" do
25
- @ability.can :read, Person, :blocked => false, :active => true
26
- @ability.can :read, Person, :admin => true
27
- @ability.query(:read, Person).conditions.should orderlessly_match("(blocked=false AND active=true) OR (admin=true)")
25
+ @ability.can :read, Project, :blocked => false, :active => true
26
+ @ability.can :read, Project, :admin => true
27
+ @ability.query(:read, Project).conditions.should orderlessly_match("(blocked=false AND active=true) OR (admin=true)")
28
28
  end
29
29
 
30
30
  it "should merge multiple can definitions into single SQL string joining with OR and AND" do
31
- @ability.can :read, Person, :blocked => false, :active => true
32
- @ability.can :read, Person, :admin => true
33
- @ability.query(:read, Person).conditions.should orderlessly_match("(blocked=false AND active=true) OR (admin=true)")
31
+ @ability.can :read, Project, :blocked => false, :active => true
32
+ @ability.can :read, Project, :admin => true
33
+ @ability.query(:read, Project).conditions.should orderlessly_match("(blocked=false AND active=true) OR (admin=true)")
34
34
  end
35
35
 
36
36
  it "should return false conditions for cannot clause" do
37
- @ability.cannot :read, Person
38
- @ability.query(:read, Person).conditions.should == "true=false"
37
+ @ability.cannot :read, Project
38
+ @ability.query(:read, Project).conditions.should == "true=false"
39
39
  end
40
40
 
41
41
  it "should return SQL for single `can` definition in front of default `cannot` condition" do
42
- @ability.cannot :read, Person
43
- @ability.can :read, Person, :blocked => false, :user_id => 1
44
- @ability.query(:read, Person).conditions.should orderlessly_match("blocked=false AND user_id=1")
42
+ @ability.cannot :read, Project
43
+ @ability.can :read, Project, :blocked => false, :user_id => 1
44
+ @ability.query(:read, Project).conditions.should orderlessly_match("blocked=false AND user_id=1")
45
45
  end
46
46
 
47
47
  it "should return true condition for single `can` definition in front of default `can` condition" do
48
- @ability.can :read, Person
49
- @ability.can :read, Person, :blocked => false, :user_id => 1
50
- @ability.query(:read, Person).conditions.should == 'true=true'
48
+ @ability.can :read, Project
49
+ @ability.can :read, Project, :blocked => false, :user_id => 1
50
+ @ability.query(:read, Project).conditions.should == 'true=true'
51
51
  end
52
52
 
53
53
  it "should return false condition for single `cannot` definition" do
54
- @ability.cannot :read, Person, :blocked => true, :user_id => 1
55
- @ability.query(:read, Person).conditions.should == 'true=false'
54
+ @ability.cannot :read, Project, :blocked => true, :user_id => 1
55
+ @ability.query(:read, Project).conditions.should == 'true=false'
56
56
  end
57
57
 
58
58
  it "should return `false condition` for single `cannot` definition in front of default `cannot` condition" do
59
- @ability.cannot :read, Person
60
- @ability.cannot :read, Person, :blocked => true, :user_id => 1
61
- @ability.query(:read, Person).conditions.should == 'true=false'
59
+ @ability.cannot :read, Project
60
+ @ability.cannot :read, Project, :blocked => true, :user_id => 1
61
+ @ability.query(:read, Project).conditions.should == 'true=false'
62
62
  end
63
63
 
64
64
  it "should return `not (sql)` for single `cannot` definition in front of default `can` condition" do
65
- @ability.can :read, Person
66
- @ability.cannot :read, Person, :blocked => true, :user_id => 1
67
- @ability.query(:read, Person).conditions.should orderlessly_match("not (blocked=true AND user_id=1)")
65
+ @ability.can :read, Project
66
+ @ability.cannot :read, Project, :blocked => true, :user_id => 1
67
+ @ability.query(:read, Project).conditions.should orderlessly_match("not (blocked=true AND user_id=1)")
68
68
  end
69
69
 
70
70
  it "should return appropriate sql conditions in complex case" do
71
- @ability.can :read, Person
72
- @ability.can :manage, Person, :id => 1
73
- @ability.can :update, Person, :manager_id => 1
74
- @ability.cannot :update, Person, :self_managed => true
75
- @ability.query(:update, Person).conditions.should == 'not (self_managed=true) AND ((manager_id=1) OR (id=1))'
76
- @ability.query(:manage, Person).conditions.should == {:id=>1}
77
- @ability.query(:read, Person).conditions.should == 'true=true'
71
+ @ability.can :read, Project
72
+ @ability.can :manage, Project, :id => 1
73
+ @ability.can :update, Project, :manager_id => 1
74
+ @ability.cannot :update, Project, :self_managed => true
75
+ @ability.query(:update, Project).conditions.should == 'not (self_managed=true) AND ((manager_id=1) OR (id=1))'
76
+ @ability.query(:manage, Project).conditions.should == {:id=>1}
77
+ @ability.query(:read, Project).conditions.should == 'true=true'
78
78
  end
79
79
 
80
80
  it "should have nil joins if no can definitions" do
81
- @ability.query(:read, Person).joins.should be_nil
81
+ @ability.query(:read, Project).joins.should be_nil
82
82
  end
83
83
 
84
84
  it "should have nil joins if no nested hashes specified in conditions" do
85
- @ability.can :read, Person, :blocked => false
86
- @ability.can :read, Person, :admin => true
87
- @ability.query(:read, Person).joins.should be_nil
85
+ @ability.can :read, Project, :blocked => false
86
+ @ability.can :read, Project, :admin => true
87
+ @ability.query(:read, Project).joins.should be_nil
88
88
  end
89
89
 
90
90
  it "should merge separate joins into a single array" do
91
- @ability.can :read, Person, :project => { :blocked => false }
92
- @ability.can :read, Person, :company => { :admin => true }
93
- @ability.query(:read, Person).joins.inspect.should orderlessly_match([:company, :project].inspect)
91
+ @ability.can :read, Project, :project => { :blocked => false }
92
+ @ability.can :read, Project, :company => { :admin => true }
93
+ @ability.query(:read, Project).joins.inspect.should orderlessly_match([:company, :project].inspect)
94
94
  end
95
95
 
96
96
  it "should merge same joins into a single array" do
97
- @ability.can :read, Person, :project => { :blocked => false }
98
- @ability.can :read, Person, :project => { :admin => true }
99
- @ability.query(:read, Person).joins.should == [:project]
97
+ @ability.can :read, Project, :project => { :blocked => false }
98
+ @ability.can :read, Project, :project => { :admin => true }
99
+ @ability.query(:read, Project).joins.should == [:project]
100
100
  end
101
101
 
102
102
  it "should merge complex, nested joins" do
103
- @ability.can :read, Person, :project => { :bar => {:test => true} }, :company => { :bar => {:test => true} }
104
- @ability.can :read, Person, :project => { :foo => {:bar => true}, :bar => {:zip => :zap} }
105
- @ability.query(:read, Person).joins.inspect.should orderlessly_match([{:project => [:bar, :foo]}, {:company => [:bar]}].inspect)
103
+ @ability.can :read, Project, :project => { :bar => {:test => true} }, :company => { :bar => {:test => true} }
104
+ @ability.can :read, Project, :project => { :foo => {:bar => true}, :bar => {:zip => :zap} }
105
+ @ability.query(:read, Project).joins.inspect.should orderlessly_match([{:project => [:bar, :foo]}, {:company => [:bar]}].inspect)
106
106
  end
107
107
  end
data/spec/spec.opts CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --backtrace
data/spec/spec_helper.rb CHANGED
@@ -19,8 +19,18 @@ class Ability
19
19
  end
20
20
  end
21
21
 
22
- # this class helps out in testing SQL conditions
23
- class Person
22
+ # Generic class to mimic a model
23
+ class Project
24
+ attr_accessor :name
25
+
26
+ def initialize(attributes = {})
27
+ @name = attributes[:name]
28
+ end
29
+
30
+ def attributes=(attributes)
31
+ @name = attributes[:name] if attributes[:name]
32
+ end
33
+
24
34
  class << self
25
35
  protected
26
36
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cancan
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ prerelease: true
5
5
  segments:
6
6
  - 1
7
- - 3
8
7
  - 4
9
- version: 1.3.4
8
+ - 0
9
+ - beta1
10
+ version: 1.4.0.beta1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Ryan Bates
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-08-31 00:00:00 -07:00
18
+ date: 2010-09-03 00:00:00 -07:00
18
19
  default_executable:
19
20
  dependencies: []
20
21