| Class | UpdateTest |
| In: |
test/unit/update_test.rb
|
| Parent: | ActiveSupport::TestCase |
# File test/unit/update_test.rb, line 21
21: def setup
22: logger.debug "Test Case: #{name}"
23: @andy, @george, @cash, @tony = users(:andy), users(:george), users(:cash), users(:tony)
24: @emails = ActionMailer::Base::deliveries
25: @emails.clear
26: end
Shows:
# File test/unit/update_test.rb, line 31
31: def test_notification
32: # 1. Note: create_templates uses update.do_update which sends emails
33: @emails.clear
34: wiki = create_templates
35: wiki.reload
36: bp = wiki.baseline_process
37: assert_equal 2, Site.count # 1 wiki, 1 baseline
38: assert_equal 3, @emails.size # STARTED and FINISHED
39: assert_not_nil wiki
40: assert_not_nil bp
41: @emails.clear
42: update = Update.create(:wiki_id => wiki.id, :baseline_process_id => bp.id, :user_id => @andy.id)
43: @andy.notify_immediate = 1
44: @george.notify_immediate = 1
45: @cash.notify_immediate = 1
46: @andy.save!
47: @george.save!
48: @cash.save!
49: update.do_update
50: assert_equal 4, @emails.size
51: email = @emails[3]
52: assert_equal ["[EPF Wiki - Test Enviroment] SCHEDULED update of Wiki Templates with Baseline Process templates_20080828",
53: "[EPF Wiki - Test Enviroment] STARTED update of Wiki Templates with Baseline Process templates_20080828",
54: "[EPF Wiki - Test Enviroment] FINISHED update of Wiki Templates with Baseline Process templates_20080828",
55: "[EPF Wiki - Test Enviroment] Wiki Templates Updated with Baseline Process templates_20080828"],
56: [@emails[0].subject, @emails[1].subject, @emails[2].subject, @emails[3].subject]
57: assert_equal ["[EPF Wiki - Test Enviroment] Wiki Templates Updated with Baseline Process templates_20080828",["andy.kaufman@epf.eclipse.org",
58: "cash.oshman@epf.eclipse.org",
59: "george.shapiro@epf.eclipse.org"], true], [email.subject, email.bcc, email.body.include?('http://localhost:3000/users/account')]
60: end
Shows
# File test/unit/update_test.rb, line 67
67: def test_reviewed_notification_email
68: @emails.clear
69: create_templates
70: wiki = Wiki.find_by_folder('templates')
71: assert_not_nil wiki
72: assert_equal 'Ready', wiki.status
73: p1, p2 = wiki.pages[23], wiki.pages[6]
74: # create some versions
75: co1 = Checkout.new(:note => 'Checkout to test notification email', :page => p1, :site => wiki, :source_version => p1.current_version, :user => @tony)
76: co2 = Checkout.new(:note => 'Checkout to test notification email', :page => p2, :site => wiki, :source_version => p2.current_version, :user => @cash)
77: # 2
78: assert !Notification.find_all_users(p1, Page.name).include?(@tony)
79: assert !Notification.find_all_users(p2, Page.name).include?(@cash)
80: assert co1.save
81: assert co2.save
82: v1 = co1.version
83: v2 = co2.version
84: assert_equal 2, Checkout.count
85: co1.checkin(@tony)
86: co2.checkin(@cash)
87: assert Notification.find_all_users(p1, Page.name).include?(@tony)
88: assert Notification.find_all_users(p2, Page.name).include?(@cash)
89: assert_equal 0, Checkout.count
90: v1.review_note = "Review note 1"
91: v2.review_note = "Review note 2"
92: v1.done = 'Y'
93: v2.done = 'Y'
94: v1.reviewer = @andy
95: v2.reviewer = @george
96: assert v1.save
97: assert v2.save
98: # create some comments
99: cmt1 = Comment.create(:text => 'Comment 1', :user => @tony, :version => v1, :page => v1.page, :site => v1.wiki)
100: cmt2 = Comment.create(:text => 'Comment 2', :user => @cash, :version => v1, :page => v1.page, :site => v1.wiki)
101: cmt3 = Comment.create(:text => 'Comment 3', :user => @george, :version => v2, :page => v2.page, :site => v2.wiki)
102: assert cmt1.save
103: assert cmt2.save
104: assert cmt3.save
105: assert Notification.find_all_users(p2, Page.name).include?(@cash)
106: assert Notification.find_all_users(p1, Page.name).include?(@tony)
107: assert Notification.find_all_users(p2, Page.name).include?(@cash)
108: assert Notification.find_all_users(p2, Page.name).include?(@george)
109: [cmt1, cmt2, cmt3].each do |cmt|
110: assert cmt.save
111: cmt.review_note = cmt.text
112: cmt.done = 'Y'
113: cmt.reviewer = @andy
114: assert cmt.save
115: end
116: for i in 1..3
117: Upload.create(:filename => 'index.html', :upload_type => 'Image', :description => 'Description of upload ' + i.to_s, :user => @cash, :reviewer => @andy, :review_note => 'Review note of upload ' + i.to_s, :done => 'Y')
118: end
119: @emails.clear
120: update = Update.new(:wiki => Wiki.find_by_folder('templates'), :baseline_process => BaselineProcess.find(:first), :user => @andy)
121: assert update.save
122: job_daily
123: assert_equal 6,@emails.size
124: assert_equal ['[EPF Wiki - Test Enviroment] SCHEDULED update of Wiki Templates with Baseline Process templates_20080828',
125: '[EPF Wiki - Test Enviroment] STARTED update of Wiki Templates with Baseline Process templates_20080828',
126: '[EPF Wiki - Test Enviroment] FINISHED update of Wiki Templates with Baseline Process templates_20080828'],
127: [@emails[0].subject,@emails[1].subject, @emails[2].subject]
128: assert_equal [["cash.oshman@epf.eclipse.org"],
129: ["tony.clifton@epf.eclipse.org"], ['george.shapiro@epf.eclipse.org'],
130: "[EPF Wiki - Test Enviroment] Your contribution has been processed",
131: "[EPF Wiki - Test Enviroment] Your contribution has been processed",
132: "[EPF Wiki - Test Enviroment] Your contribution has been processed"], [@emails[3].to, @emails[4].to, @emails[5].to, @emails[3].subject, @emails[4].subject, @emails[5].subject]
133: assert IO.readlines(File.expand_path('test/unit/notifier_test/contributions_processed.html', RAILS_ROOT)).join.index('Hi Cash Oshman')
134: # 3
135: #v1, cmt1
136: email = @emails[4]
137: assert_equal ["tony.clifton@epf.eclipse.org"], email.to
138: assert email.body.include?(v1.page.url(true))
139: assert email.body.include?(v1.page.presentation_name)
140: assert email.body.include?(v1.reviewer.name)
141: assert email.body.include?(v1.review_note)
142: assert email.body.include?(cmt1.page.url(true))
143: assert email.body.include?(cmt1.text)
144: assert email.body.include?(cmt1.reviewer.name)
145: assert email.body.include?(cmt1.review_note)
146: # 4
147: u = Upload.find(:first)
148: email = @emails[3]
149: assert_equal ["cash.oshman@epf.eclipse.org"], email.to
150: assert email.body.include?(u.url(true))
151: assert email.body.include?(u.filename)
152: assert email.body.include?(u.reviewer.name)
153: assert email.body.include?(u.review_note)
154: end