diff --git a/lib/fmrest/spyke/model/attributes.rb b/lib/fmrest/spyke/model/attributes.rb index 9b81cc6..35822be 100644 --- a/lib/fmrest/spyke/model/attributes.rb +++ b/lib/fmrest/spyke/model/attributes.rb @@ -22,7 +22,13 @@ module Attributes # when calling ActiveModels' define_attribute_method, otherwise it # will define an `attribute` method which overrides the one provided # by Spyke - self.attribute_method_matchers.shift + if respond_to? :attribute_method_patterns + # ActiveModel >= 7.1 + attribute_method_patterns.shift + else + # ActiveModel < 7.1 + attribute_method_matchers.shift + end # Keep track of attribute mappings so we can get the FM field names # for changed attributes diff --git a/spec/spyke/model/attributes_spec.rb b/spec/spyke/model/attributes_spec.rb index 69bb76c..bc249ab 100644 --- a/spec/spyke/model/attributes_spec.rb +++ b/spec/spyke/model/attributes_spec.rb @@ -24,9 +24,21 @@ # TODO: Rewrite this spec to be less dependent on ActiveModel's internals describe ".attribute_method_matchers" do it "doesn't include a plain entry" do - matcher = test_class.attribute_method_matchers.first - # ActiveModel 6 uses .target, while ActiveModel <= 5 uses method_missing_target - target = matcher.respond_to?(:target) ? matcher.target : matcher.method_missing_target + matcher = if test_class.respond_to?(:attribute_method_patterns) + test_class.attribute_method_patterns.first + else + test_class.attribute_method_matchers.first + end + target = if matcher.respond_to?(:proxy_target) + # ActiveModel >= 7.1 + matcher.proxy_target + elsif matcher.respond_to?(:target) + # ActiveModel >= 6, < 7.1 + matcher.target + else + # ActiveModel <= 5 + matcher.method_missing_target + end expect(target).to_not eq("attribute") end end