wrote more model tests

This commit is contained in:
Tyrel Souza 2014-04-09 14:37:46 -04:00
parent 7833c04d3d
commit d783fd8f09
3 changed files with 43 additions and 3 deletions

View File

@ -7,13 +7,13 @@ describe CampaignsController do
it 'creates a campaign from json post' do it 'creates a campaign from json post' do
post :create, campaign: campaign post :create, campaign: campaign
expect(response.status).to be 302 expect(response.status).to be 302
expect(Campaign.last.clientid).to eq "clientid1" expect(Campaign.last.clientid).to eq campaign[:clientid]
end 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
expect(Campaign.last.videolistings.last.videocode).to eq "video1" expect(Campaign.last.videolistings.last.videocode).to eq videolisting[:videocode]
expect(Campaign.last.videolistings.count).to eq 1 expect(Campaign.last.videolistings.count).to eq 1
end end
end end

View File

@ -1,5 +1,34 @@
require 'spec_helper' require 'spec_helper'
describe Campaign, 'associations' do describe Campaign, 'associations' do
let(:campaign){ attributes_for :campaign }
it {should have_many(:videolistings) } it {should have_many(:videolistings) }
it 'disallows duplicate campaignid' do
one = Campaign.new(campaign)
one.save
two = Campaign.new(campaign)
two.clientid = one.clientid
expect(two.valid?).to be false
end
it 'disallows duplicate billingcode' do
one = Campaign.new(campaign)
one.save
two = Campaign.new(campaign)
two.billingcode = one.billingcode
expect(two.valid?).to be false
end
it 'disallows duplicate listingcode' do
one = Campaign.new(campaign)
one.save
two = Campaign.new(campaign)
two.listingcode = one.listingcode
expect(two.valid?).to be false
end
end end

View File

@ -1,5 +1,16 @@
require 'spec_helper' require 'spec_helper'
describe Videolisting, 'associations' do describe Videolisting, 'associations' do
let(:videolisting){ attributes_for :videolisting }
it { should belong_to(:campaign) } it { should belong_to(:campaign) }
it 'disallows duplicate videocode' do
one = Videolisting.new(videolisting)
one.save
two = Videolisting.new(videolisting)
two.videocode = one.videocode
expect(two.valid?).to be false
end
end end