2014-04-07 18:41:34 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Campaign, 'associations' do
|
2014-04-09 18:37:46 +00:00
|
|
|
let(:campaign){ attributes_for :campaign }
|
2014-04-07 18:41:34 +00:00
|
|
|
it {should have_many(:videolistings) }
|
2014-04-09 18:37:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-04-28 18:16:43 +00:00
|
|
|
|
|
|
|
it 'shows how complete the videos are by percentage' do
|
|
|
|
camp = Campaign.new(campaign)
|
|
|
|
video_1 = FactoryGirl.create(:videolisting)
|
|
|
|
video_2 = FactoryGirl.create(:videolisting)
|
|
|
|
|
|
|
|
expect(camp.video_completion_percent).to eq(0) # no associations
|
|
|
|
|
|
|
|
|
|
|
|
camp.videolistings << video_1
|
|
|
|
camp.videolistings << video_2
|
|
|
|
camp.save
|
|
|
|
|
|
|
|
expect(camp.video_completion_percent).to eq(0)
|
|
|
|
|
|
|
|
camp.videolistings.first.published = true
|
|
|
|
camp.videolistings.first.save
|
|
|
|
|
|
|
|
expect(camp.video_completion_percent).to eq(50)
|
|
|
|
|
|
|
|
camp.videolistings.last.published = true
|
|
|
|
camp.videolistings.last.save
|
|
|
|
|
|
|
|
expect(camp.video_completion_percent).to eq(100)
|
|
|
|
end
|
|
|
|
|
2014-04-07 18:41:34 +00:00
|
|
|
end
|