role_up 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/role_up.rb +5 -1
- data/lib/role_up/railtie.rb +37 -0
- data/lib/role_up/version.rb +1 -1
- data/test/integration/dummy/app/controllers/application_controller.rb +4 -1
- data/test/integration/dummy/config/application.rb +0 -34
- data/test/integration/dummy/config/environments/development.rb +0 -16
- data/test/integration/dummy/config/environments/production.rb +5 -44
- data/test/integration/dummy/config/environments/test.rb +0 -26
- data/test/integration/dummy/config/routes.rb +0 -56
- data/test/integration/role_up_engine_test.rb +7 -0
- data/test/integration/support/assertion_helpers.rb +37 -0
- data/test/unit/role_up_spec_test.rb +4 -0
- data/test/unit/role_up_test.rb +4 -0
- metadata +6 -8
- data/lib/role_up/engine.rb +0 -13
- data/test/integration/dummy/config/database.yml +0 -22
- data/test/integration/dummy/config/regulate.yml +0 -10
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@ Role Up
|
|
3
3
|
`CanCan` extension that adds some real-deal syntax and file organization lovin'!
|
4
4
|
|
5
5
|
### Warning
|
6
|
-
* Changing rules in an ability class is not reflected on page reload in
|
6
|
+
* THIS SHOULD BE FIXED - Changing rules in an ability class is not reflected on page reload in
|
7
7
|
development mode
|
8
8
|
|
9
9
|
### TODO
|
data/lib/role_up.rb
CHANGED
@@ -6,7 +6,11 @@ module RoleUp
|
|
6
6
|
# Lock 'n Load
|
7
7
|
autoload :Errors , 'role_up/errors'
|
8
8
|
require 'role_up/ability'
|
9
|
-
require 'role_up/
|
9
|
+
require 'role_up/railtie' if defined? Rails
|
10
|
+
|
11
|
+
# Our file match
|
12
|
+
mattr_reader :glob
|
13
|
+
@@glob = "**/*_ability.rb"
|
10
14
|
|
11
15
|
# The class we'll authorize against
|
12
16
|
mattr_accessor :authorization_class
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "rails/railtie"
|
2
|
+
|
3
|
+
module RoleUp
|
4
|
+
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
|
7
|
+
# eager load our app/abilities directory
|
8
|
+
#
|
9
|
+
# HAPPENS FIRST
|
10
|
+
config.before_configuration do |app|
|
11
|
+
app.config.paths.app.abilities "app/abilities" , :eager_load => true , :glob => RoleUp.glob
|
12
|
+
end
|
13
|
+
|
14
|
+
# make sure our ability files are reloaded on each request in development
|
15
|
+
# ONLY if we are not caching classes
|
16
|
+
#
|
17
|
+
# HAPPENS SECOND
|
18
|
+
config.to_prepare do
|
19
|
+
RoleUp::Railtie.force_load_abilities if Rails.env.development? && !Rails.application.config.cache_classes
|
20
|
+
end
|
21
|
+
|
22
|
+
# force load our ability files if we are in a non-development environment and
|
23
|
+
# if we aren't caching classes
|
24
|
+
#
|
25
|
+
# HAPPENS THIRD
|
26
|
+
config.after_initialize do |app|
|
27
|
+
force_load_abilities if !Rails.env.development? && !app.config.cache_classes
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.force_load_abilities
|
31
|
+
Dir[ "#{ Rails.root }/app/abilities/#{ RoleUp.glob }" ].each { |a| load a }
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
data/lib/role_up/version.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
ActiveSupport::Dependencies.log_activity = true
|
2
|
+
ActiveSupport::Dependencies.logger = Rails.logger
|
3
|
+
|
1
4
|
class ApplicationController < ActionController::Base
|
2
5
|
|
3
6
|
def home
|
4
|
-
render :text =>
|
7
|
+
render :text => ( current_ability.can? :manage , Widget ).inspect
|
5
8
|
end
|
6
9
|
|
7
10
|
protect_from_forgery
|
@@ -1,45 +1,11 @@
|
|
1
1
|
require File.expand_path('../boot', __FILE__)
|
2
|
-
|
3
|
-
require "active_model/railtie"
|
4
|
-
require "active_record/railtie"
|
5
2
|
require "action_controller/railtie"
|
6
|
-
require "action_view/railtie"
|
7
|
-
require "action_mailer/railtie"
|
8
3
|
|
9
4
|
Bundler.require
|
10
5
|
require "role_up"
|
11
6
|
|
12
7
|
module Dummy
|
13
8
|
class Application < Rails::Application
|
14
|
-
# Settings in config/environments/* take precedence over those specified here.
|
15
|
-
# Application configuration should go into files in config/initializers
|
16
|
-
# -- all .rb files in that directory are automatically loaded.
|
17
|
-
|
18
|
-
# Custom directories with classes and modules you want to be autoloadable.
|
19
|
-
# config.autoload_paths += %W(#{config.root}/extras)
|
20
|
-
|
21
|
-
# Only load the plugins named here, in the order given (default is alphabetical).
|
22
|
-
# :all can be used as a placeholder for all plugins not explicitly named.
|
23
|
-
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
24
|
-
|
25
|
-
# Activate observers that should always be running.
|
26
|
-
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
27
|
-
|
28
|
-
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
29
|
-
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
30
|
-
# config.time_zone = 'Central Time (US & Canada)'
|
31
|
-
|
32
|
-
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
33
|
-
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
34
|
-
# config.i18n.default_locale = :de
|
35
|
-
|
36
|
-
# JavaScript files you want as :defaults (application.js is always included).
|
37
|
-
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
38
|
-
|
39
|
-
# Configure the default encoding used in templates for Ruby 1.9.
|
40
9
|
config.encoding = "utf-8"
|
41
|
-
|
42
|
-
# Configure sensitive parameters which will be filtered from the log file.
|
43
|
-
config.filter_parameters += [:password]
|
44
10
|
end
|
45
11
|
end
|
@@ -1,26 +1,10 @@
|
|
1
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
2
|
config.cache_classes = false
|
8
|
-
|
9
|
-
# Log error messages when you accidentally call methods on nil.
|
10
3
|
config.whiny_nils = true
|
11
|
-
|
12
|
-
# Show full error reports and disable caching
|
13
4
|
config.consider_all_requests_local = true
|
14
5
|
config.action_view.debug_rjs = true
|
15
6
|
config.action_controller.perform_caching = false
|
16
|
-
|
17
|
-
# Don't care if the mailer can't send
|
18
|
-
config.action_mailer.raise_delivery_errors = false
|
19
|
-
|
20
|
-
# Print deprecation notices to the Rails logger
|
21
7
|
config.active_support.deprecation = :log
|
22
|
-
|
23
|
-
# Only use best-standards-support built into browsers
|
24
8
|
config.action_dispatch.best_standards_support = :builtin
|
25
9
|
end
|
26
10
|
|
@@ -1,49 +1,10 @@
|
|
1
1
|
Dummy::Application.configure do
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb
|
3
|
-
|
4
|
-
# The production environment is meant for finished, "live" apps.
|
5
|
-
# Code is not reloaded between requests
|
6
2
|
config.cache_classes = true
|
7
|
-
|
8
|
-
# Full error reports are disabled and caching is turned on
|
3
|
+
config.whiny_nils = false
|
9
4
|
config.consider_all_requests_local = false
|
5
|
+
config.action_view.debug_rjs = false
|
10
6
|
config.action_controller.perform_caching = true
|
11
|
-
|
12
|
-
|
13
|
-
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
14
|
-
|
15
|
-
# For nginx:
|
16
|
-
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
|
17
|
-
|
18
|
-
# If you have no front-end server that supports something like X-Sendfile,
|
19
|
-
# just comment this out and Rails will serve the files
|
20
|
-
|
21
|
-
# See everything in the log (default is :info)
|
22
|
-
# config.log_level = :debug
|
23
|
-
|
24
|
-
# Use a different logger for distributed setups
|
25
|
-
# config.logger = SyslogLogger.new
|
26
|
-
|
27
|
-
# Use a different cache store in production
|
28
|
-
# config.cache_store = :mem_cache_store
|
29
|
-
|
30
|
-
# Disable Rails's static asset server
|
31
|
-
# In production, Apache or nginx will already do this
|
32
|
-
config.serve_static_assets = false
|
33
|
-
|
34
|
-
# Enable serving of images, stylesheets, and javascripts from an asset server
|
35
|
-
# config.action_controller.asset_host = "http://assets.example.com"
|
36
|
-
|
37
|
-
# Disable delivery errors, bad email addresses will be ignored
|
38
|
-
# config.action_mailer.raise_delivery_errors = false
|
39
|
-
|
40
|
-
# Enable threaded mode
|
41
|
-
# config.threadsafe!
|
42
|
-
|
43
|
-
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
44
|
-
# the I18n.default_locale when a translation can not be found)
|
45
|
-
config.i18n.fallbacks = true
|
46
|
-
|
47
|
-
# Send deprecation notices to registered listeners
|
48
|
-
config.active_support.deprecation = :notify
|
7
|
+
config.active_support.deprecation = :log
|
8
|
+
config.action_dispatch.best_standards_support = :builtin
|
49
9
|
end
|
10
|
+
|
@@ -1,35 +1,9 @@
|
|
1
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
2
|
config.cache_classes = true
|
9
|
-
|
10
|
-
# Log error messages when you accidentally call methods on nil.
|
11
3
|
config.whiny_nils = true
|
12
|
-
|
13
|
-
# Show full error reports and disable caching
|
14
4
|
config.consider_all_requests_local = true
|
15
5
|
config.action_controller.perform_caching = false
|
16
|
-
|
17
|
-
# Raise exceptions instead of rendering exception templates
|
18
6
|
config.action_dispatch.show_exceptions = false
|
19
|
-
|
20
|
-
# Disable request forgery protection in test environment
|
21
7
|
config.action_controller.allow_forgery_protection = false
|
22
|
-
|
23
|
-
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
-
# The :test delivery method accumulates sent emails in the
|
25
|
-
# ActionMailer::Base.deliveries array.
|
26
|
-
config.action_mailer.delivery_method = :test
|
27
|
-
|
28
|
-
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
29
|
-
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
30
|
-
# like if you have constraints or database-specific column types
|
31
|
-
# config.active_record.schema_format = :sql
|
32
|
-
|
33
|
-
# Print deprecation notices to the stderr
|
34
8
|
config.active_support.deprecation = :stderr
|
35
9
|
end
|
@@ -1,59 +1,3 @@
|
|
1
1
|
Dummy::Application.routes.draw do
|
2
2
|
root :to => "application#home"
|
3
|
-
# The priority is based upon order of creation:
|
4
|
-
# first created -> highest priority.
|
5
|
-
|
6
|
-
# Sample of regular route:
|
7
|
-
# match 'products/:id' => 'catalog#view'
|
8
|
-
# Keep in mind you can assign values other than :controller and :action
|
9
|
-
|
10
|
-
# Sample of named route:
|
11
|
-
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
12
|
-
# This route can be invoked with purchase_url(:id => product.id)
|
13
|
-
|
14
|
-
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
15
|
-
# resources :products
|
16
|
-
|
17
|
-
# Sample resource route with options:
|
18
|
-
# resources :products do
|
19
|
-
# member do
|
20
|
-
# get 'short'
|
21
|
-
# post 'toggle'
|
22
|
-
# end
|
23
|
-
#
|
24
|
-
# collection do
|
25
|
-
# get 'sold'
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
|
29
|
-
# Sample resource route with sub-resources:
|
30
|
-
# resources :products do
|
31
|
-
# resources :comments, :sales
|
32
|
-
# resource :seller
|
33
|
-
# end
|
34
|
-
|
35
|
-
# Sample resource route with more complex sub-resources
|
36
|
-
# resources :products do
|
37
|
-
# resources :comments
|
38
|
-
# resources :sales do
|
39
|
-
# get 'recent', :on => :collection
|
40
|
-
# end
|
41
|
-
# end
|
42
|
-
|
43
|
-
# Sample resource route within a namespace:
|
44
|
-
# namespace :admin do
|
45
|
-
# # Directs /admin/products/* to Admin::ProductsController
|
46
|
-
# # (app/controllers/admin/products_controller.rb)
|
47
|
-
# resources :products
|
48
|
-
# end
|
49
|
-
|
50
|
-
# You can have the root of your site routed with "root"
|
51
|
-
# just remember to delete public/index.html.
|
52
|
-
# root :to => "welcome#index"
|
53
|
-
|
54
|
-
# See how all your routes lay out with "rake routes"
|
55
|
-
|
56
|
-
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
57
|
-
# Note: This route will make all actions in every controller accessible via GET requests.
|
58
|
-
# match ':controller(/:action(/:id(.:format)))'
|
59
3
|
end
|
@@ -11,5 +11,12 @@ class RoleUp::EngineTest < MiniTest::Unit::TestCase
|
|
11
11
|
refute_empty Ability.ability_definitions
|
12
12
|
end
|
13
13
|
|
14
|
+
# Check that our path helper naming was successful
|
15
|
+
def test_ability_path_name
|
16
|
+
refute_raises do
|
17
|
+
Dummy::Application.paths.app.abilities
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
14
21
|
end
|
15
22
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class MiniTest::Unit::TestCase
|
2
|
+
|
3
|
+
def refute_raises *exp
|
4
|
+
|
5
|
+
msg = "#{exp.pop}\n" if String === exp.last
|
6
|
+
|
7
|
+
begin
|
8
|
+
yield
|
9
|
+
|
10
|
+
rescue MiniTest::Skip => e
|
11
|
+
if exp.include? MiniTest::Skip then
|
12
|
+
return e
|
13
|
+
|
14
|
+
else
|
15
|
+
raise e
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
rescue Exception => e
|
20
|
+
if exp.empty?
|
21
|
+
flunk "Unexpected exception :: #{msg}#{mu_pp(e)}"
|
22
|
+
|
23
|
+
else
|
24
|
+
details = "Unexpected #{msg}#{mu_pp(exp)} exception"
|
25
|
+
refute( exp.any? { |ex|
|
26
|
+
ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class
|
27
|
+
}, exception_details(e, details))
|
28
|
+
return e
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
data/test/unit/role_up_test.rb
CHANGED
@@ -10,6 +10,10 @@ class RoleUpTest < MiniTest::Unit::TestCase
|
|
10
10
|
assert defined? RoleUp::Errors
|
11
11
|
end
|
12
12
|
|
13
|
+
def test_that_our_glob_is_as_intended
|
14
|
+
assert_equal "**/*_ability.rb" , RoleUp.glob
|
15
|
+
end
|
16
|
+
|
13
17
|
def test_that_role_up_yields_self_on_setup
|
14
18
|
RoleUp.setup do |config|
|
15
19
|
assert_equal RoleUp , config
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: role_up
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ryan Cook
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-12 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: cancan
|
@@ -75,8 +75,8 @@ files:
|
|
75
75
|
- Rakefile
|
76
76
|
- lib/role_up.rb
|
77
77
|
- lib/role_up/ability.rb
|
78
|
-
- lib/role_up/engine.rb
|
79
78
|
- lib/role_up/errors.rb
|
79
|
+
- lib/role_up/railtie.rb
|
80
80
|
- lib/role_up/version.rb
|
81
81
|
- role_up.gemspec
|
82
82
|
- test/integration/dummy/Rakefile
|
@@ -89,7 +89,6 @@ files:
|
|
89
89
|
- test/integration/dummy/config.ru
|
90
90
|
- test/integration/dummy/config/application.rb
|
91
91
|
- test/integration/dummy/config/boot.rb
|
92
|
-
- test/integration/dummy/config/database.yml
|
93
92
|
- test/integration/dummy/config/environment.rb
|
94
93
|
- test/integration/dummy/config/environments/development.rb
|
95
94
|
- test/integration/dummy/config/environments/production.rb
|
@@ -100,7 +99,6 @@ files:
|
|
100
99
|
- test/integration/dummy/config/initializers/secret_token.rb
|
101
100
|
- test/integration/dummy/config/initializers/session_store.rb
|
102
101
|
- test/integration/dummy/config/locales/en.yml
|
103
|
-
- test/integration/dummy/config/regulate.yml
|
104
102
|
- test/integration/dummy/config/routes.rb
|
105
103
|
- test/integration/dummy/db/test.sqlite3
|
106
104
|
- test/integration/dummy/public/404.html
|
@@ -116,6 +114,7 @@ files:
|
|
116
114
|
- test/integration/dummy/public/stylesheets/.gitkeep
|
117
115
|
- test/integration/dummy/script/rails
|
118
116
|
- test/integration/role_up_engine_test.rb
|
117
|
+
- test/integration/support/assertion_helpers.rb
|
119
118
|
- test/integration/test_helper.rb
|
120
119
|
- test/unit/ability_spec_test.rb
|
121
120
|
- test/unit/ability_test.rb
|
@@ -150,7 +149,7 @@ rubyforge_project: role_up
|
|
150
149
|
rubygems_version: 1.8.5
|
151
150
|
signing_key:
|
152
151
|
specification_version: 3
|
153
|
-
summary: role_up-0.1.
|
152
|
+
summary: role_up-0.1.5
|
154
153
|
test_files:
|
155
154
|
- test/integration/dummy/Rakefile
|
156
155
|
- test/integration/dummy/app/abilities/widget_ability.rb
|
@@ -162,7 +161,6 @@ test_files:
|
|
162
161
|
- test/integration/dummy/config.ru
|
163
162
|
- test/integration/dummy/config/application.rb
|
164
163
|
- test/integration/dummy/config/boot.rb
|
165
|
-
- test/integration/dummy/config/database.yml
|
166
164
|
- test/integration/dummy/config/environment.rb
|
167
165
|
- test/integration/dummy/config/environments/development.rb
|
168
166
|
- test/integration/dummy/config/environments/production.rb
|
@@ -173,7 +171,6 @@ test_files:
|
|
173
171
|
- test/integration/dummy/config/initializers/secret_token.rb
|
174
172
|
- test/integration/dummy/config/initializers/session_store.rb
|
175
173
|
- test/integration/dummy/config/locales/en.yml
|
176
|
-
- test/integration/dummy/config/regulate.yml
|
177
174
|
- test/integration/dummy/config/routes.rb
|
178
175
|
- test/integration/dummy/db/test.sqlite3
|
179
176
|
- test/integration/dummy/public/404.html
|
@@ -189,6 +186,7 @@ test_files:
|
|
189
186
|
- test/integration/dummy/public/stylesheets/.gitkeep
|
190
187
|
- test/integration/dummy/script/rails
|
191
188
|
- test/integration/role_up_engine_test.rb
|
189
|
+
- test/integration/support/assertion_helpers.rb
|
192
190
|
- test/integration/test_helper.rb
|
193
191
|
- test/unit/ability_spec_test.rb
|
194
192
|
- test/unit/ability_test.rb
|
data/lib/role_up/engine.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# SQLite version 3.x
|
2
|
-
# gem install sqlite3-ruby (not necessary on OS X Leopard)
|
3
|
-
development:
|
4
|
-
adapter: sqlite3
|
5
|
-
database: db/development.sqlite3
|
6
|
-
pool: 5
|
7
|
-
timeout: 5000
|
8
|
-
|
9
|
-
# Warning: The database defined as "test" will be erased and
|
10
|
-
# re-generated from your development database when you run "rake".
|
11
|
-
# Do not set this db to the same as development or production.
|
12
|
-
test:
|
13
|
-
adapter: sqlite3
|
14
|
-
database: db/test.sqlite3
|
15
|
-
pool: 5
|
16
|
-
timeout: 5000
|
17
|
-
|
18
|
-
production:
|
19
|
-
adapter: sqlite3
|
20
|
-
database: db/production.sqlite3
|
21
|
-
pool: 5
|
22
|
-
timeout: 5000
|