Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Initialize instance with non-prefix attributes in ActiveRecord::Base.build #85

Open
wants to merge 1 commit into from

2 participants

@peterjm

ActiveResource::Base.build used to use the attributes to initialize the instance. That functionality was lost when the attributes started to be passed to new_element_path (see fd3616a).

This PR re-adds the functionality.

@ches

:+1:

Simple patch and very annoying issue.

@peterjm peterjm referenced this pull request in Shopify/shopify_api
Closed

Add Activeresource 4.0.0 compatibility #55

@ches

Bump :smile:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 1 deletion.
  1. +1 −1  lib/active_resource/base.rb
  2. +10 −0 test/cases/base_test.rb
View
2  lib/active_resource/base.rb
@@ -774,7 +774,7 @@ def collection_path(prefix_options = {}, query_options = nil)
# Returns the new resource instance.
#
def build(attributes = {})
- attrs = self.format.decode(connection.get("#{new_element_path(attributes)}", headers).body)
+ attrs = self.format.decode(connection.get("#{new_element_path(attributes)}", headers).body).merge(attributes)
self.new(attrs)
end
View
10 test/cases/base_test.rb
@@ -717,6 +717,16 @@ def test_build_with_attributes_for_prefix_call
assert_nothing_raised { StreetAddress.build(person_id: 1) }
end
+ def test_build_with_non_prefix_attributes
+ ActiveResource::HttpMock.respond_to do |mock|
+ mock.get "/people/1/addresses/new.json", {}, StreetAddress.new.to_json
+ end
+ assert_nothing_raised do
+ address = StreetAddress.build(person_id: 1, city: "Toronto")
+ assert_equal "Toronto", address.city
+ end
+ end
+
def test_save
rick = Person.new
assert rick.save
Something went wrong with that request. Please try again.