Fix absence matcher tests so that they run

Apparently they were supposed to be enabled for ActiveModel >= 4 but
ended up being enabled for ActiveModel 4 itself.
This commit is contained in:
Elliot Winkler 2018-09-09 20:53:37 -06:00
parent 34f7732ba8
commit 43f4252561
3 changed files with 11 additions and 2 deletions

View File

@ -21,6 +21,10 @@ module UnitTests
::ActiveModel::VERSION::MAJOR == 4
end
def active_model_supports_absence_validation?
active_model_version >= 4
end
def active_model_supports_strict?
active_model_version >= 3.2
end

View File

@ -79,7 +79,12 @@ module UnitTests
overrides[:changing_values_with]
)
if respond_to?(:write_attribute)
if (
respond_to?(:write_attribute) && (
!self.class.respond_to?(:reflect_on_association) ||
!self.class.reflect_on_association(attribute_name)
)
)
write_attribute(attribute_name, new_value)
else
super(new_value)

View File

@ -1,7 +1,7 @@
require 'unit_spec_helper'
describe Shoulda::Matchers::ActiveModel::ValidateAbsenceOfMatcher, type: :model do
if active_model_4_0?
if active_model_supports_absence_validation?
def self.available_column_types
[
:string,