fix bug with email notification check, add tests

This commit is contained in:
Kyle Drake 2015-01-06 19:57:13 -08:00
parent 8a0e121f29
commit 39ce179d16
2 changed files with 37 additions and 12 deletions

View file

@ -193,6 +193,7 @@ class Site < Sequel::Model
return if actioning_site.owner == owner return if actioning_site.owner == owner
send_email( send_email(
col: :send_comment_emails,
subject: "#{actioning_site.username.capitalize} commented on your site", subject: "#{actioning_site.username.capitalize} commented on your site",
body: render_template( body: render_template(
'email/new_comment.erb', 'email/new_comment.erb',
@ -730,7 +731,7 @@ class Site < Sequel::Model
raise ArgumentError, "argument missing: #{a}" if args[a].nil? raise ArgumentError, "argument missing: #{a}" if args[a].nil?
end end
if can_email?(args[:col]) if email && can_email?(args[:col])
EmailWorker.perform_async({ EmailWorker.perform_async({
from: FROM_EMAIL, from: FROM_EMAIL,
to: owner.email, to: owner.email,

View file

@ -7,19 +7,43 @@ describe 'site page' do
Capybara.default_driver = :rack_test Capybara.default_driver = :rack_test
end end
describe 'commenting' do
before do
@site = Fabricate :site
@commenting_site = Fabricate :site, commenting_allowed: true
page.set_rack_session id: @commenting_site.id
visit "/site/#{@site.username}"
EmailWorker.jobs.clear
end
it 'allows commenting' do it 'allows commenting' do
site = Fabricate :site
commenting_site = Fabricate :site, commenting_allowed: true
page.set_rack_session id: commenting_site.id
visit "/site/#{site.username}"
fill_in 'message', with: 'I love your site!' fill_in 'message', with: 'I love your site!'
click_button 'Post' click_button 'Post'
site.profile_comments.count.must_equal 1 @site.profile_comments.count.must_equal 1
profile_comment = site.profile_comments.first profile_comment = @site.profile_comments.first
profile_comment.actioning_site.must_equal commenting_site profile_comment.actioning_site.must_equal @commenting_site
profile_comment.message.must_equal 'I love your site!' profile_comment.message.must_equal 'I love your site!'
end end
it 'does not send comment email if not wished' do
@site.update send_comment_emails: false
fill_in 'message', with: 'I am annoying'
click_button 'Post'
@site.profile_comments.count.must_equal 1
EmailWorker.jobs.length.must_equal 0
end
it 'does not send email if there is none' do
@site.email = nil
@site.save_changes validate: false
fill_in 'message', with: 'DERP'
click_button 'Post'
EmailWorker.jobs.length.must_equal 0
end
end
it 'does not allow commenting without requirements met' do it 'does not allow commenting without requirements met' do
#site = Fabricate :site #site = Fabricate :site
#commenting_site #commenting_site