wrote more model tests
This commit is contained in:
parent
7833c04d3d
commit
d783fd8f09
@ -7,13 +7,13 @@ describe CampaignsController do
|
||||
it 'creates a campaign from json post' do
|
||||
post :create, campaign: campaign
|
||||
expect(response.status).to be 302
|
||||
expect(Campaign.last.clientid).to eq "clientid1"
|
||||
expect(Campaign.last.clientid).to eq campaign[:clientid]
|
||||
end
|
||||
|
||||
it 'creates a campaign with a nested videolisting' do
|
||||
campaign[:videolistings_attributes] = [videolisting,]
|
||||
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
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,34 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Campaign, 'associations' do
|
||||
let(:campaign){ attributes_for :campaign }
|
||||
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
|
@ -1,5 +1,16 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Videolisting, 'associations' do
|
||||
it {should belong_to(:campaign) }
|
||||
let(:videolisting){ attributes_for :videolisting }
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user