heimdallr-resource 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## 1.0.1
4
+
5
+ * load_and_authorize_resource accepts just one hash parameter from now [@_inossidabile][]
6
+
7
+ [@_inossidabile]: http://twitter.com/#!/_inossidabile
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "heimdallr-resource"
6
- s.version = "1.0.0"
6
+ s.version = "1.0.1"
7
7
  s.authors = ["Peter Zotov", "Boris Staal"]
8
8
  s.email = ["whitequark@whitequark.org", "boris@roundlake.ru"]
9
9
  s.homepage = "http://github.com/roundlake/heimdallr-resource"
@@ -4,8 +4,8 @@ module Heimdallr
4
4
 
5
5
  module ResourceImplementation
6
6
  class << self
7
- def prepare_options(klass, resource, options)
8
- options.merge! :resource => (resource || klass.name.sub(/Controller$/, '').underscore)
7
+ def prepare_options(klass, options)
8
+ options.merge! :resource => (options[:resource] || klass.name.sub(/Controller$/, '').underscore).to_s
9
9
 
10
10
  filter_options = {}
11
11
  filter_options[:only] = options.delete(:only) if options.has_key?(:only)
@@ -81,21 +81,21 @@ module Heimdallr
81
81
  extend ActiveSupport::Concern
82
82
 
83
83
  module ClassMethods
84
- def load_and_authorize_resource(resource=nil, options={})
85
- load_resource(resource, options)
86
- authorize_resource(resource, options)
84
+ def load_and_authorize_resource(options={})
85
+ load_resource(options)
86
+ authorize_resource(options)
87
87
  end
88
88
 
89
- def load_resource(resource=nil, options={})
90
- options, filter_options = Heimdallr::ResourceImplementation.prepare_options(self, resource, options)
89
+ def load_resource(options={})
90
+ options, filter_options = Heimdallr::ResourceImplementation.prepare_options(self, options)
91
91
 
92
92
  before_filter filter_options do |controller|
93
93
  Heimdallr::ResourceImplementation.load(controller, options)
94
94
  end
95
95
  end
96
96
 
97
- def authorize_resource(resource=nil, options={})
98
- options, filter_options = Heimdallr::ResourceImplementation.prepare_options(self, resource, options)
97
+ def authorize_resource(options={})
98
+ options, filter_options = Heimdallr::ResourceImplementation.prepare_options(self, options)
99
99
 
100
100
  before_filter filter_options do |controller|
101
101
  Heimdallr::ResourceImplementation.authorize(controller, options)
@@ -0,0 +1,29 @@
1
+ class FluffiesController < ApplicationController
2
+ include Heimdallr::Resource
3
+
4
+ load_and_authorize_resource :resource => :entity
5
+
6
+ def index
7
+ render :nothing => true
8
+ end
9
+
10
+ def new
11
+ render :nothing => true
12
+ end
13
+
14
+ def create
15
+ render :nothing => true
16
+ end
17
+
18
+ def edit
19
+ render :nothing => true
20
+ end
21
+
22
+ def update
23
+ render :nothing => true
24
+ end
25
+
26
+ def destroy
27
+ render :nothing => true
28
+ end
29
+ end
@@ -1,3 +1,4 @@
1
1
  Dummy::Application.routes.draw do
2
2
  resources :entity
3
+ resources :fluffies
3
4
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe FluffiesController, :type => :controller do
4
+ before(:all) do
5
+ @john = User.create! :admin => false
6
+ @maria = User.create! :admin => false
7
+ @admin = User.create! :admin => true
8
+ @private = Entity.create! :name => 'ent1', :public => false
9
+ @public = Entity.create! :name => 'ent1', :public => true, :owner_id => @john.id
10
+ end
11
+
12
+ after(:all) do
13
+ Entity.delete_all
14
+ end
15
+
16
+ it "accepts load_and_authorize_resource params" do
17
+ User.mock @admin
18
+ get :index
19
+
20
+ assigns(:entities).count.should == 2
21
+ end
22
+ end
@@ -9,8 +9,8 @@ describe EntityController, :type => :controller do
9
9
  @public = Entity.create! :name => 'ent1', :public => true, :owner_id => @john.id
10
10
  end
11
11
 
12
- describe "shows everything to admin" do
13
- it "showws everything to the admin" do
12
+ describe "CRUD" do
13
+ it "shows everything to the admin" do
14
14
  User.mock @admin
15
15
  get :index
16
16
 
@@ -38,36 +38,36 @@ describe EntityController, :type => :controller do
38
38
 
39
39
  it "allows update for admin" do
40
40
  User.mock @admin
41
- post :update, {:id => 1}
41
+ post :update, {:id => @private.id}
42
42
 
43
43
  assigns(:entity).should be_kind_of Heimdallr::Proxy::Record
44
- assigns(:entity).id.should == 1
44
+ assigns(:entity).id.should == @private.id
45
45
  end
46
46
 
47
47
  it "disallows update for non-admin" do
48
48
  User.mock @john
49
- expect { post :update, {:id => 2} }.should raise_error
49
+ expect { post :update, {:id => @public.id} }.should raise_error
50
50
  end
51
51
 
52
52
  it "allows destroy for admin" do
53
53
  User.mock @admin
54
- post :destroy, {:id => 1}
54
+ post :destroy, {:id => @private.id}
55
55
 
56
56
  assigns(:entity).should be_kind_of Heimdallr::Proxy::Record
57
- assigns(:entity).id.should == 1
57
+ assigns(:entity).id.should == @private.id
58
58
  end
59
59
 
60
60
  it "allows destroy for owner" do
61
61
  User.mock @john
62
- post :destroy, {:id => 2}
62
+ post :destroy, {:id => @public.id}
63
63
 
64
64
  assigns(:entity).should be_kind_of Heimdallr::Proxy::Record
65
- assigns(:entity).id.should == 2
65
+ assigns(:entity).id.should == @public.id
66
66
  end
67
67
 
68
68
  it "disallows destroy for nobody" do
69
69
  User.mock @maria
70
- expect { post :destroy, {:id => 2} }.should raise_error
70
+ expect { post :destroy, {:id => @public.id} }.should raise_error
71
71
  end
72
72
  end
73
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heimdallr-resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-04 00:00:00.000000000 Z
13
+ date: 2012-04-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec-rails
17
- requirement: &70329699570520 !ruby/object:Gem::Requirement
17
+ requirement: &70267893225580 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70329699570520
25
+ version_requirements: *70267893225580
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activerecord
28
- requirement: &70329699566680 !ruby/object:Gem::Requirement
28
+ requirement: &70267893201220 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70329699566680
36
+ version_requirements: *70267893201220
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: sqlite3
39
- requirement: &70329699553660 !ruby/object:Gem::Requirement
39
+ requirement: &70267893200560 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70329699553660
47
+ version_requirements: *70267893200560
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: tzinfo
50
- requirement: &70329695606560 !ruby/object:Gem::Requirement
50
+ requirement: &70267893199740 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70329695606560
58
+ version_requirements: *70267893199740
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: heimdallr
61
- requirement: &70329695604200 !ruby/object:Gem::Requirement
61
+ requirement: &70267893198820 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,7 +66,7 @@ dependencies:
66
66
  version: '0'
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *70329695604200
69
+ version_requirements: *70267893198820
70
70
  description: Heimdallr-Resource provides CanCan-like interface for Heimdallr-secured
71
71
  objects.
72
72
  email:
@@ -78,6 +78,7 @@ extra_rdoc_files: []
78
78
  files:
79
79
  - .gitignore
80
80
  - .rspec
81
+ - CHANGELOG.md
81
82
  - Gemfile
82
83
  - LICENSE
83
84
  - README.md
@@ -88,6 +89,7 @@ files:
88
89
  - spec/dummy/Rakefile
89
90
  - spec/dummy/app/controllers/application_controller.rb
90
91
  - spec/dummy/app/controllers/entity_controller.rb
92
+ - spec/dummy/app/controllers/fluffies_controller.rb
91
93
  - spec/dummy/app/helpers/application_helper.rb
92
94
  - spec/dummy/app/models/entity.rb
93
95
  - spec/dummy/app/models/user.rb
@@ -113,6 +115,7 @@ files:
113
115
  - spec/dummy/public/favicon.ico
114
116
  - spec/dummy/public/stylesheets/.gitkeep
115
117
  - spec/dummy/script/rails
118
+ - spec/fluffies_spec.rb
116
119
  - spec/resource_spec.rb
117
120
  - spec/spec_helper.rb
118
121
  homepage: http://github.com/roundlake/heimdallr-resource
@@ -143,6 +146,7 @@ test_files:
143
146
  - spec/dummy/Rakefile
144
147
  - spec/dummy/app/controllers/application_controller.rb
145
148
  - spec/dummy/app/controllers/entity_controller.rb
149
+ - spec/dummy/app/controllers/fluffies_controller.rb
146
150
  - spec/dummy/app/helpers/application_helper.rb
147
151
  - spec/dummy/app/models/entity.rb
148
152
  - spec/dummy/app/models/user.rb
@@ -168,5 +172,6 @@ test_files:
168
172
  - spec/dummy/public/favicon.ico
169
173
  - spec/dummy/public/stylesheets/.gitkeep
170
174
  - spec/dummy/script/rails
175
+ - spec/fluffies_spec.rb
171
176
  - spec/resource_spec.rb
172
177
  - spec/spec_helper.rb