Add and apply Style/BlockDelimiters rubocop rule

We were already using it most of the time, but there were a few places
were we used brackets for multiline blocks.
This commit is contained in:
Javi Martín
2019-09-30 13:08:24 +02:00
parent d42b9ff4a5
commit 70a07c095f
38 changed files with 304 additions and 257 deletions

View File

@@ -41,6 +41,9 @@ Layout/EmptyLines:
Layout/EndOfLine: Layout/EndOfLine:
EnforcedStyle: lf EnforcedStyle: lf
Layout/MultilineBlockLayout:
Enabled: true
Layout/SpaceAfterColon: Layout/SpaceAfterColon:
Enabled: true Enabled: true
@@ -229,6 +232,9 @@ RSpec/ScatteredSetup:
RSpec/VoidExpect: RSpec/VoidExpect:
Enabled: true Enabled: true
Style/BlockDelimiters:
Enabled: true
Style/PercentLiteralDelimiters: Style/PercentLiteralDelimiters:
Enabled: true Enabled: true

View File

@@ -7,10 +7,13 @@ class Admin::CommentsController < Admin::BaseController
respond_to do |format| respond_to do |format|
format.html format.html
format.csv { send_data to_csv(Comment.sort_by_newest, Comment),
format.csv do
send_data to_csv(Comment.sort_by_newest, Comment),
type: "text/csv", type: "text/csv",
disposition: "attachment", disposition: "attachment",
filename: "comments.csv" } filename: "comments.csv"
end
end end
end end

View File

@@ -12,10 +12,12 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll
.page(params[:page]) .page(params[:page])
respond_to do |format| respond_to do |format|
format.html format.html
format.csv { send_data to_csv(process_for_download, Legislation::Process), format.csv do
send_data to_csv(process_for_download, Legislation::Process),
type: "text/csv", type: "text/csv",
disposition: "attachment", disposition: "attachment",
filename: "legislation_processes.csv" } filename: "legislation_processes.csv"
end
end end
end end

View File

@@ -15,12 +15,12 @@ module Budgets
respond_to do |format| respond_to do |format|
format.html format.html
format.csv { send_data to_csv(downloadables, format.csv do
Budget::Investment, send_data to_csv(downloadables, Budget::Investment, 1),
1),
type: "text/csv", type: "text/csv",
disposition: "attachment", disposition: "attachment",
filename: "budget_investment_milestones.csv" } filename: "budget_investment_milestones.csv"
end
end end
end end

View File

@@ -13,10 +13,12 @@ module Budgets
respond_to do |format| respond_to do |format|
format.html format.html
format.csv { send_data to_csv(@investments.compatible, Budget::Investment), format.csv do
send_data to_csv(@investments.compatible, Budget::Investment),
type: "text/csv", type: "text/csv",
disposition: "attachment", disposition: "attachment",
filename: "budget_investment_results.csv" } filename: "budget_investment_results.csv"
end
end end
end end

View File

@@ -28,10 +28,12 @@ module CommentableActions
respond_to do |format| respond_to do |format|
format.html format.html
format.csv { send_data to_csv(resources_csv, resource_model), format.csv do
send_data to_csv(resources_csv, resource_model),
type: "text/csv", type: "text/csv",
disposition: "attachment", disposition: "attachment",
filename: "#{get_resource(resource_model)}.csv" } filename: "#{get_resource(resource_model)}.csv"
end
end end
end end

View File

@@ -22,17 +22,17 @@ class Dashboard::AchievementsController < Dashboard::BaseController
def groups def groups
if params[:group_by] == "week" if params[:group_by] == "week"
return executed_proposed_actions.group_by { executed_proposed_actions.group_by do |v|
|v| "#{v.executed_at.to_date.cweek}/#{v.executed_at.to_date.year}" } "#{v.executed_at.to_date.cweek}/#{v.executed_at.to_date.year}"
end end
elsif params[:group_by] == "month"
if params[:group_by] == "month" executed_proposed_actions.group_by do |v|
return executed_proposed_actions.group_by { "#{v.executed_at.to_date.year}-#{v.executed_at.to_date.month}"
|v| "#{v.executed_at.to_date.year}-#{v.executed_at.to_date.month}" }
end end
else
executed_proposed_actions.group_by { |a| a.executed_at.to_date } executed_proposed_actions.group_by { |a| a.executed_at.to_date }
end end
end
def executed_proposed_actions def executed_proposed_actions
@executed_proposed_actions ||= @executed_proposed_actions ||=

View File

@@ -25,8 +25,11 @@ class Dashboard::PollsController < Dashboard::BaseController
def update def update
respond_to do |format| respond_to do |format|
if poll.update(poll_params) if poll.update(poll_params)
format.html { redirect_to proposal_dashboard_polls_path(proposal), format.html do
notice: t("flash.actions.update.poll") } redirect_to proposal_dashboard_polls_path(proposal),
notice: t("flash.actions.update.poll")
end
format.json { head :no_content } format.json { head :no_content }
else else
format.html { render :edit } format.html { render :edit }

View File

@@ -17,10 +17,12 @@ class Legislation::ProcessesController < Legislation::BaseController
respond_to do |format| respond_to do |format|
format.html format.html
format.csv { send_data to_csv(process_for_download, Legislation::Process), format.csv do
send_data to_csv(process_for_download, Legislation::Process),
type: "text/csv", type: "text/csv",
disposition: "attachment", disposition: "attachment",
filename: "legislation_processes.csv" } filename: "legislation_processes.csv"
end
end end
end end

View File

@@ -20,11 +20,9 @@ class RemoteTranslationsController < ApplicationController
def set_remote_translations def set_remote_translations
remote_translations = remote_translations_params["remote_translations"] remote_translations = remote_translations_params["remote_translations"]
decoded_remote_translations = ActiveSupport::JSON.decode(remote_translations) decoded_remote_translations = ActiveSupport::JSON.decode(remote_translations)
@remote_translations = decoded_remote_translations.map { |remote_translation| @remote_translations = decoded_remote_translations.map do |remote_translation|
remote_translation.slice("remote_translatable_id", remote_translation.slice("remote_translatable_id", "remote_translatable_type", "locale")
"remote_translatable_type", end
"locale")
}
end end
def translations_enqueued?(remote_translation) def translations_enqueued?(remote_translation)

View File

@@ -75,8 +75,8 @@ class Poll::Question < ApplicationRecord
end end
def answers_with_read_more? def answers_with_read_more?
question_answers.visibles.any? do |answer| answer.description.present? || answer.images.any? || question_answers.visibles.any? do |answer|
answer.documents.present? || answer.videos.present? answer.description.present? || answer.images.any? || answer.documents.present? || answer.videos.present?
end end
end end

View File

@@ -3,9 +3,10 @@ require "rails_helper"
describe CommentsController do describe CommentsController do
describe "POST create" do describe "POST create" do
let(:legal_process) do
let(:legal_process) { create(:legislation_process, debate_start_date: Date.current - 3.days, create(:legislation_process, debate_start_date: Date.current - 3.days,
debate_end_date: Date.current + 2.days) } debate_end_date: Date.current + 2.days)
end
let(:question) { create(:legislation_question, process: legal_process, title: "Question 1") } let(:question) { create(:legislation_question, process: legal_process, title: "Question 1") }
let(:user) { create(:user, :level_two) } let(:user) { create(:user, :level_two) }
let(:unverified_user) { create(:user) } let(:unverified_user) { create(:user) }

View File

@@ -4,16 +4,17 @@ describe Legislation::AnnotationsController do
describe "POST create" do describe "POST create" do
let(:legal_process) { create(:legislation_process, let(:legal_process) do
allegations_start_date: Date.current - 3.days, create(:legislation_process, allegations_start_date: Date.current - 3.days,
allegations_end_date: Date.current + 2.days) } allegations_end_date: Date.current + 2.days)
let(:draft_version) { create(:legislation_draft_version, :published, end
process: legal_process, let(:draft_version) do
title: "Version 1") } create(:legislation_draft_version, :published, process: legal_process, title: "Version 1")
let(:final_version) { create(:legislation_draft_version, :published, end
:final_version, let(:final_version) do
process: legal_process, create(:legislation_draft_version, :published, :final_version,
title: "Final version") } process: legal_process, title: "Final version")
end
let(:user) { create(:user, :level_two) } let(:user) { create(:user, :level_two) }
it "creates an ahoy event" do it "creates an ahoy event" do

View File

@@ -4,8 +4,10 @@ describe Legislation::AnswersController do
describe "POST create" do describe "POST create" do
let(:legal_process) { create(:legislation_process, debate_start_date: Date.current - 3.days, let(:legal_process) do
debate_end_date: Date.current + 2.days) } create(:legislation_process, debate_start_date: Date.current - 3.days,
debate_end_date: Date.current + 2.days)
end
let(:question) { create(:legislation_question, process: legal_process, title: "Question 1") } let(:question) { create(:legislation_question, process: legal_process, title: "Question 1") }
let(:question_option) { create(:legislation_question_option, question: question, value: "Yes") } let(:question_option) { create(:legislation_question_option, question: question, value: "Yes") }
let(:user) { create(:user, :level_two) } let(:user) { create(:user, :level_two) }

View File

@@ -6,10 +6,10 @@ FactoryBot.define do
postal_code { "28002" } postal_code { "28002" }
end end
factory :local_census_records_import, class: "LocalCensusRecords::Import" do factory :local_census_records_import, class: "LocalCensusRecords::Import" do
file { file do
path = %w[spec fixtures files local_census_records import valid.csv] path = %w[spec fixtures files local_census_records import valid.csv]
Rack::Test::UploadedFile.new(Rails.root.join(*path)) Rack::Test::UploadedFile.new(Rails.root.join(*path))
} end
end end
sequence(:document_number) { |n| "#{n.to_s.rjust(8, "0")}X" } sequence(:document_number) { |n| "#{n.to_s.rjust(8, "0")}X" }

View File

@@ -51,13 +51,13 @@ describe "Admin administrators" do
end end
context "Search" do context "Search" do
let!(:administrator1) do
create(:administrator, user: create(:user, username: "Bernard Sumner", email: "bernard@sumner.com"))
end
let!(:administrator1) { create(:administrator, user: create(:user, let!(:administrator2) do
username: "Bernard Sumner", create(:administrator, user: create(:user, username: "Tony Soprano", email: "tony@soprano.com"))
email: "bernard@sumner.com")) } end
let!(:administrator2) { create(:administrator, user: create(:user,
username: "Tony Soprano",
email: "tony@soprano.com")) }
before do before do
visit admin_administrators_path visit admin_administrators_path
@@ -102,9 +102,9 @@ describe "Admin administrators" do
end end
context "Edit" do context "Edit" do
let!(:administrator1) { create(:administrator, user: create(:user, let!(:administrator1) do
username: "Bernard Sumner", create(:administrator, user: create(:user, username: "Bernard Sumner", email: "bernard@sumner.com"))
email: "bernard@sumner.com")) } end
scenario "admin can edit administrator1" do scenario "admin can edit administrator1" do
visit(edit_admin_administrator_path(administrator1)) visit(edit_admin_administrator_path(administrator1))

View File

@@ -224,14 +224,16 @@ describe "Admin budget headings" do
end end
context "Update" do context "Update" do
let(:heading) { create(:budget_heading, let(:heading) do
create(:budget_heading,
group: group, group: group,
name: "All City", name: "All City",
price: 1000, price: 1000,
population: 10000, population: 10000,
longitude: 20.50, longitude: 20.50,
latitude: -10.50, latitude: -10.50,
allow_custom_content: true) } allow_custom_content: true)
end
scenario "Updates group" do scenario "Updates group" do
visit edit_admin_budget_group_heading_path(budget, group, heading) visit edit_admin_budget_group_heading_path(budget, group, heading)

View File

@@ -1360,19 +1360,29 @@ describe "Admin budget investments" do
end end
context "Selecting" do context "Selecting" do
let!(:unfeasible_bi) do
create(:budget_investment, :unfeasible, budget: budget, title: "Unfeasible project")
end
let!(:unfeasible_bi) { create(:budget_investment, :unfeasible, budget: budget, let!(:feasible_bi) do
title: "Unfeasible project") } create(:budget_investment, :feasible, budget: budget, title: "Feasible project")
let!(:feasible_bi) { create(:budget_investment, :feasible, budget: budget, end
title: "Feasible project") }
let!(:feasible_vf_bi) { create(:budget_investment, :feasible, :finished, budget: budget, let!(:feasible_vf_bi) do
title: "Feasible, VF project") } create(:budget_investment, :feasible, :finished, budget: budget, title: "Feasible, VF project")
let!(:selected_bi) { create(:budget_investment, :selected, budget: budget, end
title: "Selected project") }
let!(:winner_bi) { create(:budget_investment, :winner, budget: budget, let!(:selected_bi) do
title: "Winner project") } create(:budget_investment, :selected, budget: budget, title: "Selected project")
let!(:undecided_bi) { create(:budget_investment, :undecided, budget: budget, end
title: "Undecided project") }
let!(:winner_bi) do
create(:budget_investment, :winner, budget: budget, title: "Winner project")
end
let!(:undecided_bi) do
create(:budget_investment, :undecided, budget: budget, title: "Undecided project")
end
scenario "Filtering by valuation and selection", :js do scenario "Filtering by valuation and selection", :js do
visit admin_budget_budget_investments_path(budget) visit admin_budget_budget_investments_path(budget)

View File

@@ -263,26 +263,22 @@ describe "Admin download settings" do
let(:budget_finished) { create(:budget, :finished) } let(:budget_finished) { create(:budget, :finished) }
let(:heading) { create(:budget_heading, budget: budget_finished, price: 1000) } let(:heading) { create(:budget_heading, budget: budget_finished, price: 1000) }
let(:investment1) { create(:budget_investment, let(:investment1) do
:selected, create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 900)
heading: heading, end
price: 200,
ballot_lines_count: 900) } let(:investment2) do
let(:investment2) { create(:budget_investment, create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 800)
:selected, end
heading: heading,
price: 300, let(:investment3) do
ballot_lines_count: 800) } create(:budget_investment, :incompatible, heading: heading, price: 500, ballot_lines_count: 700)
let(:investment3) { create(:budget_investment, end
:incompatible,
heading: heading, let(:investment4) do
price: 500, create(:budget_investment, :selected, heading: heading, price: 600, ballot_lines_count: 600)
ballot_lines_count: 700) } end
let(:investment4) { create(:budget_investment,
:selected,
heading: heading,
price: 600,
ballot_lines_count: 600) }
let(:budget) { create :budget } let(:budget) { create :budget }
before do before do

View File

@@ -234,8 +234,9 @@ describe "Notifications" do
end end
def users_without_notifications def users_without_notifications
User.all.select { |user| user.notifications.not_emailed User.all.select do |user|
.where(notifiable_type: "ProposalNotification").blank? } user.notifications.not_emailed.where(notifiable_type: "ProposalNotification").blank?
end
end end
end end

View File

@@ -368,9 +368,7 @@ describe "Proposal Notifications" do
login_as user.reload login_as user.reload
visit root_path visit root_path
within("#notifications") { within("#notifications") { expect(page).to have_content :all, "You have 3 new notifications" }
expect(page).to have_content :all, "You have 3 new notifications"
}
find(".icon-notification").click find(".icon-notification").click
expect(page).to have_css ".notification", count: 3 expect(page).to have_css ".notification", count: 3

View File

@@ -6,8 +6,9 @@ describe "Social media meta tags" do
let(:meta_keywords) { "citizen, participation, open government" } let(:meta_keywords) { "citizen, participation, open government" }
let(:meta_title) { "CONSUL" } let(:meta_title) { "CONSUL" }
let(:meta_description) { "Citizen participation tool for an open, "\ let(:meta_description) do
"transparent and democratic government." } "Citizen participation tool for an open, transparent and democratic government."
end
let(:twitter_handle) { "@consul_test" } let(:twitter_handle) { "@consul_test" }
let(:url) { "http://consul.dev" } let(:url) { "http://consul.dev" }
let(:facebook_handle) { "consultest" } let(:facebook_handle) { "consultest" }

View File

@@ -5,8 +5,10 @@ describe "Tags" do
let(:author) { create(:user, :level_two, username: "Isabel") } let(:author) { create(:user, :level_two, username: "Isabel") }
let(:budget) { create(:budget, name: "Big Budget") } let(:budget) { create(:budget, name: "Big Budget") }
let(:group) { create(:budget_group, name: "Health", budget: budget) } let(:group) { create(:budget_group, name: "Health", budget: budget) }
let!(:heading) { create(:budget_heading, name: "More hospitals", let!(:heading) do
group: group, latitude: "40.416775", longitude: "-3.703790") } create(:budget_heading, name: "More hospitals",
group: group, latitude: "40.416775", longitude: "-3.703790")
end
let!(:tag_medio_ambiente) { create(:tag, :category, name: "Medio Ambiente") } let!(:tag_medio_ambiente) { create(:tag, :category, name: "Medio Ambiente") }
let!(:tag_economia) { create(:tag, :category, name: "Economía") } let!(:tag_economia) { create(:tag, :category, name: "Economía") }
let(:admin) { create(:administrator).user } let(:admin) { create(:administrator).user }

View File

@@ -13,9 +13,9 @@ describe "Valuation budget investments" do
scenario "Disabled with a feature flag" do scenario "Disabled with a feature flag" do
Setting["process.budgets"] = nil Setting["process.budgets"] = nil
expect { expect do
visit tracking_budget_budget_investments_path(create(:budget)) visit tracking_budget_budget_investments_path(create(:budget))
}.to raise_exception(FeatureFlags::FeatureDisabled) end.to raise_exception(FeatureFlags::FeatureDisabled)
end end
scenario "Display link to tracking section" do scenario "Display link to tracking section" do
@@ -161,9 +161,9 @@ describe "Valuation budget investments" do
logout logout
login_as create(:tracker).user login_as create(:tracker).user
expect { expect do
visit tracking_budget_budget_investment_path(budget, investment) visit tracking_budget_budget_investment_path(budget, investment)
}.to raise_error "Not Found" end.to raise_error "Not Found"
end end
end end
@@ -269,9 +269,9 @@ describe "Valuation budget investments" do
logout logout
login_as create(:tracker, user: create(:user)).user login_as create(:tracker, user: create(:user)).user
expect { expect do
visit tracking_budget_budget_investment_progress_bars_path(budget, investment) visit tracking_budget_budget_investment_progress_bars_path(budget, investment)
}.to raise_error "Not Found" end.to raise_error "Not Found"
end end
scenario "create primary progress bar" do scenario "create primary progress bar" do

View File

@@ -37,9 +37,9 @@ describe "Valuation budget investments" do
scenario "Disabled with a feature flag" do scenario "Disabled with a feature flag" do
Setting["process.budgets"] = nil Setting["process.budgets"] = nil
expect { expect do
visit valuation_budget_budget_investments_path(create(:budget)) visit valuation_budget_budget_investments_path(create(:budget))
}.to raise_exception(FeatureFlags::FeatureDisabled) end.to raise_exception(FeatureFlags::FeatureDisabled)
end end
scenario "Display link to valuation section" do scenario "Display link to valuation section" do
@@ -282,9 +282,9 @@ describe "Valuation budget investments" do
logout logout
login_as create(:valuator).user login_as create(:valuator).user
expect { expect do
visit valuation_budget_budget_investment_path(budget, investment) visit valuation_budget_budget_investment_path(budget, investment)
}.to raise_error "Not Found" end.to raise_error "Not Found"
end end
scenario "preview is visible" do scenario "preview is visible" do

View File

@@ -11,14 +11,13 @@ describe RemoteTranslations::Caller do
end end
describe "#call" do describe "#call" do
let(:client) { RemoteTranslations::Microsoft::Client } let(:client) { RemoteTranslations::Microsoft::Client }
context "Debates" do context "Debates" do
let(:debate) { create(:debate) } let(:debate) { create(:debate) }
let(:remote_translation) { create(:remote_translation, let(:remote_translation) do
remote_translatable: debate, locale: :es) } create(:remote_translation, remote_translatable: debate, locale: :es)
end
let(:caller) { RemoteTranslations::Caller.new(remote_translation) } let(:caller) { RemoteTranslations::Caller.new(remote_translation) }
it "returns the resource with new translation persisted" do it "returns the resource with new translation persisted" do
@@ -65,8 +64,9 @@ describe RemoteTranslations::Caller do
context "Proposals" do context "Proposals" do
let!(:proposal) { create(:proposal) } let!(:proposal) { create(:proposal) }
let(:remote_translation) { create(:remote_translation, let(:remote_translation) do
remote_translatable: proposal, locale: :es) } create(:remote_translation, remote_translatable: proposal, locale: :es)
end
let(:caller) { RemoteTranslations::Caller.new(remote_translation) } let(:caller) { RemoteTranslations::Caller.new(remote_translation) }
it "returns the resource with new translation persisted" do it "returns the resource with new translation persisted" do
@@ -115,9 +115,9 @@ describe RemoteTranslations::Caller do
context "Budget Investments" do context "Budget Investments" do
let(:budget_investment) { create(:budget_investment) } let(:budget_investment) { create(:budget_investment) }
let(:remote_translation) { create(:remote_translation, let(:remote_translation) do
remote_translatable: budget_investment, create(:remote_translation, remote_translatable: budget_investment, locale: :es)
locale: :es) } end
let(:caller) { RemoteTranslations::Caller.new(remote_translation) } let(:caller) { RemoteTranslations::Caller.new(remote_translation) }
it "returns the resource with new translation persisted" do it "returns the resource with new translation persisted" do
@@ -162,10 +162,10 @@ describe RemoteTranslations::Caller do
end end
context "Comments" do context "Comments" do
let(:comment) { create(:comment) } let(:comment) { create(:comment) }
let(:remote_translation) { create(:remote_translation, let(:remote_translation) do
remote_translatable: comment, locale: :es) } create(:remote_translation, remote_translatable: comment, locale: :es)
end
let(:caller) { RemoteTranslations::Caller.new(remote_translation) } let(:caller) { RemoteTranslations::Caller.new(remote_translation) }
it "returns the resource with new translation persisted" do it "returns the resource with new translation persisted" do

View File

@@ -1,13 +1,13 @@
require "rails_helper" require "rails_helper"
describe Dashboard::Mailer do describe Dashboard::Mailer do
let!(:action) do
create(:dashboard_action, :proposed_action, :active, day_offset: 0, published_proposal: true)
end
let!(:action) { create(:dashboard_action, :proposed_action, :active, let!(:resource) do
day_offset: 0, create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: true)
published_proposal: true) } end
let!(:resource) { create(:dashboard_action, :resource, :active,
day_offset: 0,
published_proposal: true) }
before do before do
Setting["dashboard.emails"] = true Setting["dashboard.emails"] = true

View File

@@ -758,13 +758,13 @@ describe Budget::Investment do
end end
describe "search" do describe "search" do
context "attributes" do context "attributes" do
let(:attributes) do
let(:attributes) { { title: "save the world", { title: "save the world",
description: "in order to save the world one must think about...", description: "in order to save the world one must think about...",
title_es: "para salvar el mundo uno debe pensar en...", title_es: "para salvar el mundo uno debe pensar en...",
description_es: "uno debe pensar" } } description_es: "uno debe pensar" }
end
it "searches by title" do it "searches by title" do
budget_investment = create(:budget_investment, attributes) budget_investment = create(:budget_investment, attributes)

View File

@@ -138,19 +138,14 @@ describe Budget::Phase do
end end
it "adjusts previous enabled phase end date to its own start date" do it "adjusts previous enabled phase end date to its own start date" do
expect { expect { second_phase.update_attributes(enabled: true) }
second_phase.update_attributes(enabled: true) .to change { prev_enabled_phase.ends_at.to_date }.to(Date.current)
}.to change {
prev_enabled_phase.ends_at.to_date
}.to(Date.current)
end end
it "adjusts next enabled phase start date to its own end date" do it "adjusts next enabled phase start date to its own end date" do
expect { expect do
second_phase.update_attributes(enabled: true) second_phase.update_attributes(enabled: true)
}.to change { end.to change { next_enabled_phase.starts_at.to_date }.to(Date.current + 2.days)
next_enabled_phase.starts_at.to_date
}.to(Date.current + 2.days)
end end
end end
@@ -160,35 +155,31 @@ describe Budget::Phase do
end end
it "doesn't change previous enabled phase end date" do it "doesn't change previous enabled phase end date" do
expect { expect { second_phase.update_attributes(starts_at: Date.current, ends_at: Date.current + 2.days) }
second_phase.update_attributes(starts_at: Date.current, .not_to change { prev_enabled_phase.ends_at }
ends_at: Date.current + 2.days)
}.not_to (change { prev_enabled_phase.ends_at })
end end
it "doesn't change next enabled phase start date" do it "doesn't change next enabled phase start date" do
expect { expect { second_phase.update_attributes(starts_at: Date.current, ends_at: Date.current + 2.days) }
second_phase.update_attributes(starts_at: Date.current, .not_to change { next_enabled_phase.starts_at }
ends_at: Date.current + 2.days)
}.not_to (change { next_enabled_phase.starts_at })
end end
end end
describe "when being disabled" do describe "when being disabled" do
it "doesn't adjust previous enabled phase end date to its own start date" do it "doesn't adjust previous enabled phase end date to its own start date" do
expect { expect do
second_phase.update_attributes(enabled: false, second_phase.update_attributes(enabled: false,
starts_at: Date.current, starts_at: Date.current,
ends_at: Date.current + 2.days) ends_at: Date.current + 2.days)
}.not_to (change { prev_enabled_phase.ends_at }) end.not_to (change { prev_enabled_phase.ends_at })
end end
it "adjusts next enabled phase start date to its own start date" do it "adjusts next enabled phase start date to its own start date" do
expect { expect do
second_phase.update_attributes(enabled: false, second_phase.update_attributes(enabled: false,
starts_at: Date.current, starts_at: Date.current,
ends_at: Date.current + 2.days) ends_at: Date.current + 2.days)
}.to change { next_enabled_phase.starts_at.to_date }.to(Date.current) end.to change { next_enabled_phase.starts_at.to_date }.to(Date.current)
end end
end end
end end
@@ -217,9 +208,9 @@ describe Budget::Phase do
describe "#sanitize_description" do describe "#sanitize_description" do
it "removes not allowed html entities from the description" do it "removes not allowed html entities from the description" do
expect { expect do
first_phase.update_attributes(description: '<p><a href="/"><b>a</b></a></p> <script>javascript</script>') first_phase.update_attributes(description: '<p><a href="/"><b>a</b></a></p> <script>javascript</script>')
}.to change { first_phase.description }.to('<p><a href="/">a</a></p> javascript') end.to change { first_phase.description }.to('<p><a href="/">a</a></p> javascript')
end end
end end
end end

View File

@@ -152,21 +152,31 @@ describe Dashboard::Action do
context "#active_for" do context "#active_for" do
let!(:active_action) { create :dashboard_action, :active, day_offset: 0, required_supports: 0 } let!(:active_action) { create :dashboard_action, :active, day_offset: 0, required_supports: 0 }
let!(:not_enough_supports_action) { create :dashboard_action, :active, day_offset: 0,
required_supports: 10_000 }
let!(:inactive_action) { create :dashboard_action, :inactive } let!(:inactive_action) { create :dashboard_action, :inactive }
let!(:future_action) { create :dashboard_action, :active, day_offset: 300, let!(:not_enough_supports_action) do
required_supports: 0 } create :dashboard_action, :active, day_offset: 0, required_supports: 10_000
let!(:action_published_proposal) { create :dashboard_action, end
let!(:future_action) do
create :dashboard_action, :active, day_offset: 300, required_supports: 0
end
let!(:action_published_proposal) do
create :dashboard_action,
:active, :active,
day_offset: 0, day_offset: 0,
required_supports: 0, required_supports: 0,
published_proposal: true } published_proposal: true
let!(:action_for_draft_proposal) { create :dashboard_action, end
let!(:action_for_draft_proposal) do
create :dashboard_action,
:active, :active,
day_offset: 0, day_offset: 0,
required_supports: 0, required_supports: 0,
published_proposal: false } published_proposal: false
end
let(:proposal) { create :proposal } let(:proposal) { create :proposal }
let(:draft_proposal) { create :proposal, :draft } let(:draft_proposal) { create :proposal, :draft }
@@ -205,8 +215,9 @@ describe Dashboard::Action do
context "#course_for" do context "#course_for" do
let!(:proposed_action) { create :dashboard_action, :active, required_supports: 0 } let!(:proposed_action) { create :dashboard_action, :active, required_supports: 0 }
let!(:inactive_resource) { create :dashboard_action, :inactive, :resource, let!(:inactive_resource) do
required_supports: 0 } create :dashboard_action, :inactive, :resource, required_supports: 0
end
let!(:resource) { create :dashboard_action, :active, :resource, required_supports: 10_000 } let!(:resource) { create :dashboard_action, :active, :resource, required_supports: 10_000 }
let!(:achieved_resource) { create :dashboard_action, :active, :resource, required_supports: 0 } let!(:achieved_resource) { create :dashboard_action, :active, :resource, required_supports: 0 }
let(:proposal) { create :proposal } let(:proposal) { create :proposal }
@@ -272,12 +283,15 @@ describe Dashboard::Action do
describe "Detect new actions when there are news actions actived" do describe "Detect new actions when there are news actions actived" do
context "for published proposals" do context "for published proposals" do
let!(:proposal) { create(:proposal) } let!(:proposal) { create(:proposal) }
let!(:action) { create(:dashboard_action, :proposed_action, :active, day_offset: 0,
published_proposal: true) } let!(:action) do
let!(:resource) { create(:dashboard_action, :resource, :active, day_offset: 0, create(:dashboard_action, :proposed_action, :active, day_offset: 0, published_proposal: true)
published_proposal: true) } end
let!(:resource) do
create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: true)
end
it "when proposal has been created today and day_offset is valid only for today" do it "when proposal has been created today and day_offset is valid only for today" do
expect(Dashboard::Action.detect_new_actions_since(Date.yesterday, expect(Dashboard::Action.detect_new_actions_since(Date.yesterday,
@@ -301,12 +315,15 @@ describe Dashboard::Action do
end end
context "for draft proposals" do context "for draft proposals" do
let!(:proposal) { create(:proposal, :draft) } let!(:proposal) { create(:proposal, :draft) }
let!(:action) { create(:dashboard_action, :proposed_action, :active, day_offset: 0,
published_proposal: false) } let!(:action) do
let!(:resource) { create(:dashboard_action, :resource, :active, day_offset: 0, create(:dashboard_action, :proposed_action, :active, day_offset: 0, published_proposal: false)
published_proposal: false) } end
let!(:resource) do
create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: false)
end
it "when day_offset field is valid for today and invalid for yesterday" do it "when day_offset field is valid for today and invalid for yesterday" do
expect(Dashboard::Action.detect_new_actions_since(Date.yesterday, expect(Dashboard::Action.detect_new_actions_since(Date.yesterday,

View File

@@ -461,13 +461,13 @@ describe Debate do
end end
describe "search" do describe "search" do
context "attributes" do context "attributes" do
let(:attributes) do
let(:attributes) { { title: "save the world", { title: "save the world",
description: "in order to save the world one must think about...", description: "in order to save the world one must think about...",
title_es: "para salvar el mundo uno debe pensar en...", title_es: "para salvar el mundo uno debe pensar en...",
description_es: "uno debe pensar" } } description_es: "uno debe pensar" }
end
it "searches by title" do it "searches by title" do
debate = create(:debate, attributes) debate = create(:debate, attributes)

View File

@@ -81,9 +81,7 @@ RSpec.describe I18nContent, type: :model do
end end
it "uses the first and last parameters" do it "uses the first and last parameters" do
expect { expect { I18nContent.flat_hash("string", nil, "not hash") }.to raise_error(NoMethodError)
I18nContent.flat_hash("string", nil, "not hash")
}.to raise_error(NoMethodError)
expect(I18nContent.flat_hash(nil, nil, { q: "other string" })).to eq({ expect(I18nContent.flat_hash(nil, nil, { q: "other string" })).to eq({
q: "other string", q: "other string",
@@ -102,9 +100,7 @@ RSpec.describe I18nContent, type: :model do
end end
it "uses all parameters" do it "uses all parameters" do
expect { expect { I18nContent.flat_hash("string", "f", "not hash") }.to raise_error NoMethodError
I18nContent.flat_hash("string", "f", "not hash")
}.to raise_error NoMethodError
expect(I18nContent.flat_hash(nil, "f", { q: "other string" })).to eq({ expect(I18nContent.flat_hash(nil, "f", { q: "other string" })).to eq({
q: "other string", q: "other string",

View File

@@ -97,12 +97,17 @@ describe Legislation::Process do
describe "filter scopes" do describe "filter scopes" do
describe "open and past filters" do describe "open and past filters" do
let!(:process_1) { create(:legislation_process, start_date: Date.current - 2.days, let!(:process_1) do
end_date: Date.current + 1.day) } create(:legislation_process, start_date: Date.current - 2.days, end_date: Date.current + 1.day)
let!(:process_2) { create(:legislation_process, start_date: Date.current + 1.day, end
end_date: Date.current + 3.days) }
let!(:process_3) { create(:legislation_process, start_date: Date.current - 4.days, let!(:process_2) do
end_date: Date.current - 3.days) } create(:legislation_process, start_date: Date.current + 1.day, end_date: Date.current + 3.days)
end
let!(:process_3) do
create(:legislation_process, start_date: Date.current - 4.days, end_date: Date.current - 3.days)
end
it "filters open" do it "filters open" do
open_processes = ::Legislation::Process.open open_processes = ::Legislation::Process.open
@@ -184,15 +189,13 @@ describe Legislation::Process do
end end
it "invalid format colors" do it "invalid format colors" do
expect { expect do
create(:legislation_process, background_color: "#123ghi", font_color: "#fff") create(:legislation_process, background_color: "#123ghi", font_color: "#fff")
}.to raise_error(ActiveRecord::RecordInvalid, end.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Background color is invalid")
"Validation failed: Background color is invalid")
expect { expect do
create(:legislation_process, background_color: "#fff", font_color: "ggg") create(:legislation_process, background_color: "#fff", font_color: "ggg")
}.to raise_error(ActiveRecord::RecordInvalid, end.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Font color is invalid")
"Validation failed: Font color is invalid")
end end
end end

View File

@@ -37,11 +37,12 @@ describe Officing::Residence do
end end
describe "custom validations" do describe "custom validations" do
let(:custom_residence) do
let(:custom_residence) { build(:officing_residence, build(:officing_residence,
document_number: "12345678Z", document_number: "12345678Z",
date_of_birth: "01/01/1980", date_of_birth: "01/01/1980",
postal_code: "28001") } postal_code: "28001")
end
before do before do
Setting["feature.remote_census"] = true Setting["feature.remote_census"] = true

View File

@@ -1,10 +1,11 @@
require "rails_helper" require "rails_helper"
describe Poll::BallotSheet do describe Poll::BallotSheet do
let(:ballot_sheet) do
let(:ballot_sheet) { build(:poll_ballot_sheet, poll: create(:poll), build(:poll_ballot_sheet, poll: create(:poll),
officer_assignment: create(:poll_officer_assignment), officer_assignment: create(:poll_officer_assignment),
data: "1234;5678") } data: "1234;5678")
end
context "Validations" do context "Validations" do

View File

@@ -145,8 +145,9 @@ describe Poll do
let!(:expired_poll) { create(:poll, :expired) } let!(:expired_poll) { create(:poll, :expired) }
let!(:current_restricted_poll) { create(:poll, geozone_restricted: true, geozones: [geozone]) } let!(:current_restricted_poll) { create(:poll, geozone_restricted: true, geozones: [geozone]) }
let!(:expired_restricted_poll) { create(:poll, :expired, geozone_restricted: true, let!(:expired_restricted_poll) do
geozones: [geozone]) } create(:poll, :expired, geozone_restricted: true, geozones: [geozone])
end
let!(:all_polls) { [current_poll, expired_poll, current_poll, expired_restricted_poll] } let!(:all_polls) { [current_poll, expired_poll, current_poll, expired_restricted_poll] }
let(:non_current_polls) { [expired_poll, expired_restricted_poll] } let(:non_current_polls) { [expired_poll, expired_restricted_poll] }
@@ -313,13 +314,17 @@ describe Poll do
let(:proposal) { create :proposal } let(:proposal) { create :proposal }
let(:other_proposal) { create :proposal } let(:other_proposal) { create :proposal }
let(:poll) { create(:poll, related: proposal) } let(:poll) { create(:poll, related: proposal) }
let(:overlaping_poll) { build(:poll, related: proposal, starts_at: poll.starts_at + 1.day, let(:overlaping_poll) do
ends_at: poll.ends_at - 1.day) } build(:poll, related: proposal, starts_at: poll.starts_at + 1.day, ends_at: poll.ends_at - 1.day)
let(:non_overlaping_poll) { create(:poll, related: proposal, starts_at: poll.ends_at + 1.day, end
ends_at: poll.ends_at + 31.days) }
let(:overlaping_poll_2) { create(:poll, related: other_proposal, let(:non_overlaping_poll) do
starts_at: poll.starts_at + 1.day, create(:poll, related: proposal, starts_at: poll.ends_at + 1.day, ends_at: poll.ends_at + 31.days)
ends_at: poll.ends_at - 1.day) } end
let(:overlaping_poll_2) do
create(:poll, related: other_proposal, starts_at: poll.starts_at + 1.day, ends_at: poll.ends_at - 1.day)
end
it "a poll can not overlap itself" do it "a poll can not overlap itself" do
expect(Poll.overlaping_with(poll)).not_to include(poll) expect(Poll.overlaping_with(poll)).not_to include(poll)

View File

@@ -473,15 +473,15 @@ describe Proposal do
end end
describe "search" do describe "search" do
context "attributes" do context "attributes" do
let(:attributes) do
let(:attributes) { { title: "save the world", { title: "save the world",
summary: "basically", summary: "basically",
description: "in order to save the world one must think about...", description: "in order to save the world one must think about...",
title_es: "para salvar el mundo uno debe pensar en...", title_es: "para salvar el mundo uno debe pensar en...",
summary_es: "basicamente", summary_es: "basicamente",
description_es: "uno debe pensar" } } description_es: "uno debe pensar" }
end
it "searches by title" do it "searches by title" do
proposal = create(:proposal, attributes) proposal = create(:proposal, attributes)

View File

@@ -29,11 +29,12 @@ describe Signature do
end end
describe "custom validations" do describe "custom validations" do
let(:signature) do
let(:signature) { build(:signature, build(:signature,
document_number: "12345678Z", document_number: "12345678Z",
date_of_birth: "31/12/1980", date_of_birth: "31/12/1980",
postal_code: "28013") } postal_code: "28013")
end
before do before do
Setting["feature.remote_census"] = true Setting["feature.remote_census"] = true