Skip to content

Commit 902258c

Browse files
committed
abstract MODEL_ASSOCIATIONS constant
1 parent 6886416 commit 902258c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

lib/helpers/parse_rails.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
MODEL_ASSOCIATIONS = %i[belongs_to has_one has_many has_and_belongs_to_many].freeze
4+
35
Synvert::Helper.new 'rails/parse' do |options|
46
configure(parser: Synvert::PRISM_PARSER)
57

@@ -54,7 +56,7 @@
5456
end
5557

5658
add_callback :call_node, at: 'start' do |node|
57-
if node.receiver.nil? && %i[belongs_to has_one has_many has_and_belongs_to_many].include?(node.name)
59+
if node.receiver.nil? && MODEL_ASSOCIATIONS.include?(node.name)
5860
association_name = node.arguments.arguments.first.to_value
5961
options = {}
6062
if node.arguments.arguments.length > 1 && node.arguments.arguments.last.is_a?(Prism::KeywordHashNode)

spec/helpers/parse_rails_spec.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,10 @@ class Picture < ApplicationRecord
6565

6666
rewriter.process
6767

68-
expect(rewriter.load_data(:rails_models)).to eq({
69-
associations: [
70-
{ class_name: "Picture", name: "imageable", type: "belongs_to", polymorphic: true },
71-
{ class_name: "User", name: "organization", type: "belongs_to" },
72-
{ class_name: "User", name: "posts", type: "has_many" }
73-
]
74-
})
68+
expect(rewriter.load_data(:rails_models)[:associations]).to eq([
69+
{ class_name: "Picture", name: "imageable", type: "belongs_to", polymorphic: true },
70+
{ class_name: "User", name: "organization", type: "belongs_to" },
71+
{ class_name: "User", name: "posts", type: "has_many" }
72+
])
7573
end
7674
end

0 commit comments

Comments
 (0)