Usage of let on emails specs to DRY scenarios
This commit is contained in:
@@ -25,69 +25,64 @@ feature 'Emails' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'Proposal comments' do
|
context 'Proposal comments' do
|
||||||
scenario "Send email on proposal comment" do
|
let(:user) { create(:user, email_on_comment: true) }
|
||||||
user = create(:user, email_on_comment: true)
|
let(:proposal) { create(:proposal, author: user) }
|
||||||
proposal = create(:proposal, author: user)
|
|
||||||
|
scenario 'Send email on proposal comment' do
|
||||||
comment_on(proposal)
|
comment_on(proposal)
|
||||||
|
|
||||||
email = open_last_email
|
email = open_last_email
|
||||||
expect(email).to have_subject('Someone has commented on your citizen proposal')
|
expect(email).to have_subject('Someone has commented on your citizen proposal')
|
||||||
expect(email).to deliver_to(proposal.author)
|
expect(email).to deliver_to(proposal.author)
|
||||||
expect(email).to have_body_text(proposal_path(proposal))
|
expect(email).to have_body_text(proposal_path(proposal))
|
||||||
|
expect(email).to have_body_text(I18n.t('mailers.config.manage_email_subscriptions'))
|
||||||
|
expect(email).to have_body_text(account_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Do not send email about own proposal comments' do
|
scenario 'Do not send email about own proposal comments' do
|
||||||
user = create(:user, email_on_comment: true)
|
|
||||||
proposal = create(:proposal, author: user)
|
|
||||||
comment_on(proposal, user)
|
comment_on(proposal, user)
|
||||||
|
expect { open_last_email }.to raise_error('No email has been sent!')
|
||||||
expect { open_last_email }.to raise_error "No email has been sent!"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Do not send email about proposal comment unless set in preferences' do
|
scenario 'Do not send email about proposal comment unless set in preferences' do
|
||||||
user = create(:user, email_on_comment: false)
|
user.update(email_on_comment: false)
|
||||||
proposal = create(:proposal, author: user)
|
|
||||||
comment_on(proposal)
|
comment_on(proposal)
|
||||||
|
expect { open_last_email }.to raise_error('No email has been sent!')
|
||||||
expect { open_last_email }.to raise_error "No email has been sent!"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Debate comments' do
|
context 'Debate comments' do
|
||||||
scenario "Send email on debate comment" do
|
let(:user) { create(:user, email_on_comment: true) }
|
||||||
user = create(:user, email_on_comment: true)
|
let(:debate) { create(:debate, author: user) }
|
||||||
debate = create(:debate, author: user)
|
|
||||||
|
scenario 'Send email on debate comment' do
|
||||||
comment_on(debate)
|
comment_on(debate)
|
||||||
|
|
||||||
email = open_last_email
|
email = open_last_email
|
||||||
expect(email).to have_subject('Someone has commented on your debate')
|
expect(email).to have_subject('Someone has commented on your debate')
|
||||||
expect(email).to deliver_to(debate.author)
|
expect(email).to deliver_to(debate.author)
|
||||||
expect(email).to have_body_text(debate_path(debate))
|
expect(email).to have_body_text(debate_path(debate))
|
||||||
expect(email).to have_body_text(I18n.t("mailers.config.manage_email_subscriptions"))
|
expect(email).to have_body_text(I18n.t('mailers.config.manage_email_subscriptions'))
|
||||||
expect(email).to have_body_text(account_path)
|
expect(email).to have_body_text(account_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Do not send email about own debate comments' do
|
scenario 'Do not send email about own debate comments' do
|
||||||
user = create(:user, email_on_comment: true)
|
|
||||||
debate = create(:debate, author: user)
|
|
||||||
comment_on(debate, user)
|
comment_on(debate, user)
|
||||||
|
expect { open_last_email }.to raise_error('No email has been sent!')
|
||||||
expect { open_last_email }.to raise_error "No email has been sent!"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Do not send email about debate comment unless set in preferences' do
|
scenario 'Do not send email about debate comment unless set in preferences' do
|
||||||
user = create(:user, email_on_comment: false)
|
user.update(email_on_comment: false)
|
||||||
debate = create(:debate, author: user)
|
|
||||||
comment_on(debate)
|
comment_on(debate)
|
||||||
|
expect { open_last_email }.to raise_error('No email has been sent!')
|
||||||
expect { open_last_email }.to raise_error "No email has been sent!"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Budget investments comments' do
|
context 'Budget investments comments' do
|
||||||
|
let(:user) { create(:user, email_on_comment: true) }
|
||||||
|
let(:investment) { create(:budget_investment, author: user, budget: create(:budget)) }
|
||||||
|
|
||||||
scenario 'Send email on budget investment comment' do
|
scenario 'Send email on budget investment comment' do
|
||||||
user = create(:user, email_on_comment: true)
|
|
||||||
investment = create(:budget_investment, author: user, budget: create(:budget))
|
|
||||||
comment_on(investment)
|
comment_on(investment)
|
||||||
|
|
||||||
email = open_last_email
|
email = open_last_email
|
||||||
@@ -99,30 +94,23 @@ feature 'Emails' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Do not send email about own budget investments comments' do
|
scenario 'Do not send email about own budget investments comments' do
|
||||||
user = create(:user, email_on_comment: true)
|
|
||||||
investment = create(:budget_investment, author: user, budget: create(:budget))
|
|
||||||
comment_on(investment, user)
|
comment_on(investment, user)
|
||||||
|
expect { open_last_email }.to raise_error('No email has been sent!')
|
||||||
expect { open_last_email }.to raise_error 'No email has been sent!'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Do not send email about budget investment comment unless set in preferences' do
|
scenario 'Do not send email about budget investment comment unless set in preferences' do
|
||||||
user = create(:user, email_on_comment: false)
|
user.update(email_on_comment: false)
|
||||||
investment = create(:budget_investment, author: user, budget: create(:budget))
|
|
||||||
comment_on(investment)
|
comment_on(investment)
|
||||||
|
expect { open_last_email }.to raise_error('No email has been sent!')
|
||||||
expect { open_last_email }.to raise_error 'No email has been sent!'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Topic comments' do
|
context 'Topic comments' do
|
||||||
before do
|
let(:user) { create(:user, email_on_comment: true) }
|
||||||
@proposal = create(:proposal)
|
let(:proposal) { create(:proposal) }
|
||||||
end
|
let(:topic) { create(:topic, author: user, community: proposal.community) }
|
||||||
|
|
||||||
scenario 'Send email on topic comment' do
|
scenario 'Send email on topic comment' do
|
||||||
user = create(:user, email_on_comment: true)
|
|
||||||
topic = create(:topic, author: user, community: @proposal.community)
|
|
||||||
comment_on(topic)
|
comment_on(topic)
|
||||||
|
|
||||||
email = open_last_email
|
email = open_last_email
|
||||||
@@ -134,26 +122,22 @@ feature 'Emails' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Do not send email about own topic comments' do
|
scenario 'Do not send email about own topic comments' do
|
||||||
user = create(:user, email_on_comment: true)
|
|
||||||
topic = create(:topic, author: user, community: @proposal.community)
|
|
||||||
comment_on(topic, user)
|
comment_on(topic, user)
|
||||||
|
expect { open_last_email }.to raise_error('No email has been sent!')
|
||||||
expect { open_last_email }.to raise_error 'No email has been sent!'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Do not send email about topic comment unless set in preferences' do
|
scenario 'Do not send email about topic comment unless set in preferences' do
|
||||||
user = create(:user, email_on_comment: false)
|
user.update(email_on_comment: false)
|
||||||
topic = create(:topic, author: user, community: @proposal.community)
|
|
||||||
comment_on(topic)
|
comment_on(topic)
|
||||||
|
expect { open_last_email }.to raise_error('No email has been sent!')
|
||||||
expect { open_last_email }.to raise_error 'No email has been sent!'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Poll comments' do
|
context 'Poll comments' do
|
||||||
|
let(:user) { create(:user, email_on_comment: true) }
|
||||||
|
let(:poll) { create(:poll, author: user) }
|
||||||
|
|
||||||
scenario 'Send email on poll comment' do
|
scenario 'Send email on poll comment' do
|
||||||
user = create(:user, email_on_comment: true)
|
|
||||||
poll = create(:poll, author: user)
|
|
||||||
comment_on(poll)
|
comment_on(poll)
|
||||||
|
|
||||||
email = open_last_email
|
email = open_last_email
|
||||||
@@ -165,25 +149,21 @@ feature 'Emails' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Do not send email about own poll comments' do
|
scenario 'Do not send email about own poll comments' do
|
||||||
user = create(:user, email_on_comment: true)
|
|
||||||
poll = create(:poll, author: user)
|
|
||||||
comment_on(poll, user)
|
comment_on(poll, user)
|
||||||
|
expect { open_last_email }.to raise_error('No email has been sent!')
|
||||||
expect { open_last_email }.to raise_error 'No email has been sent!'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Do not send email about poll question comment unless set in preferences' do
|
scenario 'Do not send email about poll question comment unless set in preferences' do
|
||||||
user = create(:user, email_on_comment: false)
|
user.update(email_on_comment: false)
|
||||||
poll = create(:poll, author: user)
|
|
||||||
comment_on(poll)
|
comment_on(poll)
|
||||||
|
expect { open_last_email }.to raise_error('No email has been sent!')
|
||||||
expect { open_last_email }.to raise_error 'No email has been sent!'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Comment replies' do
|
context 'Comment replies' do
|
||||||
scenario "Send email on comment reply", :js do
|
let(:user) { create(:user, email_on_comment_reply: true) }
|
||||||
user = create(:user, email_on_comment_reply: true)
|
|
||||||
|
scenario 'Send email on comment reply', :js do
|
||||||
reply_to(user)
|
reply_to(user)
|
||||||
|
|
||||||
email = open_last_email
|
email = open_last_email
|
||||||
@@ -191,22 +171,19 @@ feature 'Emails' do
|
|||||||
expect(email).to deliver_to(user)
|
expect(email).to deliver_to(user)
|
||||||
expect(email).not_to have_body_text(debate_path(Comment.first.commentable))
|
expect(email).not_to have_body_text(debate_path(Comment.first.commentable))
|
||||||
expect(email).to have_body_text(comment_path(Comment.last))
|
expect(email).to have_body_text(comment_path(Comment.last))
|
||||||
expect(email).to have_body_text(I18n.t("mailers.config.manage_email_subscriptions"))
|
expect(email).to have_body_text(I18n.t('mailers.config.manage_email_subscriptions'))
|
||||||
expect(email).to have_body_text(account_path)
|
expect(email).to have_body_text(account_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Do not send email about own replies to own comments", :js do
|
scenario 'Do not send email about own replies to own comments', :js do
|
||||||
user = create(:user, email_on_comment_reply: true)
|
|
||||||
reply_to(user, user)
|
reply_to(user, user)
|
||||||
|
expect { open_last_email }.to raise_error('No email has been sent!')
|
||||||
expect { open_last_email }.to raise_error "No email has been sent!"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Do not send email about comment reply unless set in preferences", :js do
|
scenario 'Do not send email about comment reply unless set in preferences', :js do
|
||||||
user = create(:user, email_on_comment_reply: false)
|
user.update(email_on_comment_reply: false)
|
||||||
reply_to(user)
|
reply_to(user)
|
||||||
|
expect { open_last_email }.to raise_error('No email has been sent!')
|
||||||
expect { open_last_email }.to raise_error "No email has been sent!"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user