diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index cce880ed4..5103275fb 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -54,7 +54,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController end 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: [], image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) end diff --git a/app/controllers/admin/poll/questions/answers/images_controller.rb b/app/controllers/admin/poll/questions/answers/images_controller.rb index 1bf30907d..030e177a1 100644 --- a/app/controllers/admin/poll/questions/answers/images_controller.rb +++ b/app/controllers/admin/poll/questions/answers/images_controller.rb @@ -5,7 +5,7 @@ class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseContr end def new - @answer = ::Poll::Question::Answer.find(params[:answer_id]) + @answer = ::Poll::Question::Answer.find(params[:answer_id]) end def create diff --git a/app/controllers/admin/poll/questions/answers/videos_controller.rb b/app/controllers/admin/poll/questions/answers/videos_controller.rb index a231c1a20..e9262b6dd 100644 --- a/app/controllers/admin/poll/questions/answers/videos_controller.rb +++ b/app/controllers/admin/poll/questions/answers/videos_controller.rb @@ -33,11 +33,11 @@ class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseContr end def destroy - if @video.destroy - notice = t("flash.actions.destroy.poll_question_answer_video") - else - notice = t("flash.actions.destroy.error") - end + notice = if @video.destroy + t("flash.actions.destroy.poll_question_answer_video") + else + t("flash.actions.destroy.error") + end redirect_to :back, notice: notice end diff --git a/app/controllers/admin/poll/shifts_controller.rb b/app/controllers/admin/poll/shifts_controller.rb index 1f60b2b4e..89bb68999 100644 --- a/app/controllers/admin/poll/shifts_controller.rb +++ b/app/controllers/admin/poll/shifts_controller.rb @@ -49,7 +49,7 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController end 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]) end end diff --git a/app/controllers/direct_uploads_controller.rb b/app/controllers/direct_uploads_controller.rb index ade7d631f..a067a5d04 100644 --- a/app/controllers/direct_uploads_controller.rb +++ b/app/controllers/direct_uploads_controller.rb @@ -18,8 +18,7 @@ class DirectUploadsController < ApplicationController render json: { cached_attachment: @direct_upload.relation.cached_attachment, filename: @direct_upload.relation.attachment.original_filename, 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 @direct_upload.destroy_attachment render json: { errors: @direct_upload.errors[:attachment].join(", ") }, @@ -28,7 +27,7 @@ class DirectUploadsController < ApplicationController end 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 if @direct_upload.destroy_attachment diff --git a/app/helpers/documentables_helper.rb b/app/helpers/documentables_helper.rb index 8d9f85578..3fe56abd2 100644 --- a/app/helpers/documentables_helper.rb +++ b/app/helpers/documentables_helper.rb @@ -24,8 +24,8 @@ module DocumentablesHelper def documentable_humanized_accepted_content_types(documentable_class) documentable_class.accepted_content_types - .collect{ |content_type| content_type.split("/").last } - .join(", ") + .collect{ |content_type| content_type.split("/").last } + .join(", ") end def documentables_note(documentable) diff --git a/app/helpers/documents_helper.rb b/app/helpers/documents_helper.rb index d7e8d1dea..70eb6a27f 100644 --- a/app/helpers/documents_helper.rb +++ b/app/helpers/documents_helper.rb @@ -33,7 +33,7 @@ module DocumentsHelper def render_attachment(builder, document) 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, t("documents.form.attachment_label"), class: "button hollow #{klass}" diff --git a/app/helpers/imageables_helper.rb b/app/helpers/imageables_helper.rb index b1c8059ce..efe3c88ce 100644 --- a/app/helpers/imageables_helper.rb +++ b/app/helpers/imageables_helper.rb @@ -22,17 +22,17 @@ module ImageablesHelper def imageable_accepted_content_types_extensions Image::ACCEPTED_CONTENT_TYPE - .collect{ |content_type| ".#{content_type.split("/").last}" } - .join(",") + .collect{ |content_type| ".#{content_type.split('/').last}" } + .join(",") end def imageable_humanized_accepted_content_types Image::ACCEPTED_CONTENT_TYPE - .collect{ |content_type| content_type.split("/").last } - .join(", ") + .collect{ |content_type| content_type.split("/").last } + .join(", ") end - def imageables_note(imageable) + def imageables_note(_imageable) t "images.form.note", accepted_content_types: imageable_humanized_accepted_content_types, max_file_size: imageable_max_file_size end diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index dd4018be7..0d5b0a605 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -44,7 +44,7 @@ module PollsHelper def poll_voter_token(poll, user) Poll::Voter.where(poll: poll, user: user, origin: "web").first&.token || '' end - + def voted_before_sign_in(question) question.answers.where(author: current_user).any? { |vote| current_user.current_sign_in_at >= vote.updated_at } end diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index fe1c5f450..7b12c5d6f 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -46,12 +46,12 @@ module WelcomeHelper end def calculate_offset(debates, proposals, apply_offset) - if (debates.any? && proposals.any?) - if apply_offset - offset = "medium-offset-2 large-offset-2" - else - offset = "end" - end + if debates.any? && proposals.any? + offset = if apply_offset + "medium-offset-2 large-offset-2" + else + "end" + end end end diff --git a/app/models/concerns/followable.rb b/app/models/concerns/followable.rb index fee1ebd7f..d635cadda 100644 --- a/app/models/concerns/followable.rb +++ b/app/models/concerns/followable.rb @@ -5,7 +5,7 @@ module Followable has_many :follows, as: :followable, dependent: :destroy 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) } end diff --git a/app/models/debate.rb b/app/models/debate.rb index eb424c308..65c06345d 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -48,8 +48,8 @@ class Debate < ActiveRecord::Base attr_accessor :link_required def self.recommendations(user) - tagged_with(user.interests, any: true). - where("author_id != ?", user.id) + tagged_with(user.interests, any: true) + .where("author_id != ?", user.id) end def searchable_values diff --git a/app/models/direct_upload.rb b/app/models/direct_upload.rb index e597f9f12..6681aa7be 100644 --- a/app/models/direct_upload.rb +++ b/app/models/direct_upload.rb @@ -7,7 +7,7 @@ class DirectUpload :relation, :resource_relation, :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, 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?) @resource = @resource_type.constantize.find_or_initialize_by(id: @resource_id) - #Refactor - if @resource.respond_to?(:images) && - ((@attachment.present? && !@attachment.content_type.match(/pdf/)) || @cached_attachment.present?) - @relation = @resource.images.send("build", relation_attributtes) - elsif @resource.class.reflections[@resource_relation].macro == :has_one - @relation = @resource.send("build_#{resource_relation}", relation_attributtes) - else - @relation = @resource.send(@resource_relation).build(relation_attributtes) - end + # Refactor + @relation = if @resource.respond_to?(:images) && + ((@attachment.present? && !@attachment.content_type.match(/pdf/)) || @cached_attachment.present?) + @resource.images.send("build", relation_attributtes) + elsif @resource.class.reflections[@resource_relation].macro == :has_one + @resource.send("build_#{resource_relation}", relation_attributtes) + else + @resource.send(@resource_relation).build(relation_attributtes) + end @relation.user = user end @@ -50,7 +50,7 @@ class DirectUpload def parent_resource_attachment_validations @relation.valid? - if @relation.errors.has_key? :attachment + if @relation.errors.key? :attachment errors[:attachment] = @relation.errors[:attachment] end end diff --git a/app/models/document.rb b/app/models/document.rb index f680bc04e..8843bbed9 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -44,7 +44,7 @@ class Document < ActiveRecord::Base attachment.instance.prefix(attachment, style) end - def prefix(attachment, style) + def prefix(attachment, _style) if !attachment.instance.persisted? "cached_attachments/user/#{attachment.instance.user_id}" else diff --git a/app/models/image.rb b/app/models/image.rb index 84b38dd4a..99061f6f1 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -5,7 +5,7 @@ class Image < ActiveRecord::Base TITLE_LEGHT_RANGE = 4..80 MIN_SIZE = 475 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#" }, url: "/system/:class/:prefix/:style/:hash.:extension", @@ -52,7 +52,7 @@ class Image < ActiveRecord::Base attachment.instance.prefix(attachment, style) end - def prefix(attachment, style) + def prefix(attachment, _style) if !attachment.instance.persisted? "cached_attachments/user/#{attachment.instance.user_id}" else @@ -103,8 +103,8 @@ class Image < ActiveRecord::Base def remove_cached_attachment image = Image.new(imageable: imageable, - cached_attachment: cached_attachment, - user: user) + cached_attachment: cached_attachment, + user: user) image.set_attachment_from_cached_attachment image.attachment.destroy end diff --git a/app/models/poll/voter.rb b/app/models/poll/voter.rb index bc0118a88..778a5d88a 100644 --- a/app/models/poll/voter.rb +++ b/app/models/poll/voter.rb @@ -1,7 +1,7 @@ class Poll class Voter < ActiveRecord::Base - VALID_ORIGINS = %w{ web booth } + VALID_ORIGINS = %w{web booth}.freeze belongs_to :poll belongs_to :user diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 1a688ab30..3b0696d26 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -69,10 +69,10 @@ class Proposal < ActiveRecord::Base scope :public_for_api, -> { all } def self.recommendations(user) - tagged_with(user.interests, any: true). - where("author_id != ?", user.id). - unsuccessful. - not_followed_by_user(user) + tagged_with(user.interests, any: true) + .where("author_id != ?", user.id) + .unsuccessful + .not_followed_by_user(user) end def self.not_followed_by_user(user) diff --git a/spec/features/admin/poll/officer_assignments_spec.rb b/spec/features/admin/poll/officer_assignments_spec.rb index 20be138b9..48d10ad39 100644 --- a/spec/features/admin/poll/officer_assignments_spec.rb +++ b/spec/features/admin/poll/officer_assignments_spec.rb @@ -30,9 +30,9 @@ feature 'Officer Assignments' do expect(page).to have_content officer2.name expect(page).to_not have_content officer3.name end - end + end - scenario "Search", :js do + scenario "Search", :js do poll = create(:poll) booth = create(:poll_booth) @@ -62,7 +62,6 @@ feature 'Officer Assignments' do expect(page).to have_content officer2.name expect(page).to_not have_content officer3.name end - end - + end end \ No newline at end of file diff --git a/spec/features/admin/poll/shifts_spec.rb b/spec/features/admin/poll/shifts_spec.rb index 35df2e20e..bddd1b6b1 100644 --- a/spec/features/admin/poll/shifts_spec.rb +++ b/spec/features/admin/poll/shifts_spec.rb @@ -102,11 +102,11 @@ feature 'Admin shifts' do 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 - .reject { |date| date == Time.zone.today } - .map { |date| I18n.l(date, format: :long) } + .reject { |date| date == Time.zone.today } + .map { |date| I18n.l(date, format: :long) } recount_scrutiny_dates = (poll.ends_at.to_date..poll.ends_at.to_date + 1.week).to_a - .reject { |date| date == Time.zone.tomorrow } - .map { |date| I18n.l(date, format: :long) } + .reject { |date| date == Time.zone.tomorrow } + .map { |date| I18n.l(date, format: :long) } visit available_admin_booths_path diff --git a/spec/features/admin/settings_spec.rb b/spec/features/admin/settings_spec.rb index 73d190cb9..40baf6423 100644 --- a/spec/features/admin/settings_spec.rb +++ b/spec/features/admin/settings_spec.rb @@ -87,7 +87,6 @@ feature 'Admin settings' do expect(page).to have_content "Map configuration updated succesfully" end - end end diff --git a/spec/features/comments/polls_spec.rb b/spec/features/comments/polls_spec.rb index 8ef528cd3..0fe01cf06 100644 --- a/spec/features/comments/polls_spec.rb +++ b/spec/features/comments/polls_spec.rb @@ -21,7 +21,7 @@ feature 'Commenting polls' do end scenario 'Show' do - skip "Feature not implemented yet, review soon" + skip "Feature not implemented yet, review soon" parent_comment = create(:comment, commentable: poll) first_child = create(:comment, commentable: poll, parent: parent_comment) @@ -243,7 +243,7 @@ feature 'Commenting polls' do end 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) @@ -261,7 +261,7 @@ feature 'Commenting polls' do end 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) Flag.flag(user, comment) @@ -280,7 +280,7 @@ feature 'Commenting polls' do end 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?") comment = create(:comment, commentable: poll) @@ -310,7 +310,7 @@ feature 'Commenting polls' do feature "Moderators" 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) @@ -330,7 +330,7 @@ feature 'Commenting polls' do end 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") manuela = create(:user, username: "Manuela") @@ -359,7 +359,7 @@ feature 'Commenting polls' do end 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) @@ -372,7 +372,7 @@ feature 'Commenting polls' do feature "Administrators" 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) @@ -392,7 +392,7 @@ feature 'Commenting polls' do end 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") manuela = create(:user, username: "Manuela") @@ -421,7 +421,7 @@ feature 'Commenting polls' do end 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) diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 3d7c6acf8..39cd84760 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -394,7 +394,7 @@ feature 'Debates' do end 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) create(:follow, followable: proposal, user: 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") 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) - proposal1 = create(:proposal, tag_list: "Sport") + proposal1 = create(:proposal, tag_list: "Sport") create(:follow, followable: proposal1, user: user) visit debates_path diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index a26e8ce11..74b608ed6 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -408,7 +408,6 @@ feature 'Emails' do end expect(page).to have_content 'It will be done next week.' - email = open_last_email expect(email).to have_subject('Someone has responded to your comment') expect(email).to deliver_to(user1) diff --git a/spec/features/home_spec.rb b/spec/features/home_spec.rb index cb5349814..4854fff4d 100644 --- a/spec/features/home_spec.rb +++ b/spec/features/home_spec.rb @@ -27,7 +27,7 @@ feature "Home" do background do Setting['feature.user.recommendations'] = true user = create(:user) - proposal = create(:proposal, tag_list: "Sport" ) + proposal = create(:proposal, tag_list: "Sport") create(:follow, followable: proposal, user: user) login_as(user) end diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index 64dbf729f..3e1278bd7 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -725,10 +725,10 @@ describe Debate do end it "Should return debates ordered by cached_votes_total" do - debate1 = create(:debate, cached_votes_total: 1, tag_list: "Sport" ) - debate2 = create(:debate, cached_votes_total: 5, tag_list: "Sport" ) - debate3 = create(:debate, cached_votes_total: 10, tag_list: "Sport" ) - proposal = create(:proposal, tag_list: "Sport" ) + debate1 = create(:debate, cached_votes_total: 1, tag_list: "Sport") + debate2 = create(:debate, cached_votes_total: 5, tag_list: "Sport") + debate3 = create(:debate, cached_votes_total: 10, tag_list: "Sport") + proposal = create(:proposal, tag_list: "Sport") create(:follow, followable: proposal, user: user) result = Debate.recommendations(user).sort_by_recommendations @@ -741,7 +741,7 @@ describe Debate do it "Should return debates related with user interests" do debate1 = create(:debate, tag_list: "Sport") debate2 = create(:debate, tag_list: "Politics") - proposal1 = create(:proposal, tag_list: "Sport") + proposal1 = create(:proposal, tag_list: "Sport") create(:follow, followable: proposal1, user: user) result = Debate.recommendations(user) @@ -753,7 +753,7 @@ describe Debate do it "Should not return debates when user is the author" do debate1 = create(:debate, author: user, 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) result = Debate.recommendations(user) diff --git a/spec/models/direct_upload_spec.rb b/spec/models/direct_upload_spec.rb index 5abe06765..8cfebf076 100644 --- a/spec/models/direct_upload_spec.rb +++ b/spec/models/direct_upload_spec.rb @@ -42,7 +42,7 @@ describe DirectUpload do 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') end @@ -57,7 +57,7 @@ describe DirectUpload do uploaded_path = proposal_document_direct_upload.relation.attachment.path proposal_document_direct_upload.destroy_attachment - expect(File.exists?(uploaded_path)).to eq(false) + expect(File.exist?(uploaded_path)).to eq(false) end end diff --git a/spec/models/map_location_spec.rb b/spec/models/map_location_spec.rb index bd093a71e..62070529e 100644 --- a/spec/models/map_location_spec.rb +++ b/spec/models/map_location_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' 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 expect(map_location).to be_valid diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index 588bd4057..29338a62f 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -903,10 +903,10 @@ describe Proposal do end it "Should return proposals ordered by cached_votes_up" do - proposal1 = create(:proposal, cached_votes_up: 1, tag_list: "Sport" ) - proposal2 = create(:proposal, cached_votes_up: 5, tag_list: "Sport" ) - proposal3 = create(:proposal, cached_votes_up: 10, tag_list: "Sport" ) - proposal4 = create(:proposal, tag_list: "Sport" ) + proposal1 = create(:proposal, cached_votes_up: 1, tag_list: "Sport") + proposal2 = create(:proposal, cached_votes_up: 5, tag_list: "Sport") + proposal3 = create(:proposal, cached_votes_up: 10, tag_list: "Sport") + proposal4 = create(:proposal, tag_list: "Sport") create(:follow, followable: proposal4, user: user) result = Proposal.recommendations(user).sort_by_recommendations diff --git a/spec/shared/features/mappable.rb b/spec/shared/features/mappable.rb index ccbcd5625..65ece1f25 100644 --- a/spec/shared/features/mappable.rb +++ b/spec/shared/features/mappable.rb @@ -2,7 +2,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, include ActionView::Helpers - let!(:user) { create(:user, :level_two) } + let!(:user) { create(:user, :level_two) } before do Setting['feature.map'] = true @@ -11,7 +11,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, describe "At #{mappable_new_path}" do 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) } 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 - 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) } - 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 login_as mappable.author @@ -143,13 +143,13 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, describe "At #{mappable_show_path}" do 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) } before { set_arguments(arguments, mappable, mappable_path_arguments) } 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) @@ -157,9 +157,9 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, end 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) - arguments.merge!("id": mappable_without_map.id) + arguments[:id] = mappable_without_map.id 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 Setting['feature.map'] = false - arguments.merge!("id": mappable.id) + arguments[:id] = mappable.id visit send(mappable_show_path, arguments) @@ -212,9 +212,7 @@ def submit_budget_investment_form end 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)) - end end end diff --git a/spec/shared/features/nested_documentable.rb b/spec/shared/features/nested_documentable.rb index 24d6631a8..3661af408 100644 --- a/spec/shared/features/nested_documentable.rb +++ b/spec/shared/features/nested_documentable.rb @@ -199,8 +199,8 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na find("#tab-documents-label").click expect(page).to have_content "empty.pdf" - #Review - #Doble check why the file is stored with a name different to empty.pdf + # Review + # Doble check why the file is stored with a name different to empty.pdf expect(page).to have_css("a[href$='.pdf']") end diff --git a/spec/shared/features/nested_imageable.rb b/spec/shared/features/nested_imageable.rb index 1eef9a269..947887afa 100644 --- a/spec/shared/features/nested_imageable.rb +++ b/spec/shared/features/nested_imageable.rb @@ -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 ImagesHelper include ImageablesHelper @@ -9,15 +9,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p let!(:imageable) { create(imageable_factory_name) } 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)) - end end - if imageable.respond_to?(:author) - imageable.update(author: user) - end + imageable.update(author: user) if imageable.respond_to?(:author) end describe "at #{path}" do @@ -119,7 +115,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p click_on submit_button if has_many_images - #Pending. Review soon and test + # Pending. Review soon and test else within "#nested-image .image" do 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 if has_many_images - #Pending. Review soon and test + # Pending. Review soon and test else expect(page).to have_selector "figure img" expect(page).to have_selector "figure figcaption" @@ -230,7 +226,7 @@ rescue return 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" within "#nested-image" do image = find(".image") diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index a55ebd63c..b87a54d8e 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -163,7 +163,7 @@ module CommonActions expect(page).to have_content 'Document verified with Census' end - def confirm_phone(user=nil) + def confirm_phone(user = nil) user ||= User.last fill_in 'sms_phone', with: "611111111"