Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Nov 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/active_resource/base.rb
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions test/cases/base_test.rb
Expand Up @@ -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
Expand Down