Rubocop autocorrections

This commit is contained in:
Bertocq
2017-10-17 22:00:00 +02:00
parent ceec71e558
commit ce0a7f6fad
32 changed files with 101 additions and 111 deletions

View File

@@ -54,7 +54,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
end end
def poll_params def poll_params
params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted, :summary, :description, params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted, :summary, :description,
geozone_ids: [], geozone_ids: [],
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
end end

View File

@@ -5,7 +5,7 @@ class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseContr
end end
def new def new
@answer = ::Poll::Question::Answer.find(params[:answer_id]) @answer = ::Poll::Question::Answer.find(params[:answer_id])
end end
def create def create

View File

@@ -33,11 +33,11 @@ class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseContr
end end
def destroy def destroy
if @video.destroy notice = if @video.destroy
notice = t("flash.actions.destroy.poll_question_answer_video") t("flash.actions.destroy.poll_question_answer_video")
else else
notice = t("flash.actions.destroy.error") t("flash.actions.destroy.error")
end end
redirect_to :back, notice: notice redirect_to :back, notice: notice
end end

View File

@@ -49,7 +49,7 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController
end end
def shift_params def shift_params
shift_params = params.require(:shift).permit(:booth_id, :officer_id, :task, date:[:vote_collection_date, :recount_scrutiny_date]) shift_params = params.require(:shift).permit(:booth_id, :officer_id, :task, date: [:vote_collection_date, :recount_scrutiny_date])
shift_params.merge(date: shift_params[:date]["#{shift_params[:task]}_date".to_sym]) shift_params.merge(date: shift_params[:date]["#{shift_params[:task]}_date".to_sym])
end end
end end

View File

@@ -18,8 +18,7 @@ class DirectUploadsController < ApplicationController
render json: { cached_attachment: @direct_upload.relation.cached_attachment, render json: { cached_attachment: @direct_upload.relation.cached_attachment,
filename: @direct_upload.relation.attachment.original_filename, filename: @direct_upload.relation.attachment.original_filename,
destroy_link: render_destroy_upload_link(@direct_upload).html_safe, destroy_link: render_destroy_upload_link(@direct_upload).html_safe,
attachment_url: @direct_upload.relation.attachment.url attachment_url: @direct_upload.relation.attachment.url}
}
else else
@direct_upload.destroy_attachment @direct_upload.destroy_attachment
render json: { errors: @direct_upload.errors[:attachment].join(", ") }, render json: { errors: @direct_upload.errors[:attachment].join(", ") },
@@ -28,7 +27,7 @@ class DirectUploadsController < ApplicationController
end end
def destroy def destroy
@direct_upload = DirectUpload.new(direct_upload_params.merge(user: current_user) ) @direct_upload = DirectUpload.new(direct_upload_params.merge(user: current_user))
@direct_upload.relation.set_attachment_from_cached_attachment @direct_upload.relation.set_attachment_from_cached_attachment
if @direct_upload.destroy_attachment if @direct_upload.destroy_attachment

View File

@@ -24,8 +24,8 @@ module DocumentablesHelper
def documentable_humanized_accepted_content_types(documentable_class) def documentable_humanized_accepted_content_types(documentable_class)
documentable_class.accepted_content_types documentable_class.accepted_content_types
.collect{ |content_type| content_type.split("/").last } .collect{ |content_type| content_type.split("/").last }
.join(", ") .join(", ")
end end
def documentables_note(documentable) def documentables_note(documentable)

View File

@@ -33,7 +33,7 @@ module DocumentsHelper
def render_attachment(builder, document) def render_attachment(builder, document)
klass = document.errors[:attachment].any? ? "error" : "" klass = document.errors[:attachment].any? ? "error" : ""
klass = document.persisted? || document.cached_attachment.present? ? " hide" : "" klass = document.persisted? || document.cached_attachment.present? ? " hide" : ""
html = builder.label :attachment, html = builder.label :attachment,
t("documents.form.attachment_label"), t("documents.form.attachment_label"),
class: "button hollow #{klass}" class: "button hollow #{klass}"

View File

@@ -22,17 +22,17 @@ module ImageablesHelper
def imageable_accepted_content_types_extensions def imageable_accepted_content_types_extensions
Image::ACCEPTED_CONTENT_TYPE Image::ACCEPTED_CONTENT_TYPE
.collect{ |content_type| ".#{content_type.split("/").last}" } .collect{ |content_type| ".#{content_type.split('/').last}" }
.join(",") .join(",")
end end
def imageable_humanized_accepted_content_types def imageable_humanized_accepted_content_types
Image::ACCEPTED_CONTENT_TYPE Image::ACCEPTED_CONTENT_TYPE
.collect{ |content_type| content_type.split("/").last } .collect{ |content_type| content_type.split("/").last }
.join(", ") .join(", ")
end end
def imageables_note(imageable) def imageables_note(_imageable)
t "images.form.note", accepted_content_types: imageable_humanized_accepted_content_types, t "images.form.note", accepted_content_types: imageable_humanized_accepted_content_types,
max_file_size: imageable_max_file_size max_file_size: imageable_max_file_size
end end

View File

@@ -44,7 +44,7 @@ module PollsHelper
def poll_voter_token(poll, user) def poll_voter_token(poll, user)
Poll::Voter.where(poll: poll, user: user, origin: "web").first&.token || '' Poll::Voter.where(poll: poll, user: user, origin: "web").first&.token || ''
end end
def voted_before_sign_in(question) def voted_before_sign_in(question)
question.answers.where(author: current_user).any? { |vote| current_user.current_sign_in_at >= vote.updated_at } question.answers.where(author: current_user).any? { |vote| current_user.current_sign_in_at >= vote.updated_at }
end end

View File

@@ -46,12 +46,12 @@ module WelcomeHelper
end end
def calculate_offset(debates, proposals, apply_offset) def calculate_offset(debates, proposals, apply_offset)
if (debates.any? && proposals.any?) if debates.any? && proposals.any?
if apply_offset offset = if apply_offset
offset = "medium-offset-2 large-offset-2" "medium-offset-2 large-offset-2"
else else
offset = "end" "end"
end end
end end
end end

View File

@@ -5,7 +5,7 @@ module Followable
has_many :follows, as: :followable, dependent: :destroy has_many :follows, as: :followable, dependent: :destroy
has_many :followers, through: :follows, source: :user has_many :followers, through: :follows, source: :user
scope :followed_by_user, -> (user){ scope :followed_by_user, ->(user){
joins(:follows).where("follows.user_id = ?", user.id) joins(:follows).where("follows.user_id = ?", user.id)
} }
end end

View File

@@ -48,8 +48,8 @@ class Debate < ActiveRecord::Base
attr_accessor :link_required attr_accessor :link_required
def self.recommendations(user) def self.recommendations(user)
tagged_with(user.interests, any: true). tagged_with(user.interests, any: true)
where("author_id != ?", user.id) .where("author_id != ?", user.id)
end end
def searchable_values def searchable_values

View File

@@ -7,7 +7,7 @@ class DirectUpload
:relation, :resource_relation, :relation, :resource_relation,
:attachment, :cached_attachment, :user :attachment, :cached_attachment, :user
validates_presence_of :attachment, :resource_type, :resource_relation, :user validates :attachment, :resource_type, :resource_relation, :user, presence: true
validate :parent_resource_attachment_validations, validate :parent_resource_attachment_validations,
if: -> { attachment.present? && resource_type.present? && resource_relation.present? && user.present? } if: -> { attachment.present? && resource_type.present? && resource_relation.present? && user.present? }
@@ -19,15 +19,15 @@ class DirectUpload
if @resource_type.present? && @resource_relation.present? && (@attachment.present? || @cached_attachment.present?) if @resource_type.present? && @resource_relation.present? && (@attachment.present? || @cached_attachment.present?)
@resource = @resource_type.constantize.find_or_initialize_by(id: @resource_id) @resource = @resource_type.constantize.find_or_initialize_by(id: @resource_id)
#Refactor # Refactor
if @resource.respond_to?(:images) && @relation = if @resource.respond_to?(:images) &&
((@attachment.present? && !@attachment.content_type.match(/pdf/)) || @cached_attachment.present?) ((@attachment.present? && !@attachment.content_type.match(/pdf/)) || @cached_attachment.present?)
@relation = @resource.images.send("build", relation_attributtes) @resource.images.send("build", relation_attributtes)
elsif @resource.class.reflections[@resource_relation].macro == :has_one elsif @resource.class.reflections[@resource_relation].macro == :has_one
@relation = @resource.send("build_#{resource_relation}", relation_attributtes) @resource.send("build_#{resource_relation}", relation_attributtes)
else else
@relation = @resource.send(@resource_relation).build(relation_attributtes) @resource.send(@resource_relation).build(relation_attributtes)
end end
@relation.user = user @relation.user = user
end end
@@ -50,7 +50,7 @@ class DirectUpload
def parent_resource_attachment_validations def parent_resource_attachment_validations
@relation.valid? @relation.valid?
if @relation.errors.has_key? :attachment if @relation.errors.key? :attachment
errors[:attachment] = @relation.errors[:attachment] errors[:attachment] = @relation.errors[:attachment]
end end
end end

View File

@@ -44,7 +44,7 @@ class Document < ActiveRecord::Base
attachment.instance.prefix(attachment, style) attachment.instance.prefix(attachment, style)
end end
def prefix(attachment, style) def prefix(attachment, _style)
if !attachment.instance.persisted? if !attachment.instance.persisted?
"cached_attachments/user/#{attachment.instance.user_id}" "cached_attachments/user/#{attachment.instance.user_id}"
else else

View File

@@ -5,7 +5,7 @@ class Image < ActiveRecord::Base
TITLE_LEGHT_RANGE = 4..80 TITLE_LEGHT_RANGE = 4..80
MIN_SIZE = 475 MIN_SIZE = 475
MAX_IMAGE_SIZE = 1.megabyte MAX_IMAGE_SIZE = 1.megabyte
ACCEPTED_CONTENT_TYPE = %w(image/jpeg image/jpg) ACCEPTED_CONTENT_TYPE = %w(image/jpeg image/jpg).freeze
has_attached_file :attachment, styles: { large: "x#{MIN_SIZE}", medium: "300x300#", thumb: "140x245#" }, has_attached_file :attachment, styles: { large: "x#{MIN_SIZE}", medium: "300x300#", thumb: "140x245#" },
url: "/system/:class/:prefix/:style/:hash.:extension", url: "/system/:class/:prefix/:style/:hash.:extension",
@@ -52,7 +52,7 @@ class Image < ActiveRecord::Base
attachment.instance.prefix(attachment, style) attachment.instance.prefix(attachment, style)
end end
def prefix(attachment, style) def prefix(attachment, _style)
if !attachment.instance.persisted? if !attachment.instance.persisted?
"cached_attachments/user/#{attachment.instance.user_id}" "cached_attachments/user/#{attachment.instance.user_id}"
else else
@@ -103,8 +103,8 @@ class Image < ActiveRecord::Base
def remove_cached_attachment def remove_cached_attachment
image = Image.new(imageable: imageable, image = Image.new(imageable: imageable,
cached_attachment: cached_attachment, cached_attachment: cached_attachment,
user: user) user: user)
image.set_attachment_from_cached_attachment image.set_attachment_from_cached_attachment
image.attachment.destroy image.attachment.destroy
end end

View File

@@ -1,7 +1,7 @@
class Poll class Poll
class Voter < ActiveRecord::Base class Voter < ActiveRecord::Base
VALID_ORIGINS = %w{ web booth } VALID_ORIGINS = %w{web booth}.freeze
belongs_to :poll belongs_to :poll
belongs_to :user belongs_to :user

View File

@@ -69,10 +69,10 @@ class Proposal < ActiveRecord::Base
scope :public_for_api, -> { all } scope :public_for_api, -> { all }
def self.recommendations(user) def self.recommendations(user)
tagged_with(user.interests, any: true). tagged_with(user.interests, any: true)
where("author_id != ?", user.id). .where("author_id != ?", user.id)
unsuccessful. .unsuccessful
not_followed_by_user(user) .not_followed_by_user(user)
end end
def self.not_followed_by_user(user) def self.not_followed_by_user(user)

View File

@@ -30,9 +30,9 @@ feature 'Officer Assignments' do
expect(page).to have_content officer2.name expect(page).to have_content officer2.name
expect(page).to_not have_content officer3.name expect(page).to_not have_content officer3.name
end end
end end
scenario "Search", :js do scenario "Search", :js do
poll = create(:poll) poll = create(:poll)
booth = create(:poll_booth) booth = create(:poll_booth)
@@ -62,7 +62,6 @@ feature 'Officer Assignments' do
expect(page).to have_content officer2.name expect(page).to have_content officer2.name
expect(page).to_not have_content officer3.name expect(page).to_not have_content officer3.name
end end
end end
end end

View File

@@ -102,11 +102,11 @@ feature 'Admin shifts' do
shift2 = create(:poll_shift, :recount_scrutiny_task, officer: officer, booth: booth, date: Time.zone.tomorrow) shift2 = create(:poll_shift, :recount_scrutiny_task, officer: officer, booth: booth, date: Time.zone.tomorrow)
vote_collection_dates = (Date.current..poll.ends_at.to_date).to_a vote_collection_dates = (Date.current..poll.ends_at.to_date).to_a
.reject { |date| date == Time.zone.today } .reject { |date| date == Time.zone.today }
.map { |date| I18n.l(date, format: :long) } .map { |date| I18n.l(date, format: :long) }
recount_scrutiny_dates = (poll.ends_at.to_date..poll.ends_at.to_date + 1.week).to_a recount_scrutiny_dates = (poll.ends_at.to_date..poll.ends_at.to_date + 1.week).to_a
.reject { |date| date == Time.zone.tomorrow } .reject { |date| date == Time.zone.tomorrow }
.map { |date| I18n.l(date, format: :long) } .map { |date| I18n.l(date, format: :long) }
visit available_admin_booths_path visit available_admin_booths_path

View File

@@ -87,7 +87,6 @@ feature 'Admin settings' do
expect(page).to have_content "Map configuration updated succesfully" expect(page).to have_content "Map configuration updated succesfully"
end end
end end
end end

View File

@@ -21,7 +21,7 @@ feature 'Commenting polls' do
end end
scenario 'Show' do scenario 'Show' do
skip "Feature not implemented yet, review soon" skip "Feature not implemented yet, review soon"
parent_comment = create(:comment, commentable: poll) parent_comment = create(:comment, commentable: poll)
first_child = create(:comment, commentable: poll, parent: parent_comment) first_child = create(:comment, commentable: poll, parent: parent_comment)
@@ -243,7 +243,7 @@ feature 'Commenting polls' do
end end
scenario "Flagging as inappropriate", :js do scenario "Flagging as inappropriate", :js do
skip "Feature not implemented yet, review soon" skip "Feature not implemented yet, review soon"
comment = create(:comment, commentable: poll) comment = create(:comment, commentable: poll)
@@ -261,7 +261,7 @@ feature 'Commenting polls' do
end end
scenario "Undoing flagging as inappropriate", :js do scenario "Undoing flagging as inappropriate", :js do
skip "Feature not implemented yet, review soon" skip "Feature not implemented yet, review soon"
comment = create(:comment, commentable: poll) comment = create(:comment, commentable: poll)
Flag.flag(user, comment) Flag.flag(user, comment)
@@ -280,7 +280,7 @@ feature 'Commenting polls' do
end end
scenario "Flagging turbolinks sanity check", :js do scenario "Flagging turbolinks sanity check", :js do
skip "Feature not implemented yet, review soon" skip "Feature not implemented yet, review soon"
poll = create(:poll, title: "Should we change the world?") poll = create(:poll, title: "Should we change the world?")
comment = create(:comment, commentable: poll) comment = create(:comment, commentable: poll)
@@ -310,7 +310,7 @@ feature 'Commenting polls' do
feature "Moderators" do feature "Moderators" do
scenario "can create comment as a moderator", :js do scenario "can create comment as a moderator", :js do
skip "Feature not implemented yet, review soon" skip "Feature not implemented yet, review soon"
moderator = create(:moderator) moderator = create(:moderator)
@@ -330,7 +330,7 @@ feature 'Commenting polls' do
end end
scenario "can create reply as a moderator", :js do scenario "can create reply as a moderator", :js do
skip "Feature not implemented yet, review soon" skip "Feature not implemented yet, review soon"
citizen = create(:user, username: "Ana") citizen = create(:user, username: "Ana")
manuela = create(:user, username: "Manuela") manuela = create(:user, username: "Manuela")
@@ -359,7 +359,7 @@ feature 'Commenting polls' do
end end
scenario "can not comment as an administrator" do scenario "can not comment as an administrator" do
skip "Feature not implemented yet, review soon" skip "Feature not implemented yet, review soon"
moderator = create(:moderator) moderator = create(:moderator)
@@ -372,7 +372,7 @@ feature 'Commenting polls' do
feature "Administrators" do feature "Administrators" do
scenario "can create comment as an administrator", :js do scenario "can create comment as an administrator", :js do
skip "Feature not implemented yet, review soon" skip "Feature not implemented yet, review soon"
admin = create(:administrator) admin = create(:administrator)
@@ -392,7 +392,7 @@ feature 'Commenting polls' do
end end
scenario "can create reply as an administrator", :js do scenario "can create reply as an administrator", :js do
skip "Feature not implemented yet, review soon" skip "Feature not implemented yet, review soon"
citizen = create(:user, username: "Ana") citizen = create(:user, username: "Ana")
manuela = create(:user, username: "Manuela") manuela = create(:user, username: "Manuela")
@@ -421,7 +421,7 @@ feature 'Commenting polls' do
end end
scenario "can not comment as a moderator" do scenario "can not comment as a moderator" do
skip "Feature not implemented yet, review soon" skip "Feature not implemented yet, review soon"
admin = create(:administrator) admin = create(:administrator)

View File

@@ -394,7 +394,7 @@ feature 'Debates' do
end end
scenario 'Debates are ordered by recommendations when there is a user logged', :js do scenario 'Debates are ordered by recommendations when there is a user logged', :js do
proposal = create(:proposal, tag_list: "Sport" ) proposal = create(:proposal, tag_list: "Sport")
user = create(:user) user = create(:user)
create(:follow, followable: proposal, user: user) create(:follow, followable: proposal, user: user)
login_as(user) login_as(user)
@@ -830,7 +830,7 @@ feature 'Debates' do
debate2 = create(:debate, title: "Show what you got", cached_votes_total: 1, tag_list: "Sport") debate2 = create(:debate, title: "Show what you got", cached_votes_total: 1, tag_list: "Sport")
debate3 = create(:debate, title: "Do not display with same tag", cached_votes_total: 100, tag_list: "Sport") debate3 = create(:debate, title: "Do not display with same tag", cached_votes_total: 100, tag_list: "Sport")
debate4 = create(:debate, title: "Do not display", cached_votes_total: 1) debate4 = create(:debate, title: "Do not display", cached_votes_total: 1)
proposal1 = create(:proposal, tag_list: "Sport") proposal1 = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal1, user: user) create(:follow, followable: proposal1, user: user)
visit debates_path visit debates_path

View File

@@ -408,7 +408,6 @@ feature 'Emails' do
end end
expect(page).to have_content 'It will be done next week.' expect(page).to have_content 'It will be done next week.'
email = open_last_email email = open_last_email
expect(email).to have_subject('Someone has responded to your comment') expect(email).to have_subject('Someone has responded to your comment')
expect(email).to deliver_to(user1) expect(email).to deliver_to(user1)

View File

@@ -27,7 +27,7 @@ feature "Home" do
background do background do
Setting['feature.user.recommendations'] = true Setting['feature.user.recommendations'] = true
user = create(:user) user = create(:user)
proposal = create(:proposal, tag_list: "Sport" ) proposal = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal, user: user) create(:follow, followable: proposal, user: user)
login_as(user) login_as(user)
end end

View File

@@ -725,10 +725,10 @@ describe Debate do
end end
it "Should return debates ordered by cached_votes_total" do it "Should return debates ordered by cached_votes_total" do
debate1 = create(:debate, cached_votes_total: 1, tag_list: "Sport" ) debate1 = create(:debate, cached_votes_total: 1, tag_list: "Sport")
debate2 = create(:debate, cached_votes_total: 5, tag_list: "Sport" ) debate2 = create(:debate, cached_votes_total: 5, tag_list: "Sport")
debate3 = create(:debate, cached_votes_total: 10, tag_list: "Sport" ) debate3 = create(:debate, cached_votes_total: 10, tag_list: "Sport")
proposal = create(:proposal, tag_list: "Sport" ) proposal = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal, user: user) create(:follow, followable: proposal, user: user)
result = Debate.recommendations(user).sort_by_recommendations result = Debate.recommendations(user).sort_by_recommendations
@@ -741,7 +741,7 @@ describe Debate do
it "Should return debates related with user interests" do it "Should return debates related with user interests" do
debate1 = create(:debate, tag_list: "Sport") debate1 = create(:debate, tag_list: "Sport")
debate2 = create(:debate, tag_list: "Politics") debate2 = create(:debate, tag_list: "Politics")
proposal1 = create(:proposal, tag_list: "Sport") proposal1 = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal1, user: user) create(:follow, followable: proposal1, user: user)
result = Debate.recommendations(user) result = Debate.recommendations(user)
@@ -753,7 +753,7 @@ describe Debate do
it "Should not return debates when user is the author" do it "Should not return debates when user is the author" do
debate1 = create(:debate, author: user, tag_list: "Sport") debate1 = create(:debate, author: user, tag_list: "Sport")
debate2 = create(:debate, tag_list: "Sport") debate2 = create(:debate, tag_list: "Sport")
proposal = create(:proposal, tag_list: "Sport" ) proposal = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal, user: user) create(:follow, followable: proposal, user: user)
result = Debate.recommendations(user) result = Debate.recommendations(user)

View File

@@ -42,7 +42,7 @@ describe DirectUpload do
proposal_document_direct_upload.save_attachment proposal_document_direct_upload.save_attachment
expect(File.exists?(proposal_document_direct_upload.relation.attachment.path)).to eq(true) expect(File.exist?(proposal_document_direct_upload.relation.attachment.path)).to eq(true)
expect(proposal_document_direct_upload.relation.attachment.path).to include('cached_attachments') expect(proposal_document_direct_upload.relation.attachment.path).to include('cached_attachments')
end end
@@ -57,7 +57,7 @@ describe DirectUpload do
uploaded_path = proposal_document_direct_upload.relation.attachment.path uploaded_path = proposal_document_direct_upload.relation.attachment.path
proposal_document_direct_upload.destroy_attachment proposal_document_direct_upload.destroy_attachment
expect(File.exists?(uploaded_path)).to eq(false) expect(File.exist?(uploaded_path)).to eq(false)
end end
end end

View File

@@ -2,7 +2,7 @@ require 'rails_helper'
describe MapLocation do describe MapLocation do
let(:map_location) { build(:map_location, :proposal_map_location ) } let(:map_location) { build(:map_location, :proposal_map_location) }
it "should be valid" do it "should be valid" do
expect(map_location).to be_valid expect(map_location).to be_valid

View File

@@ -903,10 +903,10 @@ describe Proposal do
end end
it "Should return proposals ordered by cached_votes_up" do it "Should return proposals ordered by cached_votes_up" do
proposal1 = create(:proposal, cached_votes_up: 1, tag_list: "Sport" ) proposal1 = create(:proposal, cached_votes_up: 1, tag_list: "Sport")
proposal2 = create(:proposal, cached_votes_up: 5, tag_list: "Sport" ) proposal2 = create(:proposal, cached_votes_up: 5, tag_list: "Sport")
proposal3 = create(:proposal, cached_votes_up: 10, tag_list: "Sport" ) proposal3 = create(:proposal, cached_votes_up: 10, tag_list: "Sport")
proposal4 = create(:proposal, tag_list: "Sport" ) proposal4 = create(:proposal, tag_list: "Sport")
create(:follow, followable: proposal4, user: user) create(:follow, followable: proposal4, user: user)
result = Proposal.recommendations(user).sort_by_recommendations result = Proposal.recommendations(user).sort_by_recommendations

View File

@@ -2,7 +2,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
include ActionView::Helpers include ActionView::Helpers
let!(:user) { create(:user, :level_two) } let!(:user) { create(:user, :level_two) }
before do before do
Setting['feature.map'] = true Setting['feature.map'] = true
@@ -11,7 +11,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
describe "At #{mappable_new_path}" do describe "At #{mappable_new_path}" do
let!(:arguments) { {} } let!(:arguments) { {} }
let!(:mappable) { create("#{mappable_factory_name}".to_sym) } let!(:mappable) { create(mappable_factory_name.to_s.to_sym) }
let!(:map_location) { create(:map_location, "#{mappable_factory_name}_map_location".to_sym, "#{mappable_association_name}": mappable) } let!(:map_location) { create(:map_location, "#{mappable_factory_name}_map_location".to_sym, "#{mappable_association_name}": mappable) }
before { set_arguments(arguments, mappable, mappable_path_arguments) } before { set_arguments(arguments, mappable, mappable_path_arguments) }
@@ -77,10 +77,10 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
describe "At #{mappable_edit_path}" do describe "At #{mappable_edit_path}" do
let!(:mappable) { create("#{mappable_factory_name}".to_sym) } let!(:mappable) { create(mappable_factory_name.to_s.to_sym) }
let!(:map_location) { create(:map_location, "#{mappable_factory_name}_map_location".to_sym, "#{mappable_association_name}": mappable) } let!(:map_location) { create(:map_location, "#{mappable_factory_name}_map_location".to_sym, "#{mappable_association_name}": mappable) }
before { skip } unless mappable_edit_path.present? before { skip } if mappable_edit_path.blank?
scenario "Should edit map on #{mappable_factory_name} and contain default values", :js do scenario "Should edit map on #{mappable_factory_name} and contain default values", :js do
login_as mappable.author login_as mappable.author
@@ -143,13 +143,13 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
describe "At #{mappable_show_path}" do describe "At #{mappable_show_path}" do
let!(:arguments) { {} } let!(:arguments) { {} }
let!(:mappable) { create("#{mappable_factory_name}".to_sym) } let!(:mappable) { create(mappable_factory_name.to_s.to_sym) }
let!(:map_location) { create(:map_location, "#{mappable_factory_name}_map_location".to_sym, "#{mappable_association_name}": mappable) } let!(:map_location) { create(:map_location, "#{mappable_factory_name}_map_location".to_sym, "#{mappable_association_name}": mappable) }
before { set_arguments(arguments, mappable, mappable_path_arguments) } before { set_arguments(arguments, mappable, mappable_path_arguments) }
scenario "Should display map on #{mappable_factory_name} show page", :js do scenario "Should display map on #{mappable_factory_name} show page", :js do
arguments.merge!("id": mappable.id) arguments[:id] = mappable.id
visit send(mappable_show_path, arguments) visit send(mappable_show_path, arguments)
@@ -157,9 +157,9 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end end
scenario "Should not display map on #{mappable_factory_name} show when marker is not defined", :js do scenario "Should not display map on #{mappable_factory_name} show when marker is not defined", :js do
mappable_without_map = create("#{mappable_factory_name}".to_sym) mappable_without_map = create(mappable_factory_name.to_s.to_sym)
set_arguments(arguments, mappable_without_map, mappable_path_arguments) set_arguments(arguments, mappable_without_map, mappable_path_arguments)
arguments.merge!("id": mappable_without_map.id) arguments[:id] = mappable_without_map.id
visit send(mappable_show_path, arguments) visit send(mappable_show_path, arguments)
@@ -168,7 +168,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
scenario "Should not display map on #{mappable_factory_name} show page when feature.map is disable", :js do scenario "Should not display map on #{mappable_factory_name} show page when feature.map is disable", :js do
Setting['feature.map'] = false Setting['feature.map'] = false
arguments.merge!("id": mappable.id) arguments[:id] = mappable.id
visit send(mappable_show_path, arguments) visit send(mappable_show_path, arguments)
@@ -212,9 +212,7 @@ def submit_budget_investment_form
end end
def set_arguments(arguments, mappable, mappable_path_arguments) def set_arguments(arguments, mappable, mappable_path_arguments)
if mappable_path_arguments mappable_path_arguments&.each do |argument_name, path_to_value|
mappable_path_arguments.each do |argument_name, path_to_value|
arguments.merge!("#{argument_name}": mappable.send(path_to_value)) arguments.merge!("#{argument_name}": mappable.send(path_to_value))
end
end end
end end

View File

@@ -199,8 +199,8 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
find("#tab-documents-label").click find("#tab-documents-label").click
expect(page).to have_content "empty.pdf" expect(page).to have_content "empty.pdf"
#Review # Review
#Doble check why the file is stored with a name different to empty.pdf # Doble check why the file is stored with a name different to empty.pdf
expect(page).to have_css("a[href$='.pdf']") expect(page).to have_css("a[href$='.pdf']")
end end

View File

@@ -1,4 +1,4 @@
shared_examples "nested imageable" do |imageable_factory_name, path, imageable_path_arguments, fill_resource_method_name, submit_button, imageable_success_notice, has_many_images=false| shared_examples "nested imageable" do |imageable_factory_name, path, imageable_path_arguments, fill_resource_method_name, submit_button, imageable_success_notice, has_many_images = false|
include ActionView::Helpers include ActionView::Helpers
include ImagesHelper include ImagesHelper
include ImageablesHelper include ImageablesHelper
@@ -9,15 +9,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
let!(:imageable) { create(imageable_factory_name) } let!(:imageable) { create(imageable_factory_name) }
before do before do
if imageable_path_arguments imageable_path_arguments&.each do |argument_name, path_to_value|
imageable_path_arguments.each do |argument_name, path_to_value|
arguments.merge!("#{argument_name}": imageable.send(path_to_value)) arguments.merge!("#{argument_name}": imageable.send(path_to_value))
end
end end
if imageable.respond_to?(:author) imageable.update(author: user) if imageable.respond_to?(:author)
imageable.update(author: user)
end
end end
describe "at #{path}" do describe "at #{path}" do
@@ -119,7 +115,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
click_on submit_button click_on submit_button
if has_many_images if has_many_images
#Pending. Review soon and test # Pending. Review soon and test
else else
within "#nested-image .image" do within "#nested-image .image" do
expect(page).to have_content("can't be blank", count: 2) expect(page).to have_content("can't be blank", count: 2)
@@ -174,7 +170,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
imageable_redirected_to_resource_show_or_navigate_to imageable_redirected_to_resource_show_or_navigate_to
if has_many_images if has_many_images
#Pending. Review soon and test # Pending. Review soon and test
else else
expect(page).to have_selector "figure img" expect(page).to have_selector "figure img"
expect(page).to have_selector "figure figcaption" expect(page).to have_selector "figure figcaption"
@@ -230,7 +226,7 @@ rescue
return return
end end
def imageable_attach_new_file(imageable_factory_name, path, success = true) def imageable_attach_new_file(_imageable_factory_name, path, success = true)
click_link "Add image" click_link "Add image"
within "#nested-image" do within "#nested-image" do
image = find(".image") image = find(".image")

View File

@@ -163,7 +163,7 @@ module CommonActions
expect(page).to have_content 'Document verified with Census' expect(page).to have_content 'Document verified with Census'
end end
def confirm_phone(user=nil) def confirm_phone(user = nil)
user ||= User.last user ||= User.last
fill_in 'sms_phone', with: "611111111" fill_in 'sms_phone', with: "611111111"