From 0ef771c101416e218c9c2019a7afee7b33444c45 Mon Sep 17 00:00:00 2001 From: Nelly Simkova Date: Sun, 12 Nov 2023 15:22:25 +0300 Subject: [PATCH] Fix rubocop offences --- app/controllers/articles_controller.rb | 2 +- app/controllers/buildings_controller.rb | 2 +- app/controllers/monuments_controller.rb | 2 +- app/controllers/museums_controller.rb | 2 +- app/controllers/people_controller.rb | 2 +- spec/controllers/articles_controller_spec.rb | 24 ++++++++++---------- spec/helpers/application_helper_spec.rb | 4 +++- spec/rails_helper.rb | 2 +- 8 files changed, 21 insertions(+), 19 deletions(-) diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 4235507..43c5004 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -4,7 +4,7 @@ class ArticlesController < ApplicationController before_action :set_article, only: %i[show edit update destroy] def index - @pagy, @articles = pagy(Article.all.order(created_at: :desc), items: 8) + @pagy, @articles = pagy(Article.order(created_at: :desc), items: 8) end def show; end diff --git a/app/controllers/buildings_controller.rb b/app/controllers/buildings_controller.rb index eb8e8db..bcb50b5 100644 --- a/app/controllers/buildings_controller.rb +++ b/app/controllers/buildings_controller.rb @@ -4,7 +4,7 @@ class BuildingsController < ApplicationController before_action :set_building, only: %i[show edit update destroy] def index - @pagy, @buildings = pagy(Building.all.order(created_at: :desc), items: 8) + @pagy, @buildings = pagy(Building.order(created_at: :desc), items: 8) end def show; end diff --git a/app/controllers/monuments_controller.rb b/app/controllers/monuments_controller.rb index 08cb2e7..63dba40 100644 --- a/app/controllers/monuments_controller.rb +++ b/app/controllers/monuments_controller.rb @@ -4,7 +4,7 @@ class MonumentsController < ApplicationController before_action :set_monument, only: %i[show edit update destroy] def index - @pagy, @monuments = pagy(Monument.all.order(created_at: :desc), items: 8) + @pagy, @monuments = pagy(Monument.order(created_at: :desc), items: 8) end def show; end diff --git a/app/controllers/museums_controller.rb b/app/controllers/museums_controller.rb index 9ef84c6..b7df3d5 100644 --- a/app/controllers/museums_controller.rb +++ b/app/controllers/museums_controller.rb @@ -4,7 +4,7 @@ class MuseumsController < ApplicationController before_action :set_museum, only: %i[show edit update destroy] def index - @pagy, @museums = pagy(Museum.all.order(created_at: :desc), items: 8) + @pagy, @museums = pagy(Museum.order(created_at: :desc), items: 8) end def show; end diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index f84fc06..be74bc2 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -8,7 +8,7 @@ def index if params[:tag_id] @pagy, @people = pagy(Person.where(tag_id: params[:tag_id]).order(created_at: :desc), items: 8) else - @pagy, @people = pagy(Person.all.order(created_at: :desc), items: 8) + @pagy, @people = pagy(Person.order(created_at: :desc), items: 8) end end diff --git a/spec/controllers/articles_controller_spec.rb b/spec/controllers/articles_controller_spec.rb index 06e26e6..d8c830d 100644 --- a/spec/controllers/articles_controller_spec.rb +++ b/spec/controllers/articles_controller_spec.rb @@ -36,12 +36,12 @@ it 'creates a new article and redirects to the show page' do expect do post :create, params: { article: { name_ru: created_article.name_ru, - name_en: created_article.name_en, - name_be: created_article.name_be, - description_ru: created_article.description_ru, - description_en: created_article.description_en, - description_be: created_article.description_be, - images: [file] } } + name_en: created_article.name_en, + name_be: created_article.name_be, + description_ru: created_article.description_ru, + description_en: created_article.description_en, + description_be: created_article.description_be, + images: [file] } } end.to change(Article, :count).by(1) expect(response).to redirect_to(assigns(:article)) end @@ -49,8 +49,8 @@ it 'returns unprocessable_entity if article is not saved' do expect do post :create, params: { article: { name_ru: nil, - description_ru: nil, - images: file } } + description_ru: nil, + images: file } } end.not_to change(Article, :count).from(0) expect(response).to have_http_status(:unprocessable_entity) @@ -73,8 +73,8 @@ new_description = Faker::Lorem.characters(number: 40) patch :update, params: { id: saved_article.id, article: { name_ru: Faker::Lorem.characters(number: 40), - description_ru: new_description, - images: file } } + description_ru: new_description, + images: file } } expect(response).to redirect_to(assigns(:article)) saved_article.reload expect(saved_article.description_ru).to eq(new_description) @@ -82,8 +82,8 @@ it 'returns unprocessable entity if article is not updated' do patch :update, params: { id: saved_article.id, article: { name_ru: nil, - description_ru: nil, - images: file } } + description_ru: nil, + images: file } } expect(response).to have_http_status(:unprocessable_entity) expect(response).to render_template(:edit) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 6d61307..5003e46 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require_relative '../rails_helper' -RSpec.describe ApplicationHelper, type: :helper do +RSpec.describe ApplicationHelper do describe '#all_locales' do it 'returns all available locales' do expect(helper.all_locales).to eq(I18n.available_locales) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 1608640..dcc00ba 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -2,7 +2,7 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' require 'spec_helper' -require_relative './support/factory_bot' +require_relative 'support/factory_bot' require 'capybara/rspec' ENV['RAILS_ENV'] ||= 'test'