Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a block argument to should_assign_to to replace :equals

  • Loading branch information...
commit c72d85473414b02400b17313fce6eea84cfb4e02 1 parent 33f547c
@jferris jferris authored
View
11 lib/shoulda/controller/macros.rb
@@ -79,9 +79,13 @@ def should_filter_params(*keys)
#
# should_assign_to :user, :posts
# should_assign_to :user, :class => User
- # should_assign_to :user, :equals => '@user'
- def should_assign_to(*names)
+ # should_assign_to(:user) { @user }
+ def should_assign_to(*names, &block)
opts = names.extract_options!
+ if opts[:equals]
+ warn "[DEPRECATION] should_assign_to :var, :equals => 'val' " <<
+ "is deprecated. Use should_assign_to(:var) { 'val' } instead."
+ end
names.each do |name|
matcher = assign_to(name).with_kind_of(opts[:class])
test_name = matcher.description
@@ -95,6 +99,9 @@ def should_assign_to(*names)
__LINE__)
matcher = matcher.with(expected_value)
end
+ elsif block
+ expected_value = instance_eval(&block)
+ matcher = matcher.with(expected_value)
end
assert_accepts matcher, @controller
View
4 test/functional/posts_controller_test.rb
@@ -44,12 +44,16 @@ def setup
end
should_respond_with :success
should_assign_to :user, :class => User, :equals => 'users(:first)'
+ should_assign_to(:user) { users(:first) }
should_fail do
should_assign_to :user, :class => Post
end
should_fail do
should_assign_to :user, :equals => 'posts(:first)'
end
+ should_fail do
+ should_assign_to(:user) { posts(:first) }
+ end
should_assign_to :posts
should_not_assign_to :foo, :bar
should_render_page_with_metadata :description => /Posts/, :title => /index/
Please sign in to comment.
Something went wrong with that request. Please try again.