Guest User

Untitled

a guest
Mar 12th, 2018
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.19 KB | None | 0 0
  1.  
  2.  
  3. Index: app/models/domain_entities/campaign.rb
  4. ===================================================================
  5. --- app/models/domain_entities/campaign.rb (revision 598)
  6. +++ app/models/domain_entities/campaign.rb (working copy)
  7. @@ -4,36 +4,38 @@
  8. attributes :media_plan_advertiser_cpc_asf,
  9. :media_plan_advertiser_cpm_asf,
  10. :media_plan_advertiser_pays_asf,
  11. - :media_plan_agency_fee,
  12. - :media_plan_budget_amount,
  13. - :media_plan_name,
  14. - :media_plan_projected_end_date,
  15. - :media_plan_projected_start_date,
  16. - :gross_media_cost,
  17. - :net_media_cost,
  18. - :total_cost,
  19. - :media_plan_number,
  20. - :advertiser_key,
  21. - :agency_id,
  22. - :ad_server,
  23. - :client_key
  24. -
  25. - def publishers
  26. - DomainEntities::Publisher.find(:all, :conditions => { :campaign_key => self.campaign_key })
  27. - end
  28. -
  29. - def placements
  30. - DomainEntities::Placement.find(:all, :conditions => { :campaign_key => self.campaign_key })
  31. + :media_plan_agency_fee,
  32. + :media_plan_budget_amount,
  33. + :media_plan_name,
  34. + :media_plan_projected_end_date,
  35. + :media_plan_projected_start_date,
  36. + :gross_media_cost,
  37. + :net_media_cost,
  38. + :total_cost,
  39. + :media_plan_number,
  40. + :advertiser_key,
  41. + :agency_id,
  42. + :ad_server,
  43. + :client_key
  44. +
  45. + editable_attributes :media_plan_name
  46. +
  47. + def publishers
  48. + DomainEntities::Publisher.find(:all, :conditions => { :campaign_key => self.campaign_key })
  49. end
  50. -
  51. - def media_types
  52. - placements.collect(&:media_type).uniq
  53. - end
  54. -
  55. - def spend
  56. +
  57. + def placements
  58. + DomainEntities::Placement.find(:all, :conditions => { :campaign_key => self.campaign_key })
  59. + end
  60. +
  61. + def media_types
  62. + placements.collect(&:media_type).uniq
  63. + end
  64. +
  65. + def spend
  66. placements.collect(&:projected_total_spend).inject { |sum, spend| sum + spend }
  67. end
  68. -
  69. +
  70. def to_json(options = {})
  71. {
  72. :key => self.campaign_key,
  73. @@ -42,4 +44,4 @@
  74. }.to_json
  75. end
  76. end
  77. -end
  78. \ No newline at end of file
  79. +end
  80. Index: app/models/domain_entities/base.rb
  81. ===================================================================
  82. --- app/models/domain_entities/base.rb (revision 598)
  83. +++ app/models/domain_entities/base.rb (working copy)
  84. @@ -128,6 +128,16 @@
  85. end
  86. end
  87.  
  88. + def attributes
  89. + @values
  90. + end
  91. +
  92. + def attributes=(attributes)
  93. + attributes.each do |name, value|
  94. + self.send("#{name}=", value) if self.class.attributes.include?(name.to_sym)
  95. + end
  96. + end
  97. +
  98. alias_method :orig_method_missing, :method_missing
  99.  
  100. def method_missing(method, *args, &block)
  101. Index: app/controllers/campaigns_controller.rb
  102. ===================================================================
  103. --- app/controllers/campaigns_controller.rb (revision 598)
  104. +++ app/controllers/campaigns_controller.rb (working copy)
  105. @@ -15,6 +15,20 @@
  106. end
  107. end
  108. end
  109. +
  110. + # PUT /campaigns/#{campaign_key}
  111. + def update
  112. + @campaign.attributes = params[:campaign]
  113. + @campaign.save!
  114. +
  115. + respond_to do |format|
  116. + format.js # update.rjs
  117. + end
  118. + rescue DomainEntities::InvalidDomainEntityError
  119. + respond_to do |format|
  120. + format.js # update.rjs
  121. + end
  122. + end
  123.  
  124. protected
  125. def get_top_level_entities
  126. @@ -23,6 +37,9 @@
  127. @client = DomainEntities::Client.find(@advertiser.client_key)
  128. elsif params[:client_id]
  129. @client = DomainEntities::Client.find(params[:client_id])
  130. + elsif params[:id]
  131. + @campaign = DomainEntities::Campaign.find(params[:id])
  132. + @client = DomainEntities::Client.find(@campaign.client_key)
  133. end
  134. end
  135.  
  136. Index: app/views/campaigns/update.rjs
  137. ===================================================================
  138. Index: stories/campaign_editing/campaign_editing_steps.rb
  139. ===================================================================
  140. --- stories/campaign_editing/campaign_editing_steps.rb (revision 0)
  141. +++ stories/campaign_editing/campaign_editing_steps.rb (revision 0)
  142. @@ -0,0 +1,75 @@
  143. +steps_for :campaign_editing do
  144. +
  145. + # GIVEN
  146. + Given "another agency" do
  147. + @another_agency = Agency.create!(:name => "another_agency")
  148. + end
  149. +
  150. + Given "the campaign of this agency" do
  151. + create_valid_ad_server_record(@agency)
  152. +
  153. + @campaign = DomainEntities::Campaign.find(:first)
  154. + @campaign.should_not be_nil
  155. + end
  156. +
  157. + Given "the campaign of another agency" do
  158. + create_valid_ad_server_record(@another_agency)
  159. +
  160. + @another_campaign = DomainEntities::Campaign.find(:first)
  161. + @another_campaign.should_not be_nil
  162. + end
  163. +
  164. + Given "valid campaign attributes" do
  165. + @campaign_attributes = {
  166. + :media_plan_agency_fee => 56.00,
  167. + :media_plan_budget_amount => 100.34,
  168. + :media_plan_name => 'Google Inc',
  169. + :media_plan_number => 135,
  170. + :ad_server => 'world atlas'
  171. + }
  172. + end
  173. +
  174. + Given "invalid campaign attributes" do
  175. + @campaign_attributes = {
  176. + :media_plan_agency_fee => -45,
  177. + :ad_server => ''
  178. + }
  179. + end
  180. +
  181. + # WHEN
  182. +
  183. + When "I update campaign attributes" do
  184. + put_via_redirect("campaigns/#{@campaign.key}", :campaign => @campaign_attributes)
  185. + end
  186. +
  187. + When "I update campaign attributes of another agency" do
  188. + put_via_redirect("campaigns/#{@another_campaign.key}", :campaign => @campaign_attributes)
  189. + end
  190. +
  191. + # THEN
  192. +
  193. + Then "campaign attributes should NOT be updated" do
  194. + campaign = DomainEntities::Campaign.find(:first)
  195. + campaign.attributes.should == @campaign.attributes
  196. + end
  197. +
  198. + Then "campaign attributes of another agency should NOT be updated" do
  199. + campaign = DomainEntities::Campaign.find(:first)
  200. + campaign.attributes.should == @another_campaign.attributes
  201. + end
  202. +
  203. + Then "ONLY editable campaign attributes should be updated" do
  204. + campaign = DomainEntities::Campaign.find(:first)
  205. +
  206. + campaign.class.editable_attributes.should_not be_empty
  207. +
  208. + campaign.class.editable_attributes.each do |attribute|
  209. + campaign.attributes[attribute].should == @campaign_attributes[attribute]
  210. + end
  211. +
  212. + (campaign.class.attributes - campaign.class.editable_attributes).each do |attribute|
  213. + campaign.attributes[attribute].should == @campaign.attributes[attribute]
  214. + end
  215. + end
  216. +
  217. +end
  218. Index: stories/campaign_editing/campaign_editing
  219. ===================================================================
  220. --- stories/campaign_editing/campaign_editing (revision 0)
  221. +++ stories/campaign_editing/campaign_editing (revision 0)
  222. @@ -0,0 +1,63 @@
  223. +Story: editing campaign
  224. + As an agency admin
  225. + I want to be able to update campaign attributes
  226. + So that I can modify campaign data that I don't like
  227. +
  228. + Scenario: not signed in user tries to update campaign with valid attributes
  229. + Given guest
  230. + And agency user user@art.com with password pass
  231. + And the campaign of this agency
  232. + And valid campaign attributes
  233. +
  234. + When I update campaign attributes
  235. + Then I should see login page
  236. + Then campaign attributes should NOT be updated
  237. +
  238. + Scenario: regular user tries to update campaign with valid attributes
  239. + Given agency user user@art.com with password pass
  240. + And the campaign of this agency
  241. + And valid campaign attributes
  242. +
  243. + When I login with email user@art.com and password pass
  244. + Then I should be logged in
  245. +
  246. + When I update campaign attributes
  247. + Then I should see login page
  248. + And campaign attributes should NOT be updated
  249. +
  250. + Scenario: agency admin tries to update campaign of another agency with valid attributes
  251. + Given agency admin user@art.com with password pass
  252. + And another agency
  253. + And the campaign of another agency
  254. + And valid campaign attributes
  255. +
  256. + When I login with email user@art.com and password pass
  257. + Then I should be logged in
  258. +
  259. + When I update campaign attributes of another agency
  260. + Then I should see login page
  261. + And campaign attributes of another agency should NOT be updated
  262. +
  263. + Scenario: agency admin tries to update campaign with invalid attributes
  264. + Given agency admin user@art.com with password pass
  265. + And the campaign of this agency
  266. + And invalid campaign attributes
  267. +
  268. + When I login with email user@art.com and password pass
  269. + Then I should be logged in
  270. +
  271. + When I update campaign attributes
  272. + Then campaign attributes should NOT be updated
  273. +
  274. + Scenario: agency admin user tries to update campaign with valid attributes
  275. + Given agency admin user@art.com with password pass
  276. + And the campaign of this agency
  277. + And valid campaign attributes
  278. +
  279. + When I login with email user@art.com and password pass
  280. + Then I should be logged in
  281. +
  282. + When I update campaign attributes
  283. + Then ONLY editable campaign attributes should be updated
  284. +
  285. +
  286. Index: stories/campaign_editing/campaign_editing.rb
  287. ===================================================================
  288. --- stories/campaign_editing/campaign_editing.rb (revision 0)
  289. +++ stories/campaign_editing/campaign_editing.rb (revision 0)
  290. @@ -0,0 +1,7 @@
  291. +require File.join(File.dirname(__FILE__), *%w[.. helper])
  292. +require File.dirname(__FILE__) + "/" + File.basename(__FILE__,".rb") + "_steps"
  293. +require File.join(File.dirname(__FILE__), *%w[.. helpers]) + "/" + File.basename(__FILE__, ".rb") + "_helper.rb"
  294. +
  295. +with_steps_for :navigation, :template, :user, :client, :campaign_editing, :campaign_editing_helper do
  296. + run File.expand_path(__FILE__).gsub(".rb",""), :type => RailsStory
  297. +end
  298. Index: stories/helpers/campaign_editing_helper.rb
  299. ===================================================================
  300. --- stories/helpers/campaign_editing_helper.rb (revision 0)
  301. +++ stories/helpers/campaign_editing_helper.rb (revision 0)
  302. @@ -0,0 +1,17 @@
  303. +steps_for :campaign_editing_helper do
  304. +
  305. + class RailsStory
  306. + def create_valid_ad_server_record(agency)
  307. + asr = AdServerRecord.new
  308. + asr.ad_server = 'atlas'
  309. + asr.agency = agency
  310. + asr.date = Date.today
  311. +
  312. + [:client, :advertiser, :publisher, :placement, :ad, :campaign].each do |entity|
  313. + asr.send("#{entity}_key=","atlas_#{entity}_key")
  314. + end
  315. + asr.save!
  316. + end
  317. + end
  318. +
  319. +end
  320. Index: spec/models/domain_entities/ad_spec.rb
  321. ===================================================================
  322. --- spec/models/domain_entities/ad_spec.rb (revision 598)
  323. +++ spec/models/domain_entities/ad_spec.rb (working copy)
  324. @@ -8,6 +8,7 @@
  325. it_should_behave_like 'DomainEntity find(:first) functionality'
  326. it_should_behave_like 'DomainEntity save! functionality'
  327. it_should_behave_like 'DomainEntity valid? functionality'
  328. + it_should_behave_like 'DomainEntity instance functionality'
  329.  
  330. private
  331. def klass; DomainEntities::Ad; end
  332. Index: spec/models/domain_entities/domain_entities_base_spec.rb
  333. ===================================================================
  334. --- spec/models/domain_entities/domain_entities_base_spec.rb (revision 598)
  335. +++ spec/models/domain_entities/domain_entities_base_spec.rb (working copy)
  336. @@ -498,3 +498,24 @@
  337. end
  338.  
  339. end
  340. +
  341. +describe 'DomainEntity instance functionality', :shared => true do
  342. +
  343. + it "should return instance attributes as key-value pair hash" do
  344. + instance = klass.new
  345. + instance.class.attributes :client_name, :media_plan_name, :publisher_name
  346. +
  347. + instance.client_name = 'ART'
  348. + instance.media_plan_name = 'Google'
  349. + instance.attributes.should == {:client_name => 'ART', :media_plan_name => 'Google'}
  350. + end
  351. +
  352. + it "should accept instance attributes from hash with attributes= method" do
  353. + instance = klass.new
  354. + instance.class.attributes :client_name, :media_plan_name, :publisher_name
  355. +
  356. + instance.attributes = {:client_name => 'ART', :media_plan_name => 'Google'}
  357. + instance.client_name.should == 'ART'
  358. + instance.media_plan_name.should == 'Google'
  359. + end
  360. +end
  361. Index: spec/models/domain_entities/conversion_pixel_spec.rb
  362. ===================================================================
  363. --- spec/models/domain_entities/conversion_pixel_spec.rb (revision 598)
  364. +++ spec/models/domain_entities/conversion_pixel_spec.rb (working copy)
  365. @@ -30,6 +30,7 @@
  366. it_should_behave_like 'DomainEntity find(:first) functionality'
  367. it_should_behave_like 'DomainEntity save! functionality'
  368. it_should_behave_like 'DomainEntity valid? functionality'
  369. + it_should_behave_like 'DomainEntity instance functionality'
  370.  
  371. private
  372. def klass; DomainEntities::ConversionPixel; end
  373. Index: spec/models/domain_entities/advertiser_spec.rb
  374. ===================================================================
  375. --- spec/models/domain_entities/advertiser_spec.rb (revision 598)
  376. +++ spec/models/domain_entities/advertiser_spec.rb (working copy)
  377. @@ -63,6 +63,7 @@
  378. it_should_behave_like 'DomainEntity find(:first) functionality'
  379. it_should_behave_like 'DomainEntity save! functionality'
  380. it_should_behave_like 'DomainEntity valid? functionality'
  381. + it_should_behave_like 'DomainEntity instance functionality'
  382.  
  383. private
  384. def klass; DomainEntities::Advertiser; end
  385. Index: spec/models/domain_entities/placement_spec.rb
  386. ===================================================================
  387. --- spec/models/domain_entities/placement_spec.rb (revision 598)
  388. +++ spec/models/domain_entities/placement_spec.rb (working copy)
  389. @@ -8,6 +8,7 @@
  390. it_should_behave_like 'DomainEntity find(:first) functionality'
  391. it_should_behave_like 'DomainEntity save! functionality'
  392. it_should_behave_like 'DomainEntity valid? functionality'
  393. + it_should_behave_like 'DomainEntity instance functionality'
  394.  
  395. private
  396. def klass; DomainEntities::Placement; end
  397. Index: spec/models/domain_entities/package_spec.rb
  398. ===================================================================
  399. --- spec/models/domain_entities/package_spec.rb (revision 598)
  400. +++ spec/models/domain_entities/package_spec.rb (working copy)
  401. @@ -8,6 +8,7 @@
  402. it_should_behave_like 'DomainEntity find(:first) functionality'
  403. it_should_behave_like 'DomainEntity save! functionality'
  404. it_should_behave_like 'DomainEntity valid? functionality'
  405. + it_should_behave_like 'DomainEntity instance functionality'
  406.  
  407. private
  408. def klass; DomainEntities::Package; end
  409. Index: spec/models/domain_entities/publisher_spec.rb
  410. ===================================================================
  411. --- spec/models/domain_entities/publisher_spec.rb (revision 598)
  412. +++ spec/models/domain_entities/publisher_spec.rb (working copy)
  413. @@ -8,6 +8,7 @@
  414. it_should_behave_like 'DomainEntity find(:first) functionality'
  415. it_should_behave_like 'DomainEntity save! functionality'
  416. it_should_behave_like 'DomainEntity valid? functionality'
  417. + it_should_behave_like 'DomainEntity instance functionality'
  418.  
  419. private
  420. def klass; DomainEntities::Publisher; end
  421. Index: spec/models/domain_entities/client_spec.rb
  422. ===================================================================
  423. --- spec/models/domain_entities/client_spec.rb (revision 598)
  424. +++ spec/models/domain_entities/client_spec.rb (working copy)
  425. @@ -8,6 +8,7 @@
  426. it_should_behave_like 'DomainEntity find(:first) functionality'
  427. it_should_behave_like 'DomainEntity save! functionality'
  428. it_should_behave_like 'DomainEntity valid? functionality'
  429. + it_should_behave_like 'DomainEntity instance functionality'
  430.  
  431. private
  432. def klass; DomainEntities::Client; end
  433. Index: spec/models/domain_entities/campaign_spec.rb
  434. ===================================================================
  435. --- spec/models/domain_entities/campaign_spec.rb (revision 598)
  436. +++ spec/models/domain_entities/campaign_spec.rb (working copy)
  437. @@ -8,6 +8,7 @@
  438. it_should_behave_like 'DomainEntity find(:first) functionality'
  439. it_should_behave_like 'DomainEntity save! functionality'
  440. it_should_behave_like 'DomainEntity valid? functionality'
  441. + it_should_behave_like 'DomainEntity instance functionality'
  442.  
  443. private
  444. def klass; DomainEntities::Campaign; end
Add Comment
Please, Sign In to add comment