93.94% coverage:
This commit is contained in:
parent
efb6d86ea8
commit
051bbc9485
@ -60,7 +60,7 @@ class CampaignsController < ApplicationController
|
|||||||
def set_campaign
|
def set_campaign
|
||||||
listingcode = params[:listingcode]
|
listingcode = params[:listingcode]
|
||||||
if params[:campaign]
|
if params[:campaign]
|
||||||
@campaign = Campaign.find_by_listingcode(params[:campaign][:listingcode]) || not_found
|
@campaign = Campaign.find_by_listingcode(params[:campaign][:listingcode]) || not_found
|
||||||
else
|
else
|
||||||
@campaign = Campaign.find_by_listingcode(listingcode) || not_found
|
@campaign = Campaign.find_by_listingcode(listingcode) || not_found
|
||||||
end
|
end
|
||||||
|
@ -9,6 +9,11 @@ describe CampaignsController do
|
|||||||
let(:campaign){ attributes_for :campaign }
|
let(:campaign){ attributes_for :campaign }
|
||||||
let(:videolisting){ attributes_for :videolisting }
|
let(:videolisting){ attributes_for :videolisting }
|
||||||
|
|
||||||
|
it "allows you to create a campaign" do
|
||||||
|
get :new, campaign
|
||||||
|
expect(response.status).to eq 200
|
||||||
|
end
|
||||||
|
|
||||||
it 'should show the index page' do
|
it 'should show the index page' do
|
||||||
get :index
|
get :index
|
||||||
expect(response.status).to eq 200
|
expect(response.status).to eq 200
|
||||||
@ -41,6 +46,19 @@ describe CampaignsController do
|
|||||||
expect(Campaign.last.listingcode).to eq campaign[:listingcode]
|
expect(Campaign.last.listingcode).to eq campaign[:listingcode]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'creates a campaign from json post and fails' do
|
||||||
|
camp = FactoryGirl.create(:campaign)
|
||||||
|
campaign[:videolistings_attributes] = []
|
||||||
|
campaign[:videolistings_attributes] << videolisting
|
||||||
|
campaign[:listingcode] = camp.listingcode
|
||||||
|
|
||||||
|
post :create, campaign: campaign
|
||||||
|
|
||||||
|
expect(response.status).to eq 200
|
||||||
|
|
||||||
|
expect(Campaign.last.id).to_not eq campaign[:id]
|
||||||
|
end
|
||||||
|
|
||||||
it 'creates a campaign with a nested videolisting' do
|
it 'creates a campaign with a nested videolisting' do
|
||||||
campaign[:videolistings_attributes] = [videolisting,]
|
campaign[:videolistings_attributes] = [videolisting,]
|
||||||
post :create, campaign: campaign
|
post :create, campaign: campaign
|
||||||
@ -62,16 +80,37 @@ describe CampaignsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't allow edits on an already published campaign" do
|
it "doesn't allow edits on an already published campaign" do
|
||||||
|
camp = FactoryGirl.create(:campaign)
|
||||||
|
camp.processed = true
|
||||||
|
camp.save
|
||||||
|
get :edit, listingcode: camp.listingcode
|
||||||
|
expect(response.status).to eq 302
|
||||||
end
|
end
|
||||||
|
|
||||||
it "shows errors when creating and a campaign is invalid" do
|
it "allows updates" do
|
||||||
|
camp = FactoryGirl.create(:campaign)
|
||||||
|
c = Campaign.find(camp.id)
|
||||||
|
patch :update, listingcode: c.listingcode, campaign: c.attributes
|
||||||
|
expect(response.status).to eq 302
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't allow you to edit a listingcode to a prior existing one" do
|
||||||
|
camp = FactoryGirl.create(:campaign)
|
||||||
|
camp2 = FactoryGirl.create(:campaign)
|
||||||
|
|
||||||
|
c = Campaign.find(camp.id)
|
||||||
|
c.listingcode = camp2.listingcode
|
||||||
|
patch :update, listingcode: c.listingcode, campaign: c.attributes
|
||||||
|
expect(response.status).to eq 200
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can be deleted" do
|
||||||
|
camp = FactoryGirl.create(:campaign)
|
||||||
|
c = Campaign.find(camp.id)
|
||||||
|
|
||||||
|
expect{ delete :destroy, listingcode: c.listingcode}.to change(Campaign, :count).by(-1)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "it updates correctly." do
|
|
||||||
end
|
|
||||||
|
|
||||||
it "shows errors on failed updates" do
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user