diff --git a/models/site.rb b/models/site.rb index 4bd2db29..5eba1a74 100644 --- a/models/site.rb +++ b/models/site.rb @@ -193,6 +193,7 @@ class Site < Sequel::Model return if actioning_site.owner == owner send_email( + col: :send_comment_emails, subject: "#{actioning_site.username.capitalize} commented on your site", body: render_template( 'email/new_comment.erb', @@ -730,7 +731,7 @@ class Site < Sequel::Model raise ArgumentError, "argument missing: #{a}" if args[a].nil? end - if can_email?(args[:col]) + if email && can_email?(args[:col]) EmailWorker.perform_async({ from: FROM_EMAIL, to: owner.email, diff --git a/tests/acceptance/site_tests.rb b/tests/acceptance/site_tests.rb index 485d2af3..58d51a0d 100644 --- a/tests/acceptance/site_tests.rb +++ b/tests/acceptance/site_tests.rb @@ -7,19 +7,43 @@ describe 'site page' do Capybara.default_driver = :rack_test end - 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!' - click_button 'Post' - site.profile_comments.count.must_equal 1 - profile_comment = site.profile_comments.first - profile_comment.actioning_site.must_equal commenting_site - profile_comment.message.must_equal 'I love your site!' + 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 + fill_in 'message', with: 'I love your site!' + click_button 'Post' + @site.profile_comments.count.must_equal 1 + profile_comment = @site.profile_comments.first + profile_comment.actioning_site.must_equal @commenting_site + profile_comment.message.must_equal 'I love your site!' + 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 #site = Fabricate :site #commenting_site