shoulda 2.10.2 → 2.10.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Shoulda
2
- VERSION = "2.10.2"
2
+ VERSION = "2.10.3"
3
3
  end
4
4
 
5
5
  if defined? Spec
@@ -65,7 +65,7 @@ module Shoulda # :nodoc:
65
65
 
66
66
  def stringify_params!
67
67
  @params.each do |key, value|
68
- @params[key] = value.to_param
68
+ @params[key] = value.is_a?(Array) ? value.collect {|v| v.to_param } : value.to_param
69
69
  end
70
70
  end
71
71
 
@@ -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
- if subject_block
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
@@ -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
@@ -7,6 +7,6 @@ class Post < ActiveRecord::Base
7
7
 
8
8
  validates_uniqueness_of :title
9
9
  validates_presence_of :title
10
- validates_presence_of :body, :message => 'Seriously... wtf'
10
+ validates_presence_of :body, :message => 'Seriously, wtf'
11
11
  validates_numericality_of :user_id
12
12
  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 = '= 2.3.2' unless defined? 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.2
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: 2009-07-15 00:00:00 -04:00
12
+ date: 2010-01-16 00:00:00 -05:00
13
13
  default_executable: convert_to_should_syntax
14
14
  dependencies: []
15
15