Guest User

Untitled

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