Skip to content

Commit

Permalink
Merge branch 'errors_fix' of https://github.com/gsterndale/couchrest_…
Browse files Browse the repository at this point in the history
…model into errors_fix
  • Loading branch information
samlown committed Feb 2, 2011
2 parents d53c982 + 731338e commit 1ccb96b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/couchrest/model/validations/casted_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class CastedModelValidator < ActiveModel::EachValidator
def validate_each(document, attribute, value)
values = value.is_a?(Array) ? value : [value]
return if values.collect {|doc| doc.nil? || doc.valid? }.all?
document.errors.add(attribute, :invalid, :default => options[:message], :value => value)
error_options = { :value => value }
error_options[:message] = options[:message] if options[:message]
document.errors.add(attribute, :invalid, error_options)
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/couchrest/casted_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ class NotAHashButWithCastedModelMixin
@toy2.errors.should be_empty
@toy3.errors.should_not be_empty
end

it "should not use dperecated ActiveModel options" do
ActiveSupport::Deprecation.should_not_receive(:warn)
@cat.should_not be_valid
end
end

describe "on a casted model property" do
Expand Down

0 comments on commit 1ccb96b

Please sign in to comment.