From deddb39e98059c7dc6aced6e8ddcafd6722b63fd Mon Sep 17 00:00:00 2001 From: Taketo Takashima Date: Tue, 10 Dec 2024 09:26:44 +0900 Subject: [PATCH] Fix rubocop --- Gemfile | 4 +-- app/controllers/messages_controller.rb | 4 +-- app/helpers/application_helper.rb | 10 +++--- config/environments/production.rb | 2 +- config/initializers/cors.rb | 2 +- config/initializers/locale.rb | 2 +- config/routes.rb | 2 +- spec/controllers/messages_controller_spec.rb | 36 +++++++++----------- spec/helpers/application_helper_spec.rb | 2 +- spec/requests/messages_spec.rb | 2 +- spec/routing/messages_routing_spec.rb | 19 +++++------ spec/spec_helper.rb | 8 ++--- spec/support/committee_helpers.rb | 2 +- spec/views/messages/edit.html.slim_spec.rb | 5 ++- spec/views/messages/show.html.slim_spec.rb | 4 +-- 15 files changed, 50 insertions(+), 54 deletions(-) diff --git a/Gemfile b/Gemfile index ae2a29c..022f392 100644 --- a/Gemfile +++ b/Gemfile @@ -41,12 +41,12 @@ group :development, :test do gem "rubocop-rails-omakase", require: false end -#group :development do +# group :development do # gem "capistrano-ext" # gem "capistrano-rails" # gem "capistrano-rbenv" # gem "capistrano-bundler" -#end +# end group :development do # gem "web-console" diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index b085035..06d2120 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -1,5 +1,5 @@ class MessagesController < ApplicationController - before_action :set_message, only: [:show, :edit, :update] + before_action :set_message, only: [ :show, :edit, :update ] # GET /messages/1 # GET /messages/1.json @@ -15,7 +15,7 @@ def edit def update respond_to do |format| if @message.update(message_params) - format.html { redirect_to @message, notice: 'Message was successfully updated.' } + format.html { redirect_to @message, notice: "Message was successfully updated." } format.json { render :show, status: :ok, location: @message } else format.html { render :edit, status: :unprocessable_entity } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c71ee5a..3fbc5ec 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,6 +1,6 @@ module ApplicationHelper def full_title(page_title = nil) - base_title = t('common.site_title') + base_title = t("common.site_title") if page_title.blank? base_title @@ -20,12 +20,12 @@ def hbr(str) def datetime_view(datetime) return nil if datetime.blank? - datetime.strftime(t('time.formats.default')) + datetime.strftime(t("time.formats.default")) end def date_view(date) return nil if date.blank? - date.strftime(t('date.formats.default')) + date.strftime(t("date.formats.default")) end # Public: Pick the correct arguments for form_for when shallow routes are used. @@ -33,10 +33,10 @@ def date_view(date) # parent - The Resource that has_* child # child - The Resource that belongs_to parent. def shallow_args(parent, child) - child.new_record? ? [parent, child] : child + child.new_record? ? [ parent, child ] : child end def shallow_deep_args(parent, child, grandchild) - grandchild.new_record? ? [parent, child, grandchild] : grandchild + grandchild.new_record? ? [ parent, child, grandchild ] : grandchild end end diff --git a/config/environments/production.rb b/config/environments/production.rb index 663f1eb..e1ff3f2 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -57,7 +57,7 @@ # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } # Log to STDOUT by default - #config.logger = ActiveSupport::Logger.new(STDOUT) + # config.logger = ActiveSupport::Logger.new(STDOUT) # .tap { |logger| logger.formatter = ::Logger::Formatter.new } # .then { |logger| ActiveSupport::TaggedLogging.new(logger) } diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb index 9fbee22..835d425 100644 --- a/config/initializers/cors.rb +++ b/config/initializers/cors.rb @@ -11,6 +11,6 @@ resource "*", headers: :any, - methods: [:get, :post, :put, :patch, :delete, :options, :head] + methods: [ :get, :post, :put, :patch, :delete, :options, :head ] end end diff --git a/config/initializers/locale.rb b/config/initializers/locale.rb index 9a46361..4c2868a 100644 --- a/config/initializers/locale.rb +++ b/config/initializers/locale.rb @@ -1,5 +1,5 @@ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de -Rails.application.config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s] +Rails.application.config.i18n.load_path += Dir[Rails.root.join("config", "locales", "*.{rb,yml}").to_s] Rails.application.config.i18n.default_locale = :ja diff --git a/config/routes.rb b/config/routes.rb index 39ba12a..d861f07 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do - root to: 'messages#show', id: '1' + root to: "messages#show", id: "1" resources :messages, only: [ :show, :edit, :update ] diff --git a/spec/controllers/messages_controller_spec.rb b/spec/controllers/messages_controller_spec.rb index 1536b5b..c987dfe 100644 --- a/spec/controllers/messages_controller_spec.rb +++ b/spec/controllers/messages_controller_spec.rb @@ -18,8 +18,7 @@ # Message expectations are only used when there is no simpler way to specify # that an instance is receiving a specific message. -RSpec.describe MessagesController, :type => :controller do - +RSpec.describe MessagesController, type: :controller do # This should return the minimal set of attributes required to create a valid # Message. As you add validations to Message, be sure to # adjust the attributes here as well. @@ -60,37 +59,36 @@ it "updates the requested message" do message = Message.create! valid_attributes - process :update, method: :put, params: { id: message.to_param, :message => new_attributes }, session: valid_session + process :update, method: :put, params: { id: message.to_param, message: new_attributes }, session: valid_session message.reload expect(message.body).to eq new_attributes[:body] end it "assigns the requested message as @message" do message = Message.create! valid_attributes - process :update, method: :put, params: { id: message.to_param, :message => valid_attributes }, session: valid_session + process :update, method: :put, params: { id: message.to_param, message: valid_attributes }, session: valid_session expect(assigns(:message)).to eq(message) end it "redirects to the message" do message = Message.create! valid_attributes - process :update, method: :put, params: { id: message.to_param, :message => valid_attributes }, session: valid_session + process :update, method: :put, params: { id: message.to_param, message: valid_attributes }, session: valid_session expect(response).to redirect_to(message) end end -# describe "with invalid params" do -# it "assigns the message as @message" do -# message = Message.create! valid_attributes -# process :update, method: :put, params: { id: message.to_param, :message => invalid_attributes }, session: valid_session -# expect(assigns(:message)).to eq(message) -# end -# -# it "re-renders the 'edit' template" do -# message = Message.create! valid_attributes -# process :update, method: :put, params: { id: message.to_param, :message => invalid_attributes }, session: valid_session -# expect(response).to render_template("edit") -# end -# end + # describe "with invalid params" do + # it "assigns the message as @message" do + # message = Message.create! valid_attributes + # process :update, method: :put, params: { id: message.to_param, :message => invalid_attributes }, session: valid_session + # expect(assigns(:message)).to eq(message) + # end + # + # it "re-renders the 'edit' template" do + # message = Message.create! valid_attributes + # process :update, method: :put, params: { id: message.to_param, :message => invalid_attributes }, session: valid_session + # expect(response).to render_template("edit") + # end + # end end - end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 8d6e71a..43b82c3 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -10,7 +10,7 @@ # end # end # end -RSpec.describe ApplicationHelper, :type => :helper do +RSpec.describe ApplicationHelper, type: :helper do describe "nl2br" do it "replace line break to br tag" do str = "hoge\nhoge" diff --git a/spec/requests/messages_spec.rb b/spec/requests/messages_spec.rb index 1191612..436d878 100644 --- a/spec/requests/messages_spec.rb +++ b/spec/requests/messages_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe "Messages", :type => :request do +RSpec.describe "Messages", type: :request do before(:each) do @message = FactoryBot.create(:message) end diff --git a/spec/routing/messages_routing_spec.rb b/spec/routing/messages_routing_spec.rb index e66a0db..d441609 100644 --- a/spec/routing/messages_routing_spec.rb +++ b/spec/routing/messages_routing_spec.rb @@ -1,39 +1,38 @@ require "rails_helper" -RSpec.describe MessagesController, :type => :routing do +RSpec.describe MessagesController, type: :routing do describe "routing" do - it "routes to root" do - expect(:get => "/").to route_to("messages#show", id: "1") + expect(get: "/").to route_to("messages#show", id: "1") end it "routes to #show" do - expect(:get => "/messages/1").to route_to("messages#show", :id => "1") + expect(get: "/messages/1").to route_to("messages#show", id: "1") end it "routes to #edit" do - expect(:get => "/messages/1/edit").to route_to("messages#edit", :id => "1") + expect(get: "/messages/1/edit").to route_to("messages#edit", id: "1") end it "routes to #update" do - expect(:put => "/messages/1").to route_to("messages#update", :id => "1") + expect(put: "/messages/1").to route_to("messages#update", id: "1") end context "not exist" do it "routes to #create" do - expect(:post => "/messages").not_to route_to("messages#create") + expect(post: "/messages").not_to route_to("messages#create") end it "routes to #index" do - expect(:get => "/messages").not_to route_to("messages#index") + expect(get: "/messages").not_to route_to("messages#index") end it "routes to #new" do - expect(:get => "/messages/new").not_to route_to("messages#new") + expect(get: "/messages/new").not_to route_to("messages#new") end it "routes to #destroy" do - expect(:delete => "/messages/1").not_to route_to("messages#destroy", :id => "1") + expect(delete: "/messages/1").not_to route_to("messages#destroy", id: "1") end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 089dd29..bf34f28 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -44,8 +44,8 @@ # triggering implicit auto-inclusion in groups with matching metadata. config.shared_context_metadata_behavior = :apply_to_host_groups -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. # This allows you to limit a spec run to individual examples or groups # you care about by tagging them with `:focus` metadata. When nothing @@ -57,7 +57,7 @@ # Allows RSpec to persist some state between runs in order to support # the `--only-failures` and `--next-failure` CLI options. We recommend # you configure your source control system to ignore this file. -# config.example_status_persistence_file_path = "spec/examples.txt" + # config.example_status_persistence_file_path = "spec/examples.txt" # Limits the available syntax to the non-monkey patched syntax that is # recommended. For more details, see: @@ -77,7 +77,7 @@ # Print the 10 slowest examples and example groups at the # end of the spec run, to help surface which specs are running # particularly slow. -# config.profile_examples = 10 + # config.profile_examples = 10 # Run specs in random order to surface order dependencies. If you find an # order dependency and want to debug it, you can fix the order by providing diff --git a/spec/support/committee_helpers.rb b/spec/support/committee_helpers.rb index 84463c7..b5aea86 100644 --- a/spec/support/committee_helpers.rb +++ b/spec/support/committee_helpers.rb @@ -4,7 +4,7 @@ schema_path: Rails.root.join('docs', 'api.yaml').to_s, query_hash_key: 'rack.request.query_hash', parse_response_by_content_type: false, - strict_reference_validation: false, + strict_reference_validation: false } include Committee::Rails::Test::Methods diff --git a/spec/views/messages/edit.html.slim_spec.rb b/spec/views/messages/edit.html.slim_spec.rb index 8808bf8..46784f7 100644 --- a/spec/views/messages/edit.html.slim_spec.rb +++ b/spec/views/messages/edit.html.slim_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' -RSpec.describe "messages/edit", :type => :view do +RSpec.describe "messages/edit", type: :view do before(:each) do @message = assign(:message, Message.create!( - :body => "MyText" + body: "MyText" )) end @@ -11,7 +11,6 @@ render assert_select "form[action=?][method=?]", message_path(@message), "post" do - assert_select "textarea#message_body[name=?]", "message[body]" end end diff --git a/spec/views/messages/show.html.slim_spec.rb b/spec/views/messages/show.html.slim_spec.rb index ee82947..7c14708 100644 --- a/spec/views/messages/show.html.slim_spec.rb +++ b/spec/views/messages/show.html.slim_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' -RSpec.describe "messages/show", :type => :view do +RSpec.describe "messages/show", type: :view do before(:each) do @message = assign(:message, Message.create!( - :body => "MyText" + body: "MyText" )) end