From 521b6ad904219fb2d887a534143b11fc1213c8c4 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Wed, 1 Apr 2020 17:01:15 -0500 Subject: [PATCH] Add a spec for campaigns.json --- spec/controllers/campaigns_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/spec/controllers/campaigns_spec.rb b/spec/controllers/campaigns_spec.rb index eb02b8bf..55d3b83d 100644 --- a/spec/controllers/campaigns_spec.rb +++ b/spec/controllers/campaigns_spec.rb @@ -64,4 +64,29 @@ describe CampaignsController, type: :controller do expect(get: '/nonprofits/5/campaigns/4').to(route_to(controller: 'campaigns', action: 'show', nonprofit_id: '5', id: '4')) end end + + describe 'index' do + render_views + let(:nonprofit) { force_create(:nonprofit, published: true)} + let(:campaign) { force_create(:campaign, nonprofit: nonprofit, name: "simplename", goal_amount: 444)} + before(:each) do + + campaign + get(:index, params: {nonprofit_id: nonprofit.id, format: :json}) + end + + it 'has ok status' do + expect(response).to have_http_status(:ok) + end + + it 'has correct items' do + body = JSON::parse(response.body) + expect(body).to eq({data: [{id: campaign.id, + name: 'simplename', + total_raised: 0, + goal_amount: 444, + url: "///sluggy-sluggo/campaigns/slug_#{campaign.id}" + }]}.with_indifferent_access) + end + end end