Skip to content

Commit

Permalink
Updating validates_exclusion_of to ActiveModel.
Browse files Browse the repository at this point in the history
  • Loading branch information
bryckbost committed Jul 7, 2010
1 parent c9d55c9 commit bf9bd1e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 58 deletions.
1 change: 1 addition & 0 deletions UPGRADES
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
0.8 => ??
* [attribute]_before_typecast should become [attribute]_before_type_cast (note the extra _)
* Change validates_exclusion_of :within option to :in

0.7.6 => 0.8
* Proxy#owner has been removed in favor of Proxy#proxy_owner
Expand Down
2 changes: 1 addition & 1 deletion lib/mongo_mapper/plugins/keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def create_validations_for(key)
end

if key.options[:not_in]
validates_exclusion_of(attribute, :within => key.options[:not_in])
validates_exclusion_of(attribute, :in => key.options[:not_in])
end

if key.options[:length]
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ def drop_indexes(klass)
matcher.negative_failure_message = "#{receiver} had errors on #{attribute} #{receiver.errors.inspect}"
!receiver.errors[attribute].blank?
else
actual = receiver.errors[:attribute]
actual = receiver.errors[attribute]
matcher.positive_failure_message = %Q(Expected error on #{attribute} to be "#{expected_message}" but was "#{actual}")
matcher.negative_failure_message = %Q(Expected error on #{attribute} not to be "#{expected_message}" but was "#{actual}")
actual == expected_message
actual.include? expected_message
end
end

Expand Down
110 changes: 55 additions & 55 deletions test/unit/test_validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,59 +157,59 @@ class ValidationsTest < Test::Unit::TestCase
doc.should have_error_on(:name)
end
end
#
# context "validating exclusion of" do
# should "throw error if enumerator not provided" do
# @document.key :action, String
# lambda {
# @document.validates_exclusion_of :action
# }.should raise_error(ArgumentError)
# end
#
# should "work with validates_exclusion_of macro" do
# @document.key :action, String
# @document.validates_exclusion_of :action, :within => %w(kick run)
#
# doc = @document.new
# doc.should_not have_error_on(:action)
#
# doc.action = 'fart'
# doc.should_not have_error_on(:action)
#
# doc.action = 'kick'
# doc.should have_error_on(:action, 'is reserved')
# end
#
# should "work with :not_in shortcut on key definition" do
# @document.key :action, String, :not_in => %w(kick run)
#
# doc = @document.new
# doc.should_not have_error_on(:action)
#
# doc.action = 'fart'
# doc.should_not have_error_on(:action)
#
# doc.action = 'kick'
# doc.should have_error_on(:action, 'is reserved')
# end
#
# should "not have error if allow nil is true and value is nil" do
# @document.key :action, String
# @document.validates_exclusion_of :action, :within => %w(kick run), :allow_nil => true
#
# doc = @document.new
# doc.should_not have_error_on(:action)
# end
#
# should "not have error if allow blank is true and value is blank" do
# @document.key :action, String
# @document.validates_exclusion_of :action, :within => %w(kick run), :allow_nil => true
#
# doc = @document.new(:action => '')
# doc.should_not have_error_on(:action)
# end
# end
#

context "validating exclusion of" do
should "throw error if enumerator not provided" do
@document.key :action, String
lambda {
@document.validates_exclusion_of :action
}.should raise_error(ArgumentError)
end

should "work with validates_exclusion_of macro" do
@document.key :action, String
@document.validates_exclusion_of :action, :in => %w(kick run)

doc = @document.new
doc.should_not have_error_on(:action)

doc.action = 'fart'
doc.should_not have_error_on(:action)

doc.action = 'kick'
doc.should have_error_on(:action, 'is reserved')
end

should "work with :not_in shortcut on key definition" do
@document.key :action, String, :not_in => %w(kick run)

doc = @document.new
doc.should_not have_error_on(:action)

doc.action = 'fart'
doc.should_not have_error_on(:action)

doc.action = 'kick'
doc.should have_error_on(:action, 'is reserved')
end

should "not have error if allow nil is true and value is nil" do
@document.key :action, String
@document.validates_exclusion_of :action, :in => %w(kick run), :allow_nil => true

doc = @document.new
doc.should_not have_error_on(:action)
end

should "not have error if allow blank is true and value is blank" do
@document.key :action, String
@document.validates_exclusion_of :action, :in => %w(kick run), :allow_nil => true

doc = @document.new(:action => '')
doc.should_not have_error_on(:action)
end
end

# context "validating inclusion of" do
# should "throw error if enumerator not provided" do
# @document.key :action, String
Expand Down Expand Up @@ -260,8 +260,8 @@ class ValidationsTest < Test::Unit::TestCase
# doc = @document.new(:action => '')
# doc.should_not have_error_on(:action)
# end
# end
#
# end

# end # End on a Document
#
# context "On an EmbeddedDocument" do
Expand Down

0 comments on commit bf9bd1e

Please sign in to comment.