Skip to content

Commit a64ecaf

Browse files
authored
Merge pull request #511 from remiprev/zw/belongs-to-path
fix path option on belongs_to association
2 parents 8b7c6e9 + 21644bc commit a64ecaf

2 files changed

Lines changed: 3 additions & 4 deletions

File tree

lib/her/model/associations/belongs_to_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def fetch
8080
return @parent.attributes[@name] unless @params.any? || @parent.attributes[@name].blank?
8181

8282
path_params = @parent.attributes.merge(@params.merge(@klass.primary_key => foreign_key_value))
83-
path = build_association_path -> { @klass.build_request_path(path_params) }
83+
path = build_association_path -> { @klass.build_request_path(@opts[:path], path_params) }
8484
@klass.get_resource(path, @params).tap do |result|
8585
@cached_result = result if @params.blank?
8686
end

spec/model/associations_spec.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,7 @@
662662
builder.adapter :test do |stub|
663663
stub.get("/users/1") { [200, {}, { id: 1, name: "Tobias Fünke", organization: { id: 1, name: "Bluth Company Inc." }, organization_id: 1 }.to_json] }
664664
stub.get("/users/4") { [200, {}, { id: 1, name: "Tobias Fünke", organization: { id: 1, name: "Bluth Company Inc." } }.to_json] }
665-
stub.get("/users/3") { [200, {}, { id: 2, name: "Lindsay Fünke", company: nil }.to_json] }
666-
stub.get("/companies/1") { [200, {}, { id: 1, name: "Bluth Company" }.to_json] }
665+
stub.get("/users/3") { [200, {}, { id: 2, name: "Lindsay Fünke", organization: nil }.to_json] }
667666
end
668667
end
669668
end
@@ -700,7 +699,7 @@
700699
builder.use Faraday::Request::UrlEncoded
701700
builder.adapter :test do |stub|
702701
stub.get("/users/2") { [200, {}, { id: 2, name: "Lindsay Fünke", organization_id: 1 }.to_json] }
703-
stub.get("/companies/1") { [200, {}, { id: 1, name: "Bluth Company" }.to_json] }
702+
stub.get("/organizations/1") { [200, {}, { id: 1, name: "Bluth Company" }.to_json] }
704703
end
705704
end
706705
end

0 commit comments

Comments
 (0)