heimdallr-resource 1.0.0.RC1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -16
- data/README.md +7 -19
- data/Rakefile +7 -1
- data/heimdallr-resource.gemspec +5 -3
- data/lib/heimdallr/resource.rb +11 -7
- data/spec/.gitignore +1 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +7 -0
- data/spec/dummy/app/controllers/entity_controller.rb +29 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/entity.rb +14 -0
- data/spec/dummy/app/models/user.rb +9 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +43 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +5 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +23 -0
- data/spec/dummy/config/environments/test.rb +30 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/db/schema.rb +11 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/resource_spec.rb +73 -0
- data/spec/spec_helper.rb +10 -5
- metadata +102 -10
data/LICENSE
CHANGED
@@ -1,19 +1,22 @@
|
|
1
|
-
|
1
|
+
The MIT License
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
the Software without restriction, including without limitation the rights to
|
6
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
-
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
-
so, subject to the following conditions:
|
3
|
+
Copyright (c) 2012 Round Lake, inc.,
|
4
|
+
Peter Zotov <whitequark@whitequark.org>.
|
9
5
|
|
10
|
-
|
11
|
-
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
14
|
+
all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -43,27 +43,15 @@ is performed by Heimdallr Resource.
|
|
43
43
|
`authorize_resource` verifies if the current security context allows for creating or updating the records.
|
44
44
|
The checks are performed for `new`, `create`, `edit` and `update` actions.
|
45
45
|
|
46
|
-
|
46
|
+
Credits
|
47
47
|
-------
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
Funded by Round Lake.
|
49
|
+
<img src="http://roundlake.ru/assets/logo.png" align="right" />
|
52
50
|
|
53
|
-
|
54
|
-
|
55
|
-
the Software without restriction, including without limitation the rights to
|
56
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
57
|
-
of the Software, and to permit persons to whom the Software is furnished to do
|
58
|
-
so, subject to the following conditions:
|
51
|
+
* Peter Zotov ([@whitequark](http://twitter.com/#!/whitequark))
|
52
|
+
* Boris Staal ([@_inossidabile](http://twitter.com/#!/_inossidabile))
|
59
53
|
|
60
|
-
|
61
|
-
|
54
|
+
LICENSE
|
55
|
+
-------
|
62
56
|
|
63
|
-
|
64
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
65
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
66
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
67
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
68
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
69
|
-
SOFTWARE.
|
57
|
+
It is free software, and may be redistributed under the terms of MIT license.
|
data/Rakefile
CHANGED
data/heimdallr-resource.gemspec
CHANGED
@@ -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.0"
|
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"
|
@@ -15,7 +15,9 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
|
18
|
-
|
19
|
-
s.add_development_dependency "
|
18
|
+
s.add_development_dependency "rspec-rails"
|
19
|
+
s.add_development_dependency "activerecord"
|
20
|
+
s.add_development_dependency "sqlite3"
|
21
|
+
s.add_development_dependency "tzinfo"
|
20
22
|
s.add_runtime_dependency "heimdallr"
|
21
23
|
end
|
data/lib/heimdallr/resource.rb
CHANGED
@@ -5,7 +5,7 @@ module Heimdallr
|
|
5
5
|
module ResourceImplementation
|
6
6
|
class << self
|
7
7
|
def prepare_options(klass, resource, options)
|
8
|
-
options.merge! :resource => (resource || klass.name.
|
8
|
+
options.merge! :resource => (resource || klass.name.sub(/Controller$/, '').underscore)
|
9
9
|
|
10
10
|
filter_options = {}
|
11
11
|
filter_options[:only] = options.delete(:only) if options.has_key?(:only)
|
@@ -25,19 +25,19 @@ module Heimdallr
|
|
25
25
|
send(:"#{options[:resource].pluralize}")
|
26
26
|
end
|
27
27
|
else
|
28
|
-
scope = options[:resource].constantize.scoped
|
28
|
+
scope = options[:resource].camelize.constantize.scoped
|
29
29
|
end
|
30
30
|
|
31
31
|
case controller.params[:action]
|
32
32
|
when 'index'
|
33
33
|
controller.instance_variable_set(ivar_name(controller, options), scope)
|
34
34
|
when 'new', 'create'
|
35
|
-
controller.instance_variable_set(ivar_name(controller, options,
|
36
|
-
scope.new(controller.params[options[:resource]]))
|
35
|
+
controller.instance_variable_set(ivar_name(controller, options),
|
36
|
+
scope.new(controller.params[options[:resource]]))
|
37
37
|
when 'show', 'edit', 'update', 'destroy'
|
38
|
-
controller.instance_variable_set(ivar_name(controller, options,
|
38
|
+
controller.instance_variable_set(ivar_name(controller, options),
|
39
39
|
scope.find(controller.params[:"#{options[:resource]}_id"] ||
|
40
|
-
controller.params[:id]))
|
40
|
+
controller.params[:id]))
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -59,6 +59,10 @@ module Heimdallr
|
|
59
59
|
unless value.reflect_on_security[:operations].include? :update
|
60
60
|
raise Heimdallr::AccessDenied, "Cannot update model"
|
61
61
|
end
|
62
|
+
when 'destroy'
|
63
|
+
unless value.destroyable?
|
64
|
+
raise Heimdallr::AccessDenied, "Cannot delete model"
|
65
|
+
end
|
62
66
|
end
|
63
67
|
end
|
64
68
|
|
@@ -77,7 +81,7 @@ module Heimdallr
|
|
77
81
|
extend ActiveSupport::Concern
|
78
82
|
|
79
83
|
module ClassMethods
|
80
|
-
def load_and_authorize_resource(resource, options={})
|
84
|
+
def load_and_authorize_resource(resource=nil, options={})
|
81
85
|
load_resource(resource, options)
|
82
86
|
authorize_resource(resource, options)
|
83
87
|
end
|
data/spec/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.log
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
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
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class EntityController < ApplicationController
|
2
|
+
include Heimdallr::Resource
|
3
|
+
|
4
|
+
load_and_authorize_resource
|
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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Entity < ActiveRecord::Base
|
2
|
+
include Heimdallr::Model
|
3
|
+
|
4
|
+
restrict do |user, record|
|
5
|
+
if user.admin
|
6
|
+
scope :fetch
|
7
|
+
scope :delete
|
8
|
+
can [:view, :create, :update]
|
9
|
+
else
|
10
|
+
scope :fetch, -> { where('public = ? or owner_id = ?', true, user.id) }
|
11
|
+
scope :delete, -> { where('owner_id = ?', user.id) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require "rails/all"
|
4
|
+
|
5
|
+
Bundler.require(:default, Rails.env)
|
6
|
+
|
7
|
+
require "heimdallr"
|
8
|
+
require "heimdallr/resource"
|
9
|
+
|
10
|
+
module Dummy
|
11
|
+
class Application < Rails::Application
|
12
|
+
# Settings in config/environments/* take precedence over those specified here.
|
13
|
+
# Application configuration should go into files in config/initializers
|
14
|
+
# -- all .rb files in that directory are automatically loaded.
|
15
|
+
|
16
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
17
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
18
|
+
|
19
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
20
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
21
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
22
|
+
|
23
|
+
# Activate observers that should always be running.
|
24
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
25
|
+
|
26
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
27
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
28
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
29
|
+
|
30
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
31
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
32
|
+
# config.i18n.default_locale = :de
|
33
|
+
|
34
|
+
# JavaScript files you want as :defaults (application.js is always included).
|
35
|
+
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
36
|
+
|
37
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
38
|
+
config.encoding = "utf-8"
|
39
|
+
|
40
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
41
|
+
config.filter_parameters += [:password]
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,23 @@
|
|
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
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Log error messages when you accidentally call methods on nil.
|
11
|
+
config.whiny_nils = true
|
12
|
+
|
13
|
+
# Show full error reports and disable caching
|
14
|
+
config.consider_all_requests_local = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Raise exceptions instead of rendering exception templates
|
18
|
+
config.action_dispatch.show_exceptions = false
|
19
|
+
|
20
|
+
# Disable request forgery protection in test environment
|
21
|
+
config.action_controller.allow_forgery_protection = false
|
22
|
+
|
23
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
24
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
25
|
+
# like if you have constraints or database-specific column types
|
26
|
+
# config.active_record.schema_format = :sql
|
27
|
+
|
28
|
+
# Print deprecation notices to the stderr
|
29
|
+
config.active_support.deprecation = :stderr
|
30
|
+
end
|
@@ -0,0 +1,7 @@
|
|
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!
|
@@ -0,0 +1,10 @@
|
|
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
|
@@ -0,0 +1,7 @@
|
|
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'
|
@@ -0,0 +1,8 @@
|
|
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
|
@@ -0,0 +1,26 @@
|
|
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>
|
@@ -0,0 +1,26 @@
|
|
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>
|
@@ -0,0 +1,26 @@
|
|
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>
|
File without changes
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EntityController, :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
|
+
describe "shows everything to admin" do
|
13
|
+
it "showws everything to the admin" do
|
14
|
+
User.mock @admin
|
15
|
+
get :index
|
16
|
+
|
17
|
+
assigns(:entities).count.should == 2
|
18
|
+
end
|
19
|
+
|
20
|
+
it "hides non-public entities" do
|
21
|
+
User.mock @john
|
22
|
+
get :index
|
23
|
+
|
24
|
+
assigns(:entities).count.should == 1
|
25
|
+
end
|
26
|
+
|
27
|
+
it "allows creation for admin" do
|
28
|
+
User.mock @admin
|
29
|
+
post :create, {}
|
30
|
+
|
31
|
+
assigns(:entity).should be_kind_of Heimdallr::Proxy::Record
|
32
|
+
end
|
33
|
+
|
34
|
+
it "disallows creation for non-admin" do
|
35
|
+
User.mock @john
|
36
|
+
expect { post :create, {} }.should raise_error
|
37
|
+
end
|
38
|
+
|
39
|
+
it "allows update for admin" do
|
40
|
+
User.mock @admin
|
41
|
+
post :update, {:id => 1}
|
42
|
+
|
43
|
+
assigns(:entity).should be_kind_of Heimdallr::Proxy::Record
|
44
|
+
assigns(:entity).id.should == 1
|
45
|
+
end
|
46
|
+
|
47
|
+
it "disallows update for non-admin" do
|
48
|
+
User.mock @john
|
49
|
+
expect { post :update, {:id => 2} }.should raise_error
|
50
|
+
end
|
51
|
+
|
52
|
+
it "allows destroy for admin" do
|
53
|
+
User.mock @admin
|
54
|
+
post :destroy, {:id => 1}
|
55
|
+
|
56
|
+
assigns(:entity).should be_kind_of Heimdallr::Proxy::Record
|
57
|
+
assigns(:entity).id.should == 1
|
58
|
+
end
|
59
|
+
|
60
|
+
it "allows destroy for owner" do
|
61
|
+
User.mock @john
|
62
|
+
post :destroy, {:id => 2}
|
63
|
+
|
64
|
+
assigns(:entity).should be_kind_of Heimdallr::Proxy::Record
|
65
|
+
assigns(:entity).id.should == 2
|
66
|
+
end
|
67
|
+
|
68
|
+
it "disallows destroy for nobody" do
|
69
|
+
User.mock @maria
|
70
|
+
expect { post :destroy, {:id => 2} }.should raise_error
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
# Configure Rails Envinronment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
require "rspec/rails"
|
7
|
+
load File.expand_path("../dummy/db/schema.rb", __FILE__)
|
8
|
+
|
9
|
+
Rails.backtrace_cleaner.remove_silencers!
|
10
|
+
|
6
11
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
12
|
RSpec.configure do |config|
|
8
13
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heimdallr-resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Peter Zotov
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-04-
|
13
|
+
date: 2012-04-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name: rspec
|
17
|
-
requirement: &
|
16
|
+
name: rspec-rails
|
17
|
+
requirement: &70329699570520 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,43 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70329699570520
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: activerecord
|
28
|
+
requirement: &70329699566680 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70329699566680
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: sqlite3
|
39
|
+
requirement: &70329699553660 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70329699553660
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: tzinfo
|
50
|
+
requirement: &70329695606560 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70329695606560
|
26
59
|
- !ruby/object:Gem::Dependency
|
27
60
|
name: heimdallr
|
28
|
-
requirement: &
|
61
|
+
requirement: &70329695604200 !ruby/object:Gem::Requirement
|
29
62
|
none: false
|
30
63
|
requirements:
|
31
64
|
- - ! '>='
|
@@ -33,7 +66,7 @@ dependencies:
|
|
33
66
|
version: '0'
|
34
67
|
type: :runtime
|
35
68
|
prerelease: false
|
36
|
-
version_requirements: *
|
69
|
+
version_requirements: *70329695604200
|
37
70
|
description: Heimdallr-Resource provides CanCan-like interface for Heimdallr-secured
|
38
71
|
objects.
|
39
72
|
email:
|
@@ -51,6 +84,36 @@ files:
|
|
51
84
|
- Rakefile
|
52
85
|
- heimdallr-resource.gemspec
|
53
86
|
- lib/heimdallr/resource.rb
|
87
|
+
- spec/.gitignore
|
88
|
+
- spec/dummy/Rakefile
|
89
|
+
- spec/dummy/app/controllers/application_controller.rb
|
90
|
+
- spec/dummy/app/controllers/entity_controller.rb
|
91
|
+
- spec/dummy/app/helpers/application_helper.rb
|
92
|
+
- spec/dummy/app/models/entity.rb
|
93
|
+
- spec/dummy/app/models/user.rb
|
94
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
95
|
+
- spec/dummy/config.ru
|
96
|
+
- spec/dummy/config/application.rb
|
97
|
+
- spec/dummy/config/boot.rb
|
98
|
+
- spec/dummy/config/database.yml
|
99
|
+
- spec/dummy/config/environment.rb
|
100
|
+
- spec/dummy/config/environments/development.rb
|
101
|
+
- spec/dummy/config/environments/test.rb
|
102
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
103
|
+
- spec/dummy/config/initializers/inflections.rb
|
104
|
+
- spec/dummy/config/initializers/mime_types.rb
|
105
|
+
- spec/dummy/config/initializers/secret_token.rb
|
106
|
+
- spec/dummy/config/initializers/session_store.rb
|
107
|
+
- spec/dummy/config/locales/en.yml
|
108
|
+
- spec/dummy/config/routes.rb
|
109
|
+
- spec/dummy/db/schema.rb
|
110
|
+
- spec/dummy/public/404.html
|
111
|
+
- spec/dummy/public/422.html
|
112
|
+
- spec/dummy/public/500.html
|
113
|
+
- spec/dummy/public/favicon.ico
|
114
|
+
- spec/dummy/public/stylesheets/.gitkeep
|
115
|
+
- spec/dummy/script/rails
|
116
|
+
- spec/resource_spec.rb
|
54
117
|
- spec/spec_helper.rb
|
55
118
|
homepage: http://github.com/roundlake/heimdallr-resource
|
56
119
|
licenses: []
|
@@ -67,9 +130,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
131
|
none: false
|
69
132
|
requirements:
|
70
|
-
- - ! '
|
133
|
+
- - ! '>='
|
71
134
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
135
|
+
version: '0'
|
73
136
|
requirements: []
|
74
137
|
rubyforge_project:
|
75
138
|
rubygems_version: 1.8.15
|
@@ -77,4 +140,33 @@ signing_key:
|
|
77
140
|
specification_version: 3
|
78
141
|
summary: Heimdallr-Resource provides CanCan-like interface for Heimdallr-secured objects.
|
79
142
|
test_files:
|
143
|
+
- spec/dummy/Rakefile
|
144
|
+
- spec/dummy/app/controllers/application_controller.rb
|
145
|
+
- spec/dummy/app/controllers/entity_controller.rb
|
146
|
+
- spec/dummy/app/helpers/application_helper.rb
|
147
|
+
- spec/dummy/app/models/entity.rb
|
148
|
+
- spec/dummy/app/models/user.rb
|
149
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
150
|
+
- spec/dummy/config.ru
|
151
|
+
- spec/dummy/config/application.rb
|
152
|
+
- spec/dummy/config/boot.rb
|
153
|
+
- spec/dummy/config/database.yml
|
154
|
+
- spec/dummy/config/environment.rb
|
155
|
+
- spec/dummy/config/environments/development.rb
|
156
|
+
- spec/dummy/config/environments/test.rb
|
157
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
158
|
+
- spec/dummy/config/initializers/inflections.rb
|
159
|
+
- spec/dummy/config/initializers/mime_types.rb
|
160
|
+
- spec/dummy/config/initializers/secret_token.rb
|
161
|
+
- spec/dummy/config/initializers/session_store.rb
|
162
|
+
- spec/dummy/config/locales/en.yml
|
163
|
+
- spec/dummy/config/routes.rb
|
164
|
+
- spec/dummy/db/schema.rb
|
165
|
+
- spec/dummy/public/404.html
|
166
|
+
- spec/dummy/public/422.html
|
167
|
+
- spec/dummy/public/500.html
|
168
|
+
- spec/dummy/public/favicon.ico
|
169
|
+
- spec/dummy/public/stylesheets/.gitkeep
|
170
|
+
- spec/dummy/script/rails
|
171
|
+
- spec/resource_spec.rb
|
80
172
|
- spec/spec_helper.rb
|