2014-04-09 18:12:14 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe CampaignsController do
|
2014-04-14 18:41:53 +00:00
|
|
|
before (:each) do
|
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
sign_in @user
|
|
|
|
end
|
|
|
|
|
2014-04-09 18:12:14 +00:00
|
|
|
let(:campaign){ attributes_for :campaign }
|
|
|
|
let(:videolisting){ attributes_for :videolisting }
|
|
|
|
|
2014-04-15 14:38:43 +00:00
|
|
|
it 'should show the index page' do
|
|
|
|
get :index
|
|
|
|
expect(response.status).to eq 200
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should show the campaign page' do
|
|
|
|
post :create, campaign: campaign
|
|
|
|
get :show, campaign
|
|
|
|
expect(response.status).to eq 200
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises routing error when campaign not found' do
|
|
|
|
expect(lambda { get :show, { :clientid => "x" } }).to raise_error(ActionController::RoutingError)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-04-09 18:12:14 +00:00
|
|
|
it 'creates a campaign from json post' do
|
|
|
|
post :create, campaign: campaign
|
2014-04-14 18:41:53 +00:00
|
|
|
|
2014-04-09 18:12:14 +00:00
|
|
|
expect(response.status).to be 302
|
2014-04-14 18:41:53 +00:00
|
|
|
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-09 18:37:46 +00:00
|
|
|
expect(Campaign.last.clientid).to eq campaign[:clientid]
|
2014-04-09 18:12:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a campaign with a nested videolisting' do
|
|
|
|
campaign[:videolistings_attributes] = [videolisting,]
|
|
|
|
post :create, campaign: campaign
|
2014-04-14 18:41:53 +00:00
|
|
|
|
|
|
|
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-09 18:37:46 +00:00
|
|
|
expect(Campaign.last.videolistings.last.videocode).to eq videolisting[:videocode]
|
2014-04-09 18:12:14 +00:00
|
|
|
expect(Campaign.last.videolistings.count).to eq 1
|
|
|
|
end
|
|
|
|
end
|