From 8d9637249c92a36e1a3428471ff1f67b1e8a0b66 Mon Sep 17 00:00:00 2001 From: Greg Sterndale Date: Tue, 28 Dec 2010 15:22:29 -0500 Subject: [PATCH 1/2] Fix deprecated ActiveModel::Errors#add options --- lib/couchrest/model/validations/casted_model.rb | 2 +- spec/couchrest/casted_model_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/couchrest/model/validations/casted_model.rb b/lib/couchrest/model/validations/casted_model.rb index b4e89e6..fed5384 100644 --- a/lib/couchrest/model/validations/casted_model.rb +++ b/lib/couchrest/model/validations/casted_model.rb @@ -6,7 +6,7 @@ module CouchRest 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) + document.errors.add(attribute, :invalid, :message => options[:message], :value => value) end end end diff --git a/spec/couchrest/casted_model_spec.rb b/spec/couchrest/casted_model_spec.rb index dd4da5b..8c153d9 100644 --- a/spec/couchrest/casted_model_spec.rb +++ b/spec/couchrest/casted_model_spec.rb @@ -284,6 +284,11 @@ describe CouchRest::Model::CastedModel do @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 From 731338ed6c352aa4e4b2d3938e6d8d885adf1a1b Mon Sep 17 00:00:00 2001 From: Greg Sterndale Date: Tue, 28 Dec 2010 15:24:59 -0500 Subject: [PATCH 2/2] Do not specify options[:message] for ActiveModel::Errors#add if it's nil --- lib/couchrest/model/validations/casted_model.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/couchrest/model/validations/casted_model.rb b/lib/couchrest/model/validations/casted_model.rb index fed5384..5c29dac 100644 --- a/lib/couchrest/model/validations/casted_model.rb +++ b/lib/couchrest/model/validations/casted_model.rb @@ -6,7 +6,9 @@ module CouchRest 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, :message => 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