Skip to content

Commit

Permalink
Deprecated should_only_allow_numeric_values_for in favor of should_va…
Browse files Browse the repository at this point in the history
…lidate_numericality_of
  • Loading branch information
jferris committed Jan 30, 2009
1 parent 192d744 commit 5da9cb1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions lib/shoulda/active_record/macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ def should_ensure_value_in_range(attribute, range, opts = {})
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.not_a_number')</tt>
#
# Example:
# should_only_allow_numeric_values_for :age
# should_validate_numericality_of :age
#
def should_only_allow_numeric_values_for(*attributes)
def should_validate_numericality_of(*attributes)
message = get_options!(attributes, :message)
klass = model_class
attributes.each do |attribute|
Expand All @@ -318,6 +318,13 @@ def should_only_allow_numeric_values_for(*attributes)
end
end

# Deprecated. See should_validate_uniqueness_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.
Expand Down
2 changes: 1 addition & 1 deletion test/unit/post_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PostTest < Test::Unit::TestCase
should_require_unique_attributes :title
should_validate_presence_of :body, :message => /wtf/
should_validate_presence_of :title
should_only_allow_numeric_values_for :user_id
should_validate_numericality_of :user_id

should_fail do
should_validate_uniqueness_of :title, :case_sensitive => false
Expand Down
2 changes: 1 addition & 1 deletion test/unit/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class UserTest < Test::Unit::TestCase
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"
should_only_allow_numeric_values_for :ssn
should_validate_numericality_of :ssn

should_have_readonly_attributes :name

Expand Down

0 comments on commit 5da9cb1

Please sign in to comment.