diff --git a/lib/active_resource/base.rb b/lib/active_resource/base.rb index f9a66bd7f9..ecdc27a449 100644 --- a/lib/active_resource/base.rb +++ b/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 diff --git a/test/cases/base_test.rb b/test/cases/base_test.rb index 54c20bb470..c181b30e3e 100644 --- a/test/cases/base_test.rb +++ b/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