vidpush/spec/controllers/campaigns_controller_spec.rb

136 lines
3.9 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe CampaignsController do
before (:each) do
@user = FactoryGirl.create(:user)
sign_in @user
end
let(:campaign){ attributes_for :campaign }
let(:videolisting){ attributes_for :videolisting }
2014-04-24 22:07:23 +00:00
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
get :index
expect(response.status).to eq 200
end
it 'should show the campaign page' do
campaign[:videolistings_attributes] = []
campaign[:videolistings_attributes] << videolisting
post :create, campaign: campaign
get :show, campaign
expect(response.status).to eq 200
end
it 'raises routing error when campaign not found' do
2014-04-24 20:33:48 +00:00
expect(lambda { get :show, { :listingcode => "x" } }).to raise_error(ActionController::RoutingError)
end
it 'creates a campaign from json post' do
campaign[:videolistings_attributes] = []
campaign[:videolistings_attributes] << videolisting
post :create, campaign: campaign
2014-04-24 20:33:48 +00:00
expect(response.status).to eq 302
flash = response.request.env["action_dispatch.request.flash_hash"][:alert]
expect(flash).not_to eq("You need to sign in or sign up before continuing.")
2014-04-24 18:12:08 +00:00
expect(Campaign.last.listingcode).to eq campaign[:listingcode]
end
2014-04-24 22:07:23 +00:00
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
campaign[:videolistings_attributes] = [videolisting,]
2014-04-30 19:53:58 +00:00
expect do
post :create, campaign: campaign
end.to change(Campaign, :count).by(1)
flash = response.request.env["action_dispatch.request.flash_hash"][:alert]
expect(flash).not_to eq("You need to sign in or sign up before continuing.")
end
2014-04-24 21:13:39 +00:00
it "expects the clientid to be correct" do
camp = FactoryGirl.build(:campaign)
expect(camp.clientid).to eq 720
end
it "allows you to set a campaign from a campaign that is a hash" do
#line 63 camp_controller
end
2014-04-29 17:03:46 +00:00
it "doesn't allow edits on an already sent campaign" do
2014-04-24 22:07:23 +00:00
camp = FactoryGirl.create(:campaign)
2014-04-29 17:03:46 +00:00
camp.sent = true
2014-04-24 22:07:23 +00:00
camp.save
get :edit, listingcode: camp.listingcode
expect(response.status).to eq 302
2014-04-24 21:13:39 +00:00
end
2014-04-24 22:07:23 +00:00
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
2014-04-24 21:13:39 +00:00
end
2014-04-24 22:07:23 +00:00
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
2014-04-24 21:13:39 +00:00
end
2014-04-24 22:07:23 +00:00
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)
2014-04-24 21:13:39 +00:00
end
2014-04-24 22:07:23 +00:00
2014-05-06 16:36:00 +00:00
it "allows sending to better video successfully" do
camp = FactoryGirl.create(:campaign)
c = Campaign.find(camp.id)
patch :update, listingcode: c.listingcode, campaign: c.attributes, send: true
c_published = Campaign.find(camp.id)
expect(response.status).to eq 302
expect(c_published.sent).to eq(true)
end
it "allows sending to better video and shows errors" do
camp = FactoryGirl.create(:campaign)
camp.listingcode = "videolistingmissing"
camp.save
c = Campaign.find(camp.id)
patch :update, listingcode: c.listingcode, campaign: c.attributes, send: true
expect(response.status).to eq 200 # no redirect, show error on page.
end
2014-04-24 22:07:23 +00:00
end