shoulda 2.10.2 → 2.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/shoulda.rb +1 -1
- data/lib/shoulda/action_controller/matchers/route_matcher.rb +1 -1
- data/lib/shoulda/context.rb +16 -5
- data/test/matchers/controller/route_matcher_test.rb +17 -0
- data/test/other/context_test.rb +14 -0
- data/test/rails_root/app/models/post.rb +1 -1
- data/test/rails_root/config/environment.rb +1 -1
- metadata +2 -2
data/lib/shoulda.rb
CHANGED
data/lib/shoulda/context.rb
CHANGED
@@ -230,11 +230,7 @@ module Shoulda
|
|
230
230
|
# The subject is used by all macros that require an instance of the class
|
231
231
|
# being tested.
|
232
232
|
def subject
|
233
|
-
|
234
|
-
instance_eval(&subject_block)
|
235
|
-
else
|
236
|
-
get_instance_of(self.class.described_type)
|
237
|
-
end
|
233
|
+
@shoulda_subject ||= construct_subject
|
238
234
|
end
|
239
235
|
|
240
236
|
def subject_block # :nodoc:
|
@@ -262,6 +258,16 @@ module Shoulda
|
|
262
258
|
def instance_variable_name_for(klass) # :nodoc:
|
263
259
|
klass.to_s.split('::').last.underscore
|
264
260
|
end
|
261
|
+
|
262
|
+
private
|
263
|
+
|
264
|
+
def construct_subject
|
265
|
+
if subject_block
|
266
|
+
instance_eval(&subject_block)
|
267
|
+
else
|
268
|
+
get_instance_of(self.class.described_type)
|
269
|
+
end
|
270
|
+
end
|
265
271
|
end
|
266
272
|
|
267
273
|
class Context # :nodoc:
|
@@ -321,6 +327,11 @@ module Shoulda
|
|
321
327
|
self.subject_block = block
|
322
328
|
end
|
323
329
|
|
330
|
+
def subject_block
|
331
|
+
return @subject_block if @subject_block
|
332
|
+
parent.subject_block
|
333
|
+
end
|
334
|
+
|
324
335
|
def full_name
|
325
336
|
parent_name = parent.full_name if am_subcontext?
|
326
337
|
return [parent_name, name].join(" ").strip
|
@@ -2,6 +2,23 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
|
2
2
|
|
3
3
|
class RouteToMatcherTest < ActionController::TestCase # :nodoc:
|
4
4
|
|
5
|
+
context "given a controller with a defined glob url" do
|
6
|
+
setup do
|
7
|
+
@controller = define_controller('Examples').new
|
8
|
+
define_routes do |map|
|
9
|
+
map.connect 'examples/*id', :controller => 'examples',
|
10
|
+
:action => 'example'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
should "accept glob route" do
|
15
|
+
assert_accepts route(:get, '/examples/foo/bar').
|
16
|
+
to(:action => 'example', :id => ['foo', 'bar']),
|
17
|
+
@controller
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
5
22
|
context "given a controller with a defined route" do
|
6
23
|
setup do
|
7
24
|
@controller = define_controller('Examples').new
|
data/test/other/context_test.rb
CHANGED
@@ -169,6 +169,12 @@ class ContextTest < ActiveSupport::TestCase # :nodoc:
|
|
169
169
|
should "return the result of the block as the subject" do
|
170
170
|
assert_equal @expected, subject
|
171
171
|
end
|
172
|
+
|
173
|
+
context "nested context block without a subject block" do
|
174
|
+
should "return the result of the parent context's subject block" do
|
175
|
+
assert_equal @expected, subject
|
176
|
+
end
|
177
|
+
end
|
172
178
|
end
|
173
179
|
end
|
174
180
|
end
|
@@ -187,3 +193,11 @@ class SubjectTest < ActiveSupport::TestCase
|
|
187
193
|
assert_equal @expected, subject
|
188
194
|
end
|
189
195
|
end
|
196
|
+
|
197
|
+
class SubjectLazinessTest < ActiveSupport::TestCase
|
198
|
+
subject { Subject.new }
|
199
|
+
|
200
|
+
should "only build the subject once" do
|
201
|
+
assert_equal subject, subject
|
202
|
+
end
|
203
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Specifies gem version of Rails to use when vendor/rails is not present
|
2
2
|
old_verbose, $VERBOSE = $VERBOSE, nil
|
3
|
-
RAILS_GEM_VERSION = '
|
3
|
+
RAILS_GEM_VERSION = '>= 2.3.2' unless defined? RAILS_GEM_VERSION
|
4
4
|
$VERBOSE = old_verbose
|
5
5
|
|
6
6
|
require File.join(File.dirname(__FILE__), 'boot')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoulda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.10.
|
4
|
+
version: 2.10.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tammer Saleh
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-16 00:00:00 -05:00
|
13
13
|
default_executable: convert_to_should_syntax
|
14
14
|
dependencies: []
|
15
15
|
|