Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/controllers/api/v1/owners_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ class Api::V1::OwnersController < Api::BaseController
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found

def show
payload = @rubygem.owners.map { |owner| owner.payload.merge("role" => owner.ownerships.find_by(rubygem: @rubygem).role) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to make this more SQL effective. Now it seems to trigger additional query per each owner.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @simi
I believe my latest commit reduces it back down to one query

respond_to do |format|
format.json { render json: @rubygem.owners }
format.yaml { render yaml: @rubygem.owners }
format.json { render json: payload }
format.yaml { render yaml: payload }
end
end

Expand Down
15 changes: 15 additions & 0 deletions test/functional/api/v1/owners_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ def self.should_respond_to(format)
should respond_with :not_found
end


context "GET /api/v1/gems/:gem/owners.json" do
setup do
@user = create(:user)
@rubygem = create(:rubygem, owners: [@user])
get :show, params: { rubygem_id: @rubygem.slug }, format: :json
end
should "include associated users id, handle, and role in response" do
user_payload = JSON.parse(@response.body).first
assert_equal "owner", user_payload["role"]
assert_equal @user.id, user_payload["id"]
assert_equal @user.handle, user_payload["handle"]
end
end

should "route POST /api/v1/gems/rubygem/owners.json" do
route = { controller: "api/v1/owners",
action: "create",
Expand Down
Loading