Fix hound warnings

This commit is contained in:
decabeza
2019-03-26 18:21:19 +01:00
parent eda6ea7f12
commit f47ec9d7dc
12 changed files with 203 additions and 145 deletions

View File

@@ -8,11 +8,12 @@ class Management::ProposalsController < Management::BaseController
before_action :load_categories, only: [:new, :edit] before_action :load_categories, only: [:new, :edit]
before_action :load_geozones, only: [:edit] before_action :load_geozones, only: [:edit]
has_orders %w{confidence_score hot_score created_at most_commented random}, only: [:index, :print] has_orders %w[confidence_score hot_score created_at most_commented random], only: [:index, :print]
has_orders %w{most_voted newest}, only: :show has_orders %w[most_voted newest], only: :show
def create def create
@resource = resource_model.new(strong_params.merge(author: current_user, published_at: Time.now)) @resource = resource_model.new(strong_params.merge(author: current_user,
published_at: Time.now))
if @resource.save if @resource.save
track_event track_event
@@ -51,8 +52,9 @@ class Management::ProposalsController < Management::BaseController
end end
def proposal_params def proposal_params
params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url, params.require(:proposal).permit(:title, :question, :summary, :description, :external_url,
:responsible_name, :tag_list, :terms_of_service, :geozone_id, :skip_map, :video_url, :responsible_name, :tag_list, :terms_of_service,
:geozone_id, :skip_map,
map_location_attributes: [:latitude, :longitude, :zoom]) map_location_attributes: [:latitude, :longitude, :zoom])
end end

View File

@@ -6,18 +6,20 @@ class PollsController < ApplicationController
load_and_authorize_resource load_and_authorize_resource
has_filters %w[current expired] has_filters %w[current expired]
has_orders %w{most_voted newest oldest}, only: :show has_orders %w[most_voted newest oldest], only: :show
::Poll::Answer # trigger autoload ::Poll::Answer # trigger autoload
def index def index
@polls = @polls.public_polls.send(@current_filter).includes(:geozones).sort_for_list.page(params[:page]) @polls = @polls.public_polls.send(@current_filter).includes(:geozones)
.sort_for_list.page(params[:page])
end end
def show def show
@questions = @poll.questions.for_render.sort_for_list @questions = @poll.questions.for_render.sort_for_list
@token = poll_voter_token(@poll, current_user) @token = poll_voter_token(@poll, current_user)
@poll_questions_answers = Poll::Question::Answer.where(question: @poll.questions).where.not(description: "").order(:given_order) @poll_questions_answers = Poll::Question::Answer.where(question: @poll.questions)
.where.not(description: "").order(:given_order)
@answers_by_question_id = {} @answers_by_question_id = {}
poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id)) poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id))

View File

@@ -1,8 +1,8 @@
class Dashboard::ExecutedAction < ActiveRecord::Base class Dashboard::ExecutedAction < ActiveRecord::Base
belongs_to :proposal belongs_to :proposal
belongs_to :action, class_name: 'Dashboard::Action' belongs_to :action, class_name: "Dashboard::Action"
has_many :administrator_tasks, as: :source, dependent: :destroy, class_name: 'Dashboard::AdministratorTask' has_many :administrator_tasks, as: :source, dependent: :destroy, class_name: "Dashboard::AdministratorTask"
validates :proposal, presence: true, uniqueness: { scope: :action } validates :proposal, presence: true, uniqueness: { scope: :action }
validates :action, presence: true validates :action, presence: true

View File

@@ -42,7 +42,7 @@ class Poll < ActiveRecord::Base
scope :sort_for_list, -> { order(:geozone_restricted, :starts_at, :name) } scope :sort_for_list, -> { order(:geozone_restricted, :starts_at, :name) }
def self.overlaping_with(poll) def self.overlaping_with(poll)
where('? < ends_at and ? >= starts_at', poll.starts_at.beginning_of_day, poll.ends_at.end_of_day) where("? < ends_at and ? >= starts_at", poll.starts_at.beginning_of_day, poll.ends_at.end_of_day)
.where.not(id: poll.id) .where.not(id: poll.id)
.where(related: poll.related) .where(related: poll.related)
end end
@@ -122,7 +122,7 @@ class Poll < ActiveRecord::Base
return unless starts_at.present? return unless starts_at.present?
return unless ends_at.present? return unless ends_at.present?
return unless Poll.overlaping_with(self).any? return unless Poll.overlaping_with(self).any?
errors.add(:starts_at, I18n.t('activerecord.errors.messages.another_poll_active')) errors.add(:starts_at, I18n.t("activerecord.errors.messages.another_poll_active"))
end end
def public? def public?

View File

@@ -27,14 +27,14 @@ class Proposal < ActiveRecord::Base
acts_as_paranoid column: :hidden_at acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases include ActsAsParanoidAliases
RETIRE_OPTIONS = %w(duplicated started unfeasible done other) RETIRE_OPTIONS = %w[duplicated started unfeasible done other]
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"
belongs_to :geozone belongs_to :geozone
has_many :comments, as: :commentable, dependent: :destroy has_many :comments, as: :commentable, dependent: :destroy
has_many :proposal_notifications, dependent: :destroy has_many :proposal_notifications, dependent: :destroy
has_many :dashboard_executed_actions, dependent: :destroy, class_name: 'Dashboard::ExecutedAction' has_many :dashboard_executed_actions, dependent: :destroy, class_name: "Dashboard::ExecutedAction"
has_many :dashboard_actions, through: :dashboard_executed_actions, class_name: 'Dashboard::Action' has_many :dashboard_actions, through: :dashboard_executed_actions, class_name: "Dashboard::Action"
has_many :polls, as: :related has_many :polls, as: :related
validates :title, presence: true validates :title, presence: true
@@ -228,7 +228,7 @@ class Proposal < ActiveRecord::Base
end end
def self.proposals_orders(user) def self.proposals_orders(user)
orders = %w{hot_score confidence_score created_at relevance archival_date} orders = %w[hot_score confidence_score created_at relevance archival_date]
orders << "recommendations" if Setting["feature.user.recommendations_on_proposals"] && user&.recommended_proposals orders << "recommendations" if Setting["feature.user.recommendations_on_proposals"] && user&.recommended_proposals
return orders return orders
end end

View File

@@ -1,6 +1,6 @@
require 'rails_helper' require "rails_helper"
feature 'Admin dashboard actions' do feature "Admin dashboard actions" do
let(:admin) { create :administrator } let(:admin) { create :administrator }
before do before do
@@ -16,99 +16,99 @@ feature 'Admin dashboard actions' do
"Save", "Save",
"Action created successfully" "Action created successfully"
context 'when visiting index' do context "when visiting index" do
context 'and no actions defined' do context "and no actions defined" do
before do before do
visit admin_dashboard_actions_path visit admin_dashboard_actions_path
end end
scenario 'shows that there are no records available' do scenario "shows that there are no records available" do
expect(page).to have_content('No records found') expect(page).to have_content("No records found")
end end
end end
context 'and actions defined' do context "and actions defined" do
let!(:action) { create :dashboard_action } let!(:action) { create :dashboard_action }
before do before do
visit admin_dashboard_actions_path visit admin_dashboard_actions_path
end end
scenario 'shows the action data' do scenario "shows the action data" do
expect(page).to have_content(action.title) expect(page).to have_content(action.title)
end end
end end
end end
context 'when creating an action' do context "when creating an action" do
let(:action) { build :dashboard_action } let(:action) { build :dashboard_action }
before do before do
visit admin_dashboard_actions_path visit admin_dashboard_actions_path
click_link 'Create resource or action' click_link "Create resource or action"
end end
scenario 'Creates a new action' do scenario "Creates a new action" do
fill_in 'dashboard_action_title', with: action.title fill_in "dashboard_action_title", with: action.title
fill_in 'dashboard_action_description', with: action.description fill_in "dashboard_action_description", with: action.description
click_button 'Save' click_button "Save"
expect(page).to have_content(action.title) expect(page).to have_content(action.title)
end end
scenario 'Renders create form in case data is invalid' do scenario "Renders create form in case data is invalid" do
click_button 'Save' click_button "Save"
expect(page).to have_content('errors prevented this Dashboard/Action from being saved.') expect(page).to have_content("errors prevented this Dashboard/Action from being saved.")
end end
end end
context 'when editing an action' do context "when editing an action" do
let!(:action) { create :dashboard_action } let!(:action) { create :dashboard_action }
let(:title) { Faker::Lorem.sentence } let(:title) { Faker::Lorem.sentence }
before do before do
visit admin_dashboard_actions_path visit admin_dashboard_actions_path
click_link 'Edit' click_link "Edit"
end end
scenario 'Updates the action' do scenario "Updates the action" do
fill_in 'dashboard_action_title', with: title fill_in "dashboard_action_title", with: title
click_button 'Save' click_button "Save"
expect(page).to have_content(title) expect(page).to have_content(title)
end end
scenario 'Renders edit form in case data is invalid' do scenario "Renders edit form in case data is invalid" do
fill_in 'dashboard_action_title', with: 'x' fill_in "dashboard_action_title", with: "x"
click_button 'Save' click_button "Save"
expect(page).to have_content('error prevented this Dashboard/Action from being saved.') expect(page).to have_content("error prevented this Dashboard/Action from being saved.")
end end
end end
context 'when destroying an action' do context "when destroying an action" do
let!(:action) { create :dashboard_action } let!(:action) { create :dashboard_action }
before do before do
visit admin_dashboard_actions_path visit admin_dashboard_actions_path
end end
scenario 'deletes the action', js: true do scenario "deletes the action", js: true do
page.accept_confirm do page.accept_confirm do
click_link 'Delete' click_link "Delete"
end end
expect(page).not_to have_content(action.title) expect(page).not_to have_content(action.title)
end end
scenario 'can not delete actions that have been executed', js: true do scenario "can not delete actions that have been executed", js: true do
_executed_action = create(:dashboard_executed_action, action: action) _executed_action = create(:dashboard_executed_action, action: action)
page.accept_confirm do page.accept_confirm do
click_link 'Delete' click_link "Delete"
end end
expect(page).to have_content('Cannot delete record because dependent executed actions exist') expect(page).to have_content("Cannot delete record because dependent executed actions exist")
end end
end end
end end

View File

@@ -1,6 +1,6 @@
require 'rails_helper' require "rails_helper"
feature 'Polls' do feature "Polls" do
let!(:proposal) { create(:proposal, :draft) } let!(:proposal) { create(:proposal, :draft) }
before do before do
@@ -8,99 +8,99 @@ feature 'Polls' do
visit proposal_dashboard_path(proposal) visit proposal_dashboard_path(proposal)
end end
scenario 'Has a link to polls feature' do scenario "Has a link to polls feature" do
expect(page).to have_link('Polls') expect(page).to have_link("Polls")
end end
scenario 'Create a poll', :js do scenario "Create a poll", :js do
click_link 'Polls' click_link "Polls"
click_link 'Create poll' click_link "Create poll"
start_date = 1.week.from_now start_date = 1.week.from_now
end_date = 2.weeks.from_now end_date = 2.weeks.from_now
fill_in "poll_name", with: 'Upcoming poll' fill_in "poll_name", with: "Proposal poll"
fill_in 'poll_starts_at', with: start_date.strftime('%d/%m/%Y') fill_in "poll_starts_at", with: start_date.strftime("%d/%m/%Y")
fill_in 'poll_ends_at', with: end_date.strftime('%d/%m/%Y') fill_in "poll_ends_at", with: end_date.strftime("%d/%m/%Y")
fill_in 'poll_description', with: "Upcomming poll's description. This poll..." fill_in "poll_description", with: "Proposal's poll description. This poll..."
expect(page).not_to have_css('#poll_results_enabled') expect(page).not_to have_css("#poll_results_enabled")
expect(page).not_to have_css('#poll_stats_enabled') expect(page).not_to have_css("#poll_stats_enabled")
click_link 'Add question' click_link "Add question"
fill_in 'Question', with: 'First question' fill_in "Question", with: "First question"
click_link 'Add answer' click_link "Add answer"
fill_in 'Title', with: 'First answer'
click_button 'Create poll' fill_in "Answer", with: "First answer"
expect(page).to have_content 'Poll created successfully' click_button "Create poll"
expect(page).to have_content 'Upcoming poll' expect(page).to have_content "Poll created successfully"
expect(page).to have_content "Proposal poll"
expect(page).to have_content I18n.l(start_date.to_date) expect(page).to have_content I18n.l(start_date.to_date)
end end
scenario 'Create a poll redirects back to form when invalid data', js: true do scenario "Create a poll redirects back to form when invalid data", js: true do
click_link 'Polls' click_link "Polls"
click_link 'Create poll' click_link "Create poll"
click_button 'Create poll' click_button "Create poll"
expect(page).to have_content('New poll') expect(page).to have_content("New poll")
end end
scenario 'Edit poll is allowed for upcoming polls' do
poll = create(:poll, :incoming, related: proposal) poll = create(:poll, :incoming, related: proposal)
scenario "Edit poll is allowed for upcoming polls" do
visit proposal_dashboard_polls_path(proposal) visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do within "div#poll_#{poll.id}" do
expect(page).to have_content('Edit survey') expect(page).to have_content("Edit survey")
click_link 'Edit survey' click_link "Edit survey"
end end
click_button 'Update poll' click_button "Update poll"
expect(page).to have_content 'Poll updated successfully' expect(page).to have_content "Poll updated successfully"
end end
scenario 'Edit poll redirects back when invalid data', js: true do
poll = create(:poll, :incoming, related: proposal) poll = create(:poll, :incoming, related: proposal)
scenario "Edit poll redirects back when invalid data", js: true do
visit proposal_dashboard_polls_path(proposal) visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do within "div#poll_#{poll.id}" do
expect(page).to have_content('Edit survey') expect(page).to have_content("Edit survey")
click_link 'Edit survey' click_link "Edit survey"
end end
fill_in "poll_name", with: '' fill_in "poll_name", with: ""
click_button 'Update poll' click_button "Update poll"
expect(page).to have_content('Edit poll') expect(page).to have_content("Edit poll")
end end
scenario 'Edit poll is not allowed for current polls' do scenario "Edit poll is not allowed for current polls" do
poll = create(:poll, :current, related: proposal) poll = create(:poll, :current, related: proposal)
visit proposal_dashboard_polls_path(proposal) visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do within "div#poll_#{poll.id}" do
expect(page).not_to have_content('Edit survey') expect(page).not_to have_content("Edit survey")
end end
end end
scenario 'Edit poll is not allowed for expired polls' do scenario "Edit poll is not allowed for expired polls" do
poll = create(:poll, :expired, related: proposal) poll = create(:poll, :expired, related: proposal)
visit proposal_dashboard_polls_path(proposal) visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do within "div#poll_#{poll.id}" do
expect(page).not_to have_content('Edit survey') expect(page).not_to have_content("Edit survey")
end end
end end
@@ -153,52 +153,52 @@ feature 'Polls' do
end end
end end
scenario 'View results not available for upcoming polls' do
poll = create(:poll, :incoming, related: proposal) poll = create(:poll, :incoming, related: proposal)
scenario "View results not available for upcoming polls" do
visit proposal_dashboard_polls_path(proposal) visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do within "div#poll_#{poll.id}" do
expect(page).not_to have_content('View results') expect(page).not_to have_content("View results")
end end
end end
scenario 'View results available for current polls' do scenario "View results available for current polls" do
poll = create(:poll, :current, related: proposal) poll = create(:poll, :current, related: proposal)
visit proposal_dashboard_polls_path(proposal) visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do within "div#poll_#{poll.id}" do
expect(page).to have_content('View results') expect(page).to have_content("View results")
end end
end end
scenario 'View results available for expired polls' do scenario "View results available for expired polls" do
poll = create(:poll, :expired, related: proposal) poll = create(:poll, :expired, related: proposal)
visit proposal_dashboard_polls_path(proposal) visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do within "div#poll_#{poll.id}" do
expect(page).to have_content('View results') expect(page).to have_content("View results")
end end
end end
scenario 'View results redirects to results in public zone', js: true do scenario "View results redirects to results in public zone", js: true do
poll = create(:poll, :expired, related: proposal) poll = create(:poll, :expired, related: proposal)
visit proposal_dashboard_polls_path(proposal) visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do within "div#poll_#{poll.id}" do
click_link 'View results' click_link "View results"
end end
page.driver.browser.switch_to.window page.driver.browser.window_handles.last do page.driver.browser.switch_to.window page.driver.browser.window_handles.last do
expect(page.current_path).to eq(results_poll_path(poll)) expect(page).to have_current_path(results_poll_path(poll))
end end
end end
scenario 'Poll card' do scenario "Poll card" do
poll = create(:poll, :expired, related: proposal) poll = create(:poll, :expired, related: proposal)
visit proposal_dashboard_polls_path(proposal) visit proposal_dashboard_polls_path(proposal)

View File

@@ -1,16 +1,16 @@
require 'rails_helper' require "rails_helper"
describe Admin::ProposalDashboardActionsHelper do describe Admin::ProposalDashboardActionsHelper do
describe 'active_human_readable' do describe "active_human_readable" do
context 'when active is true' do context "when active is true" do
it 'returns label for active state' do it "returns label for active state" do
expect(active_human_readable(true)).to eq(t('admin.dashboard.actions.index.active')) expect(active_human_readable(true)).to eq(t("admin.dashboard.actions.index.active"))
end end
end end
context 'when active is false' do context "when active is false" do
it 'returns label for inactive state' do it "returns label for inactive state" do
expect(active_human_readable(false)).to eq(t('admin.dashboard.actions.index.inactive')) expect(active_human_readable(false)).to eq(t("admin.dashboard.actions.index.inactive"))
end end
end end
end end

View File

@@ -34,18 +34,25 @@ describe Dashboard::Mailer do
expect(email).to deliver_from("CONSUL <noreply@consul.dev>") expect(email).to deliver_from("CONSUL <noreply@consul.dev>")
expect(email).to deliver_to(proposal.author) expect(email).to deliver_to(proposal.author)
expect(email).to have_subject("More news about your citizen proposal in Decide Madrid") expect(email).to have_subject("More news about your citizen proposal")
expect(email).to have_body_text("Hello #{proposal.author.name},") expect(email).to have_body_text("Hello #{proposal.author.name},")
expect(email).to have_body_text("As you know, on the #{proposal.created_at.day} day of the #{proposal.created_at.strftime("%B")} you created the proposal in draft mode #{proposal.title} on the Decide Madrid platform.") expect(email).to have_body_text("As you know, on the #{proposal.created_at.day} day of "\
"the #{proposal.created_at.strftime("%B")} you created "\
"the proposal in draft mode #{proposal.title}.")
expect(email).to have_body_text("Whenever you want you can publish on this link:") expect(email).to have_body_text("Whenever you want you can publish on this link:")
expect(email).to have_body_text("Seize this moment! Learn, add other people with the same interests and prepare the diffusion that you will need when you publish your proposal definitively.") expect(email).to have_body_text("Seize this moment! Learn, add other people with the same "\
expect(email).to have_body_text("And to accompany you in this challenge, here are the news...") "interests and prepare the diffusion that you will need "\
"when you publish your proposal definitively.")
expect(email).to have_body_text("And to accompany you in this challenge, "\
"here are the news...")
expect(email).to have_body_text("NEW UNLOCKED RESOURCE") expect(email).to have_body_text("NEW UNLOCKED RESOURCE")
expect(email).to have_body_text("#{resource.title}") expect(email).to have_body_text("#{resource.title}")
expect(email).to have_body_text("Take a look at this NEW recommended ACTION:") expect(email).to have_body_text("Take a look at this NEW recommended ACTION:")
expect(email).to have_body_text("#{action.title}") expect(email).to have_body_text("#{action.title}")
expect(email).to have_body_text("#{action.description}") expect(email).to have_body_text("#{action.description}")
expect(email).to have_body_text("As always, enter the Proposals Panel and we will tell you in detail how to use these resources and how to get the most out of it.") expect(email).to have_body_text("As always, enter the Proposals Panel and we will tell "\
"you in detail how to use these resources and how to get "\
"the most out of it.")
expect(email).to have_body_text("Go ahead, discover them!") expect(email).to have_body_text("Go ahead, discover them!")
end end
end end
@@ -60,20 +67,30 @@ describe Dashboard::Mailer do
expect(email).to deliver_from("CONSUL <noreply@consul.dev>") expect(email).to deliver_from("CONSUL <noreply@consul.dev>")
expect(email).to deliver_to(proposal.author) expect(email).to deliver_to(proposal.author)
expect(email).to have_subject("More news about your citizen proposal in Decide Madrid") expect(email).to have_subject("More news about your citizen proposal")
expect(email).to have_body_text("Hello #{proposal.author.name},") expect(email).to have_body_text("Hello #{proposal.author.name},")
expect(email).to have_body_text("As you know, on the #{proposal.published_at.day} day of the #{proposal.published_at.strftime("%B")} you published the proposal #{proposal.title} on the Decide Madrid platform.") expect(email).to have_body_text("As you know, on the #{proposal.published_at.day} day of "\
expect(email).to have_body_text("And so, you have a new resource available to help you keep moving forward.") "the #{proposal.published_at.strftime("%B")} you "\
"published the proposal #{proposal.title}.")
expect(email).to have_body_text("And so, you have a new resource available to help "\
"you keep moving forward.")
expect(email).to have_body_text("NEW UNLOCKED RESOURCE") expect(email).to have_body_text("NEW UNLOCKED RESOURCE")
expect(email).to have_body_text("#{resource.title}") expect(email).to have_body_text("#{resource.title}")
limit_to_archive_proposal = proposal.created_at.to_date + Setting["months_to_archive_proposals"].to_i.months months_to_archive_proposals = Setting["months_to_archive_proposals"].to_i.months
limit_to_archive_proposal = proposal.created_at.to_date + months_to_archive_proposals
days_count = (limit_to_archive_proposal - Date.today).to_i days_count = (limit_to_archive_proposal - Date.today).to_i
expect(email).to have_body_text("You are missing #{days_count} days before your proposal gets the #{Setting["votes_for_proposal_success"]} supports and goes to referendum. Cheer up and keep spreading. Are you short of ideas?")
expect(email).to have_body_text("You are missing #{days_count} days before your proposal "\
"gets the #{Setting["votes_for_proposal_success"]} "\
"supports and goes to referendum. Cheer up and keep "\
"spreading. Are you short of ideas?")
expect(email).to have_body_text("NEW RECOMMENDED DIFFUSION ACTION") expect(email).to have_body_text("NEW RECOMMENDED DIFFUSION ACTION")
expect(email).to have_body_text("#{action.title}") expect(email).to have_body_text("#{action.title}")
expect(email).to have_body_text("#{action.description}") expect(email).to have_body_text("#{action.description}")
expect(email).to have_body_text("As always, enter the Proposals Panel and we will tell you in detail how to use these resources and how to get the most out of it.") expect(email).to have_body_text("As always, enter the Proposals Panel and we will tell "\
"you in detail how to use these resources and how to get "\
"the most out of it.")
expect(email).to have_body_text("Go ahead, discover them!") expect(email).to have_body_text("Go ahead, discover them!")
end end
end end
@@ -96,19 +113,39 @@ describe Dashboard::Mailer do
expect(email).to deliver_from("CONSUL <noreply@consul.dev>") expect(email).to deliver_from("CONSUL <noreply@consul.dev>")
expect(email).to deliver_to(proposal.author) expect(email).to deliver_to(proposal.author)
expect(email).to have_subject("Your draft citizen proposal in Decide Madrid is created") expect(email).to have_subject("Your draft citizen proposal is created")
expect(email).to have_body_text("Hi #{proposal.author.name}!") expect(email).to have_body_text("Hi #{proposal.author.name}!")
expect(email).to have_body_text("Your #{proposal.title} proposal has been successfully created.") expect(email).to have_body_text("Your #{proposal.title} proposal has been "\
expect(email).to have_body_text("Take advantage that your proposal is not public yet and get ready to contact a lot of people.") "successfully created.")
expect(email).to have_body_text(I18n.t("mailers.new_actions_notification_on_create.text_2", link: proposal_dashboard_url(proposal)).html_safe) expect(email).to have_body_text("Take advantage that your proposal is not public yet and "\
expect(email).to have_body_text("We know that creating a proposal with a hook and getting the necessary support can seem complicated. But dont worry because we are going to help you!") "get ready to contact a lot of people.")
expect(email).to have_body_text("You have a tool that will be your new best ally: The Citizen Proposals panel.") expect(email).to have_body_text(I18n.t("mailers.new_actions_notification_on_create.text_2",
expect(email).to have_body_text("Enter every day in the panel of your proposal to use the tips and resources that we will share with you.") link: proposal_dashboard_url(proposal)).html_safe)
expect(email).to have_body_text("These tips, actions and resources will give you ideas and also practical solutions to get more support and a wider community. Dont forget them!") expect(email).to have_body_text("We know that creating a proposal with a hook and getting "\
expect(email).to have_body_text("As you gain more support, you will unlock new and better resources. At the moment, you have an e-mail template to send massively to all your contacts, a poster to print, among other features and rewards that you will discover. Dont stop adding support and we will not stop rewarding and helping you!") "the necessary support can seem complicated. But dont "\
expect(email).to have_body_text("You have #{Setting['months_to_archive_proposals']} months since you publish the proposal to get #{Setting['votes_for_proposal_success']} support and your proposal can become a reality. But the first days are the most important. It is a challenge. Get ready!") "worry because we are going to help you!")
expect(email).to have_body_text("You have a tool that will be your new best ally: "\
"The Citizen Proposals panel.")
expect(email).to have_body_text("Enter every day in the panel of your proposal to use the "\
"tips and resources that we will share with you.")
expect(email).to have_body_text("These tips, actions and resources will give you ideas and "\
"also practical solutions to get more support and a wider "\
"community. Dont forget them!")
expect(email).to have_body_text("As you gain more support, you will unlock new and better "\
"resources. At the moment, you have an e-mail template to "\
"send massively to all your contacts, a poster to print, "\
"among other features and rewards that you will discover. "\
"Dont stop adding support and we will not stop rewarding "\
"and helping you!")
expect(email).to have_body_text("You have #{Setting['months_to_archive_proposals']} months "\
"since you publish the proposal to get "\
"#{Setting['votes_for_proposal_success']} support and your "\
"proposal can become a reality. But the first days are the "\
"most important. It is a challenge. Get ready!")
expect(email).to have_body_text("And for you to start with all the motivation,") expect(email).to have_body_text("And for you to start with all the motivation,")
expect(email).to have_body_text("here you have several resources and a whole list of tips that will come to you every day to prepare the broadcast!") expect(email).to have_body_text("here you have several resources and a whole list of "\
"tips that will come to you every day to prepare the "\
"broadcast!")
expect(email).to have_body_text("Go ahead, discover them!") expect(email).to have_body_text("Go ahead, discover them!")
end end
end end
@@ -120,8 +157,10 @@ describe Dashboard::Mailer do
end end
let!(:proposal) { build(:proposal, :draft) } let!(:proposal) { build(:proposal, :draft) }
let!(:resource) { create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: true) } let!(:resource) { create(:dashboard_action, :resource, :active, day_offset: 0,
let!(:proposed_action) { create(:dashboard_action, :proposed_action, :active, day_offset: 0, published_proposal: true) } published_proposal: true) }
let!(:proposed_action) { create(:dashboard_action, :proposed_action, :active, day_offset: 0,
published_proposal: true) }
it "sends emails when detect new actions when publish a proposal" do it "sends emails when detect new actions when publish a proposal" do
proposal.save proposal.save
@@ -131,19 +170,34 @@ describe Dashboard::Mailer do
expect(email).to deliver_from("CONSUL <noreply@consul.dev>") expect(email).to deliver_from("CONSUL <noreply@consul.dev>")
expect(email).to deliver_to(proposal.author) expect(email).to deliver_to(proposal.author)
expect(email).to have_subject("Your citizen proposal is already published Dont stop spreading!") expect(email).to have_subject("Your citizen proposal is already "\
expect(email).to have_body_text("Congratulations #{proposal.author.name}! Your proposal #{proposal.title} has been created successfully.") "published Dont stop spreading!")
expect(email).to have_body_text("Congratulations #{proposal.author.name}! Your proposal "\
"#{proposal.title} has been created successfully.")
expect(email).to have_body_text("And now, go for your first 100 supports!") expect(email).to have_body_text("And now, go for your first 100 supports!")
expect(email).to have_body_text("Why 100?") expect(email).to have_body_text("Why 100?")
expect(email).to have_body_text("Our experience tells us that the first day is fundamental. Because in addition to having the energy to launch something new, being a newly published proposal, you will have the important visibility of being among the new proposals highlighted in Decide Madrid.") expect(email).to have_body_text("Our experience tells us that the first day is fundamental. "\
expect(email).to have_body_text("Get 100 supports on the first day, and you will have a first community to back you up.") "Because in addition to having the energy to launch "\
expect(email).to have_body_text("That is why we challenge you to get it, but not without a lot of help!") "something new, being a newly published proposal, you will "\
expect(email).to have_body_text("Remember that in your Proposal Panel you have new resources available and recommendations for dissemination actions.") "have the important visibility of being among the new "\
expect(email).to have_body_text("Come in every day to see your progress and use the tips and resources we will share with you. They are ideas and also practical solutions to get the support you need.") "proposals highlighted.")
expect(email).to have_body_text("As you get more support, you will unlock new and better resources. Do not stop adding support and we will not stop rewarding and helping you!") expect(email).to have_body_text("Get 100 supports on the first day, and you will have "\
"a first community to back you up.")
expect(email).to have_body_text("That is why we challenge you to get it, but not without "\
"a lot of help!")
expect(email).to have_body_text("Remember that in your Proposal Panel you have new "\
"resources available and recommendations for "\
"dissemination actions.")
expect(email).to have_body_text("Come in every day to see your progress and use the tips "\
"and resources we will share with you. They are ideas and "\
"also practical solutions to get the support you need.")
expect(email).to have_body_text("As you get more support, you will unlock new and better "\
"resources. Do not stop adding support and we will not stop "\
"rewarding and helping you!")
expect(email).to have_body_text("And for you to start at full speed...") expect(email).to have_body_text("And for you to start at full speed...")
expect(email).to have_body_text("Here is a great resource at your disposal!") expect(email).to have_body_text("Here is a great resource at your disposal!")
expect(email).to have_body_text("You will also find this new recommended dissemination action...") expect(email).to have_body_text("You will also find this new recommended dissemination "\
"action...")
expect(email).to have_body_text("You sure have more resources to use!") expect(email).to have_body_text("You sure have more resources to use!")
expect(email).to have_body_text("Go ahead, discover them!") expect(email).to have_body_text("Go ahead, discover them!")
end end

View File

@@ -137,7 +137,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
visit send(path, arguments) visit send(path, arguments)
documentable_attach_new_file( documentable_attach_new_file(
Rails.root.join("spec/fixtures/files/logo_header.png"), Rails.root.join("spec/fixtures/files/logo_header.gif"),
false false
) )
@@ -158,7 +158,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
visit send(path, arguments) visit send(path, arguments)
documentable_attach_new_file( documentable_attach_new_file(
Rails.root.join("spec/fixtures/files/logo_header.png"), Rails.root.join("spec/fixtures/files/logo_header.gif"),
false false
) )
@@ -239,7 +239,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end end
login_as user_to_login login_as user_to_login
visit send(path, arguments) visit send(path, arguments)
FILENAMES ||= %w(clippy empty logo).freeze FILENAMES ||= %w[clippy empty logo].freeze
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name