Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/operations/health_insurances/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def apply_custom_filter(query)
if %w[true false].include?(params[:custom])
query.by_custom(custom: params[:custom], user: user)
else
query.where(custom: false)
query.where(user: user)
end
end
end
Expand Down
26 changes: 26 additions & 0 deletions spec/operations/health_insurances/list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@
)
end

context "when filtering by user" do
it "returns only health insurances for the specified user" do
user1 = create(:user)
user2 = create(:user)
health_insurance_user1 = create(:health_insurance, custom: true, user: user1)
create(:health_insurance, custom: true, user: user2)

result_user1 = described_class.call(user: user1)
expect(result_user1.health_insurances).to all(have_attributes(user: user1))
expect(result_user1.health_insurances[0].id).to eq(health_insurance_user1.id)

result_user2 = described_class.call(user: user2)
expect(result_user2.health_insurances).to all(have_attributes(user: user2))
end

it "returns no health insurances for user without any" do
user1 = create(:user)
create(:health_insurance, custom: true, user: user1)
user2 = create(:user)

result = described_class.call(user: user2)

expect(result.health_insurances).to be_empty
end
end

context "when custom is true" do
it "returns only the custom health_insurances for the given user" do
user = create(:user)
Expand Down
5 changes: 3 additions & 2 deletions spec/requests/api/v1/health_insurances_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

before do
headers = auth_token_for(create(:user))
get "/api/v1/health_insurances", headers: headers
params = { custom: false }
get "/api/v1/health_insurances", headers: headers, params: params
end

it "returns ok" do
Expand Down Expand Up @@ -62,7 +63,7 @@
before do
create_list(:health_insurance, 8)
headers = auth_token_for(create(:user))
get "/api/v1/health_insurances", params: { page: 2, per_page: 5 }, headers: headers
get "/api/v1/health_insurances", params: { page: 2, per_page: 5, custom: false }, headers: headers
end

it "returns only 3 health_insurances" do
Expand Down
Loading