diff --git a/Appraisals b/Appraisals index 8e976665..8d1e20c9 100644 --- a/Appraisals +++ b/Appraisals @@ -26,6 +26,7 @@ appraise '4.0' do gem 'bcrypt-ruby', '~> 3.0.0' #FIXME: This should be ~> 3.1.0 for Rails 4.0 gem 'jquery-rails' gem 'sass-rails', '~> 4.0.0' + gem 'activeresource', require: 'active_resource' # Test suite makes heavy use of attr_accessible gem 'protected_attributes' diff --git a/NEWS.md b/NEWS.md index 8bb280e6..04bd87da 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # HEAD +* Fix a regression with context-dependent validations in ActiveResource + * shoulda-matchers is now fully compatible with Rails 4. * When not using RSpec, shoulda-matchers is now auto-included into diff --git a/gemfiles/4.0.gemfile b/gemfiles/4.0.gemfile index 9fefc4a9..b8f55bf2 100644 --- a/gemfiles/4.0.gemfile +++ b/gemfiles/4.0.gemfile @@ -13,6 +13,7 @@ gem "rails", "4.0.0" gem "bcrypt-ruby", "~> 3.0.0" gem "jquery-rails" gem "sass-rails", "~> 4.0.0" +gem "activeresource", :require=>"active_resource" gem "protected_attributes" gemspec :path=>"../" \ No newline at end of file diff --git a/gemfiles/4.0.gemfile.lock b/gemfiles/4.0.gemfile.lock index 7219b102..b33c09fb 100644 --- a/gemfiles/4.0.gemfile.lock +++ b/gemfiles/4.0.gemfile.lock @@ -25,6 +25,10 @@ GEM activesupport (= 4.0.0) arel (~> 4.0.0) activerecord-deprecated_finders (1.0.3) + activeresource (4.0.0) + activemodel (~> 4.0) + activesupport (~> 4.0) + rails-observers (~> 0.1.1) activesupport (4.0.0) i18n (~> 0.6, >= 0.6.4) minitest (~> 4.2) @@ -86,6 +90,8 @@ GEM bundler (>= 1.3.0, < 2.0) railties (= 4.0.0) sprockets-rails (~> 2.0.0) + rails-observers (0.1.2) + activemodel (~> 4.0) railties (4.0.0) actionpack (= 4.0.0) activesupport (= 4.0.0) @@ -134,6 +140,7 @@ PLATFORMS DEPENDENCIES activerecord-jdbc-adapter activerecord-jdbcsqlite3-adapter + activeresource appraisal (~> 0.4) aruba bcrypt-ruby (~> 3.0.0) diff --git a/lib/shoulda/matchers/active_model/validation_message_finder.rb b/lib/shoulda/matchers/active_model/validation_message_finder.rb index 7b96ef5d..d36d9754 100644 --- a/lib/shoulda/matchers/active_model/validation_message_finder.rb +++ b/lib/shoulda/matchers/active_model/validation_message_finder.rb @@ -59,7 +59,7 @@ module Shoulda end def validate_instance - @instance.valid?(@context) + @instance.valid?(*@context) @instance end end diff --git a/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb b/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb index d544d8b2..209cfe60 100644 --- a/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +++ b/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb @@ -134,6 +134,16 @@ describe Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher do end end + context 'an active_resource model' do + context 'with the validation context' do + it 'does not raise an exception' do + expect { + active_resource_model.should validate_presence_of(:attr) + }.to_not raise_exception + end + end + end + def matcher validate_presence_of(:attr) end @@ -161,4 +171,10 @@ describe Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher do end end.new end + + def active_resource_model + define_active_resource_class :foo, :attr => :string do + validates_presence_of :attr + end.new + end end diff --git a/spec/support/active_resource_builder.rb b/spec/support/active_resource_builder.rb new file mode 100644 index 00000000..e7877217 --- /dev/null +++ b/spec/support/active_resource_builder.rb @@ -0,0 +1,27 @@ +module ActiveResourceBuilder + def self.included(example_group) + example_group.class_eval do + after do + ActiveSupport::Dependencies.clear + end + end + end + + def define_active_resource_class(class_name, attributes = {}, &block) + define_class(class_name, ActiveResource::Base) do + schema do + attributes.each do |attr, type| + attribute attr, type + end + end + + if block_given? + class_eval(&block) + end + end + end +end + +RSpec.configure do |config| + config.include ActiveResourceBuilder +end