be9-acl9 0.9.4 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ h2. 0.10.0 (03-May-2009)
2
+
3
+ * Use context+matchy combo for testing
4
+ * Bugfix: unwanted double quote in generated SQL statement
5
+
1
6
  h2. 0.9.4 (27-Feb-2009)
2
7
 
3
8
  * Introduce :if and :unless rule options.
data/Rakefile CHANGED
@@ -1,29 +1,29 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
- require 'spec/rake/spectask'
3
+ require 'rake/testtask'
4
4
 
5
- desc 'Default: run specs.'
6
- task :default => :spec
5
+ desc 'Default: run tests.'
6
+ task :default => :test
7
7
 
8
8
  begin
9
9
  require 'jeweler'
10
10
  Jeweler::Tasks.new do |s|
11
11
  s.name = "acl9"
12
- s.summary = "Yet another role-based authorization system for Rails with a nice DSL for access control lists."
12
+ s.summary = "Yet another role-based authorization system for Rails"
13
13
  s.email = "olegdashevskii@gmail.com"
14
14
  s.homepage = "http://github.com/be9/acl9"
15
- s.description = "Yet another role-based authorization system for Rails with a nice DSL for access control lists."
15
+ s.description = "Role-based authorization system for Rails with a nice DSL for access control lists"
16
16
  s.authors = ["oleg dashevskii"]
17
- s.files = FileList["[A-Z]*", "{lib,spec}/**/*.rb"]
18
- s.add_development_dependency "rspec", ">= 1.1.12"
19
- s.add_development_dependency "rspec-rails", ">= 1.1.12"
17
+ s.files = FileList["[A-Z]*", "{lib,test}/**/*.rb"]
18
+ s.add_development_dependency "jeremymcanally-context", ">= 0.5.5"
19
+ s.add_development_dependency "jnunemaker-matchy", ">= 0.4.0"
20
20
  end
21
21
  rescue LoadError
22
22
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
23
23
  end
24
24
 
25
- desc 'Run the specs'
26
- Spec::Rake::SpecTask.new(:spec) do |t|
27
- t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
28
- t.spec_files = FileList['spec/**/*_spec.rb']
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/*_test.rb'
28
+ test.verbose = false
29
29
  end
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 9
3
- :patch: 4
2
+ :minor: 10
3
+ :patch: 0
4
4
  :major: 0
@@ -44,9 +44,14 @@ module Acl9
44
44
  end
45
45
 
46
46
  def debug_dump(klass)
47
- Rails::logger.debug "=== Acl9 access_control expression dump (#{klass.to_s})"
48
- Rails::logger.debug self.to_s
49
- Rails::logger.debug "======"
47
+ return unless logger
48
+ logger.debug "=== Acl9 access_control expression dump (#{klass.to_s})"
49
+ logger.debug self.to_s
50
+ logger.debug "======"
51
+ end
52
+
53
+ def logger
54
+ ActionController::Base.logger
50
55
  end
51
56
  end
52
57
 
@@ -34,7 +34,7 @@ module Acl9
34
34
 
35
35
  sql_where = <<-'EOS'
36
36
  WHERE authorizable_type = '#{self.class.base_class.to_s}'
37
- AND authorizable_id = #{id}"
37
+ AND authorizable_id = #{id}
38
38
  EOS
39
39
 
40
40
  has_many :accepted_roles, :as => :authorizable, :class_name => role, :dependent => :destroy
@@ -0,0 +1,209 @@
1
+ require 'test_helper'
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'acl9')
3
+ require 'support/controllers'
4
+
5
+ #######################################################################
6
+
7
+ class Admin
8
+ def has_role?(role, obj = nil)
9
+ role == "admin"
10
+ end
11
+ end
12
+
13
+ class OwnerOfFoo
14
+ def has_role?(role, obj)
15
+ role == 'owner' && obj == MyDearFoo.instance
16
+ end
17
+ end
18
+
19
+ class Bartender
20
+ def has_role?(role, obj)
21
+ role == 'bartender' && obj == ACLIvars::VenerableBar
22
+ end
23
+ end
24
+
25
+ class TheOnlyUser
26
+ include Singleton
27
+
28
+ def has_role?(role, subj)
29
+ role == "the_only_one"
30
+ end
31
+ end
32
+
33
+ #######################################################################
34
+
35
+ module BaseTests
36
+ # permit anonymous to index and show and admin everywhere else
37
+ def self.included(klass)
38
+ klass.class_eval do
39
+ [:index, :show].each do |act|
40
+ it "should permit anonymous to #{act}" do
41
+ get act
42
+ @response.body.should == 'OK'
43
+ end
44
+ end
45
+
46
+ [:new, :edit, :update, :delete, :destroy].each do |act|
47
+ it "should forbid anonymous to #{act}" do
48
+ get act
49
+ @response.body.should == 'AccessDenied'
50
+ end
51
+ end
52
+
53
+ [:index, :show, :new, :edit, :update, :delete, :destroy].each do |act|
54
+ it "should permit admin to #{act}" do
55
+ get act, :user => Admin.new
56
+ @response.body.should == 'OK'
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ module ShouldRespondToAcl
64
+ def self.included(klass)
65
+ klass.class_eval do
66
+ it "should add :acl as a method" do
67
+ @controller.should respond_to(:acl)
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ #######################################################################
74
+
75
+ class ACLBlockTest < ActionController::TestCase
76
+ tests ACLBlock
77
+
78
+ include BaseTests
79
+ end
80
+
81
+ class ACLMethodTest < ActionController::TestCase
82
+ tests ACLMethod
83
+
84
+ include BaseTests
85
+ include ShouldRespondToAcl
86
+ end
87
+
88
+ class ACLMethod2Test < ActionController::TestCase
89
+ tests ACLMethod2
90
+
91
+ include BaseTests
92
+ include ShouldRespondToAcl
93
+ end
94
+
95
+ class ACLArgumentsTest < ActionController::TestCase
96
+ tests ACLArguments
97
+
98
+ include BaseTests
99
+ end
100
+
101
+ class ACLBooleanMethodTest < ActionController::TestCase
102
+ tests ACLBooleanMethod
103
+
104
+ include BaseTests
105
+ end
106
+
107
+ class ACLIvarsTest < ActionController::TestCase
108
+ tests ACLIvars
109
+
110
+ it "should allow owner of foo to destroy" do
111
+ delete :destroy, :user => OwnerOfFoo.new
112
+ @response.body.should == 'OK'
113
+ end
114
+
115
+ it "should allow bartender to destroy" do
116
+ delete :destroy, :user => Bartender.new
117
+ @response.body.should == 'OK'
118
+ end
119
+ end
120
+
121
+ class ACLSubjectMethodTest < ActionController::TestCase
122
+ tests ACLSubjectMethod
123
+
124
+ it "should allow the only user to index" do
125
+ get :index, :user => TheOnlyUser.instance
126
+ @response.body.should == 'OK'
127
+ end
128
+
129
+ it "should deny anonymous to index" do
130
+ get :index
131
+ @response.body.should == 'AccessDenied'
132
+ end
133
+ end
134
+
135
+ class ACLObjectsHashTest < ActionController::TestCase
136
+ tests ACLObjectsHash
137
+
138
+ it "should consider objects hash and prefer it to @ivar" do
139
+ get :allow, :user => OwnerOfFoo.new
140
+ @response.body.should == 'OK'
141
+ end
142
+
143
+ it "should return AccessDenied when not logged in" do
144
+ get :allow
145
+ @response.body.should == 'AccessDenied'
146
+ end
147
+ end
148
+
149
+ class ACLHelperMethodTest < ActionController::TestCase
150
+ tests ACLHelperMethod
151
+
152
+ it "should return OK checking helper method" do
153
+ get :allow, :user => OwnerOfFoo.new
154
+ @response.body.should == 'OK'
155
+ end
156
+
157
+ it "should return AccessDenied when not logged in" do
158
+ get :allow
159
+ @response.body.should == 'AccessDenied'
160
+ end
161
+ end
162
+
163
+ class ArgumentsCheckingTest < ActiveSupport::TestCase
164
+ def arg_err(&block)
165
+ lambda do
166
+ block.call
167
+ end.should raise_error(ArgumentError)
168
+ end
169
+
170
+ it "should raise ArgumentError without a block" do
171
+ arg_err do
172
+ class FailureController < ApplicationController
173
+ access_control
174
+ end
175
+ end
176
+ end
177
+
178
+ it "should raise ArgumentError with 1st argument which is not a symbol" do
179
+ arg_err do
180
+ class FailureController < ApplicationController
181
+ access_control 123 do end
182
+ end
183
+ end
184
+ end
185
+
186
+ it "should raise ArgumentError with more than 1 positional argument" do
187
+ arg_err do
188
+ class FailureController < ApplicationController
189
+ access_control :foo, :bar do end
190
+ end
191
+ end
192
+ end
193
+
194
+ it "should raise ArgumentError with :helper => true and no method name" do
195
+ arg_err do
196
+ class FailureController < ApplicationController
197
+ access_control :helper => true do end
198
+ end
199
+ end
200
+ end
201
+
202
+ it "should raise ArgumentError with :helper => :method and a method name" do
203
+ arg_err do
204
+ class FailureController < ApplicationController
205
+ access_control :meth, :helper => :another_meth do end
206
+ end
207
+ end
208
+ end
209
+ end
@@ -1,5 +1,5 @@
1
1
  require 'ostruct'
2
- require File.join(File.dirname(__FILE__), 'spec_helper')
2
+ require 'test_helper'
3
3
  require File.join(File.dirname(__FILE__), '..', 'lib', 'acl9', 'controller_extensions', 'dsl_base')
4
4
 
5
5
  class FakeUser
@@ -77,7 +77,8 @@ class DslTester < Acl9::Dsl::Base
77
77
  end
78
78
  end
79
79
 
80
- describe Acl9::Dsl::Base do
80
+ #describe Acl9::Dsl::Base do
81
+ class DslBaseTest < Test::Unit::TestCase
81
82
  class ThatFoo; end
82
83
  class ThatBar; end
83
84
 
@@ -379,7 +380,7 @@ describe Acl9::Dsl::Base do
379
380
  forbid(@user2, :foo => @foo)
380
381
  end
381
382
 
382
- it "#allow with invalid value for preposition should raise an ArgumentError" do
383
+ it "#allow with invalid value for preposition :#{prep} should raise an ArgumentError" do
383
384
  arg_err do
384
385
  allow :hom, :by => 1
385
386
  end
@@ -409,7 +410,7 @@ describe Acl9::Dsl::Base do
409
410
  permit(@user2, :foo => @foo)
410
411
  end
411
412
 
412
- it "#deny with invalid value for preposition should raise an ArgumentError" do
413
+ it "#deny with invalid value for preposition :#{prep} should raise an ArgumentError" do
413
414
  arg_err do
414
415
  deny :her, :for => "him"
415
416
  end
@@ -445,7 +446,7 @@ describe Acl9::Dsl::Base do
445
446
  end
446
447
  end
447
448
 
448
- describe do
449
+ describe "" do
449
450
  after do
450
451
  %w(index show).each { |act| @list.permit(nil, act) }
451
452
  %w(edit update delete destroy).each { |act| @list.forbid(nil, act) }
@@ -752,3 +753,4 @@ describe Acl9::Dsl::Base do
752
753
  end
753
754
  end
754
755
  end
756
+
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
1
+ require 'test_helper'
2
+
2
3
  require File.join(File.dirname(__FILE__), '..', 'lib', 'acl9')
3
4
 
4
5
  module SomeHelper
@@ -10,7 +11,7 @@ module SomeHelper
10
11
  end
11
12
  end
12
13
 
13
- describe SomeHelper do
14
+ class HelperTest < Test::Unit::TestCase
14
15
  module Hamlet
15
16
  def current_user
16
17
  user = Object.new
@@ -1,10 +1,11 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
1
+ require 'test_helper'
2
2
  require File.join(File.dirname(__FILE__), '..', 'lib', 'acl9')
3
- require File.join(File.dirname(__FILE__), 'models')
3
+ require 'support/models'
4
4
 
5
5
  #Logger = ActiveRecord::Base.logger
6
+ load 'support/schema.rb'
6
7
 
7
- describe "Roles" do
8
+ class RolesTest < Test::Unit::TestCase
8
9
  before do
9
10
  Role.destroy_all
10
11
  [User, Foo, Bar].each { |model| model.delete_all }
@@ -24,7 +25,7 @@ describe "Roles" do
24
25
  it "#has_role! without object (global role)" do
25
26
  lambda do
26
27
  @user.has_role!('admin')
27
- end.should change(Role, :count).from(0).to(1)
28
+ end.should change { Role.count }.from(0).to(1)
28
29
 
29
30
  @user.has_role?('admin').should be_true
30
31
  @user2.has_role?('admin').should be_false
@@ -118,7 +119,7 @@ describe "Roles" do
118
119
 
119
120
  lambda do
120
121
  @user.has_no_role!('3133t')
121
- end.should change(@user.roles, :count).by(-1)
122
+ end.should change { @user.roles.count }.by(-1)
122
123
 
123
124
  @user.has_role?('3133t').should be_false
124
125
  end
@@ -128,7 +129,7 @@ describe "Roles" do
128
129
 
129
130
  lambda do
130
131
  @user.has_no_role!('manager', @foo)
131
- end.should change(@user.roles, :count).by(-1)
132
+ end.should change { @user.roles.count }.by(-1)
132
133
 
133
134
  @user.has_role?('manager', @foo).should be_false
134
135
  @user.has_role?('user', @foo).should be_true # another role on the same object
@@ -139,7 +140,7 @@ describe "Roles" do
139
140
 
140
141
  lambda do
141
142
  @user.has_no_role!('admin', Foo)
142
- end.should change(@user.roles, :count).by(-1)
143
+ end.should change { @user.roles.count }.by(-1)
143
144
 
144
145
  @user.has_role?('admin', Foo).should be_false
145
146
  @user.has_role?('admin').should be_true # global role
@@ -150,7 +151,7 @@ describe "Roles" do
150
151
 
151
152
  lambda do
152
153
  @user.has_no_roles_for!
153
- end.should change(@user.roles, :count).by(-4)
154
+ end.should change { @user.roles.count }.by(-4)
154
155
 
155
156
  @user.has_role?('admin').should be_false
156
157
  @user.has_role?('3133t').should be_false
@@ -163,7 +164,7 @@ describe "Roles" do
163
164
 
164
165
  lambda do
165
166
  @user.has_no_roles_for! @foo
166
- end.should change(@user.roles, :count).by(-2)
167
+ end.should change { @user.roles.count }.by(-2)
167
168
 
168
169
  @user.has_role?('user', @foo).should be_false
169
170
  @user.has_role?('manager', @foo).should be_false
@@ -174,7 +175,7 @@ describe "Roles" do
174
175
 
175
176
  lambda do
176
177
  @user.has_no_roles_for! Foo
177
- end.should change(@user.roles, :count).by(-4)
178
+ end.should change { @user.roles.count }.by(-4)
178
179
 
179
180
  @user.has_role?('admin', Foo).should be_false
180
181
  @user.has_role?('manager', Foo).should be_false
@@ -235,7 +236,7 @@ describe "Roles" do
235
236
  end
236
237
  end
237
238
 
238
- describe "Roles with custom class names" do
239
+ class RolesWithCustomClassNamesTest < Test::Unit::TestCase
239
240
  before do
240
241
  AnotherRole.destroy_all
241
242
  [AnotherSubject, FooBar].each { |model| model.delete_all }
@@ -249,7 +250,7 @@ describe "Roles with custom class names" do
249
250
  lambda do
250
251
  @subj.has_role!('admin')
251
252
  @subj.has_role!('user', @foobar)
252
- end.should change(AnotherRole, :count).from(0).to(2)
253
+ end.should change { AnotherRole.count }.from(0).to(2)
253
254
 
254
255
  @subj.has_role?('admin').should be_true
255
256
  @subj2.has_role?('admin').should be_false
@@ -261,3 +262,4 @@ describe "Roles with custom class names" do
261
262
  @subj2.has_no_roles!
262
263
  end
263
264
  end
265
+
@@ -1,4 +1,4 @@
1
- class ApplicationController
1
+ class ApplicationController < ActionController::Base
2
2
  rescue_from Acl9::AccessDenied do |e|
3
3
  render :text => 'AccessDenied'
4
4
  end
@@ -150,3 +150,4 @@ class ACLHelperMethod < ApplicationController
150
150
  params[:user]
151
151
  end
152
152
  end
153
+
File without changes
File without changes
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'context'
4
+ require 'matchy'
5
+ require 'active_support'
6
+ require 'active_record'
7
+ require 'action_controller'
8
+ require 'action_controller/test_process'
9
+
10
+ ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :dbfile => 'test.sqlite3')
11
+
12
+ class Test::Unit::TestCase
13
+ custom_matcher :be_false do |receiver, matcher, args|
14
+ !receiver
15
+ end
16
+
17
+ custom_matcher :be_true do |receiver, matcher, args|
18
+ !!receiver
19
+ end
20
+ end
21
+
22
+ ActionController::Routing::Routes.draw do |map|
23
+ map.connect ":controller/:action/:id"
24
+ end
25
+
26
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
27
+ ActionController::Base.logger = ActiveRecord::Base.logger
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: be9-acl9
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - oleg dashevskii
@@ -9,66 +9,65 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-27 00:00:00 -08:00
12
+ date: 2009-05-03 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: rspec
16
+ name: jeremymcanally-context
17
17
  type: :development
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.1.12
23
+ version: 0.5.5
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: rspec-rails
26
+ name: jnunemaker-matchy
27
27
  type: :development
28
28
  version_requirement:
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.1.12
33
+ version: 0.4.0
34
34
  version:
35
- description: Yet another role-based authorization system for Rails with a nice DSL for access control lists.
35
+ description: Role-based authorization system for Rails with a nice DSL for access control lists
36
36
  email: olegdashevskii@gmail.com
37
37
  executables: []
38
38
 
39
39
  extensions: []
40
40
 
41
- extra_rdoc_files: []
42
-
41
+ extra_rdoc_files:
42
+ - README.textile
43
43
  files:
44
44
  - CHANGELOG.textile
45
45
  - MIT-LICENSE
46
- - Rakefile
47
46
  - README.textile
47
+ - Rakefile
48
48
  - TODO
49
49
  - VERSION.yml
50
+ - lib/acl9.rb
50
51
  - lib/acl9/config.rb
52
+ - lib/acl9/controller_extensions.rb
51
53
  - lib/acl9/controller_extensions/dsl_base.rb
52
54
  - lib/acl9/controller_extensions/generators.rb
53
- - lib/acl9/controller_extensions.rb
54
55
  - lib/acl9/helpers.rb
56
+ - lib/acl9/model_extensions.rb
55
57
  - lib/acl9/model_extensions/object.rb
56
58
  - lib/acl9/model_extensions/subject.rb
57
- - lib/acl9/model_extensions.rb
58
- - lib/acl9.rb
59
- - spec/access_control_spec.rb
60
- - spec/controllers.rb
61
- - spec/db/schema.rb
62
- - spec/dsl_base_spec.rb
63
- - spec/helpers_spec.rb
64
- - spec/models.rb
65
- - spec/roles_spec.rb
66
- - spec/spec_helper.rb
59
+ - test/access_control_test.rb
60
+ - test/dsl_base_test.rb
61
+ - test/helpers_test.rb
62
+ - test/roles_test.rb
63
+ - test/support/controllers.rb
64
+ - test/support/models.rb
65
+ - test/support/schema.rb
66
+ - test/test_helper.rb
67
67
  has_rdoc: true
68
68
  homepage: http://github.com/be9/acl9
69
69
  post_install_message:
70
70
  rdoc_options:
71
- - --inline-source
72
71
  - --charset=UTF-8
73
72
  require_paths:
74
73
  - lib
@@ -89,7 +88,14 @@ requirements: []
89
88
  rubyforge_project:
90
89
  rubygems_version: 1.2.0
91
90
  signing_key:
92
- specification_version: 2
93
- summary: Yet another role-based authorization system for Rails with a nice DSL for access control lists.
94
- test_files: []
95
-
91
+ specification_version: 3
92
+ summary: Yet another role-based authorization system for Rails
93
+ test_files:
94
+ - test/helpers_test.rb
95
+ - test/support/schema.rb
96
+ - test/support/models.rb
97
+ - test/support/controllers.rb
98
+ - test/dsl_base_test.rb
99
+ - test/access_control_test.rb
100
+ - test/test_helper.rb
101
+ - test/roles_test.rb
@@ -1,182 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
2
- require File.join(File.dirname(__FILE__), '..', 'lib', 'acl9')
3
- require File.join(File.dirname(__FILE__), 'controllers')
4
-
5
- describe "permit anonymous to index and show and admin everywhere else", :shared => true do
6
- class Admin
7
- def has_role?(role, obj = nil)
8
- role == "admin"
9
- end
10
- end
11
-
12
- [:index, :show].each do |act|
13
- it "should permit anonymous to #{act}" do
14
- get act
15
- response.body.should == 'OK'
16
- end
17
- end
18
-
19
- [:new, :edit, :update, :delete, :destroy].each do |act|
20
- it "should forbid anonymous to #{act}" do
21
- get act
22
- response.body.should == 'AccessDenied'
23
- end
24
- end
25
-
26
- [:index, :show, :new, :edit, :update, :delete, :destroy].each do |act|
27
- it "should permit admin to #{act}" do
28
- get act, :user => Admin.new
29
- response.body.should == 'OK'
30
- end
31
- end
32
- end
33
-
34
- describe ACLBlock, :type => :controller do
35
- it_should_behave_like "permit anonymous to index and show and admin everywhere else"
36
- end
37
-
38
- describe ACLMethod, :type => :controller do
39
- it "should add :acl as a method" do
40
- controller.should respond_to(:acl)
41
- end
42
-
43
- it_should_behave_like "permit anonymous to index and show and admin everywhere else"
44
- end
45
-
46
- describe ACLMethod2, :type => :controller do
47
- it "should add :acl as a method" do
48
- controller.should respond_to(:acl)
49
- end
50
-
51
- it_should_behave_like "permit anonymous to index and show and admin everywhere else"
52
- end
53
-
54
- describe ACLArguments, :type => :controller do
55
- it_should_behave_like "permit anonymous to index and show and admin everywhere else"
56
- end
57
-
58
- describe ACLBooleanMethod, :type => :controller do
59
- it_should_behave_like "permit anonymous to index and show and admin everywhere else"
60
- end
61
-
62
- describe ACLIvars, :type => :controller do
63
- class OwnerOfFoo
64
- def has_role?(role, obj)
65
- role == 'owner' && obj == MyDearFoo.instance
66
- end
67
- end
68
-
69
- class Bartender
70
- def has_role?(role, obj)
71
- role == 'bartender' && obj == ACLIvars::VenerableBar
72
- end
73
- end
74
-
75
- it "should allow owner of foo to destroy" do
76
- delete :destroy, :user => OwnerOfFoo.new
77
- response.body.should == 'OK'
78
- end
79
-
80
- it "should allow bartender to destroy" do
81
- delete :destroy, :user => Bartender.new
82
- response.body.should == 'OK'
83
- end
84
- end
85
-
86
- describe ACLSubjectMethod, :type => :controller do
87
- class TheOnlyUser
88
- include Singleton
89
-
90
- def has_role?(role, subj)
91
- role == "the_only_one"
92
- end
93
- end
94
-
95
- it "should allow the only user to index" do
96
- get :index, :user => TheOnlyUser.instance
97
- response.body.should == 'OK'
98
- end
99
-
100
- it "should deny anonymous to index" do
101
- get :index
102
- response.body.should == 'AccessDenied'
103
- end
104
- end
105
-
106
- class FooOwner
107
- def has_role?(role_name, obj)
108
- role_name == 'owner' && obj == MyDearFoo.instance
109
- end
110
- end
111
-
112
- describe ACLObjectsHash, :type => :controller do
113
- it "should consider objects hash and prefer it to @ivar" do
114
- get :allow, :user => FooOwner.new
115
- response.body.should == 'OK'
116
- end
117
-
118
- it "should return AccessDenied when not logged in" do
119
- get :allow
120
- response.body.should == 'AccessDenied'
121
- end
122
- end
123
-
124
- describe ACLHelperMethod, :type => :controller do
125
- it "should return OK checking helper method" do
126
- get :allow, :user => FooOwner.new
127
- response.body.should == 'OK'
128
- end
129
-
130
- it "should return AccessDenied when not logged in" do
131
- get :allow
132
- response.body.should == 'AccessDenied'
133
- end
134
- end
135
-
136
- describe "Argument checking" do
137
- def arg_err(&block)
138
- lambda do
139
- block.call
140
- end.should raise_error(ArgumentError)
141
- end
142
-
143
- it "should raise ArgumentError without a block" do
144
- arg_err do
145
- class FailureController < ApplicationController
146
- access_control
147
- end
148
- end
149
- end
150
-
151
- it "should raise ArgumentError with 1st argument which is not a symbol" do
152
- arg_err do
153
- class FailureController < ApplicationController
154
- access_control 123 do end
155
- end
156
- end
157
- end
158
-
159
- it "should raise ArgumentError with more than 1 positional argument" do
160
- arg_err do
161
- class FailureController < ApplicationController
162
- access_control :foo, :bar do end
163
- end
164
- end
165
- end
166
-
167
- it "should raise ArgumentError with :helper => true and no method name" do
168
- arg_err do
169
- class FailureController < ApplicationController
170
- access_control :helper => true do end
171
- end
172
- end
173
- end
174
-
175
- it "should raise ArgumentError with :helper => :method and a method name" do
176
- arg_err do
177
- class FailureController < ApplicationController
178
- access_control :meth, :helper => :another_meth do end
179
- end
180
- end
181
- end
182
- end
@@ -1,48 +0,0 @@
1
- require 'rubygems'
2
- require 'activesupport'
3
- require 'spec'
4
- require 'activerecord'
5
- require 'action_controller'
6
-
7
- require 'action_controller/test_process'
8
- require 'action_controller/integration'
9
-
10
- require 'active_record/fixtures'
11
-
12
- require 'rails/version'
13
-
14
- require 'spec/rails/matchers'
15
- require 'spec/rails/mocks'
16
-
17
- class ApplicationController < ActionController::Base
18
- end
19
-
20
- require 'spec/rails/example'
21
-
22
- begin
23
- require 'spec/rails/extensions'
24
- rescue MissingSourceFile
25
- # it tries to load application.rb
26
- end
27
-
28
- #require 'spec/rails/interop/testcase'
29
-
30
- this_dir = File.dirname(__FILE__)
31
-
32
- RAILS_ROOT = File.join(this_dir, "..")
33
-
34
- ActiveRecord::Base.logger = Logger.new(this_dir + "/debug.log")
35
-
36
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => "#{this_dir}/db/test.sqlite3")
37
-
38
- load(File.join(this_dir, "db", "schema.rb"))
39
-
40
- ActionController::Routing::Routes.draw do |map|
41
- map.connect ":controller/:action/:id"
42
- end
43
-
44
- module Rails
45
- mattr_accessor :logger
46
- end
47
-
48
- Rails.logger = ActiveRecord::Base.logger