mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 09:42:36 +02:00
fix bug with email notification check, add tests
This commit is contained in:
parent
8a0e121f29
commit
39ce179d16
2 changed files with 37 additions and 12 deletions
|
@ -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,
|
||||||
|
|
|
@ -7,19 +7,43 @@ describe 'site page' do
|
||||||
Capybara.default_driver = :rack_test
|
Capybara.default_driver = :rack_test
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'allows commenting' do
|
describe 'commenting' do
|
||||||
site = Fabricate :site
|
before do
|
||||||
commenting_site = Fabricate :site, commenting_allowed: true
|
@site = Fabricate :site
|
||||||
page.set_rack_session id: commenting_site.id
|
@commenting_site = Fabricate :site, commenting_allowed: true
|
||||||
visit "/site/#{site.username}"
|
page.set_rack_session id: @commenting_site.id
|
||||||
fill_in 'message', with: 'I love your site!'
|
visit "/site/#{@site.username}"
|
||||||
click_button 'Post'
|
EmailWorker.jobs.clear
|
||||||
site.profile_comments.count.must_equal 1
|
end
|
||||||
profile_comment = site.profile_comments.first
|
|
||||||
profile_comment.actioning_site.must_equal commenting_site
|
it 'allows commenting' do
|
||||||
profile_comment.message.must_equal 'I love your site!'
|
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
|
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
|
||||||
|
|
Loading…
Add table
Reference in a new issue