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

Pass the build arguments through to new_element_path. #43

Merged
merged 1 commit into from Oct 25, 2012
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 @@ -766,7 +766,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}", headers).body).merge(attributes)
attrs = self.format.decode(connection.get("#{new_element_path(attributes)}", headers).body)
self.new(attrs)
end

Expand Down
14 changes: 14 additions & 0 deletions test/cases/base_test.rb
Expand Up @@ -656,6 +656,20 @@ def test_build_with_custom_header
Person.headers.delete('key')
end

def test_build_without_attributes_for_prefix_call
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/people/1/addresses/new.json", {}, StreetAddress.new.to_json
end
assert_raise(ActiveResource::InvalidRequestError) { StreetAddress.build }
end

def test_build_with_attributes_for_prefix_call
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/people/1/addresses/new.json", {}, StreetAddress.new.to_json
end
assert_nothing_raised { StreetAddress.build(person_id: 1) }
end

def test_save
rick = Person.new
assert rick.save
Expand Down