monty-rspec-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.md +27 -0
  5. data/Rakefile +20 -0
  6. data/lib/monty-rspec-rails.rb +80 -0
  7. metadata +68 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 stonean
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ monty-rspec-rails
2
+ =============
3
+
4
+ Rspec Rails helpers for [Monty](http://github.com/stonean/monty)
5
+
6
+ In your spec/spec_helper.rb
7
+
8
+ require 'monty-rspec-rails'
9
+ include Monty::RspecRails
10
+
11
+
12
+
13
+ Note on Patches/Pull Requests
14
+ =============
15
+
16
+ * Fork the project.
17
+ * Make your feature addition or bug fix.
18
+ * Add tests for it. This is important so I don't break it in a
19
+ future version unintentionally.
20
+ * Commit, do not mess with rakefile, version, or history.
21
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
22
+ * Send me a pull request. Bonus points for topic branches.
23
+
24
+ Copyright
25
+ =============
26
+
27
+ Copyright (c) 2010 stonean. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ require 'lib/monty-rspec-rails'
5
+
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "monty-rspec-rails"
10
+ gem.version = Monty::RspecRails.version
11
+ gem.summary = %Q{RSpec Rails helpers for Monty}
12
+ gem.description = %Q{RSpec Rails helpers for Monty}
13
+ gem.email = "andy@stonean.com"
14
+ gem.homepage = "http://github.com/stonean/monty-rspec-rails"
15
+ gem.authors = ["stonean"]
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
@@ -0,0 +1,80 @@
1
+ module Monty
2
+ module RspecRails
3
+ def self.version
4
+ '0.1.0'
5
+ end
6
+
7
+ def public_user
8
+ logout
9
+ controller.session[:access_rights] = Monty::Configuration.public_access
10
+ end
11
+
12
+ def authenticated_user
13
+ login
14
+ controller.session[:access_rights] = Monty.authenticated_access
15
+ end
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 = "/#{c}/#{method}"
28
+ session_regexp.should match(path)
29
+ end
30
+ end
31
+
32
+ def no_actions_are_allowed
33
+ c = controller.controller_path
34
+
35
+ controller_actions.each do |method|
36
+ path = "/#{c}/#{method}"
37
+ session_regexp.should_not match(path)
38
+ end
39
+ end
40
+
41
+ def only_actions_are_allowed(*actions)
42
+ c = controller.controller_path
43
+
44
+ actions.each do |method|
45
+ path = "/#{c}/#{method}"
46
+ session_regexp.should match(path)
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def login(session_stubs = {}, user_stubs = {})
53
+ UserSession.stub!(:find).and_return(user_session(session_stubs, user_stubs))
54
+ end
55
+
56
+ def user_session(stubs = {}, user_stubs = {})
57
+ @current_user_session ||= mock_model(UserSession, {:user => current_user(user_stubs)}.merge(stubs))
58
+ end
59
+
60
+ def current_user(stubs = {})
61
+ @current_user ||= mock_model(User, stubs)
62
+ end
63
+
64
+ def logout
65
+ @current_user_session = nil
66
+ end
67
+
68
+ def session_regexp
69
+ @session_regexp ||= Regexp.new(/\A#{allowed_actions}\z/)
70
+ end
71
+
72
+ def allowed_actions
73
+ controller.session[:access_rights]
74
+ end
75
+
76
+ def controller_actions
77
+ controller.send :action_methods
78
+ end
79
+ end
80
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monty-rspec-rails
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - stonean
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-11 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: RSpec Rails helpers for Monty
22
+ email: andy@stonean.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - LICENSE
29
+ - README.md
30
+ files:
31
+ - .document
32
+ - .gitignore
33
+ - LICENSE
34
+ - README.md
35
+ - Rakefile
36
+ - lib/monty-rspec-rails.rb
37
+ has_rdoc: true
38
+ homepage: http://github.com/stonean/monty-rspec-rails
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options:
43
+ - --charset=UTF-8
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.6
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: RSpec Rails helpers for Monty
67
+ test_files: []
68
+