From 4c110e8100d232d0b9ca44d65caf64f06df93a2a Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Mon, 13 Nov 2017 08:46:56 -0400 Subject: [PATCH] Add email specs for Topic --- app/helpers/mailer_helper.rb | 3 ++- config/locales/en/activerecord.yml | 5 ++++- config/locales/es/activerecord.yml | 3 +++ spec/features/emails_spec.rb | 35 ++++++++++++++++++++++++++++++ spec/support/common_actions.rb | 2 ++ 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/app/helpers/mailer_helper.rb b/app/helpers/mailer_helper.rb index e541eebb6..e0ab9c71b 100644 --- a/app/helpers/mailer_helper.rb +++ b/app/helpers/mailer_helper.rb @@ -3,7 +3,8 @@ module MailerHelper def commentable_url(commentable) return debate_url(commentable) if commentable.is_a?(Debate) return proposal_url(commentable) if commentable.is_a?(Proposal) + return community_topic_url(commentable.community_id, commentable) if commentable.is_a?(Topic) return budget_investment_url(commentable.budget_id, commentable) if commentable.is_a?(Budget::Investment) end -end \ No newline at end of file +end diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index bceaf5106..89e46b1a8 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -88,6 +88,9 @@ en: images: one: "Image" other: "Images" + topic: + one: "Topic" + other: "Topics" attributes: budget: name: "Name" @@ -281,4 +284,4 @@ en: attributes: image: image_width: "Width must be %{required_width}px" - image_height: "Height must be %{required_height}px" \ No newline at end of file + image_height: "Height must be %{required_height}px" diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index d0d3294cd..d08b1c7ff 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -88,6 +88,9 @@ es: images: one: "Imagen" other: "Imágenes" + topic: + one: "Tema" + other: "Temas" attributes: budget: name: "Nombre" diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index e04de4fc0..769e6db38 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -115,6 +115,41 @@ feature 'Emails' do end end + context 'Topic comments' do + before(:each) do + @proposal = create(:proposal) + end + + scenario 'Send email on topic comment', :js do + user = create(:user, email_on_comment: true) + topic = create(:topic, author: user, community: @proposal.community) + comment_on(topic) + + email = open_last_email + expect(email).to have_subject('Someone has commented on your topic') + expect(email).to deliver_to(topic.author) + expect(email).to have_body_text(community_topic_path(topic, community_id: topic.community_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 topic comments', :js do + user = create(:user, email_on_comment: true) + topic = create(:topic, author: user, community: @proposal.community) + comment_on(topic, user) + + expect { open_last_email }.to raise_error 'No email has been sent!' + end + + scenario 'Do not send email about topic comment unless set in preferences', :js do + user = create(:user, email_on_comment: false) + topic = create(:topic, author: user, community: @proposal.community) + comment_on(topic) + + 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 03325170a..438b6c163 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -81,6 +81,8 @@ module CommonActions proposal_path(commentable) elsif commentable.is_a?(Debate) debate_path(commentable) + elsif commentable.is_a?(Topic) + community_topic_path(commentable, community_id: commentable.community_id) else budget_investment_path(commentable, budget_id: commentable.budget_id) end