Description:
added verify plug-in, fixed form_for, form_tag in views, changed named_scope to scope
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r319:f7101d4aef84 - - 34 files changed: 619 inserted, 210 deleted
new file 100644 |
@@ -0,0 +1,20 | |||||
|
|
1 | + Copyright (c) 2010 David Heinemeier Hansson | ||
|
|
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. |
@@ -0,0 +1,34 | |||||
|
|
1 | + This module provides a class-level method for specifying that certain | ||
|
|
2 | + actions are guarded against being called without certain prerequisites | ||
|
|
3 | + being met. This is essentially a special kind of before_filter. | ||
|
|
4 | + | ||
|
|
5 | + An action may be guarded against being invoked without certain request | ||
|
|
6 | + parameters being set, or without certain session values existing. | ||
|
|
7 | + | ||
|
|
8 | + When a verification is violated, values may be inserted into the flash, and | ||
|
|
9 | + a specified redirection is triggered. If no specific action is configured, | ||
|
|
10 | + verification failures will by default result in a 400 Bad Request response. | ||
|
|
11 | + | ||
|
|
12 | + Usage: | ||
|
|
13 | + | ||
|
|
14 | + class GlobalController < ActionController::Base | ||
|
|
15 | + # Prevent the #update_settings action from being invoked unless | ||
|
|
16 | + # the 'admin_privileges' request parameter exists. The | ||
|
|
17 | + # settings action will be redirected to in current controller | ||
|
|
18 | + # if verification fails. | ||
|
|
19 | + verify :params => "admin_privileges", :only => :update_post, | ||
|
|
20 | + :redirect_to => { :action => "settings" } | ||
|
|
21 | + | ||
|
|
22 | + # Disallow a post from being updated if there was no information | ||
|
|
23 | + # submitted with the post, and if there is no active post in the | ||
|
|
24 | + # session, and if there is no "note" key in the flash. The route | ||
|
|
25 | + # named category_url will be redirected to if verification fails. | ||
|
|
26 | + | ||
|
|
27 | + verify :params => "post", :session => "post", "flash" => "note", | ||
|
|
28 | + :only => :update_post, | ||
|
|
29 | + :add_flash => { "alert" => "Failed to create your message" }, | ||
|
|
30 | + :redirect_to => :category_url | ||
|
|
31 | + | ||
|
|
32 | + Note that these prerequisites are not business rules. They do not examine | ||
|
|
33 | + the content of the session or the parameters. That level of validation should | ||
|
|
34 | + be encapsulated by your domain model or helper methods in the controller. No newline at end of file |
@@ -0,0 +1,22 | |||||
|
|
1 | + require 'rake' | ||
|
|
2 | + require 'rake/testtask' | ||
|
|
3 | + require 'rdoc/task' | ||
|
|
4 | + | ||
|
|
5 | + desc 'Default: run unit tests.' | ||
|
|
6 | + task :default => :test | ||
|
|
7 | + | ||
|
|
8 | + desc 'Test the verification plugin.' | ||
|
|
9 | + Rake::TestTask.new(:test) do |t| | ||
|
|
10 | + t.libs << 'lib' | ||
|
|
11 | + t.libs << 'test' | ||
|
|
12 | + t.pattern = 'test/**/*_test.rb' | ||
|
|
13 | + end | ||
|
|
14 | + | ||
|
|
15 | + desc 'Generate documentation for the verification plugin.' | ||
|
|
16 | + Rake::RDocTask.new(:rdoc) do |rdoc| | ||
|
|
17 | + rdoc.rdoc_dir = 'rdoc' | ||
|
|
18 | + rdoc.title = 'Verification' | ||
|
|
19 | + rdoc.options << '--line-numbers' << '--inline-source' | ||
|
|
20 | + rdoc.rdoc_files.include('README') | ||
|
|
21 | + rdoc.rdoc_files.include('lib/**/*.rb') | ||
|
|
22 | + end |
@@ -0,0 +1,3 | |||||
|
|
1 | + # Include hook code here | ||
|
|
2 | + | ||
|
|
3 | + require 'action_controller/verification' No newline at end of file |
@@ -0,0 +1,132 | |||||
|
|
1 | + module ActionController #:nodoc: | ||
|
|
2 | + module Verification #:nodoc: | ||
|
|
3 | + extend ActiveSupport::Concern | ||
|
|
4 | + | ||
|
|
5 | + include AbstractController::Callbacks, Flash, Rendering | ||
|
|
6 | + | ||
|
|
7 | + # This module provides a class-level method for specifying that certain | ||
|
|
8 | + # actions are guarded against being called without certain prerequisites | ||
|
|
9 | + # being met. This is essentially a special kind of before_filter. | ||
|
|
10 | + # | ||
|
|
11 | + # An action may be guarded against being invoked without certain request | ||
|
|
12 | + # parameters being set, or without certain session values existing. | ||
|
|
13 | + # | ||
|
|
14 | + # When a verification is violated, values may be inserted into the flash, and | ||
|
|
15 | + # a specified redirection is triggered. If no specific action is configured, | ||
|
|
16 | + # verification failures will by default result in a 400 Bad Request response. | ||
|
|
17 | + # | ||
|
|
18 | + # Usage: | ||
|
|
19 | + # | ||
|
|
20 | + # class GlobalController < ActionController::Base | ||
|
|
21 | + # # Prevent the #update_settings action from being invoked unless | ||
|
|
22 | + # # the 'admin_privileges' request parameter exists. The | ||
|
|
23 | + # # settings action will be redirected to in current controller | ||
|
|
24 | + # # if verification fails. | ||
|
|
25 | + # verify :params => "admin_privileges", :only => :update_post, | ||
|
|
26 | + # :redirect_to => { :action => "settings" } | ||
|
|
27 | + # | ||
|
|
28 | + # # Disallow a post from being updated if there was no information | ||
|
|
29 | + # # submitted with the post, and if there is no active post in the | ||
|
|
30 | + # # session, and if there is no "note" key in the flash. The route | ||
|
|
31 | + # # named category_url will be redirected to if verification fails. | ||
|
|
32 | + # | ||
|
|
33 | + # verify :params => "post", :session => "post", "flash" => "note", | ||
|
|
34 | + # :only => :update_post, | ||
|
|
35 | + # :add_flash => { "alert" => "Failed to create your message" }, | ||
|
|
36 | + # :redirect_to => :category_url | ||
|
|
37 | + # | ||
|
|
38 | + # Note that these prerequisites are not business rules. They do not examine | ||
|
|
39 | + # the content of the session or the parameters. That level of validation should | ||
|
|
40 | + # be encapsulated by your domain model or helper methods in the controller. | ||
|
|
41 | + module ClassMethods | ||
|
|
42 | + # Verify the given actions so that if certain prerequisites are not met, | ||
|
|
43 | + # the user is redirected to a different action. The +options+ parameter | ||
|
|
44 | + # is a hash consisting of the following key/value pairs: | ||
|
|
45 | + # | ||
|
|
46 | + # <tt>:params</tt>:: | ||
|
|
47 | + # a single key or an array of keys that must be in the <tt>params</tt> | ||
|
|
48 | + # hash in order for the action(s) to be safely called. | ||
|
|
49 | + # <tt>:session</tt>:: | ||
|
|
50 | + # a single key or an array of keys that must be in the <tt>session</tt> | ||
|
|
51 | + # in order for the action(s) to be safely called. | ||
|
|
52 | + # <tt>:flash</tt>:: | ||
|
|
53 | + # a single key or an array of keys that must be in the flash in order | ||
|
|
54 | + # for the action(s) to be safely called. | ||
|
|
55 | + # <tt>:method</tt>:: | ||
|
|
56 | + # a single key or an array of keys--any one of which must match the | ||
|
|
57 | + # current request method in order for the action(s) to be safely called. | ||
|
|
58 | + # (The key should be a symbol: <tt>:get</tt> or <tt>:post</tt>, for | ||
|
|
59 | + # example.) | ||
|
|
60 | + # <tt>:xhr</tt>:: | ||
|
|
61 | + # true/false option to ensure that the request is coming from an Ajax | ||
|
|
62 | + # call or not. | ||
|
|
63 | + # <tt>:add_flash</tt>:: | ||
|
|
64 | + # a hash of name/value pairs that should be merged into the session's | ||
|
|
65 | + # flash if the prerequisites cannot be satisfied. | ||
|
|
66 | + # <tt>:add_headers</tt>:: | ||
|
|
67 | + # a hash of name/value pairs that should be merged into the response's | ||
|
|
68 | + # headers hash if the prerequisites cannot be satisfied. | ||
|
|
69 | + # <tt>:redirect_to</tt>:: | ||
|
|
70 | + # the redirection parameters to be used when redirecting if the | ||
|
|
71 | + # prerequisites cannot be satisfied. You can redirect either to named | ||
|
|
72 | + # route or to the action in some controller. | ||
|
|
73 | + # <tt>:render</tt>:: | ||
|
|
74 | + # the render parameters to be used when the prerequisites cannot be satisfied. | ||
|
|
75 | + # <tt>:only</tt>:: | ||
|
|
76 | + # only apply this verification to the actions specified in the associated | ||
|
|
77 | + # array (may also be a single value). | ||
|
|
78 | + # <tt>:except</tt>:: | ||
|
|
79 | + # do not apply this verification to the actions specified in the associated | ||
|
|
80 | + # array (may also be a single value). | ||
|
|
81 | + def verify(options={}) | ||
|
|
82 | + before_filter :only => options[:only], :except => options[:except] do | ||
|
|
83 | + verify_action options | ||
|
|
84 | + end | ||
|
|
85 | + end | ||
|
|
86 | + end | ||
|
|
87 | + | ||
|
|
88 | + private | ||
|
|
89 | + | ||
|
|
90 | + def verify_action(options) #:nodoc: | ||
|
|
91 | + if prereqs_invalid?(options) | ||
|
|
92 | + flash.update(options[:add_flash]) if options[:add_flash] | ||
|
|
93 | + response.headers.merge!(options[:add_headers]) if options[:add_headers] | ||
|
|
94 | + apply_remaining_actions(options) unless performed? | ||
|
|
95 | + end | ||
|
|
96 | + end | ||
|
|
97 | + | ||
|
|
98 | + def prereqs_invalid?(options) # :nodoc: | ||
|
|
99 | + verify_presence_of_keys_in_hash_flash_or_params(options) || | ||
|
|
100 | + verify_method(options) || | ||
|
|
101 | + verify_request_xhr_status(options) | ||
|
|
102 | + end | ||
|
|
103 | + | ||
|
|
104 | + def verify_presence_of_keys_in_hash_flash_or_params(options) # :nodoc: | ||
|
|
105 | + [*options[:params] ].find { |v| v && params[v.to_sym].nil? } || | ||
|
|
106 | + [*options[:session]].find { |v| session[v].nil? } || | ||
|
|
107 | + [*options[:flash] ].find { |v| flash[v].nil? } | ||
|
|
108 | + end | ||
|
|
109 | + | ||
|
|
110 | + def verify_method(options) # :nodoc: | ||
|
|
111 | + [*options[:method]].all? { |v| request.request_method_symbol != v.to_sym } if options[:method] | ||
|
|
112 | + end | ||
|
|
113 | + | ||
|
|
114 | + def verify_request_xhr_status(options) # :nodoc: | ||
|
|
115 | + !!request.xhr? != options[:xhr] unless options[:xhr].nil? | ||
|
|
116 | + end | ||
|
|
117 | + | ||
|
|
118 | + def apply_redirect_to(redirect_to_option) # :nodoc: | ||
|
|
119 | + (redirect_to_option.is_a?(Symbol) && redirect_to_option != :back) ? self.__send__(redirect_to_option) : redirect_to_option | ||
|
|
120 | + end | ||
|
|
121 | + | ||
|
|
122 | + def apply_remaining_actions(options) # :nodoc: | ||
|
|
123 | + case | ||
|
|
124 | + when options[:render] ; render(options[:render]) | ||
|
|
125 | + when options[:redirect_to] ; redirect_to(apply_redirect_to(options[:redirect_to])) | ||
|
|
126 | + else head(:bad_request) | ||
|
|
127 | + end | ||
|
|
128 | + end | ||
|
|
129 | + end | ||
|
|
130 | + end | ||
|
|
131 | + | ||
|
|
132 | + ActionController::Base.send :include, ActionController::Verification |
@@ -0,0 +1,1 | |||||
|
|
1 | + require 'action_controller/verification' |
@@ -0,0 +1,20 | |||||
|
|
1 | + require 'bundler/setup' | ||
|
|
2 | + require 'test/unit' | ||
|
|
3 | + require 'active_support' | ||
|
|
4 | + require 'action_controller' | ||
|
|
5 | + require 'mocha' | ||
|
|
6 | + | ||
|
|
7 | + require File.dirname(__FILE__) + '/../lib/action_controller/verification' | ||
|
|
8 | + | ||
|
|
9 | + SharedTestRoutes = ActionDispatch::Routing::RouteSet.new | ||
|
|
10 | + SharedTestRoutes.draw do | ||
|
|
11 | + match ":controller(/:action(/:id))" | ||
|
|
12 | + end | ||
|
|
13 | + | ||
|
|
14 | + ActionController::Base.send :include, SharedTestRoutes.url_helpers | ||
|
|
15 | + | ||
|
|
16 | + module ActionController | ||
|
|
17 | + class TestCase | ||
|
|
18 | + setup { @routes = SharedTestRoutes } | ||
|
|
19 | + end | ||
|
|
20 | + end |
@@ -0,0 +1,289 | |||||
|
|
1 | + require 'test_helper' | ||
|
|
2 | + | ||
|
|
3 | + class VerificationTestController < ActionController::Base | ||
|
|
4 | + verify :only => :guarded_one, :params => "one", | ||
|
|
5 | + :add_flash => { :error => 'unguarded' }, | ||
|
|
6 | + :redirect_to => { :action => "unguarded" } | ||
|
|
7 | + | ||
|
|
8 | + verify :only => :guarded_two, :params => %w( one two ), | ||
|
|
9 | + :redirect_to => { :action => "unguarded" } | ||
|
|
10 | + | ||
|
|
11 | + verify :only => :guarded_with_flash, :params => "one", | ||
|
|
12 | + :add_flash => { :notice => "prereqs failed" }, | ||
|
|
13 | + :redirect_to => { :action => "unguarded" } | ||
|
|
14 | + | ||
|
|
15 | + verify :only => :guarded_in_session, :session => "one", | ||
|
|
16 | + :redirect_to => { :action => "unguarded" } | ||
|
|
17 | + | ||
|
|
18 | + verify :only => [:multi_one, :multi_two], :session => %w( one two ), | ||
|
|
19 | + :redirect_to => { :action => "unguarded" } | ||
|
|
20 | + | ||
|
|
21 | + verify :only => :guarded_by_method, :method => :post, | ||
|
|
22 | + :redirect_to => { :action => "unguarded" } | ||
|
|
23 | + | ||
|
|
24 | + verify :only => :guarded_by_xhr, :xhr => true, | ||
|
|
25 | + :redirect_to => { :action => "unguarded" } | ||
|
|
26 | + | ||
|
|
27 | + verify :only => :guarded_by_not_xhr, :xhr => false, | ||
|
|
28 | + :redirect_to => { :action => "unguarded" } | ||
|
|
29 | + | ||
|
|
30 | + before_filter :unconditional_redirect, :only => :two_redirects | ||
|
|
31 | + verify :only => :two_redirects, :method => :post, | ||
|
|
32 | + :redirect_to => { :action => "unguarded" } | ||
|
|
33 | + | ||
|
|
34 | + verify :only => :must_be_post, :method => :post, :render => { :status => 405, :text => "Must be post" }, :add_headers => { "Allow" => "POST" } | ||
|
|
35 | + | ||
|
|
36 | + verify :only => :must_be_put, :method => :put, :render => { :status => 405, :text => "Must be put" }, :add_headers => { "Allow" => "PUT" } | ||
|
|
37 | + | ||
|
|
38 | + verify :only => :guarded_one_for_named_route_test, :params => "one", | ||
|
|
39 | + :redirect_to => :foo_url | ||
|
|
40 | + | ||
|
|
41 | + verify :only => :no_default_action, :params => "santa" | ||
|
|
42 | + | ||
|
|
43 | + verify :only => :guarded_with_back, :method => :post, | ||
|
|
44 | + :redirect_to => :back | ||
|
|
45 | + | ||
|
|
46 | + def guarded_one | ||
|
|
47 | + render :text => "#{params[:one]}" | ||
|
|
48 | + end | ||
|
|
49 | + | ||
|
|
50 | + def guarded_one_for_named_route_test | ||
|
|
51 | + render :text => "#{params[:one]}" | ||
|
|
52 | + end | ||
|
|
53 | + | ||
|
|
54 | + def guarded_with_flash | ||
|
|
55 | + render :text => "#{params[:one]}" | ||
|
|
56 | + end | ||
|
|
57 | + | ||
|
|
58 | + def guarded_two | ||
|
|
59 | + render :text => "#{params[:one]}:#{params[:two]}" | ||
|
|
60 | + end | ||
|
|
61 | + | ||
|
|
62 | + def guarded_in_session | ||
|
|
63 | + render :text => "#{session["one"]}" | ||
|
|
64 | + end | ||
|
|
65 | + | ||
|
|
66 | + def multi_one | ||
|
|
67 | + render :text => "#{session["one"]}:#{session["two"]}" | ||
|
|
68 | + end | ||
|
|
69 | + | ||
|
|
70 | + def multi_two | ||
|
|
71 | + render :text => "#{session["two"]}:#{session["one"]}" | ||
|
|
72 | + end | ||
|
|
73 | + | ||
|
|
74 | + def guarded_by_method | ||
|
|
75 | + render :text => "#{request.method}" | ||
|
|
76 | + end | ||
|
|
77 | + | ||
|
|
78 | + def guarded_by_xhr | ||
|
|
79 | + render :text => "#{!!request.xhr?}" | ||
|
|
80 | + end | ||
|
|
81 | + | ||
|
|
82 | + def guarded_by_not_xhr | ||
|
|
83 | + render :text => "#{!!request.xhr?}" | ||
|
|
84 | + end | ||
|
|
85 | + | ||
|
|
86 | + def unguarded | ||
|
|
87 | + render :text => "#{params[:one]}" | ||
|
|
88 | + end | ||
|
|
89 | + | ||
|
|
90 | + def two_redirects | ||
|
|
91 | + render :nothing => true | ||
|
|
92 | + end | ||
|
|
93 | + | ||
|
|
94 | + def must_be_post | ||
|
|
95 | + render :text => "Was a post!" | ||
|
|
96 | + end | ||
|
|
97 | + | ||
|
|
98 | + def must_be_put | ||
|
|
99 | + render :text => "Was a put!" | ||
|
|
100 | + end | ||
|
|
101 | + | ||
|
|
102 | + def guarded_with_back | ||
|
|
103 | + render :text => "#{params[:one]}" | ||
|
|
104 | + end | ||
|
|
105 | + | ||
|
|
106 | + def no_default_action | ||
|
|
107 | + # Will never run | ||
|
|
108 | + end | ||
|
|
109 | + | ||
|
|
110 | + protected | ||
|
|
111 | + | ||
|
|
112 | + def unconditional_redirect | ||
|
|
113 | + redirect_to :action => "unguarded" | ||
|
|
114 | + end | ||
|
|
115 | + end | ||
|
|
116 | + | ||
|
|
117 | + class VerificationTest < ActionController::TestCase | ||
|
|
118 | + tests ::VerificationTestController | ||
|
|
119 | + | ||
|
|
120 | + def test_using_symbol_back_with_no_referrer | ||
|
|
121 | + assert_raise(ActionController::RedirectBackError) { get :guarded_with_back } | ||
|
|
122 | + end | ||
|
|
123 | + | ||
|
|
124 | + def test_using_symbol_back_redirects_to_referrer | ||
|
|
125 | + @request.env["HTTP_REFERER"] = "/foo" | ||
|
|
126 | + get :guarded_with_back | ||
|
|
127 | + assert_redirected_to '/foo' | ||
|
|
128 | + end | ||
|
|
129 | + | ||
|
|
130 | + def test_no_deprecation_warning_for_named_route | ||
|
|
131 | + assert_not_deprecated do | ||
|
|
132 | + with_routing do |set| | ||
|
|
133 | + set.draw do | ||
|
|
134 | + match 'foo', :to => 'test#foo', :as => :foo | ||
|
|
135 | + match 'verification_test/:action', :to => ::VerificationTestController | ||
|
|
136 | + end | ||
|
|
137 | + get :guarded_one_for_named_route_test, :two => "not one" | ||
|
|
138 | + assert_redirected_to '/foo' | ||
|
|
139 | + end | ||
|
|
140 | + end | ||
|
|
141 | + end | ||
|
|
142 | + | ||
|
|
143 | + def test_guarded_one_with_prereqs | ||
|
|
144 | + get :guarded_one, :one => "here" | ||
|
|
145 | + assert_equal "here", @response.body | ||
|
|
146 | + end | ||
|
|
147 | + | ||
|
|
148 | + def test_guarded_one_without_prereqs | ||
|
|
149 | + get :guarded_one | ||
|
|
150 | + assert_redirected_to :action => "unguarded" | ||
|
|
151 | + assert_equal 'unguarded', flash[:error] | ||
|
|
152 | + end | ||
|
|
153 | + | ||
|
|
154 | + def test_guarded_with_flash_with_prereqs | ||
|
|
155 | + get :guarded_with_flash, :one => "here" | ||
|
|
156 | + assert_equal "here", @response.body | ||
|
|
157 | + assert flash.empty? | ||
|
|
158 | + end | ||
|
|
159 | + | ||
|
|
160 | + def test_guarded_with_flash_without_prereqs | ||
|
|
161 | + get :guarded_with_flash | ||
|
|
162 | + assert_redirected_to :action => "unguarded" | ||
|
|
163 | + assert_equal "prereqs failed", flash[:notice] | ||
|
|
164 | + end | ||
|
|
165 | + | ||
|
|
166 | + def test_guarded_two_with_prereqs | ||
|
|
167 | + get :guarded_two, :one => "here", :two => "there" | ||
|
|
168 | + assert_equal "here:there", @response.body | ||
|
|
169 | + end | ||
|
|
170 | + | ||
|
|
171 | + def test_guarded_two_without_prereqs_one | ||
|
|
172 | + get :guarded_two, :two => "there" | ||
|
|
173 | + assert_redirected_to :action => "unguarded" | ||
|
|
174 | + end | ||
|
|
175 | + | ||
|
|
176 | + def test_guarded_two_without_prereqs_two | ||
|
|
177 | + get :guarded_two, :one => "here" | ||
|
|
178 | + assert_redirected_to :action => "unguarded" | ||
|
|
179 | + end | ||
|
|
180 | + | ||
|
|
181 | + def test_guarded_two_without_prereqs_both | ||
|
|
182 | + get :guarded_two | ||
|
|
183 | + assert_redirected_to :action => "unguarded" | ||
|
|
184 | + end | ||
|
|
185 | + | ||
|
|
186 | + def test_unguarded_with_params | ||
|
|
187 | + get :unguarded, :one => "here" | ||
|
|
188 | + assert_equal "here", @response.body | ||
|
|
189 | + end | ||
|
|
190 | + | ||
|
|
191 | + def test_unguarded_without_params | ||
|
|
192 | + get :unguarded | ||
|
|
193 | + assert @response.body.blank? | ||
|
|
194 | + end | ||
|
|
195 | + | ||
|
|
196 | + def test_guarded_in_session_with_prereqs | ||
|
|
197 | + get :guarded_in_session, {}, "one" => "here" | ||
|
|
198 | + assert_equal "here", @response.body | ||
|
|
199 | + end | ||
|
|
200 | + | ||
|
|
201 | + def test_guarded_in_session_without_prereqs | ||
|
|
202 | + get :guarded_in_session | ||
|
|
203 | + assert_redirected_to :action => "unguarded" | ||
|
|
204 | + end | ||
|
|
205 | + | ||
|
|
206 | + def test_multi_one_with_prereqs | ||
|
|
207 | + get :multi_one, {}, "one" => "here", "two" => "there" | ||
|
|
208 | + assert_equal "here:there", @response.body | ||
|
|
209 | + end | ||
|
|
210 | + | ||
|
|
211 | + def test_multi_one_without_prereqs | ||
|
|
212 | + get :multi_one | ||
|
|
213 | + assert_redirected_to :action => "unguarded" | ||
|
|
214 | + end | ||
|
|
215 | + | ||
|
|
216 | + def test_multi_two_with_prereqs | ||
|
|
217 | + get :multi_two, {}, "one" => "here", "two" => "there" | ||
|
|
218 | + assert_equal "there:here", @response.body | ||
|
|
219 | + end | ||
|
|
220 | + | ||
|
|
221 | + def test_multi_two_without_prereqs | ||
|
|
222 | + get :multi_two | ||
|
|
223 | + assert_redirected_to :action => "unguarded" | ||
|
|
224 | + end | ||
|
|
225 | + | ||
|
|
226 | + def test_guarded_by_method_with_prereqs | ||
|
|
227 | + post :guarded_by_method | ||
|
|
228 | + assert_equal "POST", @response.body | ||
|
|
229 | + end | ||
|
|
230 | + | ||
|
|
231 | + def test_guarded_by_method_without_prereqs | ||
|
|
232 | + get :guarded_by_method | ||
|
|
233 | + assert_redirected_to :action => "unguarded" | ||
|
|
234 | + end | ||
|
|
235 | + | ||
|
|
236 | + def test_guarded_by_xhr_with_prereqs | ||
|
|
237 | + xhr :post, :guarded_by_xhr | ||
|
|
238 | + assert_equal "true", @response.body | ||
|
|
239 | + end | ||
|
|
240 | + | ||
|
|
241 | + def test_guarded_by_xhr_without_prereqs | ||
|
|
242 | + get :guarded_by_xhr | ||
|
|
243 | + assert_redirected_to :action => "unguarded" | ||
|
|
244 | + end | ||
|
|
245 | + | ||
|
|
246 | + def test_guarded_by_not_xhr_with_prereqs | ||
|
|
247 | + get :guarded_by_not_xhr | ||
|
|
248 | + assert_equal "false", @response.body | ||
|
|
249 | + end | ||
|
|
250 | + | ||
|
|
251 | + def test_guarded_by_not_xhr_without_prereqs | ||
|
|
252 | + xhr :post, :guarded_by_not_xhr | ||
|
|
253 | + assert_redirected_to :action => "unguarded" | ||
|
|
254 | + end | ||
|
|
255 | + | ||
|
|
256 | + def test_guarded_post_and_calls_render_succeeds | ||
|
|
257 | + post :must_be_post | ||
|
|
258 | + assert_equal "Was a post!", @response.body | ||
|
|
259 | + end | ||
|
|
260 | + | ||
|
|
261 | + def test_guarded_put_and_calls_render_succeeds | ||
|
|
262 | + put :must_be_put | ||
|
|
263 | + assert_equal "Was a put!", @response.body | ||
|
|
264 | + end | ||
|
|
265 | + | ||
|
|
266 | + def test_default_failure_should_be_a_bad_request | ||
|
|
267 | + post :no_default_action | ||
|
|
268 | + assert_response :bad_request | ||
|
|
269 | + end | ||
|
|
270 | + | ||
|
|
271 | + def test_guarded_post_and_calls_render_fails_and_sets_allow_header | ||
|
|
272 | + get :must_be_post | ||
|
|
273 | + assert_response 405 | ||
|
|
274 | + assert_equal "Must be post", @response.body | ||
|
|
275 | + assert_equal "POST", @response.headers["Allow"] | ||
|
|
276 | + end | ||
|
|
277 | + | ||
|
|
278 | + def test_second_redirect | ||
|
|
279 | + assert_nothing_raised { get :two_redirects } | ||
|
|
280 | + end | ||
|
|
281 | + | ||
|
|
282 | + def test_guarded_http_method_respects_overwritten_request_method | ||
|
|
283 | + # Overwrite http method on application level like Rails supports via sending a _method parameter | ||
|
|
284 | + @request.stubs(:request_method_symbol).returns(:put) | ||
|
|
285 | + | ||
|
|
286 | + post :must_be_put | ||
|
|
287 | + assert_equal "Was a put!", @response.body | ||
|
|
288 | + end | ||
|
|
289 | + end |
@@ -0,0 +1,26 | |||||
|
|
1 | + $:.push File.expand_path("../lib", __FILE__) | ||
|
|
2 | + | ||
|
|
3 | + Gem::Specification.new do |s| | ||
|
|
4 | + s.name = "verification" | ||
|
|
5 | + s.version = "1.0.3" | ||
|
|
6 | + s.platform = Gem::Platform::RUBY | ||
|
|
7 | + s.authors = ["David Heinemeier Hansson"] | ||
|
|
8 | + s.email = ["david@loudthinking.com"] | ||
|
|
9 | + s.homepage = "https://rubygems.org/gems/verification" | ||
|
|
10 | + s.summary = %q{Verify preconditions for Rails actions} | ||
|
|
11 | + s.description = %q{Verify preconditions for Rails actions} | ||
|
|
12 | + | ||
|
|
13 | + s.files = `git ls-files`.split("\n") | ||
|
|
14 | + s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
|
|
15 | + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
|
|
16 | + s.require_paths = ["lib"] | ||
|
|
17 | + | ||
|
|
18 | + s.add_dependency('activesupport', '>= 3.0.0', '< 3.3.0') | ||
|
|
19 | + s.add_dependency('actionpack', '>= 3.0.0', '< 3.3.0') | ||
|
|
20 | + | ||
|
|
21 | + s.add_development_dependency('rake') | ||
|
|
22 | + s.add_development_dependency('test-unit') | ||
|
|
23 | + s.add_development_dependency('activesupport') | ||
|
|
24 | + s.add_development_dependency('actionpack') | ||
|
|
25 | + s.add_development_dependency('mocha') | ||
|
|
26 | + end |
@@ -41,3 +41,7 | |||||
|
41 | gem "rdiscount", :require => "rdiscount" |
|
41 | gem "rdiscount", :require => "rdiscount" |
|
42 | gem "test-unit" |
|
42 | gem "test-unit" |
|
43 | gem 'will_paginate', '~> 3.0.0' |
|
43 | gem 'will_paginate', '~> 3.0.0' |
|
|
44 | + | ||
|
|
45 | + group :test, :development do | ||
|
|
46 | + gem "rspec-rails", "~> 2.0" | ||
|
|
47 | + end |
@@ -37,6 +37,7 | |||||
|
37 | coffee-script-source |
|
37 | coffee-script-source |
|
38 | execjs |
|
38 | execjs |
|
39 | coffee-script-source (1.3.3) |
|
39 | coffee-script-source (1.3.3) |
|
|
40 | + diff-lcs (1.1.3) | ||
|
40 | erubis (2.7.0) |
|
41 | erubis (2.7.0) |
|
41 | execjs (1.4.0) |
|
42 | execjs (1.4.0) |
|
42 | multi_json (~> 1.0) |
|
43 | multi_json (~> 1.0) |
@@ -81,6 +82,19 | |||||
|
81 | rdiscount (1.6.8) |
|
82 | rdiscount (1.6.8) |
|
82 | rdoc (3.12) |
|
83 | rdoc (3.12) |
|
83 | json (~> 1.4) |
|
84 | json (~> 1.4) |
|
|
85 | + rspec (2.11.0) | ||
|
|
86 | + rspec-core (~> 2.11.0) | ||
|
|
87 | + rspec-expectations (~> 2.11.0) | ||
|
|
88 | + rspec-mocks (~> 2.11.0) | ||
|
|
89 | + rspec-core (2.11.1) | ||
|
|
90 | + rspec-expectations (2.11.3) | ||
|
|
91 | + diff-lcs (~> 1.1.3) | ||
|
|
92 | + rspec-mocks (2.11.3) | ||
|
|
93 | + rspec-rails (2.11.0) | ||
|
|
94 | + actionpack (>= 3.0) | ||
|
|
95 | + activesupport (>= 3.0) | ||
|
|
96 | + railties (>= 3.0) | ||
|
|
97 | + rspec (~> 2.11.0) | ||
|
84 | sass (3.2.1) |
|
98 | sass (3.2.1) |
|
85 | sass-rails (3.2.5) |
|
99 | sass-rails (3.2.5) |
|
86 | railties (~> 3.2.0) |
|
100 | railties (~> 3.2.0) |
@@ -113,6 +127,7 | |||||
|
113 | prototype-rails |
|
127 | prototype-rails |
|
114 | rails (= 3.2.8) |
|
128 | rails (= 3.2.8) |
|
115 | rdiscount |
|
129 | rdiscount |
|
|
130 | + rspec-rails (~> 2.0) | ||
|
116 | sass-rails (~> 3.2.3) |
|
131 | sass-rails (~> 3.2.3) |
|
117 | test-unit |
|
132 | test-unit |
|
118 | tmail |
|
133 | tmail |
@@ -3,6 +3,6 | |||||
|
3 | has_and_belongs_to_many :users |
|
3 | has_and_belongs_to_many :users |
|
4 | has_and_belongs_to_many :problems |
|
4 | has_and_belongs_to_many :problems |
|
5 |
|
5 | ||
|
6 |
- |
|
6 | + scope :enabled, :conditions => {:enabled => true} |
|
7 |
|
7 | ||
|
8 | end |
|
8 | end |
@@ -8,7 +8,7 | |||||
|
8 | validates_format_of :name, :with => /^\w+$/ |
|
8 | validates_format_of :name, :with => /^\w+$/ |
|
9 | validates_presence_of :full_name |
|
9 | validates_presence_of :full_name |
|
10 |
|
10 | ||
|
11 |
- |
|
11 | + scope :available, :conditions => {:available => true} |
|
12 |
|
12 | ||
|
13 | DEFAULT_TIME_LIMIT = 1 |
|
13 | DEFAULT_TIME_LIMIT = 1 |
|
14 | DEFAULT_MEMORY_LIMIT = 32 |
|
14 | DEFAULT_MEMORY_LIMIT = 32 |
@@ -23,7 +23,7 | |||||
|
23 |
|
23 | ||
|
24 | has_and_belongs_to_many :contests, :uniq => true, :order => 'name' |
|
24 | has_and_belongs_to_many :contests, :uniq => true, :order => 'name' |
|
25 |
|
25 | ||
|
26 |
- |
|
26 | + scope :activated_users, :conditions => {:activated => true} |
|
27 |
|
27 | ||
|
28 | validates_presence_of :login |
|
28 | validates_presence_of :login |
|
29 | validates_uniqueness_of :login |
|
29 | validates_uniqueness_of :login |
@@ -2,7 +2,7 | |||||
|
2 |
|
2 | ||
|
3 | <%= error_messages_for :announcement %> |
|
3 | <%= error_messages_for :announcement %> |
|
4 |
|
4 | ||
|
5 | - <% form_for(@announcement) do |f| %> |
|
5 | + <%= form_for(@announcement) do |f| %> |
|
6 | <p> |
|
6 | <p> |
|
7 | <b>Title</b><br /> |
|
7 | <b>Title</b><br /> |
|
8 | <%= f.text_field :title %> |
|
8 | <%= f.text_field :title %> |
@@ -2,7 +2,7 | |||||
|
2 |
|
2 | ||
|
3 | <%= error_messages_for :announcement %> |
|
3 | <%= error_messages_for :announcement %> |
|
4 |
|
4 | ||
|
5 | - <% form_for(@announcement) do |f| %> |
|
5 | + <%= form_for(@announcement) do |f| %> |
|
6 | <p> |
|
6 | <p> |
|
7 | <b>Title</b><br /> |
|
7 | <b>Title</b><br /> |
|
8 | <%= f.text_field :title %> |
|
8 | <%= f.text_field :title %> |
@@ -1,6 +1,6 | |||||
|
1 | <h1>Editing contest</h1> |
|
1 | <h1>Editing contest</h1> |
|
2 |
|
2 | ||
|
3 | - <% form_for(@contest) do |f| %> |
|
3 | + <%= form_for(@contest) do |f| %> |
|
4 | <%= f.error_messages %> |
|
4 | <%= f.error_messages %> |
|
5 |
|
5 | ||
|
6 | <table> |
|
6 | <table> |
@@ -1,6 +1,6 | |||||
|
1 | <h1>New contest</h1> |
|
1 | <h1>New contest</h1> |
|
2 |
|
2 | ||
|
3 | - <% form_for(@contest) do |f| %> |
|
3 | + <%= form_for(@contest) do |f| %> |
|
4 | <%= f.error_messages %> |
|
4 | <%= f.error_messages %> |
|
5 |
|
5 | ||
|
6 | <p> |
|
6 | <p> |
@@ -12,7 +12,7 | |||||
|
12 | %hr/ |
|
12 | %hr/ |
|
13 |
|
13 | ||
|
14 | %div{ :style => "border: solid 1px gray; padding: 4px; background: #eeeeff;"} |
|
14 | %div{ :style => "border: solid 1px gray; padding: 4px; background: #eeeeff;"} |
|
15 |
- |
|
15 | + = form_tag :controller => 'login', :action => 'login' do |
|
16 | %table |
|
16 | %table |
|
17 | %tr |
|
17 | %tr |
|
18 | %td{:align => "right"} |
|
18 | %td{:align => "right"} |
@@ -1,4 +1,4 | |||||
|
1 | - <% form_tag({:action => 'submit'}, :multipart => true) do %> |
|
1 | + <%= form_tag({:action => 'submit'}, :multipart => true) do %> |
|
2 | <b>Problem:</b> <%= select 'submission', 'problem_id', |
|
2 | <b>Problem:</b> <%= select 'submission', 'problem_id', |
|
3 | [[(t 'main.specified_in_header'),'-1']] + |
|
3 | [[(t 'main.specified_in_header'),'-1']] + |
|
4 | @problems.collect {|p| [p.full_name, p.id]}, |
|
4 | @problems.collect {|p| [p.full_name, p.id]}, |
@@ -1,6 +1,6 | |||||
|
1 | <h1>Editing problem</h1> |
|
1 | <h1>Editing problem</h1> |
|
2 |
|
2 | ||
|
3 | - <% form_tag :action => 'update', :id => @problem do %> |
|
3 | + <%= form_tag :action => 'update', :id => @problem do %> |
|
4 | <%= render :partial => 'form' %> |
|
4 | <%= render :partial => 'form' %> |
|
5 | <%= submit_tag 'Edit' %> |
|
5 | <%= submit_tag 'Edit' %> |
|
6 | <% end %> |
|
6 | <% end %> |
@@ -14,7 +14,7 | |||||
|
14 | </p> |
|
14 | </p> |
|
15 |
|
15 | ||
|
16 | <div class="submitbox"> |
|
16 | <div class="submitbox"> |
|
17 | - <% form_tag :action => 'quick_create' do %> |
|
17 | + <%= form_tag :action => 'quick_create' do %> |
|
18 | <b>Quick New:</b> |
|
18 | <b>Quick New:</b> |
|
19 | <label for="problem_name">Name</label> |
|
19 | <label for="problem_name">Name</label> |
|
20 | <%= text_field 'problem', 'name' %> | |
|
20 | <%= text_field 'problem', 'name' %> | |
@@ -1,6 +1,6 | |||||
|
1 | <h1>New problem</h1> |
|
1 | <h1>New problem</h1> |
|
2 |
|
2 | ||
|
3 | - <% form_tag :action => 'create' do %> |
|
3 | + <%= form_tag :action => 'create' do %> |
|
4 | <%= render :partial => 'form' %> |
|
4 | <%= render :partial => 'form' %> |
|
5 | <%= submit_tag "Create" %> |
|
5 | <%= submit_tag "Create" %> |
|
6 | <% end %> |
|
6 | <% end %> |
@@ -2,7 +2,7 | |||||
|
2 |
|
2 | ||
|
3 | <%= error_messages_for :site %> |
|
3 | <%= error_messages_for :site %> |
|
4 |
|
4 | ||
|
5 | - <% form_for(@site) do |f| %> |
|
5 | + <%= form_for(@site) do |f| %> |
|
6 | <p> |
|
6 | <p> |
|
7 | <b>Name</b><br /> |
|
7 | <b>Name</b><br /> |
|
8 | <%= f.text_field :name %> |
|
8 | <%= f.text_field :name %> |
@@ -2,7 +2,7 | |||||
|
2 |
|
2 | ||
|
3 | <%= error_messages_for :site %> |
|
3 | <%= error_messages_for :site %> |
|
4 |
|
4 | ||
|
5 | - <% form_for(@site) do |f| %> |
|
5 | + <%= form_for(@site) do |f| %> |
|
6 | <p> |
|
6 | <p> |
|
7 | <b>Name</b><br /> |
|
7 | <b>Name</b><br /> |
|
8 | <%= f.text_field :name %> |
|
8 | <%= f.text_field :name %> |
@@ -15,7 +15,7 | |||||
|
15 | <%= link_to "[no contest]", :action => 'contests', :id => 'none' %> |
|
15 | <%= link_to "[no contest]", :action => 'contests', :id => 'none' %> |
|
16 | <% end %> |
|
16 | <% end %> |
|
17 | <br/> |
|
17 | <br/> |
|
18 | - <% form_tag :action => 'assign_from_list' do %> |
|
18 | + <%= form_tag :action => 'assign_from_list' do %> |
|
19 | <%= hidden_field_tag 'users_contest_id', (@contest ? @contest.id : 'none') %> |
|
19 | <%= hidden_field_tag 'users_contest_id', (@contest ? @contest.id : 'none') %> |
|
20 | Assign all to |
|
20 | Assign all to |
|
21 | <%= select("new_contest","id",Contest.all.collect {|c| [c.title, c.id]}) %> |
|
21 | <%= select("new_contest","id",Contest.all.collect {|c| [c.title, c.id]}) %> |
@@ -1,6 +1,6 | |||||
|
1 | <h1>Editing user</h1> |
|
1 | <h1>Editing user</h1> |
|
2 |
|
2 | ||
|
3 | - <% form_tag :action => 'update', :id => @user do %> |
|
3 | + <%= form_tag :action => 'update', :id => @user do %> |
|
4 | <%= render :partial => 'form' %> |
|
4 | <%= render :partial => 'form' %> |
|
5 | <%= submit_tag 'Edit' %> |
|
5 | <%= submit_tag 'Edit' %> |
|
6 | <% end %> |
|
6 | <% end %> |
@@ -2,7 +2,7 | |||||
|
2 |
|
2 | ||
|
3 | <div class="submitbox"> |
|
3 | <div class="submitbox"> |
|
4 | <b>Quick add</b> |
|
4 | <b>Quick add</b> |
|
5 | - <% form_tag :action => 'create' do %> |
|
5 | + <%= form_tag :action => 'create' do %> |
|
6 | <table border="0"> |
|
6 | <table border="0"> |
|
7 | <tr> |
|
7 | <tr> |
|
8 | <td><label for="user_login">Login</label></td> |
|
8 | <td><label for="user_login">Login</label></td> |
@@ -23,7 +23,7 | |||||
|
23 | <% end %> |
|
23 | <% end %> |
|
24 | <br/> |
|
24 | <br/> |
|
25 | <b>Import from site management</b> |
|
25 | <b>Import from site management</b> |
|
26 | - <% form_tag({:action => 'import'}, :multipart => true) do %> |
|
26 | + <%= form_tag({:action => 'import'}, :multipart => true) do %> |
|
27 | File: <%= file_field_tag 'file' %> <%= submit_tag 'Import' %> |
|
27 | File: <%= file_field_tag 'file' %> <%= submit_tag 'Import' %> |
|
28 | <% end %> |
|
28 | <% end %> |
|
29 | <br/> |
|
29 | <br/> |
@@ -1,6 +1,6 | |||||
|
1 | <h1>New user</h1> |
|
1 | <h1>New user</h1> |
|
2 |
|
2 | ||
|
3 | - <% form_tag :action => 'create' do %> |
|
3 | + <%= form_tag :action => 'create' do %> |
|
4 | <%= render :partial => 'form' %> |
|
4 | <%= render :partial => 'form' %> |
|
5 | <%= submit_tag "Create" %> |
|
5 | <%= submit_tag "Create" %> |
|
6 | <% end %> |
|
6 | <% end %> |
@@ -1,6 +1,6 | |||||
|
1 | <h1>Adding list of users</h1> |
|
1 | <h1>Adding list of users</h1> |
|
2 |
|
2 | ||
|
3 | - <% form_tag :action => 'create_from_list' do %> |
|
3 | + <%= form_tag :action => 'create_from_list' do %> |
|
4 | <%= submit_tag 'create users' %><br/> |
|
4 | <%= submit_tag 'create users' %><br/> |
|
5 | List of user information in this format: <tt>user_id,name(,passwd(,alias))</tt><br/> |
|
5 | List of user information in this format: <tt>user_id,name(,passwd(,alias))</tt><br/> |
|
6 | Note that <tt>passwd</tt> and <tt>alias</tt> is optional.<br/> |
|
6 | Note that <tt>passwd</tt> and <tt>alias</tt> is optional.<br/> |
@@ -1,54 +1,38 | |||||
|
1 |
- # This file is copied to |
|
1 | + # This file is copied to spec/ when you run 'rails generate rspec:install' |
|
2 | - # from the project root directory. |
|
||
|
3 | ENV["RAILS_ENV"] ||= 'test' |
|
2 | ENV["RAILS_ENV"] ||= 'test' |
|
4 |
- require File.expand_path( |
|
3 | + require File.expand_path("../../config/environment", __FILE__) |
|
5 |
- require ' |
|
4 | + require 'rspec/rails' |
|
6 |
- require ' |
|
5 | + require 'rspec/autorun' |
|
7 | - |
|
||
|
8 | - # Uncomment the next line to use webrat's matchers |
|
||
|
9 | - #require 'webrat/integrations/rspec-rails' |
|
||
|
10 | - |
|
||
|
11 | - # Requires supporting files with custom matchers and macros, etc, |
|
||
|
12 | - # in ./support/ and its subdirectories. |
|
||
|
13 | - Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f} |
|
||
|
14 | - |
|
||
|
15 | - Spec::Runner.configure do |config| |
|
||
|
16 | - # If you're not using ActiveRecord you should remove these |
|
||
|
17 | - # lines, delete config/database.yml and disable :active_record |
|
||
|
18 | - # in your config/boot.rb |
|
||
|
19 | - config.use_transactional_fixtures = true |
|
||
|
20 | - config.use_instantiated_fixtures = false |
|
||
|
21 | - config.fixture_path = RAILS_ROOT + '/test/fixtures/' |
|
||
|
22 |
|
6 | ||
|
23 | - # == Fixtures |
|
7 | + # Requires supporting ruby files with custom matchers and macros, etc, |
|
24 | - # |
|
8 | + # in spec/support/ and its subdirectories. |
|
25 | - # You can declare fixtures for each example_group like this: |
|
9 | + Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} |
|
26 | - # describe "...." do |
|
10 | + |
|
27 | - # fixtures :table_a, :table_b |
|
11 | + RSpec.configure do |config| |
|
28 | - # |
|
12 | + # ## Mock Framework |
|
29 | - # Alternatively, if you prefer to declare them only once, you can |
|
||
|
30 | - # do so right here. Just uncomment the next line and replace the fixture |
|
||
|
31 | - # names with your fixtures. |
|
||
|
32 | - # |
|
||
|
33 | - # config.global_fixtures = :table_a, :table_b |
|
||
|
34 | # |
|
13 | # |
|
35 | - # If you declare global fixtures, be aware that they will be declared |
|
14 | + # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: |
|
36 | - # for all of your examples, even those that don't use them. |
|
||
|
37 | - # |
|
||
|
38 | - # You can also declare which fixtures to use (for example fixtures for test/fixtures): |
|
||
|
39 | - # |
|
||
|
40 | - # config.fixture_path = RAILS_ROOT + '/spec/fixtures/' |
|
||
|
41 | - # |
|
||
|
42 | - # == Mock Framework |
|
||
|
43 | - # |
|
||
|
44 | - # RSpec uses it's own mocking framework by default. If you prefer to |
|
||
|
45 | - # use mocha, flexmock or RR, uncomment the appropriate line: |
|
||
|
46 | # |
|
15 | # |
|
47 | # config.mock_with :mocha |
|
16 | # config.mock_with :mocha |
|
48 | # config.mock_with :flexmock |
|
17 | # config.mock_with :flexmock |
|
49 | # config.mock_with :rr |
|
18 | # config.mock_with :rr |
|
50 | - # |
|
19 | + |
|
51 | - # == Notes |
|
20 | + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures |
|
52 | - # |
|
21 | + config.fixture_path = "#{::Rails.root}/spec/fixtures" |
|
53 | - # For more information take a look at Spec::Runner::Configuration and Spec::Runner |
|
22 | + |
|
|
23 | + # If you're not using ActiveRecord, or you'd prefer not to run each of your | ||
|
|
24 | + # examples within a transaction, remove the following line or assign false | ||
|
|
25 | + # instead of true. | ||
|
|
26 | + config.use_transactional_fixtures = true | ||
|
|
27 | + | ||
|
|
28 | + # If true, the base class of anonymous controllers will be inferred | ||
|
|
29 | + # automatically. This will be the default behavior in future versions of | ||
|
|
30 | + # rspec-rails. | ||
|
|
31 | + config.infer_base_class_for_anonymous_controllers = false | ||
|
|
32 | + | ||
|
|
33 | + # Run specs in random order to surface order dependencies. If you find an | ||
|
|
34 | + # order dependency and want to debug it, you can fix the order by providing | ||
|
|
35 | + # the seed, which is printed after each run. | ||
|
|
36 | + # --seed 1234 | ||
|
|
37 | + config.order = "random" | ||
|
54 | end |
|
38 | end |
deleted file |
You need to be logged in to leave comments.
Login now