walruz-rails 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/walruz/controller_mixin.rb +1 -1
- data/rails_generators/templates/policy_spec.rb +3 -7
- data/rails_generators/templates/policy_test.rb +5 -7
- data/rails_generators/templates/spec_task.rake +21 -0
- data/rails_generators/templates/test_task.rake +10 -0
- data/rails_generators/walruz_generator.rb +8 -3
- metadata +4 -2
@@ -62,7 +62,7 @@ module Walruz
|
|
62
62
|
error_message = "There is neither an instance variable @%s nor a instance method %s on the %s instance context" % [subject, subject, controller.class.name]
|
63
63
|
raise ArgumentError.new(error_message)
|
64
64
|
end
|
65
|
-
params = Walruz
|
65
|
+
params = Walruz.authorize!(controller.send(:current_user), action, subject_instance)
|
66
66
|
controller.set_policy_params!(params)
|
67
67
|
end
|
68
68
|
end
|
@@ -5,10 +5,6 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
5
5
|
|
6
6
|
describe Policies::<%= class_name %> do
|
7
7
|
|
8
|
-
before(:each) do
|
9
|
-
@policy = Policies::<%= class_name %>.new
|
10
|
-
end
|
11
|
-
|
12
8
|
describe "with valid actor and subject" do
|
13
9
|
|
14
10
|
before(:each) do
|
@@ -17,7 +13,7 @@ describe Policies::<%= class_name %> do
|
|
17
13
|
|
18
14
|
it "should return true" do
|
19
15
|
pending
|
20
|
-
#
|
16
|
+
# Walruz.satisfies?(@actor, :<%= file_name %>, @subject).should be_true
|
21
17
|
end
|
22
18
|
|
23
19
|
end
|
@@ -30,9 +26,9 @@ describe Policies::<%= class_name %> do
|
|
30
26
|
|
31
27
|
it "should return false" do
|
32
28
|
pending
|
33
|
-
#
|
29
|
+
# Walruz.satisfies?(@actor, :<%= file_name %>, @subject).should be_false
|
34
30
|
end
|
35
31
|
|
36
32
|
end
|
37
33
|
|
38
|
-
end
|
34
|
+
end
|
@@ -6,17 +6,15 @@
|
|
6
6
|
class Policies::<%= class_name %>Test < Test::Unit
|
7
7
|
|
8
8
|
def setup
|
9
|
-
|
9
|
+
# setup associations btw actor and subject
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def test_return_true_with_valid_association_of_actor_and_subject
|
13
|
-
#
|
14
|
-
# assert !@policy.safe_authorized?(actor, subject)[0]
|
13
|
+
# assert Walruz.satisfies?(actor, :<%= file_name %>, subject)
|
15
14
|
end
|
16
15
|
|
17
16
|
def test_return_false_with_invalid_association_of_actor_and_subject
|
18
|
-
#
|
19
|
-
# assert @policy.safe_authorized?(actor, subject)[0]
|
17
|
+
# assert !Walruz.satisfies?(actor, :<%= file_name %>, subject)
|
20
18
|
end
|
21
19
|
|
22
|
-
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Generate rSpec tasks
|
2
|
+
begin
|
3
|
+
require "spec/rake/spectask"
|
4
|
+
rescue MissingSourceFile
|
5
|
+
raise <<-MSG
|
6
|
+
I tried to generate some spec rake tasks for you, but it seems you have some problem with
|
7
|
+
your rSpec installation, please check and try again.
|
8
|
+
MSG
|
9
|
+
else
|
10
|
+
spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :walruz_noop
|
11
|
+
task :walruz_noop do
|
12
|
+
end
|
13
|
+
namespace :spec do
|
14
|
+
desc "Run all walruz policies specs in spec/policies"
|
15
|
+
Spec::Rake::SpecTask.new(:policies => spec_prereq) do |t|
|
16
|
+
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
|
17
|
+
t.spec_files = FileList["spec/policies/**/*_spec.rb"]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Generate Test::Unit tasks
|
2
|
+
require "rake/testtask"
|
3
|
+
namespace :test do
|
4
|
+
Rake::TestTask.new(:policies => "db:test:prepare") do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.pattern = 'test/policies/**/*_test.rb'
|
7
|
+
t.verbose = true
|
8
|
+
end
|
9
|
+
Rake::Task['test:policies'].comment = "Run all walruz policies tests in test/policies"
|
10
|
+
end
|
@@ -2,7 +2,6 @@ class WalruzGenerator < Rails::Generator::Base
|
|
2
2
|
|
3
3
|
def manifest
|
4
4
|
record do |m|
|
5
|
-
m.directory 'config/initializers'
|
6
5
|
m.file('walruz_initializer.rb', 'config/initializers/walruz_initializer.rb')
|
7
6
|
|
8
7
|
m.directory 'lib/walruz'
|
@@ -10,7 +9,13 @@ class WalruzGenerator < Rails::Generator::Base
|
|
10
9
|
m.file('policies.rb', 'lib/walruz/policies.rb')
|
11
10
|
m.file('actor_is_subject_example.rb', 'lib/walruz/policies/actor_is_subject.rb')
|
12
11
|
|
13
|
-
|
12
|
+
task_template_name = if File.exists?(File.join(Rails.root, "spec"))
|
13
|
+
'spec_task.rake'
|
14
|
+
else
|
15
|
+
'test_task.rake'
|
16
|
+
end
|
17
|
+
m.file(task_template_name, 'lib/tasks/walruz.rake')
|
18
|
+
|
14
19
|
m.file('unauthorized.html', 'public/unauthorized.html')
|
15
20
|
end
|
16
21
|
end
|
@@ -19,4 +24,4 @@ class WalruzGenerator < Rails::Generator::Base
|
|
19
24
|
"Usage: #{$0} walruz"
|
20
25
|
end
|
21
26
|
|
22
|
-
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: walruz-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Gonzalez
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-25 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -103,6 +103,8 @@ files:
|
|
103
103
|
- rails_generators/templates/policy.rb
|
104
104
|
- rails_generators/templates/policy_spec.rb
|
105
105
|
- rails_generators/templates/policy_test.rb
|
106
|
+
- rails_generators/templates/spec_task.rake
|
107
|
+
- rails_generators/templates/test_task.rake
|
106
108
|
- rails_generators/templates/unauthorized.html
|
107
109
|
- rails_generators/templates/walruz_initializer.rb
|
108
110
|
- rails_generators/walruz_generator.rb
|