monty-rspec-rails 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.md +42 -0
  2. data/lib/monty-rspec-rails.rb +8 -46
  3. metadata +4 -4
data/README.md CHANGED
@@ -8,6 +8,48 @@ In your spec/spec_helper.rb
8
8
  require 'monty-rspec-rails'
9
9
  include Monty::RspecRails
10
10
 
11
+ Some test examples:
12
+
13
+ describe UsersController do
14
+
15
+ describe "public" do
16
+ before do
17
+ public_user
18
+ end
19
+
20
+ it '#new is allowed' do
21
+ request_allowed?(:new).should be_true
22
+ end
23
+
24
+ # Need to pass in the :post method to mimic the Rails request
25
+ it '#create is allowed' do
26
+ request_allowed?(:create, :post).should be_true
27
+ end
28
+
29
+ # Need to pass in the :post method and the put param
30
+ # to mimic the Rails request
31
+ it '#update is not allowed' do
32
+ request_allowed?(:update, :post, :_method => 'put').should be_false
33
+ end
34
+
35
+ it '#show is not allowed' do
36
+ request_allowed?(:show).should be_false
37
+ end
38
+ end
39
+
40
+ describe "protected" do
41
+ before do
42
+ authenticated_user
43
+ end
44
+
45
+ it '#show is not allowed' do
46
+ request_allowed?(:show).should be_true
47
+ end
48
+
49
+ # And so on..
50
+ end
51
+ end
52
+
11
53
 
12
54
 
13
55
  Note on Patches/Pull Requests
@@ -1,7 +1,7 @@
1
1
  module Monty
2
2
  module RspecRails
3
3
  def self.version
4
- '0.1.1'
4
+ '0.2.0'
5
5
  end
6
6
 
7
7
  def public_user
@@ -14,40 +14,14 @@ module Monty
14
14
  controller.session[:access_rights] = Monty.authenticated_access
15
15
  end
16
16
 
17
- def all_actions_are_allowed(hash = {})
18
- actions = controller_actions
19
-
20
- if excepts = hash.delete(:except)
21
- excepts = Array.new(excepts)
22
- actions.reject!{|m| excepts.include?(m.to_sym)}
23
- end
24
-
25
- c = controller.controller_path
26
- actions.each do |method|
27
- path = URI.parse(controller.url_for(:controller => c, :action => method)).path
28
- next if path == "/"
29
- session_regexp.should match(path)
30
- end
31
- end
32
-
33
- def no_actions_are_allowed
34
- c = controller.controller_path
35
-
36
- controller_actions.each do |method|
37
- path = URI.parse(controller.url_for(:controller => c, :action => method)).path
38
- session_regexp.should_not match(path)
39
- end
40
- end
41
-
42
- def only_actions_are_allowed(*actions)
43
- c = controller.controller_path
44
-
45
- actions.each do |method|
46
- path = URI.parse(controller.url_for(:controller => c, :action => method)).path
47
- session_regexp.should match(path)
48
- end
17
+ def request_allowed?(action, method = 'get', params = {})
18
+ path = URI.parse(controller.url_for(:controller => controller.controller_path, :action => action)).path
19
+ delivery = Monty::Delivery.new 'REQUEST_PATH' => path,
20
+ 'REQUEST_METHOD' => method.to_s,
21
+ 'rack.session' => controller.session,
22
+ 'rack.input' => StringIO.new(params.to_query)
23
+ delivery.allowed?
49
24
  end
50
-
51
25
  private
52
26
 
53
27
  def login(session_stubs = {}, user_stubs = {})
@@ -65,17 +39,5 @@ module Monty
65
39
  def logout
66
40
  @current_user_session = nil
67
41
  end
68
-
69
- def session_regexp
70
- @session_regexp ||= Regexp.new(/\A#{allowed_actions}\z/)
71
- end
72
-
73
- def allowed_actions
74
- controller.session[:access_rights]
75
- end
76
-
77
- def controller_actions
78
- controller.send :action_methods
79
- end
80
42
  end
81
43
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - stonean
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-13 00:00:00 -04:00
17
+ date: 2010-05-19 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20