diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index 74b608ed6..e04de4fc0 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -84,6 +84,37 @@ feature 'Emails' do end end + context 'Budget investments comments' do + scenario 'Send email on budget investment comment', :js do + user = create(:user, email_on_comment: true) + investment = create(:budget_investment, author: user, budget: create(:budget)) + comment_on(investment) + + email = open_last_email + expect(email).to have_subject('Someone has commented on your investment') + expect(email).to deliver_to(investment.author) + expect(email).to have_body_text(budget_investment_path(investment, budget_id: investment.budget_id)) + expect(email).to have_body_text(I18n.t('mailers.config.manage_email_subscriptions')) + expect(email).to have_body_text(account_path) + end + + scenario 'Do not send email about own budget investments comments', :js do + user = create(:user, email_on_comment: true) + investment = create(:budget_investment, author: user, budget: create(:budget)) + comment_on(investment, user) + + expect { open_last_email }.to raise_error 'No email has been sent!' + end + + scenario 'Do not send email about budget investment comment unless set in preferences', :js do + user = create(:user, email_on_comment: false) + investment = create(:budget_investment, author: user, budget: create(:budget)) + comment_on(investment) + + expect { open_last_email }.to raise_error 'No email has been sent!' + end + end + context 'Comment replies' do scenario "Send email on comment reply", :js do user = create(:user, email_on_comment_reply: true) diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index c1c7bfd2a..03325170a 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -77,10 +77,16 @@ module CommonActions user ||= create(:user) login_as(user) - commentable_path = commentable.is_a?(Proposal) ? proposal_path(commentable) : debate_path(commentable) + commentable_path = if commentable.is_a?(Proposal) + proposal_path(commentable) + elsif commentable.is_a?(Debate) + debate_path(commentable) + else + budget_investment_path(commentable, budget_id: commentable.budget_id) + end visit commentable_path - fill_in "comment-body-#{commentable.class.name.underscore}_#{commentable.id}", with: 'Have you thought about...?' + fill_in "comment-body-#{commentable.class.name.gsub(/::/, '_').downcase}_#{commentable.id}", with: 'Have you thought about...?' click_button 'Publish comment' expect(page).to have_content 'Have you thought about...?'