Skip to content

Commit

Permalink
generalize the validates_length_of to just check an error
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyril David committed Mar 16, 2010
1 parent 8e5a1a3 commit dbfe5c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/rspec-rails-matchers.rb
@@ -1,7 +1,7 @@
require 'rspec'
require 'rspec/matchers'

$LOAD_PATH.unshift(File.expand_path('../../../', __FILE__))
$LOAD_PATH.unshift(File.expand_path('../', __FILE__))

module RspecRailsMatchers
autoload :Message, 'rspec_rails_matchers/message'
Expand Down
10 changes: 2 additions & 8 deletions lib/rspec_rails_matchers/validations/length_of.rb
Expand Up @@ -26,10 +26,7 @@ def validates_minimum?( model, min, attr )
if min && min >= 1
model.send("#{attr}=", 'a' * (min - 1))

model.invalid? &&
model.errors[attr].include?(
I18n::t('errors.messages.too_short', :count => min)
)
model.invalid? && model.errors[attr].any?
end
end

Expand All @@ -39,10 +36,7 @@ def validates_maximum?( model, max, attr )
if max
model.send("#{attr}=", 'a' * (max + 1))

model.invalid? &&
model.errors[attr].include?(
I18n::t('errors.messages.too_long', :count => max)
)
model.invalid? && model.errors[attr].any?
end
end
end
Expand Down

0 comments on commit dbfe5c6

Please sign in to comment.