diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3d8ec7d..49c4723 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -16,8 +16,9 @@ def lookup end def show - user = User.find(params[:id]) - render json: user + ids = params[:id].split(',') if params.key(:id) + users = User.where(id: ids || []) + render json: users.first if ids.count == 1 else users end def me diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 6c4896d..a57f0c1 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -655,6 +655,41 @@ end end + context 'GET /users/:id,:id2,' do + context "with mutliple ids" do + it "returns the 2 the two users" do + users = create_list(:user, 2) + get "#{host}/users/#{users[0].id},#{users[1].id}" + + expect(json.data.first.attributes.state_code).to eq(users[0].state_code) + expect(json.data.first.attributes.email).to eq(users[0].email) + expect(json.data.first.id).to eq(users[0].id.to_s) + + expect(json.data.last.attributes.state_code).to eq(users.last.state_code) + expect(json.data.last.attributes.email).to eq(users.last.email) + expect(json.data.last.id).to eq(users.last.id.to_s) + end + + it "is successfull response" do + users = create_list(:user, 2) + get "#{host}/users/#{users[0].id},#{users[1].id}" + expect(last_response.status).to eq(200) + end + end + + context "with no ids specified" do + it "returns no results" do + get "#{host}/users" + expect(json.data).to be_empty + end + + it "returns no results" do + get "#{host}/users" + expect(last_response.status).to eq(200) + end + end + end + context 'GET /users/:id' do email = 'test-user@mail.com' password = 'password'