diff --git a/test/activemodel_validation_test.rb b/test/activemodel_validation_test.rb index 06eafd9..dc249a3 100644 --- a/test/activemodel_validation_test.rb +++ b/test/activemodel_validation_test.rb @@ -265,7 +265,11 @@ def email_present? # valid. it "is valid" do _(form.validate({ username: "not yo", email: "bla" })).must_equal true - _(form.errors.messages).must_equal({:username=>[], :email=>[]}) + if self.class.rails_greater_6_0? + _(form.errors.messages).must_equal({}) + else + _(form.errors.messages).must_equal({:username=>[], :email=>[]}) + end if self.class.rails5? _(form.errors.details.inspect).must_equal "{}" end @@ -312,7 +316,11 @@ def email_present? _(form.errors.messages).must_equal(email: ["can't be blank", "fill it out!"], username: ["not ok", "must be yo"], policy: ["error_text", "another error"]) # keep added errors after validate _(form.validate(username: "username", email: "email@email.com")).must_equal false - _(form.errors.messages).must_equal(policy: ["error_text", "another error"], username: [], email: []) + if self.class.rails_greater_6_0? + _(form.errors.messages).must_equal(policy: ["error_text", "another error"]) + else + _(form.errors.messages).must_equal(policy: ["error_text", "another error"], username: [], email: []) + end _(form.errors.added?(:policy, "error_text")).must_equal true _(form.errors.added?(:policy, "another error")).must_equal true _(form.errors.details).must_equal( diff --git a/test/test_helper.rb b/test/test_helper.rb index 3963d3e..c77ce70 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -39,6 +39,10 @@ class Album < ActiveRecord::Base load "#{File.dirname(__FILE__)}/support/schema.rb" Minitest::Spec.class_eval do + def self.rails_greater_6_0? + (::ActiveModel::VERSION::MAJOR == 6 and ::ActiveModel::VERSION::MINOR >= 1) || (::ActiveModel::VERSION::MAJOR >= 7) + end + def self.rails5? ::ActiveModel::VERSION::MAJOR.in? [5,6] end