Skip to content

Commit

Permalink
Support Rails / ActiveRecord 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
emptyflask authored and pilaf committed Dec 22, 2023
1 parent 9d9d00f commit 55b145a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/fmrest/spyke/model/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 15 additions & 3 deletions spec/spyke/model/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 55b145a

Please sign in to comment.