From f3c2adfa455aae07fca2dc44a4965a0276ac16d1 Mon Sep 17 00:00:00 2001 From: rhymes Date: Tue, 18 Feb 2020 17:21:42 +0100 Subject: [PATCH] Routine rubocop fixes (#6138) --- .rubocop_todo.yml | 12 ++++++------ config/environments/development.rb | 15 +-------------- config/initializers/docker.rb | 13 +++++++++++++ db/seeds.rb | 2 +- lib/tasks/fetch.rake | 2 +- spec/factories/users.rb | 1 - ...ndex_existing_articles_with_approved_spec.rb} | 0 spec/requests/api/v0/chat_channels_spec.rb | 16 ++++++---------- spec/requests/classified_listings_spec.rb | 2 +- spec/requests/internal/configs_spec.rb | 3 +++ .../comment_hide_or_unhide_request.rb | 2 -- spec/requests/user/user_profile_spec.rb | 8 -------- spec/services/articles/creator_spec.rb | 2 +- spec/support/api_analytics_shared_examples.rb | 2 +- 14 files changed, 34 insertions(+), 46 deletions(-) create mode 100644 config/initializers/docker.rb rename spec/lib/data_update_scripts/{re_index_existing_articles_spec.rb => re_index_existing_articles_with_approved_spec.rb} (100%) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 74b9d27f5..b08d81982 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -7,17 +7,17 @@ require: # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-01-27 18:38:25 +0100 using RuboCop version 0.79.0. +# on 2020-02-18 09:06:00 +0100 using RuboCop version 0.79.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 236 +# Offense count: 241 Metrics/AbcSize: Max: 75 -# Offense count: 13 +# Offense count: 10 # Configuration parameters: CountComments, ExcludedMethods. # ExcludedMethods: refine Metrics/BlockLength: @@ -33,7 +33,7 @@ RSpec/ExampleLength: - 'spec/requests/api/v0/articles_spec.rb' - 'spec/requests/display_ad_events_spec.rb' -# Offense count: 500 +# Offense count: 559 # Configuration parameters: AggregateFailuresByDefault. RSpec/MultipleExpectations: Max: 8 @@ -63,7 +63,7 @@ Rails/OutputSafety: - 'app/models/message.rb' - 'app/views/articles/feed.rss.builder' -# Offense count: 26 +# Offense count: 27 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle. # SupportedStyles: nested, compact @@ -76,7 +76,7 @@ Style/GuardClause: Exclude: - 'app/models/article.rb' -# Offense count: 3566 +# Offense count: 3757 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https diff --git a/config/environments/development.rb b/config/environments/development.rb index 0d45dbba3..e68f2a40c 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -96,8 +96,8 @@ Rails.application.configure do # Debug is the default log_level, but can be changed per environment. config.log_level = :debug - # See for other config options config.after_initialize do + # See for other Bullet config options Bullet.enable = true Bullet.add_footer = true @@ -117,19 +117,6 @@ Rails.application.configure do end end end - - # Docker specific development configuration - if File.file?("/.dockerenv") - # Using shell tools so we don't need to require Socket and IPAddr - host_ip = `/sbin/ip route|awk '/default/ { print $3 }'`.strip - logger = Logger.new(STDOUT) - logger.info "Whitelisting #{host_ip} for BetterErrors and Web Console" - - if defined?(BetterErrors::Middleware) - BetterErrors::Middleware.allow_ip!(host_ip) - end - config.web_console.whitelisted_ips << host_ip - end end Rails.application.routes.default_url_options = { host: Rails.application.config.app_domain } diff --git a/config/initializers/docker.rb b/config/initializers/docker.rb new file mode 100644 index 000000000..6bfa8ed2b --- /dev/null +++ b/config/initializers/docker.rb @@ -0,0 +1,13 @@ +# Docker specific development configuration +if Rails.env.development? && File.file?("/.dockerenv") + # Using shell tools so we don't need to require Socket and IPAddr + host_ip = `/sbin/ip route|awk '/default/ { print $3 }'`.strip + logger = Logger.new(STDOUT) + logger.info "Whitelisting #{host_ip} for BetterErrors and Web Console" + + if defined?(BetterErrors::Middleware) + BetterErrors::Middleware.allow_ip!(host_ip) + end + + Rails.application.config.web_console.whitelisted_ips << host_ip +end diff --git a/db/seeds.rb b/db/seeds.rb index de7da2c5d..9f3615120 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -96,7 +96,7 @@ num_articles.times do |i| markdown = <<~MARKDOWN --- - title: #{Faker::Book.title} #{Faker::Lorem.sentence(word_count: 2).chomp(".")} + title: #{Faker::Book.title} #{Faker::Lorem.sentence(word_count: 2).chomp('.')} published: true cover_image: #{Faker::Company.logo} tags: #{tags.join(', ')} diff --git a/lib/tasks/fetch.rake b/lib/tasks/fetch.rake index cd1810551..96782b5c7 100644 --- a/lib/tasks/fetch.rake +++ b/lib/tasks/fetch.rake @@ -2,7 +2,7 @@ desc "This task is called by the Heroku scheduler add-on" task get_podcast_episodes: :environment do Podcast.published.select(:id).find_each do |podcast| - Podcasts::GetEpisodesWorker.perform_async({ podcast_id: podcast.id, limit: 5 }) + Podcasts::GetEpisodesWorker.perform_async(podcast_id: podcast.id, limit: 5) end end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index e6851d3a0..cb0f8aaeb 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -57,7 +57,6 @@ FactoryBot.define do end end - trait :trusted do after(:build) { |user| user.add_role(:trusted) } end diff --git a/spec/lib/data_update_scripts/re_index_existing_articles_spec.rb b/spec/lib/data_update_scripts/re_index_existing_articles_with_approved_spec.rb similarity index 100% rename from spec/lib/data_update_scripts/re_index_existing_articles_spec.rb rename to spec/lib/data_update_scripts/re_index_existing_articles_with_approved_spec.rb diff --git a/spec/requests/api/v0/chat_channels_spec.rb b/spec/requests/api/v0/chat_channels_spec.rb index 02cc7f83b..47c21306a 100644 --- a/spec/requests/api/v0/chat_channels_spec.rb +++ b/spec/requests/api/v0/chat_channels_spec.rb @@ -41,10 +41,9 @@ RSpec.describe "Api::V0::ChatChannels", type: :request do get api_chat_channel_path(chat_channel.id) response_channel = response.parsed_body - expected_keys = %w[ - type_of id description channel_name username channel_users channel_mod_ids pending_users_select_fields - ] - expect(response_channel.keys).to match_array(expected_keys) + expect(response_channel.keys).to match_array( + %w[type_of id description channel_name username channel_users channel_mod_ids pending_users_select_fields], + ) %w[id description channel_name channel_mod_ids].each do |attr| expect(response_channel[attr]).to eq(chat_channel.public_send(attr)) @@ -57,17 +56,15 @@ RSpec.describe "Api::V0::ChatChannels", type: :request do it "returns the correct channel users representation" do get api_chat_channel_path(chat_channel.id) - response_channel = response.parsed_body - response_channel_users = response_channel["channel_users"] + response_channel_users = response.parsed_body["channel_users"] - membership = user.chat_channel_memberships.last expected_last_opened_at = Time.zone.parse(response_channel_users[user.username]["last_opened_at"]).to_i response_user = response_channel_users[user.username] expect(response_user["profile_image"]).to eq(ProfileImage.new(user).get(width: 90)) expect(response_user["darker_color"]).to eq(user.decorate.darker_color) expect(response_user["name"]).to eq(user.name) - expect(expected_last_opened_at).to eq(membership.last_opened_at.to_i) + expect(expected_last_opened_at).to eq(user.chat_channel_memberships.last.last_opened_at.to_i) expect(response_user["username"]).to eq(user.username) expect(response_user["id"]).to eq(user.id) end @@ -80,8 +77,7 @@ RSpec.describe "Api::V0::ChatChannels", type: :request do get api_chat_channel_path(chat_channel.id) - response_channel = response.parsed_body - response_pending_user_select_fields = response_channel["pending_users_select_fields"].first + response_pending_user_select_fields = response.parsed_body["pending_users_select_fields"].first expected_updated_at = Time.zone.parse(response_pending_user_select_fields["updated_at"]).to_i diff --git a/spec/requests/classified_listings_spec.rb b/spec/requests/classified_listings_spec.rb index 75f7dd69e..997734d5e 100644 --- a/spec/requests/classified_listings_spec.rb +++ b/spec/requests/classified_listings_spec.rb @@ -440,7 +440,7 @@ RSpec.describe "ClassifiedListings", type: :request do end end - context "when deleting org listing" do + context "when deleting draft org listing" do it "redirect to dashboard" do delete "/listings/#{org_listing_draft.id}" expect(response).to redirect_to("/listings/dashboard") diff --git a/spec/requests/internal/configs_spec.rb b/spec/requests/internal/configs_spec.rb index a5f2bbae6..b6645281e 100644 --- a/spec/requests/internal/configs_spec.rb +++ b/spec/requests/internal/configs_spec.rb @@ -16,6 +16,7 @@ RSpec.describe "/internal/config", type: :request do end end + # rubocop:disable RSpec/NestedGroups describe "POST internal/events" do context "when admin has typical admin permissions but not single resource" do before do @@ -37,6 +38,7 @@ RSpec.describe "/internal/config", type: :request do before do sign_in(admin_plus_config) end + describe "staff" do it "does not allow the staff_user_id to be updated" do expect(SiteConfig.staff_user_id).to eq(1) @@ -180,4 +182,5 @@ RSpec.describe "/internal/config", type: :request do end end end + # rubocop:enable RSpec/NestedGroups end diff --git a/spec/requests/shared_examples/comment_hide_or_unhide_request.rb b/spec/requests/shared_examples/comment_hide_or_unhide_request.rb index f62fb2be1..0c2f24e90 100644 --- a/spec/requests/shared_examples/comment_hide_or_unhide_request.rb +++ b/spec/requests/shared_examples/comment_hide_or_unhide_request.rb @@ -35,9 +35,7 @@ RSpec.shared_examples "PATCH /comments/:comment_id/hide or unhide" do |args| it "returns 200 on a good request" do expect(response).to have_http_status(:ok) end - end - context "when logged in as the commentable author" do it "displays having hidden comments if some unhidden" do sign_in commentable_author second_comment = create(:comment, commentable: article, user: commentable_author) diff --git a/spec/requests/user/user_profile_spec.rb b/spec/requests/user/user_profile_spec.rb index b15cf93d9..d2e36146e 100644 --- a/spec/requests/user/user_profile_spec.rb +++ b/spec/requests/user/user_profile_spec.rb @@ -123,14 +123,6 @@ RSpec.describe "UserProfiles", type: :request do end end - describe "GET /user" do - it "renders to appropriate page" do - user = create(:user) - get "/#{user.username}" - expect(response.body).to include CGI.escapeHTML(user.name) - end - end - describe "redirect to moderation" do it "redirects to admin" do user = create(:user) diff --git a/spec/services/articles/creator_spec.rb b/spec/services/articles/creator_spec.rb index f7098b435..becd52f28 100644 --- a/spec/services/articles/creator_spec.rb +++ b/spec/services/articles/creator_spec.rb @@ -47,7 +47,7 @@ RSpec.describe Articles::Creator, type: :service do end end - context "when valid attributes" do + context "when invalid attributes" do let(:invalid_attributes) { attributes_for(:article) } before do diff --git a/spec/support/api_analytics_shared_examples.rb b/spec/support/api_analytics_shared_examples.rb index 66df84dee..d9617a17c 100644 --- a/spec/support/api_analytics_shared_examples.rb +++ b/spec/support/api_analytics_shared_examples.rb @@ -23,7 +23,7 @@ RSpec.shared_examples "GET /api/analytics/:endpoint authorization examples" do | end context "when a valid token is given but the user is not a pro" do - before { get "/api/analytics/#{endpoint}?#{params}", headers: { "api-key" => "abadskajdlsak" } } + before { get "/api/analytics/#{endpoint}?#{params}", headers: { "api-key" => api_token.secret } } it "renders an error message: 'unauthorized' in JSON" do expect(JSON.parse(response.body)["error"]).to eq "unauthorized"