diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 49536af..f4a4d92 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,15 +1,4 @@ module ApplicationHelper - def producttypeid_list(options={}) - producttypeids = [] - producttypeids << ["720 - Basic Montage", 720] - producttypeids << ["721 - Advanced Montage", 721] - producttypeids << ["722 - Basic Video Shoot", 722] - producttypeids << ["723 - Repurposed", 723] - producttypeids << ["724 - Repurposed Edit", 724] - return options.empty? ? producttypeids : convert_to_hash(producttypeids)[options[:item]] - - end - def voiceoverselection_list(options={}) voiceoverselections = [] voiceoverselections << ["1 - Male", 1] @@ -30,8 +19,6 @@ module ApplicationHelper return options.empty? ? musicselections : convert_to_hash(musicselections)[options[:item]] end - - def us_states(options={}) states = [ ['Alabama', 'AL'], diff --git a/app/models/campaign.rb b/app/models/campaign.rb index e1ed05c..a03b52e 100644 --- a/app/models/campaign.rb +++ b/app/models/campaign.rb @@ -8,16 +8,15 @@ class Campaign < ActiveRecord::Base validates :productsandservices, presence: true after_save :send_to_better_video validate :has_at_least_one_videolisting - - + after_initialize :set_defaults + def set_defaults + self.clientid = 720 + end def has_at_least_one_videolisting errors.add(:base, 'Must add at least one Videolisting') if self.videolistings.blank? end - def init - self.clientid = 720 - end def send_to_better_video if self.processed_changed? && self.processed == true diff --git a/app/models/videolisting.rb b/app/models/videolisting.rb index 5610ecf..9e482b4 100644 --- a/app/models/videolisting.rb +++ b/app/models/videolisting.rb @@ -4,12 +4,13 @@ class Videolisting < ActiveRecord::Base validates :voiceoverselection, presence: true validates :musicselection, presence: true after_save :send_notification_after_change + after_initialize :set_defaults - def init + + def set_defaults self.producttypeid = 721 end - def asseturls_array self.asseturls.split(',').collect { |url| { asseturl: url.strip } } end diff --git a/spec/controllers/campaigns_controller_spec.rb b/spec/controllers/campaigns_controller_spec.rb index 081d944..a534b13 100644 --- a/spec/controllers/campaigns_controller_spec.rb +++ b/spec/controllers/campaigns_controller_spec.rb @@ -51,4 +51,27 @@ describe CampaignsController do expect(Campaign.last.videolistings.last.videocode).to eq videolisting[:videocode] expect(Campaign.last.videolistings.count).to eq 1 end + + 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 + + it "doesn't allow edits on an already published campaign" do + end + + it "shows errors when creating and a campaign is invalid" do + + end + + it "it updates correctly." do + end + + it "shows errors on failed updates" do + + end end diff --git a/spec/factories/campaigns.rb b/spec/factories/campaigns.rb index 0084014..d39122f 100644 --- a/spec/factories/campaigns.rb +++ b/spec/factories/campaigns.rb @@ -1,7 +1,7 @@ FactoryGirl.define do factory :campaign do - clientid 720 + # clientid 720 sequence(:billingcode) { |x| "billingcode#{x}" } sequence(:listingcode) { |x| "listingcode#{x}" } address "123 Anywhere Street" diff --git a/spec/helpers/helpers_spec.rb b/spec/helpers/helpers_spec.rb new file mode 100644 index 0000000..27c9433 --- /dev/null +++ b/spec/helpers/helpers_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe ApplicationHelper, 'helpers' do + it "gets all voiceovers" do + expect(voiceoverselection_list).to include(["1 - Male", 1]) + end + + it "gets a voiceover" do + expect(voiceoverselection_list(item: 1)).to eq("1 - Male") + end + + it "gets all music selections" do + expect(musicselection_list).to include(["0 - No Preference", 0]) + end + + it "gets a music selection" do + expect(musicselection_list(item: 0)).to eq("0 - No Preference") + end + + it "gets all states" do + expect(us_states).to include(['New Hampshire', 'NH']) + end + + it "gets a state" do + expect(us_states(item: 'NH')).to eq("New Hampshire") + end +end \ No newline at end of file diff --git a/spec/models/videolisting_spec.rb b/spec/models/videolisting_spec.rb index 67509e0..098af66 100644 --- a/spec/models/videolisting_spec.rb +++ b/spec/models/videolisting_spec.rb @@ -13,4 +13,9 @@ describe Videolisting, 'associations' do expect(two.valid?).to be false end + + it "has asseturls array working correctly" do + listing = FactoryGirl.create(:videolisting) + expect(listing.asseturls_array).to include({asseturl: "http://s3.amazon.com/555555/catering.jpg"}) + end end \ No newline at end of file