Description:
added verify plug-in, fixed form_for, form_tag in views, changed named_scope to scope
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r319:f7101d4aef84 - - 34 files changed: 619 inserted, 210 deleted

@@ -0,0 +1,3
1 + source "https://rubygems.org"
2 +
3 + gemspec
@@ -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
@@ -32,12 +32,16
32
32
33 # Deploy with Capistrano
33 # Deploy with Capistrano
34 # gem 'capistrano'
34 # gem 'capistrano'
35
35
36 # To use debugger
36 # To use debugger
37 # gem 'debugger'
37 # gem 'debugger'
38
38
39 gem "haml"
39 gem "haml"
40 gem "tmail"
40 gem "tmail"
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
@@ -28,24 +28,25
28 activesupport (3.2.8)
28 activesupport (3.2.8)
29 i18n (~> 0.6)
29 i18n (~> 0.6)
30 multi_json (~> 1.0)
30 multi_json (~> 1.0)
31 arel (3.0.2)
31 arel (3.0.2)
32 builder (3.0.3)
32 builder (3.0.3)
33 coffee-rails (3.2.2)
33 coffee-rails (3.2.2)
34 coffee-script (>= 2.2.0)
34 coffee-script (>= 2.2.0)
35 railties (~> 3.2.0)
35 railties (~> 3.2.0)
36 coffee-script (2.2.0)
36 coffee-script (2.2.0)
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)
43 haml (3.1.7)
44 haml (3.1.7)
44 hike (1.2.1)
45 hike (1.2.1)
45 i18n (0.6.1)
46 i18n (0.6.1)
46 journey (1.0.4)
47 journey (1.0.4)
47 json (1.7.5)
48 json (1.7.5)
48 mail (2.4.4)
49 mail (2.4.4)
49 i18n (>= 0.4.0)
50 i18n (>= 0.4.0)
50 mime-types (~> 1.16)
51 mime-types (~> 1.16)
51 treetop (~> 1.4.8)
52 treetop (~> 1.4.8)
@@ -72,24 +73,37
72 railties (= 3.2.8)
73 railties (= 3.2.8)
73 railties (3.2.8)
74 railties (3.2.8)
74 actionpack (= 3.2.8)
75 actionpack (= 3.2.8)
75 activesupport (= 3.2.8)
76 activesupport (= 3.2.8)
76 rack-ssl (~> 1.3.2)
77 rack-ssl (~> 1.3.2)
77 rake (>= 0.8.7)
78 rake (>= 0.8.7)
78 rdoc (~> 3.4)
79 rdoc (~> 3.4)
79 thor (>= 0.14.6, < 2.0)
80 thor (>= 0.14.6, < 2.0)
80 rake (0.9.2.2)
81 rake (0.9.2.2)
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)
87 sass (>= 3.1.10)
101 sass (>= 3.1.10)
88 tilt (~> 1.3)
102 tilt (~> 1.3)
89 sprockets (2.1.3)
103 sprockets (2.1.3)
90 hike (~> 1.2)
104 hike (~> 1.2)
91 rack (~> 1.0)
105 rack (~> 1.0)
92 tilt (~> 1.1, != 1.3.0)
106 tilt (~> 1.1, != 1.3.0)
93 test-unit (2.5.2)
107 test-unit (2.5.2)
94 thor (0.16.0)
108 thor (0.16.0)
95 tilt (1.3.3)
109 tilt (1.3.3)
@@ -104,17 +118,18
104 will_paginate (3.0.3)
118 will_paginate (3.0.3)
105
119
106 PLATFORMS
120 PLATFORMS
107 ruby
121 ruby
108
122
109 DEPENDENCIES
123 DEPENDENCIES
110 coffee-rails (~> 3.2.1)
124 coffee-rails (~> 3.2.1)
111 haml
125 haml
112 mysql2
126 mysql2
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
119 uglifier (>= 1.0.3)
134 uglifier (>= 1.0.3)
120 will_paginate (~> 3.0.0)
135 will_paginate (~> 3.0.0)
@@ -1,8 +1,8
1 class Contest < ActiveRecord::Base
1 class Contest < ActiveRecord::Base
2
2
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 - named_scope :enabled, :conditions => {:enabled => true}
6 + scope :enabled, :conditions => {:enabled => true}
7
7
8 end
8 end
@@ -1,23 +1,23
1 class Problem < ActiveRecord::Base
1 class Problem < ActiveRecord::Base
2
2
3 belongs_to :description
3 belongs_to :description
4 has_and_belongs_to_many :contests, :uniq => true
4 has_and_belongs_to_many :contests, :uniq => true
5 has_many :test_pairs, :dependent => :delete_all
5 has_many :test_pairs, :dependent => :delete_all
6
6
7 validates_presence_of :name
7 validates_presence_of :name
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 - named_scope :available, :conditions => {:available => true}
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
15
15
16 def self.find_available_problems
16 def self.find_available_problems
17 Problem.available.all(:order => "date_added DESC")
17 Problem.available.all(:order => "date_added DESC")
18 end
18 end
19
19
20 def self.create_from_import_form_params(params, old_problem=nil)
20 def self.create_from_import_form_params(params, old_problem=nil)
21 org_problem = old_problem || Problem.new
21 org_problem = old_problem || Problem.new
22 import_params, problem = Problem.extract_params_and_check(params,
22 import_params, problem = Problem.extract_params_and_check(params,
23 org_problem)
23 org_problem)
@@ -14,25 +14,25
14 has_many :replied_messages,
14 has_many :replied_messages,
15 :class_name => "Message",
15 :class_name => "Message",
16 :foreign_key => "receiver_id",
16 :foreign_key => "receiver_id",
17 :order => 'created_at DESC'
17 :order => 'created_at DESC'
18
18
19 has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy
19 has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy
20
20
21 belongs_to :site
21 belongs_to :site
22 belongs_to :country
22 belongs_to :country
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 - named_scope :activated_users, :conditions => {:activated => true}
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
30 validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/
30 validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/
31 validates_length_of :login, :within => 3..30
31 validates_length_of :login, :within => 3..30
32
32
33 validates_presence_of :full_name
33 validates_presence_of :full_name
34 validates_length_of :full_name, :minimum => 1
34 validates_length_of :full_name, :minimum => 1
35
35
36 validates_presence_of :password, :if => :password_required?
36 validates_presence_of :password, :if => :password_required?
37 validates_length_of :password, :within => 4..20, :if => :password_required?
37 validates_length_of :password, :within => 4..20, :if => :password_required?
38 validates_confirmation_of :password, :if => :password_required?
38 validates_confirmation_of :password, :if => :password_required?
@@ -1,17 +1,17
1 <h1>Editing announcement</h1>
1 <h1>Editing announcement</h1>
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 %>
9 </p>
9 </p>
10
10
11 <p>
11 <p>
12 <b>Notes</b> (shown internally, used to organize announcements)<br />
12 <b>Notes</b> (shown internally, used to organize announcements)<br />
13 <%= f.text_field :notes %>
13 <%= f.text_field :notes %>
14 </p>
14 </p>
15
15
16 <p>
16 <p>
17 <b>Body</b><br />
17 <b>Body</b><br />
@@ -1,17 +1,17
1 <h1>New announcement</h1>
1 <h1>New announcement</h1>
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 %>
9 </p>
9 </p>
10
10
11 <p>
11 <p>
12 <b>Notes</b> (shown internally, used to organize announcements)<br />
12 <b>Notes</b> (shown internally, used to organize announcements)<br />
13 <%= f.text_field :notes %>
13 <%= f.text_field :notes %>
14 </p>
14 </p>
15
15
16 <p>
16 <p>
17 <b>Body</b><br />
17 <b>Body</b><br />
@@ -1,15 +1,15
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>
7 <tr>
7 <tr>
8 <td><%= f.label :name %></td>
8 <td><%= f.label :name %></td>
9 <td><%= f.text_field :name %></td>
9 <td><%= f.text_field :name %></td>
10 </tr>
10 </tr>
11 <tr>
11 <tr>
12 <td><%= f.label :title %></td>
12 <td><%= f.label :title %></td>
13 <td><%= f.text_field :title %></td>
13 <td><%= f.text_field :title %></td>
14 </tr>
14 </tr>
15 <tr>
15 <tr>
@@ -1,15 +1,15
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>
7 <%= f.label :name %><br />
7 <%= f.label :name %><br />
8 <%= f.text_field :name %>
8 <%= f.text_field :name %>
9 </p>
9 </p>
10 <p>
10 <p>
11 <%= f.label :title %><br />
11 <%= f.label :title %><br />
12 <%= f.text_field :title %>
12 <%= f.text_field :title %>
13 </p>
13 </p>
14 <p>
14 <p>
15 <%= f.label :enabled %><br />
15 <%= f.label :enabled %><br />
@@ -3,25 +3,25
3
3
4 - if !@hidelogin
4 - if !@hidelogin
5 =t 'login.message'
5 =t 'login.message'
6 %br/
6 %br/
7 %br/
7 %br/
8
8
9 - if flash[:notice]
9 - if flash[:notice]
10 %hr/
10 %hr/
11 %b= flash[:notice]
11 %b= flash[:notice]
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 - - form_tag :controller => 'login', :action => 'login' do
15 + = form_tag :controller => 'login', :action => 'login' do
16 %table
16 %table
17 %tr
17 %tr
18 %td{:align => "right"}
18 %td{:align => "right"}
19 ="#{t 'login_label'}:"
19 ="#{t 'login_label'}:"
20 %td= text_field_tag 'login'
20 %td= text_field_tag 'login'
21 %tr
21 %tr
22 %td{:align => "right"}
22 %td{:align => "right"}
23 ="#{t 'password_label'}:"
23 ="#{t 'password_label'}:"
24 %td= password_field_tag
24 %td= password_field_tag
25 = submit_tag t('login.login_submit')
25 = submit_tag t('login.login_submit')
26 %br/
26 %br/
27
27
@@ -1,8 +1,8
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]},
5 :selected => '-1' %>
5 :selected => '-1' %>
6 <b>File:</b> <%= file_field_tag 'file' %>
6 <b>File:</b> <%= file_field_tag 'file' %>
7 <%= submit_tag 'Submit' %>
7 <%= submit_tag 'Submit' %>
8 <% end %>
8 <% end %>
@@ -1,9 +1,9
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 %>
7
7
8 <%= link_to 'Show', :action => 'show', :id => @problem %> |
8 <%= link_to 'Show', :action => 'show', :id => @problem %> |
9 <%= link_to 'Back', :action => 'list' %>
9 <%= link_to 'Back', :action => 'list' %>
@@ -5,25 +5,25
5
5
6 <h1>Listing problems</h1>
6 <h1>Listing problems</h1>
7
7
8 <p>
8 <p>
9 <%= link_to '[New problem]', :action => 'new' %>
9 <%= link_to '[New problem]', :action => 'new' %>
10 <%= link_to '[Manage problems]', :action => 'manage' %>
10 <%= link_to '[Manage problems]', :action => 'manage' %>
11 <%= link_to '[Import problems]', :action => 'import' %>
11 <%= link_to '[Import problems]', :action => 'import' %>
12 <%= link_to '[Turn off all problems]', :action => 'turn_all_off' %>
12 <%= link_to '[Turn off all problems]', :action => 'turn_all_off' %>
13 <%= link_to '[Turn on all problems]', :action => 'turn_all_on' %>
13 <%= link_to '[Turn on all problems]', :action => 'turn_all_on' %>
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' %> |
21 <label for="problem_full_name">Full name</label>
21 <label for="problem_full_name">Full name</label>
22 <%= text_field 'problem', 'full_name' %>
22 <%= text_field 'problem', 'full_name' %>
23 <%= submit_tag "Create" %>
23 <%= submit_tag "Create" %>
24 <% end %>
24 <% end %>
25 </div>
25 </div>
26
26
27 <table>
27 <table>
28 <tr>
28 <tr>
29 <th>Name</th>
29 <th>Name</th>
@@ -1,8 +1,8
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 %>
7
7
8 <%= link_to 'Back', :action => 'list' %>
8 <%= link_to 'Back', :action => 'list' %>
@@ -1,17 +1,17
1 <h1>Editing site</h1>
1 <h1>Editing site</h1>
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 %>
9 </p>
9 </p>
10
10
11 <p>
11 <p>
12 <b>Password</b><br />
12 <b>Password</b><br />
13 <%= f.text_field :password %>
13 <%= f.text_field :password %>
14 </p>
14 </p>
15
15
16 <p>
16 <p>
17 <b>Started</b><br />
17 <b>Started</b><br />
@@ -1,17 +1,17
1 <h1>New site</h1>
1 <h1>New site</h1>
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 %>
9 </p>
9 </p>
10
10
11 <p>
11 <p>
12 <b>Password</b><br />
12 <b>Password</b><br />
13 <%= f.text_field :password %>
13 <%= f.text_field :password %>
14 </p>
14 </p>
15
15
16 <p>
16 <p>
17 <b>Started</b><br />
17 <b>Started</b><br />
@@ -6,25 +6,25
6 <div class="submitbox">
6 <div class="submitbox">
7 <%= link_to '[View all users]', :action => 'list' %>
7 <%= link_to '[View all users]', :action => 'list' %>
8 <% if Configuration.multicontests? %>
8 <% if Configuration.multicontests? %>
9 <%= link_to '[Manage bulk users in contests]', :action => 'contest_management' %>
9 <%= link_to '[Manage bulk users in contests]', :action => 'contest_management' %>
10 <br/>
10 <br/>
11 View users in:
11 View users in:
12 <% @contests.each do |contest| %>
12 <% @contests.each do |contest| %>
13 <%= link_to "[#{contest.name}]", :action => 'contests', :id => contest.id %>
13 <%= link_to "[#{contest.name}]", :action => 'contests', :id => contest.id %>
14 <% end %>
14 <% end %>
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]}) %>
22 <%= submit_tag "Assign", :confirm => 'Are you sure?' %>
22 <%= submit_tag "Assign", :confirm => 'Are you sure?' %>
23 <% end %>
23 <% end %>
24 </div>
24 </div>
25
25
26 <table class="info">
26 <table class="info">
27 <tr class="info-head">
27 <tr class="info-head">
28 <th>Login</th>
28 <th>Login</th>
29 <th>Full name</th>
29 <th>Full name</th>
30 <th>Email</th>
30 <th>Email</th>
@@ -1,9 +1,9
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 %>
7
7
8 <%= link_to 'Show', :action => 'show', :id => @user %> |
8 <%= link_to 'Show', :action => 'show', :id => @user %> |
9 <%= link_to 'Back', :action => 'list' %>
9 <%= link_to 'Back', :action => 'list' %>
@@ -1,38 +1,38
1 <h1>Listing users</h1>
1 <h1>Listing users</h1>
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>
9 <td><label for="user_full_name">Full name</label></td>
9 <td><label for="user_full_name">Full name</label></td>
10 <td><label for="user_password">Password</label></td>
10 <td><label for="user_password">Password</label></td>
11 <td><label for="user_password_confirmation">Confirm</label></td>
11 <td><label for="user_password_confirmation">Confirm</label></td>
12 <td><label for="user_email">Email</label></td>
12 <td><label for="user_email">Email</label></td>
13 </tr>
13 </tr>
14 <tr>
14 <tr>
15 <td><%= text_field 'user', 'login', :size => 10 %></td>
15 <td><%= text_field 'user', 'login', :size => 10 %></td>
16 <td><%= text_field 'user', 'full_name', :size => 30 %></td>
16 <td><%= text_field 'user', 'full_name', :size => 30 %></td>
17 <td><%= password_field 'user', 'password', :size => 10 %></td>
17 <td><%= password_field 'user', 'password', :size => 10 %></td>
18 <td><%= password_field 'user', 'password_confirmation', :size => 10 %></td>
18 <td><%= password_field 'user', 'password_confirmation', :size => 10 %></td>
19 <td><%= text_field 'user', 'email', :size => 15 %></td>
19 <td><%= text_field 'user', 'email', :size => 15 %></td>
20 <td><%= submit_tag "Create" %></td>
20 <td><%= submit_tag "Create" %></td>
21 </tr>
21 </tr>
22 </table>
22 </table>
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/>
30 <b>What else: </b>
30 <b>What else: </b>
31 <%= link_to '[New user]', :action => 'new' %>
31 <%= link_to '[New user]', :action => 'new' %>
32 <%= link_to '[New list of users]', :action => 'new_list' %>
32 <%= link_to '[New list of users]', :action => 'new_list' %>
33 <%= link_to '[View administrators]', :action => 'admin' %>
33 <%= link_to '[View administrators]', :action => 'admin' %>
34 <%= link_to '[Random passwords]', :action => 'random_all_passwords' %>
34 <%= link_to '[Random passwords]', :action => 'random_all_passwords' %>
35 <%= link_to '[View active users]', :action => 'active' %>
35 <%= link_to '[View active users]', :action => 'active' %>
36 <%= link_to '[Mass mailing]', :action => 'mass_mailing' %>
36 <%= link_to '[Mass mailing]', :action => 'mass_mailing' %>
37 <% if Configuration.multicontests? %>
37 <% if Configuration.multicontests? %>
38 <br/><b>Multi-contest:</b>
38 <br/><b>Multi-contest:</b>
@@ -1,8 +1,8
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 %>
7
7
8 <%= link_to 'Back', :action => 'list' %>
8 <%= link_to 'Back', :action => 'list' %>
@@ -1,8 +1,8
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/>
7 <%= text_area_tag 'user_list', nil, :rows => 50, :cols => 80 %>
7 <%= text_area_tag 'user_list', nil, :rows => 50, :cols => 80 %>
8 <% end %>
8 <% end %>
@@ -1,54 +1,38
1 - # This file is copied to ~/spec when you run 'ruby script/generate rspec'
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(File.join(File.dirname(__FILE__),'..','config','environment'))
3 + require File.expand_path("../../config/environment", __FILE__)
5 - require 'spec/autorun'
4 + require 'rspec/rails'
6 - require 'spec/rails'
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