Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed functionality deprecated in 2.10 [#192 state:resolved]

  • Loading branch information...
commit 9f24c1d464694b66a8a48ad702fe3f4b6efb17a0 1 parent 8cef841
@jferris jferris authored
View
65 lib/shoulda/action_controller/macros.rb
@@ -71,8 +71,6 @@ def should_filter_params(*keys)
#
# Options:
# * <tt>:class</tt> - The expected class of the instance variable being checked.
- # * <tt>:equals</tt> - [DEPRECATED] A string which is evaluated and
- # compared for equality with the instance variable being checked.
#
# If a block is passed, the assigned variable is expected to be equal to
# the return value of that block.
@@ -83,25 +81,11 @@ def should_filter_params(*keys)
# should_assign_to :user, :class => User
# 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
+ klass = get_options!(names, :class)
names.each do |name|
- matcher = assign_to(name).with_kind_of(opts[:class])
- test_name = matcher.description
- test_name << " which is equal to #{opts[:equals]}" if opts[:equals]
- should test_name do
- if opts[:equals]
- instantiate_variables_from_assigns do
- expected_value = eval(opts[:equals],
- self.send(:binding),
- __FILE__,
- __LINE__)
- matcher = matcher.with(expected_value)
- end
- elsif block
+ matcher = assign_to(name).with_kind_of(klass)
+ should matcher.description do
+ if block
expected_value = instance_eval(&block)
matcher = matcher.with(expected_value)
end
@@ -158,36 +142,15 @@ def should_respond_with_content_type(content_type)
#
# should_set_session(:user_id) { @user.id }
# should_set_session(:message) { "Free stuff" }
- def should_set_session(key, expected = nil, &block)
+ def should_set_session(key, &block)
matcher = set_session(key)
- if expected
- warn "[DEPRECATION] should_set_session :key, 'val' is deprecated. " <<
- "Use should_set_session(:key) { 'val' } instead."
- end
should matcher.description do
- if expected
- instantiate_variables_from_assigns do
- expected_value = eval(expected,
- self.send(:binding),
- __FILE__,
- __LINE__)
- matcher = matcher.to(expected_value)
- end
- else
- expected_value = instance_eval(&block)
- matcher = matcher.to(expected_value)
- end
+ expected_value = instance_eval(&block)
+ matcher = matcher.to(expected_value)
assert_accepts matcher, @controller
end
end
- # Deprecated. See should_set_session
- def should_return_from_session(key, expected)
- warn "[DEPRECATION] should_return_from_session 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.
# Example:
#
@@ -230,19 +193,9 @@ def should_render_without_layout
#
# should_redirect_to("the user's profile") { user_url(@user) }
def should_redirect_to(description, &block)
- unless block
- warn "[DEPRECATION] should_redirect_to without a block is " <<
- "deprecated. Use should_redirect_to('somewhere') { } instead."
- end
should "redirect to #{description}" do
- if block
- url = instance_eval(&block)
- else
- instantiate_variables_from_assigns do
- url = eval(description, self.send(:binding), __FILE__, __LINE__)
- end
- end
- assert_redirected_to url
+ expected_url = instance_eval(&block)
+ assert_redirected_to expected_url
end
end
View
35 lib/shoulda/active_record/macros.rb
@@ -48,13 +48,6 @@ def should_validate_presence_of(*attributes)
end
end
- # Deprecated. See should_validate_presence_of
- def should_require_attributes(*attributes)
- warn "[DEPRECATION] should_require_attributes is deprecated. " <<
- "Use should_validate_presence_of instead."
- should_validate_presence_of(*attributes)
- end
-
# Ensures that the model cannot be saved if one of the attributes listed is not unique.
# Requires an existing record
#
@@ -90,13 +83,6 @@ def should_validate_uniqueness_of(*attributes)
end
end
- # Deprecated. See should_validate_uniqueness_of
- def should_require_unique_attributes(*attributes)
- warn "[DEPRECATION] should_require_unique_attributes is deprecated. " <<
- "Use should_validate_uniqueness_of instead."
- should_validate_uniqueness_of(*attributes)
- end
-
# Ensures that the attribute can be set on mass update.
#
# should_allow_mass_assignment_of :first_name, :last_name
@@ -129,13 +115,6 @@ def should_not_allow_mass_assignment_of(*attributes)
end
end
- # Deprecated. See should_not_allow_mass_assignment_of
- def should_protect_attributes(*attributes)
- warn "[DEPRECATION] should_protect_attributes is deprecated. " <<
- "Use should_not_allow_mass_assignment_of instead."
- should_not_allow_mass_assignment_of(*attributes)
- end
-
# Ensures that the attribute cannot be changed once the record has been created.
#
# should_have_readonly_attributes :password, :admin_flag
@@ -335,13 +314,6 @@ def should_validate_numericality_of(*attributes)
end
end
- # Deprecated. See should_validate_numericality_of
- def should_only_allow_numeric_values_for(*attributes)
- warn "[DEPRECATION] should_only_allow_numeric_values_for is " <<
- "deprecated. Use should_validate_numericality_of instead."
- should_validate_numericality_of(*attributes)
- end
-
# Ensures that the has_many relationship exists. Will also test that the
# associated table has the required columns. Works with polymorphic
# associations.
@@ -548,13 +520,6 @@ def should_validate_acceptance_of(*attributes)
end
end
- # Deprecated. See should_validate_uniqueness_of
- def should_require_acceptance_of(*attributes)
- warn "[DEPRECATION] should_require_acceptance_of is deprecated. " <<
- "Use should_validate_acceptance_of instead."
- should_validate_acceptance_of(*attributes)
- end
-
# Ensures that the model has a method named scope_name that returns a NamedScope object with the
# proxy options set to the options you supply. scope_name can be either a symbol, or a method
# call which will be evaled against the model. The eval'd method call has access to all the same
View
25 test/functional/posts_controller_test.rb
@@ -43,15 +43,12 @@ def setup
get :index, :user_id => users(:first)
end
should_respond_with :success
- should_assign_to :user, :class => User, :equals => 'users(:first)'
+ should_assign_to :user, :class => User
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
@@ -69,20 +66,10 @@ def setup
should_respond_with_content_type 'application/rss+xml'
should_respond_with_content_type :rss
should_respond_with_content_type /rss/
- context "deprecated" do # to avoid redefining a test
- should_return_from_session :special, "'$2 off your next purchase'"
- end
- should_fail do
- should_return_from_session :special, "'not special'"
- end
should_set_session(:mischief) { nil }
- should_return_from_session :malarky, "nil"
- should_set_session :special, "'$2 off your next purchase'"
- should_set_session :special_user_id, '@user.id'
- context "with a block" do
- should_set_session(:special_user_id) { @user.id }
- end
- should_fail do # to avoid redefining a test
+ should_set_session(:special) { '$2 off your next purchase' }
+ should_set_session(:special_user_id) { @user.id }
+ should_fail do
should_set_session(:special_user_id) { 'value' }
end
should_assign_to :user, :posts
@@ -110,13 +97,9 @@ def setup
:body => 'blah blah blah' }
end
- should_redirect_to 'user_post_url(@post.user, @post)'
should_redirect_to('the created post') { user_post_url(users(:first),
assigns(:post)) }
should_fail do
- should_redirect_to 'user_posts_url(@post.user)'
- end
- should_fail do
should_redirect_to('elsewhere') { user_posts_url(users(:first)) }
end
end
View
2  test/unit/address_test.rb
@@ -6,5 +6,5 @@ class AddressTest < ActiveSupport::TestCase
should_belong_to :addressable
should_validate_uniqueness_of :title, :scoped_to => [:addressable_id, :addressable_type]
should_ensure_length_at_least :zip, 5
- should_only_allow_numeric_values_for :zip
+ should_validate_numericality_of :zip
end
View
3  test/unit/dog_test.rb
@@ -5,6 +5,5 @@ class Pets::DogTest < ActiveSupport::TestCase
should_belong_to :address, :dependent => :destroy
should_have_many :treats
should_have_and_belong_to_many :fleas
- should_require_attributes :treats, :fleas
- should_validate_presence_of :owner_id
+ should_validate_presence_of :owner_id, :treats, :fleas
end
View
2  test/unit/post_test.rb
@@ -8,7 +8,7 @@ class PostTest < ActiveSupport::TestCase
should_have_many :tags, :through => :taggings
should_have_many :through_tags, :through => :taggings
- should_require_unique_attributes :title
+ should_validate_uniqueness_of :title
should_validate_presence_of :body, :message => /wtf/
should_validate_presence_of :title
should_validate_numericality_of :user_id
View
2  test/unit/tag_test.rb
@@ -6,7 +6,7 @@ class TagTest < ActiveSupport::TestCase
should_ensure_length_at_least :name, 2
- should_protect_attributes :secret
+ should_not_allow_mass_assignment_of :secret
should_allow_mass_assignment_of :name
should_fail do
View
1  test/unit/user_test.rb
@@ -56,7 +56,6 @@ class UserTest < ActiveSupport::TestCase
should_have_db_column :email, :type => "string", :default => nil, :precision => nil, :limit => 255,
:null => true, :scale => nil
should_validate_acceptance_of :eula
- should_require_acceptance_of :eula
should_validate_uniqueness_of :email, :scoped_to => :name, :case_sensitive => false
should_ensure_length_is :ssn, 9, :message => "Social Security Number is not the right length"
Please sign in to comment.
Something went wrong with that request. Please try again.