heimdallr-resource 1.0.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/.rspec +1 -2
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +9 -5
  4. data/heimdallr-resource.gemspec +4 -3
  5. data/lib/heimdallr-resource.rb +2 -0
  6. data/lib/heimdallr/resource.rb +21 -191
  7. data/lib/heimdallr/resource_implementation.rb +190 -0
  8. data/spec/{resource_spec.rb → controllers/entities_controller_spec.rb} +25 -7
  9. data/spec/controllers/fluffies_controller_spec.rb +20 -0
  10. data/spec/controllers/things_controller_spec.rb +31 -0
  11. data/spec/dummy/app/controllers/{entity_controller.rb → entities_controller.rb} +6 -2
  12. data/spec/dummy/app/controllers/things_controller.rb +29 -0
  13. data/spec/dummy/app/models/entity.rb +2 -0
  14. data/spec/dummy/app/models/thing.rb +16 -0
  15. data/spec/dummy/config/application.rb +1 -1
  16. data/spec/dummy/config/routes.rb +6 -5
  17. data/spec/dummy/db/schema.rb +5 -0
  18. data/spec/models/resource_implementation_spec.rb +382 -0
  19. data/spec/models/resource_spec.rb +91 -0
  20. data/spec/spec_helper.rb +1 -0
  21. metadata +44 -48
  22. data/spec/dummy/Rakefile +0 -7
  23. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  24. data/spec/dummy/config/environments/development.rb +0 -23
  25. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  26. data/spec/dummy/config/initializers/inflections.rb +0 -10
  27. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  28. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  29. data/spec/dummy/config/initializers/session_store.rb +0 -8
  30. data/spec/dummy/config/locales/en.yml +0 -5
  31. data/spec/dummy/public/404.html +0 -26
  32. data/spec/dummy/public/422.html +0 -26
  33. data/spec/dummy/public/500.html +0 -26
  34. data/spec/dummy/public/favicon.ico +0 -0
  35. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  36. data/spec/dummy/script/rails +0 -6
  37. data/spec/fluffies_spec.rb +0 -22
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe Heimdallr::Resource do
4
+
5
+ let(:controller_class) { Class.new }
6
+ let(:controller) { controller_class.new }
7
+
8
+ before do
9
+ controller_class.class_eval do
10
+ include Heimdallr::Resource
11
+ def params
12
+ {}
13
+ end
14
+ end
15
+ end
16
+
17
+ context ".load_resource" do
18
+ it "sets up a before filter which passes the call to ResourceImplementation" do
19
+ mock(controller_class).before_filter({}) { |options, block| block.call(controller) }
20
+ stub(Heimdallr::ResourceImplementation).new(controller, :resource => :entity).mock!.load_resource
21
+ controller_class.load_resource :resource => :entity
22
+ end
23
+
24
+ it "passes relevant options to the filter" do
25
+ mock(controller_class).before_filter(:only => [:create, :update]) { |options, block| block.call(controller) }
26
+ stub(Heimdallr::ResourceImplementation).new(controller, :resource => :entity).mock!.load_resource
27
+ controller_class.load_resource :resource => :entity, :only => [:create, :update]
28
+ end
29
+
30
+ it "figures out the resource name based on the controller name" do
31
+ mock(controller_class).before_filter({}) { |options, block| block.call(controller) }
32
+ stub(Heimdallr::ResourceImplementation).new(controller, :resource => 'entity').mock!.load_resource
33
+ stub(controller_class).name { 'EntitiesController' }
34
+ controller_class.load_resource
35
+ end
36
+
37
+ it "figures out the resource name correctly if the controller is namespaced" do
38
+ mock(controller_class).before_filter({}) { |options, block| block.call(controller) }
39
+ stub(Heimdallr::ResourceImplementation).new(controller, :resource => 'some_project/entity').mock!.load_resource
40
+ stub(controller_class).name { 'SomeProject::EntitiesController' }
41
+ controller_class.load_resource
42
+ end
43
+ end
44
+
45
+ context ".load_and_authorize_resource" do
46
+ it "sets up a before filter which passes the call to ResourceImplementation" do
47
+ mock(controller_class).before_filter({}) { |options, block| block.call(controller) }
48
+ stub(Heimdallr::ResourceImplementation).new(controller, :resource => :entity).mock!.load_and_authorize_resource
49
+ controller_class.load_and_authorize_resource :resource => :entity
50
+ end
51
+
52
+ it "passes relevant options to the filter" do
53
+ mock(controller_class).before_filter(:except => :index) { |options, block| block.call(controller) }
54
+ stub(Heimdallr::ResourceImplementation).new(controller, :resource => :entity).mock!.load_and_authorize_resource
55
+ controller_class.load_and_authorize_resource :resource => :entity, :except => :index
56
+ end
57
+ end
58
+
59
+ context ".skip_authorization_check" do
60
+ it "prepends a before filter which sets controller's instance variable to true" do
61
+ mock(controller_class).prepend_before_filter({}) { |options, block| block.call(controller) }
62
+ controller_class.skip_authorization_check
63
+ controller.instance_variable_get(:@_skip_authorization_check).should be_true
64
+ end
65
+
66
+ it "passes options to the filter" do
67
+ mock(controller_class).prepend_before_filter({:only => :show}) { |options, block| block.call(controller) }
68
+ controller_class.skip_authorization_check :only => :show
69
+ end
70
+
71
+ it "makes #skip_authorization_check? return true" do
72
+ mock(controller_class).prepend_before_filter({}) { |options, block| block.call(controller) }
73
+ controller_class.skip_authorization_check
74
+ controller.send(:skip_authorization_check?).should be_true
75
+ end
76
+ end
77
+
78
+ context "heimdallr_options" do
79
+ it "stores options in class attribute" do
80
+ controller_subclass = Class.new(controller_class)
81
+ controller_subsubclass = Class.new(controller_subclass)
82
+ options1 = {:option => 1}
83
+ options2 = {:option => 2}
84
+ controller_subclass.send :own_heimdallr_options=, options1
85
+ controller_subsubclass.send :own_heimdallr_options=, options2
86
+ controller_subclass.heimdallr_options.should == options1
87
+ controller_subsubclass.heimdallr_options.should == options2
88
+ controller_class.respond_to?(:heimdallr_options).should be_false
89
+ end
90
+ end
91
+ end
@@ -13,4 +13,5 @@ RSpec.configure do |config|
13
13
  config.treat_symbols_as_metadata_keys_with_true_values = true
14
14
  config.run_all_when_everything_filtered = true
15
15
  config.filter_run :focus
16
+ config.mock_with :rr
16
17
  end
metadata CHANGED
@@ -1,20 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heimdallr-resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Peter Zotov
9
9
  - Boris Staal
10
+ - Alexander Pavlenko
11
+ - Shamil Fattakhov
10
12
  autorequire:
11
13
  bindir: bin
12
14
  cert_chain: []
13
- date: 2012-05-27 00:00:00.000000000 Z
15
+ date: 2012-12-13 00:00:00.000000000 Z
14
16
  dependencies:
15
17
  - !ruby/object:Gem::Dependency
16
18
  name: rspec-rails
17
- requirement: &70177728312580 !ruby/object:Gem::Requirement
19
+ requirement: &70153342340180 !ruby/object:Gem::Requirement
18
20
  none: false
19
21
  requirements:
20
22
  - - ! '>='
@@ -22,10 +24,21 @@ dependencies:
22
24
  version: '0'
23
25
  type: :development
24
26
  prerelease: false
25
- version_requirements: *70177728312580
27
+ version_requirements: *70153342340180
28
+ - !ruby/object:Gem::Dependency
29
+ name: rr
30
+ requirement: &70153342339680 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: *70153342339680
26
39
  - !ruby/object:Gem::Dependency
27
40
  name: activerecord
28
- requirement: &70177728312140 !ruby/object:Gem::Requirement
41
+ requirement: &70153342339200 !ruby/object:Gem::Requirement
29
42
  none: false
30
43
  requirements:
31
44
  - - ! '>='
@@ -33,10 +46,10 @@ dependencies:
33
46
  version: '0'
34
47
  type: :development
35
48
  prerelease: false
36
- version_requirements: *70177728312140
49
+ version_requirements: *70153342339200
37
50
  - !ruby/object:Gem::Dependency
38
51
  name: sqlite3
39
- requirement: &70177728311720 !ruby/object:Gem::Requirement
52
+ requirement: &70153342338720 !ruby/object:Gem::Requirement
40
53
  none: false
41
54
  requirements:
42
55
  - - ! '>='
@@ -44,10 +57,10 @@ dependencies:
44
57
  version: '0'
45
58
  type: :development
46
59
  prerelease: false
47
- version_requirements: *70177728311720
60
+ version_requirements: *70153342338720
48
61
  - !ruby/object:Gem::Dependency
49
62
  name: tzinfo
50
- requirement: &70177728311300 !ruby/object:Gem::Requirement
63
+ requirement: &70153342338240 !ruby/object:Gem::Requirement
51
64
  none: false
52
65
  requirements:
53
66
  - - ! '>='
@@ -55,10 +68,10 @@ dependencies:
55
68
  version: '0'
56
69
  type: :development
57
70
  prerelease: false
58
- version_requirements: *70177728311300
71
+ version_requirements: *70153342338240
59
72
  - !ruby/object:Gem::Dependency
60
73
  name: heimdallr
61
- requirement: &70177728310880 !ruby/object:Gem::Requirement
74
+ requirement: &70153342337820 !ruby/object:Gem::Requirement
62
75
  none: false
63
76
  requirements:
64
77
  - - ! '>='
@@ -66,12 +79,13 @@ dependencies:
66
79
  version: '0'
67
80
  type: :runtime
68
81
  prerelease: false
69
- version_requirements: *70177728310880
82
+ version_requirements: *70153342337820
70
83
  description: Heimdallr-Resource provides CanCan-like interface for Heimdallr-secured
71
84
  objects.
72
85
  email:
73
86
  - whitequark@whitequark.org
74
87
  - boris@roundlake.ru
88
+ - a.pavlenko@roundlake.ru
75
89
  executables: []
76
90
  extensions: []
77
91
  extra_rdoc_files: []
@@ -84,14 +98,19 @@ files:
84
98
  - README.md
85
99
  - Rakefile
86
100
  - heimdallr-resource.gemspec
101
+ - lib/heimdallr-resource.rb
87
102
  - lib/heimdallr/resource.rb
103
+ - lib/heimdallr/resource_implementation.rb
88
104
  - spec/.gitignore
89
- - spec/dummy/Rakefile
105
+ - spec/controllers/entities_controller_spec.rb
106
+ - spec/controllers/fluffies_controller_spec.rb
107
+ - spec/controllers/things_controller_spec.rb
90
108
  - spec/dummy/app/controllers/application_controller.rb
91
- - spec/dummy/app/controllers/entity_controller.rb
109
+ - spec/dummy/app/controllers/entities_controller.rb
92
110
  - spec/dummy/app/controllers/fluffies_controller.rb
93
- - spec/dummy/app/helpers/application_helper.rb
111
+ - spec/dummy/app/controllers/things_controller.rb
94
112
  - spec/dummy/app/models/entity.rb
113
+ - spec/dummy/app/models/thing.rb
95
114
  - spec/dummy/app/models/user.rb
96
115
  - spec/dummy/app/views/layouts/application.html.erb
97
116
  - spec/dummy/config.ru
@@ -99,24 +118,11 @@ files:
99
118
  - spec/dummy/config/boot.rb
100
119
  - spec/dummy/config/database.yml
101
120
  - spec/dummy/config/environment.rb
102
- - spec/dummy/config/environments/development.rb
103
121
  - spec/dummy/config/environments/test.rb
104
- - spec/dummy/config/initializers/backtrace_silencers.rb
105
- - spec/dummy/config/initializers/inflections.rb
106
- - spec/dummy/config/initializers/mime_types.rb
107
- - spec/dummy/config/initializers/secret_token.rb
108
- - spec/dummy/config/initializers/session_store.rb
109
- - spec/dummy/config/locales/en.yml
110
122
  - spec/dummy/config/routes.rb
111
123
  - spec/dummy/db/schema.rb
112
- - spec/dummy/public/404.html
113
- - spec/dummy/public/422.html
114
- - spec/dummy/public/500.html
115
- - spec/dummy/public/favicon.ico
116
- - spec/dummy/public/stylesheets/.gitkeep
117
- - spec/dummy/script/rails
118
- - spec/fluffies_spec.rb
119
- - spec/resource_spec.rb
124
+ - spec/models/resource_implementation_spec.rb
125
+ - spec/models/resource_spec.rb
120
126
  - spec/spec_helper.rb
121
127
  homepage: http://github.com/roundlake/heimdallr-resource
122
128
  licenses: []
@@ -143,12 +149,15 @@ signing_key:
143
149
  specification_version: 3
144
150
  summary: Heimdallr-Resource provides CanCan-like interface for Heimdallr-secured objects.
145
151
  test_files:
146
- - spec/dummy/Rakefile
152
+ - spec/controllers/entities_controller_spec.rb
153
+ - spec/controllers/fluffies_controller_spec.rb
154
+ - spec/controllers/things_controller_spec.rb
147
155
  - spec/dummy/app/controllers/application_controller.rb
148
- - spec/dummy/app/controllers/entity_controller.rb
156
+ - spec/dummy/app/controllers/entities_controller.rb
149
157
  - spec/dummy/app/controllers/fluffies_controller.rb
150
- - spec/dummy/app/helpers/application_helper.rb
158
+ - spec/dummy/app/controllers/things_controller.rb
151
159
  - spec/dummy/app/models/entity.rb
160
+ - spec/dummy/app/models/thing.rb
152
161
  - spec/dummy/app/models/user.rb
153
162
  - spec/dummy/app/views/layouts/application.html.erb
154
163
  - spec/dummy/config.ru
@@ -156,22 +165,9 @@ test_files:
156
165
  - spec/dummy/config/boot.rb
157
166
  - spec/dummy/config/database.yml
158
167
  - spec/dummy/config/environment.rb
159
- - spec/dummy/config/environments/development.rb
160
168
  - spec/dummy/config/environments/test.rb
161
- - spec/dummy/config/initializers/backtrace_silencers.rb
162
- - spec/dummy/config/initializers/inflections.rb
163
- - spec/dummy/config/initializers/mime_types.rb
164
- - spec/dummy/config/initializers/secret_token.rb
165
- - spec/dummy/config/initializers/session_store.rb
166
- - spec/dummy/config/locales/en.yml
167
169
  - spec/dummy/config/routes.rb
168
170
  - spec/dummy/db/schema.rb
169
- - spec/dummy/public/404.html
170
- - spec/dummy/public/422.html
171
- - spec/dummy/public/500.html
172
- - spec/dummy/public/favicon.ico
173
- - spec/dummy/public/stylesheets/.gitkeep
174
- - spec/dummy/script/rails
175
- - spec/fluffies_spec.rb
176
- - spec/resource_spec.rb
171
+ - spec/models/resource_implementation_spec.rb
172
+ - spec/models/resource_spec.rb
177
173
  - spec/spec_helper.rb
@@ -1,7 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require File.expand_path('../config/application', __FILE__)
5
- require 'rake'
6
-
7
- Dummy::Application.load_tasks
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
@@ -1,23 +0,0 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
6
- # since you don't have to restart the webserver when you make code changes.
7
- config.cache_classes = false
8
-
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
11
-
12
- # Show full error reports and disable caching
13
- config.consider_all_requests_local = true
14
- config.action_view.debug_rjs = true
15
- config.action_controller.perform_caching = false
16
-
17
- # Print deprecation notices to the Rails logger
18
- config.active_support.deprecation = :log
19
-
20
- # Only use best-standards-support built into browsers
21
- config.action_dispatch.best_standards_support = :builtin
22
- end
23
-
@@ -1,7 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
- # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
-
6
- # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
- # Rails.backtrace_cleaner.remove_silencers!
@@ -1,10 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Add new inflection rules using the following format
4
- # (all these examples are active by default):
5
- # ActiveSupport::Inflector.inflections do |inflect|
6
- # inflect.plural /^(ox)$/i, '\1en'
7
- # inflect.singular /^(ox)en/i, '\1'
8
- # inflect.irregular 'person', 'people'
9
- # inflect.uncountable %w( fish sheep )
10
- # end
@@ -1,5 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Add new mime types for use in respond_to blocks:
4
- # Mime::Type.register "text/richtext", :rtf
5
- # Mime::Type.register_alias "text/html", :iphone
@@ -1,7 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Your secret key for verifying the integrity of signed cookies.
4
- # If you change this key, all old signed cookies will become invalid!
5
- # Make sure the secret is at least 30 characters and all random,
6
- # no regular words or you'll be exposed to dictionary attacks.
7
- Dummy::Application.config.secret_token = 'b8d5d5687c012c2ef1a7a6e8006172402c48a3dcccca67c076eaad81c4712ad236ca2717c3706df7b286468c749d223f22acb0d96c27bdf33bbdbb9684ad46e5'
@@ -1,8 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
-
5
- # Use the database for sessions instead of the cookie-based default,
6
- # which shouldn't be used to store highly confidential information
7
- # (create the session table with "rails generate session_migration")
8
- # Dummy::Application.config.session_store :active_record_store
@@ -1,5 +0,0 @@
1
- # Sample localization file for English. Add more files in this directory for other locales.
2
- # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
-
4
- en:
5
- hello: "Hello world"
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>The page you were looking for doesn't exist (404)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/404.html -->
21
- <div class="dialog">
22
- <h1>The page you were looking for doesn't exist.</h1>
23
- <p>You may have mistyped the address or the page may have moved.</p>
24
- </div>
25
- </body>
26
- </html>
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>The change you wanted was rejected (422)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/422.html -->
21
- <div class="dialog">
22
- <h1>The change you wanted was rejected.</h1>
23
- <p>Maybe you tried to change something you didn't have access to.</p>
24
- </div>
25
- </body>
26
- </html>
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>We're sorry, but something went wrong (500)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/500.html -->
21
- <div class="dialog">
22
- <h1>We're sorry, but something went wrong.</h1>
23
- <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
- </div>
25
- </body>
26
- </html>