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

@@ -33,10 +33,10 @@ 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

@@ -22,7 +22,7 @@ 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
@@ -32,7 +32,7 @@ module ImageablesHelper
.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

@@ -46,11 +46,11 @@ 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,14 +19,14 @@ 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
@@ -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

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

@@ -64,5 +64,4 @@ feature 'Officer Assignments' do
end end
end end
end end

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

@@ -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)

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
@@ -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

@@ -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"