Skip to content

Commit

Permalink
Deprecated should_return_from_session in favor of should_set_session [t…
Browse files Browse the repository at this point in the history
…houghtbot#146 state:resolved]
  • Loading branch information
jferris committed Feb 9, 2009
1 parent 33705c8 commit 738228f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
18 changes: 12 additions & 6 deletions lib/shoulda/action_controller/macros.rb
Expand Up @@ -152,14 +152,13 @@ def should_respond_with_content_type(content_type)
# set by the controller are available to the evaled string. # set by the controller are available to the evaled string.
# Example: # Example:
# #
# should_return_from_session(:user_id) { '@user.id' } # should_set_session(:user_id) { '@user.id' }
# should_return_from_session(:message) { "Free stuff" } # should_set_session(:message) { "Free stuff" }
def should_return_from_session(key, expected = nil, &block) def should_set_session(key, expected = nil, &block)
matcher = set_session(key) matcher = set_session(key)
if expected if expected
warn "[DEPRECATION] should_return_from_session :key, 'val' is " << warn "[DEPRECATION] should_set_session :key, 'val' is deprecated. " <<
"deprecated. Use should_return_from_session(:key) { 'val' } " << "Use should_set_session(:key) { 'val' } instead."
"instead."
end end
should matcher.description do should matcher.description do
if expected if expected
Expand All @@ -178,6 +177,13 @@ def should_return_from_session(key, expected = nil, &block)
end end
end end


# Deprecated. See should_set_session
def should_return_from_session(key, expected)
warn "[DEPRECATION] should_require_attributes is deprecated. " <<
"Use should_set_session instead."
should_set_session(key, expected)
end

# Macro that creates a test asserting that the controller rendered the given template. # Macro that creates a test asserting that the controller rendered the given template.
# Example: # Example:
# #
Expand Down
7 changes: 4 additions & 3 deletions test/functional/posts_controller_test.rb
Expand Up @@ -70,10 +70,11 @@ def setup
should_respond_with_content_type :rss should_respond_with_content_type :rss
should_respond_with_content_type /rss/ should_respond_with_content_type /rss/
should_return_from_session :special, "'$2 off your next purchase'" should_return_from_session :special, "'$2 off your next purchase'"
should_return_from_session :special_user_id, '@user.id' should_set_session :special, "'$2 off your next purchase'"
should_return_from_session(:special_user_id) { @user.id } should_set_session :special_user_id, '@user.id'
should_set_session(:special_user_id) { @user.id }
should_fail do should_fail do
should_return_from_session(:special_user_id) { 'value' } should_set_session(:special_user_id) { 'value' }
end end
should_assign_to :user, :posts should_assign_to :user, :posts
should_not_assign_to :foo, :bar should_not_assign_to :foo, :bar
Expand Down

0 comments on commit 738228f

Please sign in to comment.