Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: app/models/domain_entities/campaign.rb
- ===================================================================
- --- app/models/domain_entities/campaign.rb (revision 598)
- +++ app/models/domain_entities/campaign.rb (working copy)
- @@ -4,36 +4,38 @@
- attributes :media_plan_advertiser_cpc_asf,
- :media_plan_advertiser_cpm_asf,
- :media_plan_advertiser_pays_asf,
- - :media_plan_agency_fee,
- - :media_plan_budget_amount,
- - :media_plan_name,
- - :media_plan_projected_end_date,
- - :media_plan_projected_start_date,
- - :gross_media_cost,
- - :net_media_cost,
- - :total_cost,
- - :media_plan_number,
- - :advertiser_key,
- - :agency_id,
- - :ad_server,
- - :client_key
- -
- - def publishers
- - DomainEntities::Publisher.find(:all, :conditions => { :campaign_key => self.campaign_key })
- - end
- -
- - def placements
- - DomainEntities::Placement.find(:all, :conditions => { :campaign_key => self.campaign_key })
- + :media_plan_agency_fee,
- + :media_plan_budget_amount,
- + :media_plan_name,
- + :media_plan_projected_end_date,
- + :media_plan_projected_start_date,
- + :gross_media_cost,
- + :net_media_cost,
- + :total_cost,
- + :media_plan_number,
- + :advertiser_key,
- + :agency_id,
- + :ad_server,
- + :client_key
- +
- + editable_attributes :media_plan_name
- +
- + def publishers
- + DomainEntities::Publisher.find(:all, :conditions => { :campaign_key => self.campaign_key })
- end
- -
- - def media_types
- - placements.collect(&:media_type).uniq
- - end
- -
- - def spend
- +
- + def placements
- + DomainEntities::Placement.find(:all, :conditions => { :campaign_key => self.campaign_key })
- + end
- +
- + def media_types
- + placements.collect(&:media_type).uniq
- + end
- +
- + def spend
- placements.collect(&:projected_total_spend).inject { |sum, spend| sum + spend }
- end
- -
- +
- def to_json(options = {})
- {
- :key => self.campaign_key,
- @@ -42,4 +44,4 @@
- }.to_json
- end
- end
- -end
- \ No newline at end of file
- +end
- Index: app/models/domain_entities/base.rb
- ===================================================================
- --- app/models/domain_entities/base.rb (revision 598)
- +++ app/models/domain_entities/base.rb (working copy)
- @@ -128,6 +128,16 @@
- end
- end
- + def attributes
- + @values
- + end
- +
- + def attributes=(attributes)
- + attributes.each do |name, value|
- + self.send("#{name}=", value) if self.class.attributes.include?(name.to_sym)
- + end
- + end
- +
- alias_method :orig_method_missing, :method_missing
- def method_missing(method, *args, &block)
- Index: app/controllers/campaigns_controller.rb
- ===================================================================
- --- app/controllers/campaigns_controller.rb (revision 598)
- +++ app/controllers/campaigns_controller.rb (working copy)
- @@ -15,6 +15,20 @@
- end
- end
- end
- +
- + # PUT /campaigns/#{campaign_key}
- + def update
- + @campaign.attributes = params[:campaign]
- + @campaign.save!
- +
- + respond_to do |format|
- + format.js # update.rjs
- + end
- + rescue DomainEntities::InvalidDomainEntityError
- + respond_to do |format|
- + format.js # update.rjs
- + end
- + end
- protected
- def get_top_level_entities
- @@ -23,6 +37,9 @@
- @client = DomainEntities::Client.find(@advertiser.client_key)
- elsif params[:client_id]
- @client = DomainEntities::Client.find(params[:client_id])
- + elsif params[:id]
- + @campaign = DomainEntities::Campaign.find(params[:id])
- + @client = DomainEntities::Client.find(@campaign.client_key)
- end
- end
- Index: app/views/campaigns/update.rjs
- ===================================================================
- Index: stories/campaign_editing/campaign_editing_steps.rb
- ===================================================================
- --- stories/campaign_editing/campaign_editing_steps.rb (revision 0)
- +++ stories/campaign_editing/campaign_editing_steps.rb (revision 0)
- @@ -0,0 +1,75 @@
- +steps_for :campaign_editing do
- +
- + # GIVEN
- + Given "another agency" do
- + @another_agency = Agency.create!(:name => "another_agency")
- + end
- +
- + Given "the campaign of this agency" do
- + create_valid_ad_server_record(@agency)
- +
- + @campaign = DomainEntities::Campaign.find(:first)
- + @campaign.should_not be_nil
- + end
- +
- + Given "the campaign of another agency" do
- + create_valid_ad_server_record(@another_agency)
- +
- + @another_campaign = DomainEntities::Campaign.find(:first)
- + @another_campaign.should_not be_nil
- + end
- +
- + Given "valid campaign attributes" do
- + @campaign_attributes = {
- + :media_plan_agency_fee => 56.00,
- + :media_plan_budget_amount => 100.34,
- + :media_plan_name => 'Google Inc',
- + :media_plan_number => 135,
- + :ad_server => 'world atlas'
- + }
- + end
- +
- + Given "invalid campaign attributes" do
- + @campaign_attributes = {
- + :media_plan_agency_fee => -45,
- + :ad_server => ''
- + }
- + end
- +
- + # WHEN
- +
- + When "I update campaign attributes" do
- + put_via_redirect("campaigns/#{@campaign.key}", :campaign => @campaign_attributes)
- + end
- +
- + When "I update campaign attributes of another agency" do
- + put_via_redirect("campaigns/#{@another_campaign.key}", :campaign => @campaign_attributes)
- + end
- +
- + # THEN
- +
- + Then "campaign attributes should NOT be updated" do
- + campaign = DomainEntities::Campaign.find(:first)
- + campaign.attributes.should == @campaign.attributes
- + end
- +
- + Then "campaign attributes of another agency should NOT be updated" do
- + campaign = DomainEntities::Campaign.find(:first)
- + campaign.attributes.should == @another_campaign.attributes
- + end
- +
- + Then "ONLY editable campaign attributes should be updated" do
- + campaign = DomainEntities::Campaign.find(:first)
- +
- + campaign.class.editable_attributes.should_not be_empty
- +
- + campaign.class.editable_attributes.each do |attribute|
- + campaign.attributes[attribute].should == @campaign_attributes[attribute]
- + end
- +
- + (campaign.class.attributes - campaign.class.editable_attributes).each do |attribute|
- + campaign.attributes[attribute].should == @campaign.attributes[attribute]
- + end
- + end
- +
- +end
- Index: stories/campaign_editing/campaign_editing
- ===================================================================
- --- stories/campaign_editing/campaign_editing (revision 0)
- +++ stories/campaign_editing/campaign_editing (revision 0)
- @@ -0,0 +1,63 @@
- +Story: editing campaign
- + As an agency admin
- + I want to be able to update campaign attributes
- + So that I can modify campaign data that I don't like
- +
- + Scenario: not signed in user tries to update campaign with valid attributes
- + Given guest
- + And agency user user@art.com with password pass
- + And the campaign of this agency
- + And valid campaign attributes
- +
- + When I update campaign attributes
- + Then I should see login page
- + Then campaign attributes should NOT be updated
- +
- + Scenario: regular user tries to update campaign with valid attributes
- + Given agency user user@art.com with password pass
- + And the campaign of this agency
- + And valid campaign attributes
- +
- + When I login with email user@art.com and password pass
- + Then I should be logged in
- +
- + When I update campaign attributes
- + Then I should see login page
- + And campaign attributes should NOT be updated
- +
- + Scenario: agency admin tries to update campaign of another agency with valid attributes
- + Given agency admin user@art.com with password pass
- + And another agency
- + And the campaign of another agency
- + And valid campaign attributes
- +
- + When I login with email user@art.com and password pass
- + Then I should be logged in
- +
- + When I update campaign attributes of another agency
- + Then I should see login page
- + And campaign attributes of another agency should NOT be updated
- +
- + Scenario: agency admin tries to update campaign with invalid attributes
- + Given agency admin user@art.com with password pass
- + And the campaign of this agency
- + And invalid campaign attributes
- +
- + When I login with email user@art.com and password pass
- + Then I should be logged in
- +
- + When I update campaign attributes
- + Then campaign attributes should NOT be updated
- +
- + Scenario: agency admin user tries to update campaign with valid attributes
- + Given agency admin user@art.com with password pass
- + And the campaign of this agency
- + And valid campaign attributes
- +
- + When I login with email user@art.com and password pass
- + Then I should be logged in
- +
- + When I update campaign attributes
- + Then ONLY editable campaign attributes should be updated
- +
- +
- Index: stories/campaign_editing/campaign_editing.rb
- ===================================================================
- --- stories/campaign_editing/campaign_editing.rb (revision 0)
- +++ stories/campaign_editing/campaign_editing.rb (revision 0)
- @@ -0,0 +1,7 @@
- +require File.join(File.dirname(__FILE__), *%w[.. helper])
- +require File.dirname(__FILE__) + "/" + File.basename(__FILE__,".rb") + "_steps"
- +require File.join(File.dirname(__FILE__), *%w[.. helpers]) + "/" + File.basename(__FILE__, ".rb") + "_helper.rb"
- +
- +with_steps_for :navigation, :template, :user, :client, :campaign_editing, :campaign_editing_helper do
- + run File.expand_path(__FILE__).gsub(".rb",""), :type => RailsStory
- +end
- Index: stories/helpers/campaign_editing_helper.rb
- ===================================================================
- --- stories/helpers/campaign_editing_helper.rb (revision 0)
- +++ stories/helpers/campaign_editing_helper.rb (revision 0)
- @@ -0,0 +1,17 @@
- +steps_for :campaign_editing_helper do
- +
- + class RailsStory
- + def create_valid_ad_server_record(agency)
- + asr = AdServerRecord.new
- + asr.ad_server = 'atlas'
- + asr.agency = agency
- + asr.date = Date.today
- +
- + [:client, :advertiser, :publisher, :placement, :ad, :campaign].each do |entity|
- + asr.send("#{entity}_key=","atlas_#{entity}_key")
- + end
- + asr.save!
- + end
- + end
- +
- +end
- Index: spec/models/domain_entities/ad_spec.rb
- ===================================================================
- --- spec/models/domain_entities/ad_spec.rb (revision 598)
- +++ spec/models/domain_entities/ad_spec.rb (working copy)
- @@ -8,6 +8,7 @@
- it_should_behave_like 'DomainEntity find(:first) functionality'
- it_should_behave_like 'DomainEntity save! functionality'
- it_should_behave_like 'DomainEntity valid? functionality'
- + it_should_behave_like 'DomainEntity instance functionality'
- private
- def klass; DomainEntities::Ad; end
- Index: spec/models/domain_entities/domain_entities_base_spec.rb
- ===================================================================
- --- spec/models/domain_entities/domain_entities_base_spec.rb (revision 598)
- +++ spec/models/domain_entities/domain_entities_base_spec.rb (working copy)
- @@ -498,3 +498,24 @@
- end
- end
- +
- +describe 'DomainEntity instance functionality', :shared => true do
- +
- + it "should return instance attributes as key-value pair hash" do
- + instance = klass.new
- + instance.class.attributes :client_name, :media_plan_name, :publisher_name
- +
- + instance.client_name = 'ART'
- + instance.media_plan_name = 'Google'
- + instance.attributes.should == {:client_name => 'ART', :media_plan_name => 'Google'}
- + end
- +
- + it "should accept instance attributes from hash with attributes= method" do
- + instance = klass.new
- + instance.class.attributes :client_name, :media_plan_name, :publisher_name
- +
- + instance.attributes = {:client_name => 'ART', :media_plan_name => 'Google'}
- + instance.client_name.should == 'ART'
- + instance.media_plan_name.should == 'Google'
- + end
- +end
- Index: spec/models/domain_entities/conversion_pixel_spec.rb
- ===================================================================
- --- spec/models/domain_entities/conversion_pixel_spec.rb (revision 598)
- +++ spec/models/domain_entities/conversion_pixel_spec.rb (working copy)
- @@ -30,6 +30,7 @@
- it_should_behave_like 'DomainEntity find(:first) functionality'
- it_should_behave_like 'DomainEntity save! functionality'
- it_should_behave_like 'DomainEntity valid? functionality'
- + it_should_behave_like 'DomainEntity instance functionality'
- private
- def klass; DomainEntities::ConversionPixel; end
- Index: spec/models/domain_entities/advertiser_spec.rb
- ===================================================================
- --- spec/models/domain_entities/advertiser_spec.rb (revision 598)
- +++ spec/models/domain_entities/advertiser_spec.rb (working copy)
- @@ -63,6 +63,7 @@
- it_should_behave_like 'DomainEntity find(:first) functionality'
- it_should_behave_like 'DomainEntity save! functionality'
- it_should_behave_like 'DomainEntity valid? functionality'
- + it_should_behave_like 'DomainEntity instance functionality'
- private
- def klass; DomainEntities::Advertiser; end
- Index: spec/models/domain_entities/placement_spec.rb
- ===================================================================
- --- spec/models/domain_entities/placement_spec.rb (revision 598)
- +++ spec/models/domain_entities/placement_spec.rb (working copy)
- @@ -8,6 +8,7 @@
- it_should_behave_like 'DomainEntity find(:first) functionality'
- it_should_behave_like 'DomainEntity save! functionality'
- it_should_behave_like 'DomainEntity valid? functionality'
- + it_should_behave_like 'DomainEntity instance functionality'
- private
- def klass; DomainEntities::Placement; end
- Index: spec/models/domain_entities/package_spec.rb
- ===================================================================
- --- spec/models/domain_entities/package_spec.rb (revision 598)
- +++ spec/models/domain_entities/package_spec.rb (working copy)
- @@ -8,6 +8,7 @@
- it_should_behave_like 'DomainEntity find(:first) functionality'
- it_should_behave_like 'DomainEntity save! functionality'
- it_should_behave_like 'DomainEntity valid? functionality'
- + it_should_behave_like 'DomainEntity instance functionality'
- private
- def klass; DomainEntities::Package; end
- Index: spec/models/domain_entities/publisher_spec.rb
- ===================================================================
- --- spec/models/domain_entities/publisher_spec.rb (revision 598)
- +++ spec/models/domain_entities/publisher_spec.rb (working copy)
- @@ -8,6 +8,7 @@
- it_should_behave_like 'DomainEntity find(:first) functionality'
- it_should_behave_like 'DomainEntity save! functionality'
- it_should_behave_like 'DomainEntity valid? functionality'
- + it_should_behave_like 'DomainEntity instance functionality'
- private
- def klass; DomainEntities::Publisher; end
- Index: spec/models/domain_entities/client_spec.rb
- ===================================================================
- --- spec/models/domain_entities/client_spec.rb (revision 598)
- +++ spec/models/domain_entities/client_spec.rb (working copy)
- @@ -8,6 +8,7 @@
- it_should_behave_like 'DomainEntity find(:first) functionality'
- it_should_behave_like 'DomainEntity save! functionality'
- it_should_behave_like 'DomainEntity valid? functionality'
- + it_should_behave_like 'DomainEntity instance functionality'
- private
- def klass; DomainEntities::Client; end
- Index: spec/models/domain_entities/campaign_spec.rb
- ===================================================================
- --- spec/models/domain_entities/campaign_spec.rb (revision 598)
- +++ spec/models/domain_entities/campaign_spec.rb (working copy)
- @@ -8,6 +8,7 @@
- it_should_behave_like 'DomainEntity find(:first) functionality'
- it_should_behave_like 'DomainEntity save! functionality'
- it_should_behave_like 'DomainEntity valid? functionality'
- + it_should_behave_like 'DomainEntity instance functionality'
- private
- def klass; DomainEntities::Campaign; end
Add Comment
Please, Sign In to add comment