stffn-declarative_authorization 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/test/schema.sql ADDED
@@ -0,0 +1,32 @@
1
+ CREATE TABLE 'test_models' (
2
+ 'id' INTEGER PRIMARY KEY NOT NULL,
3
+ 'test_attr_through_id' INTEGER,
4
+ 'content' text,
5
+ 'created_at' datetime,
6
+ 'updated_at' datetime
7
+ );
8
+
9
+ CREATE TABLE 'test_attrs' (
10
+ 'id' INTEGER PRIMARY KEY NOT NULL,
11
+ 'test_model_id' integer,
12
+ 'test_another_model_id' integer,
13
+ 'test_attr_through_id' INTEGER,
14
+ 'n_way_join_item_id' INTEGER,
15
+ 'test_model_security_model_id' integer,
16
+ 'attr' integer default 1
17
+ );
18
+
19
+ CREATE TABLE 'test_attr_throughs' (
20
+ 'id' INTEGER PRIMARY KEY NOT NULL,
21
+ 'test_attr_id' integer
22
+ );
23
+
24
+ CREATE TABLE 'test_model_security_models' (
25
+ 'id' INTEGER PRIMARY KEY NOT NULL,
26
+ 'attr' integer default 1,
27
+ 'attr_2' integer default 1
28
+ );
29
+
30
+ CREATE TABLE 'n_way_join_items' (
31
+ 'id' INTEGER PRIMARY KEY NOT NULL
32
+ );
@@ -0,0 +1,99 @@
1
+ require 'test/unit'
2
+ RAILS_ROOT = File.dirname(__FILE__) + '/../../../../'
3
+ require File.dirname(__FILE__) + '/../lib/rails_legacy.rb'
4
+ require File.dirname(__FILE__) + '/../lib/authorization.rb'
5
+ require File.dirname(__FILE__) + '/../lib/in_controller.rb'
6
+
7
+ unless defined?(ActiveRecord)
8
+ if File.directory? RAILS_ROOT + 'config'
9
+ puts 'using config/boot.rb'
10
+ ENV['RAILS_ENV'] = 'test'
11
+ require File.join(RAILS_ROOT, 'config', 'boot.rb')
12
+ else
13
+ # simply use installed gems if available
14
+ puts 'using rubygems'
15
+ require 'rubygems'
16
+ gem 'actionpack'; gem 'activerecord'; gem 'activesupport'; gem 'rails'
17
+ end
18
+
19
+ %w(action_pack action_controller active_record active_support initializer).each {|f| require f}
20
+ end
21
+
22
+ begin
23
+ require 'ruby-debug'
24
+ rescue MissingSourceFile; end
25
+
26
+
27
+ class MockDataObject
28
+ def initialize (attrs = {})
29
+ attrs.each do |key, value|
30
+ instance_variable_set(:"@#{key}", value)
31
+ self.class.class_eval do
32
+ attr_reader key
33
+ end
34
+ end
35
+ end
36
+
37
+ def descends_from_active_record?
38
+ true
39
+ end
40
+
41
+ def self.table_name
42
+ "mocks"
43
+ end
44
+ end
45
+
46
+ class MockUser < MockDataObject
47
+ def initialize (*roles)
48
+ options = roles.last.is_a?(::Hash) ? roles.pop : {}
49
+ super(options.merge(:role_symbols => roles))
50
+ end
51
+ end
52
+
53
+ class MocksController < ActionController::Base
54
+ attr_accessor :current_user
55
+ attr_writer :authorization_engine
56
+
57
+ def authorized?
58
+ !!@authorized
59
+ end
60
+
61
+ def self.define_action_methods (*methods)
62
+ methods.each do |method|
63
+ define_method method do
64
+ @authorized = true
65
+ render :text => 'nothing'
66
+ end
67
+ end
68
+ end
69
+
70
+ def logger (*args)
71
+ Class.new do
72
+ def warn(*args)
73
+ #p args
74
+ end
75
+ alias_method :info, :warn
76
+ def warn?; end
77
+ alias_method :info?, :warn?
78
+ end.new
79
+ end
80
+ end
81
+
82
+ ActionController::Routing::Routes.draw do |map|
83
+ map.connect ':controller/:action/:id'
84
+ end
85
+ ActionController::Base.send :include, Authorization::AuthorizationInController
86
+ require "action_controller/test_process"
87
+
88
+ class Test::Unit::TestCase
89
+ def request! (user, action, reader, params = {})
90
+ action = action.to_sym if action.is_a?(String)
91
+ @controller.current_user = user
92
+ @controller.authorization_engine = Authorization::Engine.new(reader)
93
+
94
+ ((params.delete(:clear) || []) + [:@authorized]).each do |var|
95
+ @controller.instance_variable_set(var, nil)
96
+ end
97
+ get action, params
98
+ end
99
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stffn-declarative_authorization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steffen Bartsch
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-13 00:00:00 -08:00
12
+ date: 2009-02-25 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -38,6 +38,30 @@ files:
38
38
  - authorization_rules.dist.rb
39
39
  - garlic_example.rb
40
40
  - init.rb
41
+ - app/controllers/authorization_rules_controller.rb
42
+ - app/controllers/authorization_usages_controller.rb
43
+ - app/helpers/authorization_rules_helper.rb
44
+ - app/views/authorization_usages/index.html.erb
45
+ - app/views/authorization_rules/index.html.erb
46
+ - app/views/authorization_rules/graph.dot.erb
47
+ - app/views/authorization_rules/graph.html.erb
48
+ - config/routes.rb
49
+ - lib/in_controller.rb
50
+ - lib/reader.rb
51
+ - lib/rails_legacy.rb
52
+ - lib/obligation_scope.rb
53
+ - lib/in_model.rb
54
+ - lib/helper.rb
55
+ - lib/authorization.rb
56
+ - lib/maintenance.rb
57
+ - test/authorization_test.rb
58
+ - test/schema.sql
59
+ - test/maintenance_test.rb
60
+ - test/model_test.rb
61
+ - test/controller_test.rb
62
+ - test/helper_test.rb
63
+ - test/dsl_reader_test.rb
64
+ - test/test_helper.rb
41
65
  has_rdoc: true
42
66
  homepage: http://github.com/stffn/declarative_authorization
43
67
  post_install_message: