cancan 1.3.4 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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/matchers.rb CHANGED
@@ -1,4 +1,4 @@
1
- Spec::Matchers.define :orderlessly_match do |original_string|
1
+ RSpec::Matchers.define :orderlessly_match do |original_string|
2
2
  match do |given_string|
3
3
  original_string.split('').sort == given_string.split('').sort
4
4
  end
data/spec/spec.opts CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --backtrace
data/spec/spec_helper.rb CHANGED
@@ -1,15 +1,17 @@
1
1
  require 'rubygems'
2
- require 'spec'
3
- require 'active_support'
4
- require 'active_record'
5
- require 'action_controller'
6
- require 'action_view'
2
+ require 'bundler/setup'
3
+ Bundler.require(:default)
4
+ require 'supermodel' # shouldn't Bundler do this already?
5
+ require 'active_support/all'
7
6
  require 'matchers'
8
- require 'cancan'
9
7
  require 'cancan/matchers'
10
8
 
11
- Spec::Runner.configure do |config|
9
+ RSpec.configure do |config|
12
10
  config.mock_with :rr
11
+ config.before(:each) do
12
+ Project.delete_all
13
+ Category.delete_all
14
+ end
13
15
  end
14
16
 
15
17
  class Ability
@@ -19,8 +21,13 @@ class Ability
19
21
  end
20
22
  end
21
23
 
22
- # this class helps out in testing SQL conditions
23
- class Person
24
+ class Category < SuperModel::Base
25
+ has_many :projects
26
+ end
27
+
28
+ class Project < SuperModel::Base
29
+ belongs_to :category
30
+
24
31
  class << self
25
32
  protected
26
33
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cancan
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 5
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
- - 3
8
8
  - 4
9
- version: 1.3.4
9
+ - 1
10
+ version: 1.4.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Ryan Bates
@@ -14,10 +15,75 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-08-31 00:00:00 -07:00
18
+ date: 2010-11-12 00:00:00 -08:00
18
19
  default_executable:
19
- dependencies: []
20
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 62196431
30
+ segments:
31
+ - 2
32
+ - 0
33
+ - 0
34
+ - beta
35
+ - 22
36
+ version: 2.0.0.beta.22
37
+ type: :development
38
+ version_requirements: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ name: rails
41
+ prerelease: false
42
+ requirement: &id002 !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ hash: 7
48
+ segments:
49
+ - 3
50
+ - 0
51
+ - 0
52
+ version: 3.0.0
53
+ type: :development
54
+ version_requirements: *id002
55
+ - !ruby/object:Gem::Dependency
56
+ name: rr
57
+ prerelease: false
58
+ requirement: &id003 !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ hash: 33
64
+ segments:
65
+ - 0
66
+ - 10
67
+ - 11
68
+ version: 0.10.11
69
+ type: :development
70
+ version_requirements: *id003
71
+ - !ruby/object:Gem::Dependency
72
+ name: supermodel
73
+ prerelease: false
74
+ requirement: &id004 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ hash: 19
80
+ segments:
81
+ - 0
82
+ - 1
83
+ - 4
84
+ version: 0.1.4
85
+ type: :development
86
+ version_requirements: *id004
21
87
  description: Simple authorization solution for Rails which is decoupled from user roles. All permissions are stored in a single location.
22
88
  email: ryan@railscasts.com
23
89
  executables: []
@@ -33,6 +99,7 @@ files:
33
99
  - lib/cancan/controller_additions.rb
34
100
  - lib/cancan/controller_resource.rb
35
101
  - lib/cancan/exceptions.rb
102
+ - lib/cancan/inherited_resource.rb
36
103
  - lib/cancan/matchers.rb
37
104
  - lib/cancan/query.rb
38
105
  - lib/cancan.rb
@@ -42,12 +109,14 @@ files:
42
109
  - spec/cancan/controller_additions_spec.rb
43
110
  - spec/cancan/controller_resource_spec.rb
44
111
  - spec/cancan/exceptions_spec.rb
112
+ - spec/cancan/inherited_resource_spec.rb
45
113
  - spec/cancan/matchers_spec.rb
46
114
  - spec/cancan/query_spec.rb
47
115
  - spec/matchers.rb
48
116
  - spec/spec.opts
49
117
  - spec/spec_helper.rb
50
118
  - CHANGELOG.rdoc
119
+ - Gemfile
51
120
  - LICENSE
52
121
  - Rakefile
53
122
  - README.rdoc
@@ -62,16 +131,20 @@ rdoc_options: []
62
131
  require_paths:
63
132
  - lib
64
133
  required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
65
135
  requirements:
66
136
  - - ">="
67
137
  - !ruby/object:Gem::Version
138
+ hash: 3
68
139
  segments:
69
140
  - 0
70
141
  version: "0"
71
142
  required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
72
144
  requirements:
73
145
  - - ">="
74
146
  - !ruby/object:Gem::Version
147
+ hash: 19
75
148
  segments:
76
149
  - 1
77
150
  - 3
@@ -80,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
153
  requirements: []
81
154
 
82
155
  rubyforge_project: cancan
83
- rubygems_version: 1.3.6
156
+ rubygems_version: 1.3.7
84
157
  signing_key:
85
158
  specification_version: 3
86
159
  summary: Simple authorization solution for Rails.