Skip to content

Commit 09198d4

Browse files
committed
fix: allow ActiveRecord method definitions
1 parent ee38ee3 commit 09198d4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/anchor/resource.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ def anchor_attributes_properties(included_fields:)
6767
model_method = options[:delegate] || attr
6868
resource_method = attr
6969

70-
model_method_defined = _model_class.try(:method_defined?, model_method.to_sym)
70+
model_method_defined = _model_class.try(
71+
:method_defined?,
72+
model_method.to_sym,
73+
) && !_model_class.instance_method(model_method.to_sym)
74+
.owner.is_a?(ActiveRecord::AttributeMethods::GeneratedAttributeMethods)
7175
resource_method_defined = @anchor_method_added_count[resource_method.to_sym] > 1
7276
serializer_defined = (_model_class.try(:attribute_types) || {})[model_method.to_s].respond_to?(:coder)
7377
method_defined = model_method_defined || resource_method_defined || serializer_defined

spec/anchor/example_schema_snapshot_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
RSpec.describe "Example" do
55
def self.snapshot_test(filename, generate)
66
it "generates correct #{filename} schema" do
7+
User.find_or_create_by!(name: "User", role: :admin) # allows ActiveRecord to define instance methods for columns
8+
79
schema = generate.call
810
path = Rails.root.join("test/files", filename)
911
unless File.file?(path)

0 commit comments

Comments
 (0)