Rubocop fixes (#18461)
* Rubocop fixes * Fixed most Capybara/SpecificMatcher violations * Moved flash notice texts to locales
This commit is contained in:
parent
2ca01b0c9a
commit
455399bdba
30 changed files with 52 additions and 51 deletions
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
ignore([%r{^bin/*}, %r{^config/*}, %r{^db/*}, %r{^lib/*}, %r{^log/*}, %r{^public/*}, %r{^tmp/*}, %r{^node_modules/*}])
|
||||
|
||||
rspec_options = {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class PasswordsController < Devise::PasswordsController
|
|||
protected
|
||||
|
||||
def after_sending_reset_password_instructions_path_for(_resource_name)
|
||||
flash[:global_notice] = "Your password reset instructions have been sent."
|
||||
flash[:global_notice] = I18n.t("devise.passwords.reset_instructions_sent")
|
||||
session[:referrer]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -318,7 +318,7 @@ class StoriesController < ApplicationController
|
|||
end
|
||||
|
||||
def redirect_to_lowercase_username
|
||||
return unless params[:username] && params[:username]&.match?(/[[:upper:]]/)
|
||||
return unless params[:username]&.match?(/[[:upper:]]/)
|
||||
|
||||
redirect_permanently_to("/#{params[:username].downcase}")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ module Users
|
|||
authorize current_user, policy_class: UserPolicy
|
||||
|
||||
if current_user.notification_setting.update(users_notification_setting_params)
|
||||
flash[:settings_notice] = "Your notification settings have been updated."
|
||||
flash[:settings_notice] = I18n.t("users_controller.notifications_settings_updated")
|
||||
else
|
||||
Honeycomb.add_field("error", current_user.notification_setting.errors.messages.compact_blank)
|
||||
Honeycomb.add_field("errored", true)
|
||||
|
|
|
|||
|
|
@ -155,5 +155,5 @@ end
|
|||
# rubocop:enable Metrics/BlockLength
|
||||
|
||||
Rails.application.routes.default_url_options = {
|
||||
protocol: (ENV.fetch("APP_PROTOCOL", "http://")).delete_suffix("://")
|
||||
protocol: ENV.fetch("APP_PROTOCOL", "http://").delete_suffix("://")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,6 +117,7 @@ en:
|
|||
updated_config: Your config has been updated. Refresh to see all changes.
|
||||
updated_profile: Your profile was successfully updated.
|
||||
token_expired: Your token has expired, please request a new one. Tokens only last for 12 hours after account deletion is initiated.
|
||||
notifications_settings_updated: Your notifications settings have been updated.
|
||||
video_states_controller:
|
||||
related_article_not_found: Related article not found
|
||||
video_state_updated: Video state updated
|
||||
|
|
|
|||
|
|
@ -117,6 +117,7 @@ fr:
|
|||
updated_config: Your config has been updated. Refresh to see all changes.
|
||||
updated_profile: Your profile was successfully updated.
|
||||
token_expired: Your token has expired, please request a new one. Tokens only last for 12 hours after account deletion is initiated.
|
||||
notifications_settings_updated: Your notifications settings have been updated.
|
||||
video_states_controller:
|
||||
related_article_not_found: Related article not found
|
||||
video_state_updated: Video state updated
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ en:
|
|||
success: Successfully authenticated from %{kind} account.
|
||||
passwords:
|
||||
no_token: You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided.
|
||||
reset_instructions_sent: Your password reset instructions have been sent.
|
||||
send_instructions: You will receive an email with instructions on how to reset your password in a few minutes.
|
||||
send_paranoid_instructions: If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes.
|
||||
updated: Your password has been changed successfully. You are now signed in.
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ FactoryBot.define do
|
|||
published: #{published}
|
||||
tags: #{tags if with_tags}
|
||||
date: #{date if with_date}
|
||||
series: #{with_collection&.slug if with_collection}
|
||||
series: #{with_collection&.slug}
|
||||
canonical_url: #{canonical_url if with_canonical_url}
|
||||
#{"cover_image: #{Faker::Avatar.image}" if with_main_image && main_image_from_frontmatter}
|
||||
---
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ RSpec.describe Comments::CommunityWellnessQuery, type: :query do
|
|||
user6 = create(:user)
|
||||
|
||||
# Add 2 comments per week (including week 0) for `user6`
|
||||
(0..33).each do |i|
|
||||
34.times do |i|
|
||||
num_days_ago = (2 + (i * 7)).days.ago
|
||||
create_comment_time_ago(user6.id, num_days_ago, commentable: articles.sample)
|
||||
create_comment_time_ago(user6.id, num_days_ago, commentable: articles.sample)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ RSpec.describe "/admin/moderation/reports", type: :request do
|
|||
it "renders with status 200" do
|
||||
sign_in single_resource_admin
|
||||
get admin_reports_path
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ RSpec.describe "/admin/moderation/reports", type: :request do
|
|||
create(:reaction, category: "vomit", reactable: user, user: trusted_user)
|
||||
sign_in admin
|
||||
get admin_reports_path
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ RSpec.describe "NavigationLinks", type: :request do
|
|||
|
||||
it "returns a successful response" do
|
||||
get admin_navigation_links_path
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ RSpec.describe "/admin/moderations/privileged_reactions", type: :request do
|
|||
it "renders with status 200" do
|
||||
sign_in single_resource_admin
|
||||
get admin_moderator_actions_path
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -8,14 +8,14 @@ RSpec.describe "/admin/advanced/response_templates", type: :request do
|
|||
describe "GET /admin/advanced/response_templates" do
|
||||
it "renders with status 200" do
|
||||
get admin_response_templates_path
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
|
||||
context "when there are response templates to render" do
|
||||
it "renders with status 200" do
|
||||
create(:response_template)
|
||||
get admin_response_templates_path
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ RSpec.describe "/admin/advanced/response_templates", type: :request do
|
|||
it "renders with status 200" do
|
||||
sign_in single_resource_admin
|
||||
get admin_response_templates_path
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -33,7 +33,7 @@ RSpec.describe "/admin/advanced/response_templates", type: :request do
|
|||
describe "GET /admin/advanced/response_templates/new" do
|
||||
it "renders with status 200" do
|
||||
get admin_response_templates_path
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ RSpec.describe "/admin/advanced/secrets", type: :request do
|
|||
describe "GET /admin/advanced/secrets" do
|
||||
it "renders with status 200" do
|
||||
get admin_secrets_path
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
|
||||
it "displays an alert when Vault is not enabled" do
|
||||
|
|
@ -42,14 +42,14 @@ RSpec.describe "/admin/advanced/secrets", type: :request do
|
|||
it "successfully sets a secret and shows flash message" do
|
||||
allow(AppSecrets).to receive(:[]=)
|
||||
put admin_secrets_path, params: valid_params
|
||||
expect(response.status).to eq 302
|
||||
expect(response).to have_http_status :found
|
||||
expect(AppSecrets).to have_received(:[]=).with(valid_secret, "SECRET_VALUE")
|
||||
expect(flash[:success]).to include("Secret #{valid_secret} was successfully updated in Vault")
|
||||
end
|
||||
|
||||
it "returns a bad_request with invalid params" do
|
||||
put admin_secrets_path, params: {}
|
||||
expect(response.status).to eq 400
|
||||
expect(response).to have_http_status :bad_request
|
||||
end
|
||||
|
||||
it "creates an audit log" do
|
||||
|
|
|
|||
|
|
@ -27,14 +27,14 @@ RSpec.describe "/admin/content_manager/tags", type: :request do
|
|||
describe "GET /admin/content_manager/tags" do
|
||||
it "responds with 200 OK" do
|
||||
get admin_tags_path
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /admin/content_manager/tags/:id" do
|
||||
it "responds with 200 OK" do
|
||||
get edit_admin_tag_path(tag.id)
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@ RSpec.describe "HealthCheck", type: :request do
|
|||
it "returns an unauthorized request" do
|
||||
allow_any_instance_of(ActionDispatch::Request).to receive(:remote_addr).and_return("0.0.0.0") # rubocop:disable RSpec/AnyInstance
|
||||
get app_api_health_checks_path
|
||||
expect(response.status).to eq(401)
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/health_checks/app" do
|
||||
it "returns json success" do
|
||||
get app_api_health_checks_path, headers: headers
|
||||
expect(response.status).to eq(200)
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.parsed_body["message"]).to eq("App is up!")
|
||||
end
|
||||
end
|
||||
|
|
@ -25,14 +25,14 @@ RSpec.describe "HealthCheck", type: :request do
|
|||
describe "GET /api/health_checks/database" do
|
||||
it "returns json success if connection check succeeds" do
|
||||
get database_api_health_checks_path, headers: headers
|
||||
expect(response.status).to eq(200)
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.parsed_body["message"]).to eq("Database connected")
|
||||
end
|
||||
|
||||
it "returns json failure if connection check fails" do
|
||||
allow(ActiveRecord::Base).to receive(:connected?).and_return(false)
|
||||
get database_api_health_checks_path, headers: headers
|
||||
expect(response.status).to eq(500)
|
||||
expect(response).to have_http_status(:internal_server_error)
|
||||
expect(response.parsed_body["message"]).to eq("Database NOT connected!")
|
||||
end
|
||||
end
|
||||
|
|
@ -40,7 +40,7 @@ RSpec.describe "HealthCheck", type: :request do
|
|||
describe "GET /api/health_checks/cache" do
|
||||
it "returns json success if connection check succeeds" do
|
||||
get cache_api_health_checks_path, headers: headers
|
||||
expect(response.status).to eq(200)
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.parsed_body["message"]).to eq("Redis connected")
|
||||
end
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ RSpec.describe "HealthCheck", type: :request do
|
|||
allow(Redis).to receive(:new).and_return(redis_obj)
|
||||
allow(redis_obj).to receive(:ping).and_return("fail")
|
||||
get cache_api_health_checks_path, headers: headers
|
||||
expect(response.status).to eq(500)
|
||||
expect(response).to have_http_status(:internal_server_error)
|
||||
expect(response.parsed_body["message"]).to eq("Redis NOT connected!")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@ RSpec.describe "HealthCheck", type: :request do
|
|||
it "returns an unauthorized request" do
|
||||
allow_any_instance_of(ActionDispatch::Request).to receive(:remote_addr).and_return("0.0.0.0") # rubocop:disable RSpec/AnyInstance
|
||||
get app_api_health_checks_path
|
||||
expect(response.status).to eq(401)
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/health_checks/app" do
|
||||
it "returns json success" do
|
||||
get app_api_health_checks_path, headers: headers
|
||||
expect(response.status).to eq(200)
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.parsed_body["message"]).to eq("App is up!")
|
||||
end
|
||||
end
|
||||
|
|
@ -25,14 +25,14 @@ RSpec.describe "HealthCheck", type: :request do
|
|||
describe "GET /api/health_checks/database" do
|
||||
it "returns json success if connection check succeeds" do
|
||||
get database_api_health_checks_path, headers: headers
|
||||
expect(response.status).to eq(200)
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.parsed_body["message"]).to eq("Database connected")
|
||||
end
|
||||
|
||||
it "returns json failure if connection check fails" do
|
||||
allow(ActiveRecord::Base).to receive(:connected?).and_return(false)
|
||||
get database_api_health_checks_path, headers: headers
|
||||
expect(response.status).to eq(500)
|
||||
expect(response).to have_http_status(:internal_server_error)
|
||||
expect(response.parsed_body["message"]).to eq("Database NOT connected!")
|
||||
end
|
||||
end
|
||||
|
|
@ -40,7 +40,7 @@ RSpec.describe "HealthCheck", type: :request do
|
|||
describe "GET /api/health_checks/cache" do
|
||||
it "returns json success if connection check succeeds" do
|
||||
get cache_api_health_checks_path, headers: headers
|
||||
expect(response.status).to eq(200)
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.parsed_body["message"]).to eq("Redis connected")
|
||||
end
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ RSpec.describe "HealthCheck", type: :request do
|
|||
allow(Redis).to receive(:new).and_return(redis_obj)
|
||||
allow(redis_obj).to receive(:ping).and_return("fail")
|
||||
get cache_api_health_checks_path, headers: headers
|
||||
expect(response.status).to eq(500)
|
||||
expect(response).to have_http_status(:internal_server_error)
|
||||
expect(response.parsed_body["message"]).to eq("Redis NOT connected!")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -320,7 +320,7 @@ RSpec.describe "Dashboards", type: :request do
|
|||
sign_in user
|
||||
get "/dashboard/analytics"
|
||||
within "nav" do
|
||||
expect(page).to have_selector("a[href='/dashboard']")
|
||||
expect(page).to have_link(href: "/dashboard")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ RSpec.describe "Devices", type: :request do
|
|||
it "returns an error" do
|
||||
delete device_path(123)
|
||||
|
||||
expect(response.status).to eq(404)
|
||||
expect(response).to have_http_status(:not_found)
|
||||
expect(response.parsed_body["error"]).to eq("Not Found")
|
||||
expect(response.parsed_body["status"]).to eq(404)
|
||||
end
|
||||
|
|
@ -66,7 +66,7 @@ RSpec.describe "Devices", type: :request do
|
|||
it "return an error if device id doesn't match params" do
|
||||
delete device_path(123), params: incomplete_params
|
||||
|
||||
expect(response.status).to eq(404)
|
||||
expect(response).to have_http_status(:not_found)
|
||||
expect(response.parsed_body["error"]).to eq("Not Found")
|
||||
expect(response.parsed_body["status"]).to eq(404)
|
||||
end
|
||||
|
|
@ -85,7 +85,7 @@ RSpec.describe "Devices", type: :request do
|
|||
delete device_path(device.user.id), params: params
|
||||
|
||||
expect(user.devices.count).to eq(0)
|
||||
expect(response.status).to eq(204)
|
||||
expect(response).to have_http_status(:no_content)
|
||||
expect(Device.find_by(id: device.id)).to be_nil
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ RSpec.describe "EmailSubscriptions", type: :request do
|
|||
describe "GET /email_subscriptions/unsubscribe" do
|
||||
it "returns 200 if valid" do
|
||||
get email_subscriptions_unsubscribe_url(ut: generate_token(user.id))
|
||||
expect(response.status).to be(200)
|
||||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
|
||||
it "does unsubscribe the user" do
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ RSpec.describe "ProfileFieldGroups", type: :request do
|
|||
|
||||
it "returns a successful response" do
|
||||
get profile_field_groups_path
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
|
||||
it "returns all groups with all fields by default" do
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ RSpec.describe "Stories::TaggedArticlesIndex", type: :request do
|
|||
end
|
||||
|
||||
def renders_page
|
||||
expect(response.status).to eq(200)
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include(tag.name)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ RSpec.describe "StoriesIndex", type: :request do
|
|||
it "does not set cache-related headers if private" do
|
||||
allow(Settings::UserExperience).to receive(:public).and_return(false)
|
||||
get "/"
|
||||
expect(response.status).to eq(200)
|
||||
expect(response).to have_http_status(:ok)
|
||||
|
||||
expect(response.headers["X-Accel-Expires"]).to be_nil
|
||||
expect(response.headers["Cache-Control"]).not_to eq("public, no-cache")
|
||||
|
|
@ -148,7 +148,7 @@ RSpec.describe "StoriesIndex", type: :request do
|
|||
it "sets correct cache headers", :aggregate_failures do
|
||||
get "/"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response).to have_http_status(:ok)
|
||||
sets_fastly_headers
|
||||
sets_nginx_headers
|
||||
end
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ RSpec.describe "UserOrganization", type: :request do
|
|||
|
||||
it "redirects to the proper org settings page" do
|
||||
create_org
|
||||
expect(response.status).to eq 302
|
||||
expect(response).to have_http_status :found
|
||||
expect(response.redirect_url).to include "/settings/organization/#{Organization.last.id}"
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ RSpec.describe "UserBlock", type: :request do
|
|||
sign_out(blocker)
|
||||
get "/user_blocks/#{blocked.id}"
|
||||
expect(response.media_type).to eq "application/json"
|
||||
expect(response.status).to eq 401
|
||||
expect(response).to have_http_status :unauthorized
|
||||
expect(response.parsed_body["result"]).to eq "not-logged-in"
|
||||
end
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ RSpec.describe "UserBlock", type: :request do
|
|||
sign_out blocker
|
||||
post "/user_blocks", params: { user_block: { blocked_id: blocked.id } }
|
||||
expect(response.media_type).to eq "application/json"
|
||||
expect(response.status).to eq 401
|
||||
expect(response).to have_http_status :unauthorized
|
||||
expect(response.parsed_body["result"]).to eq "not-logged-in"
|
||||
end
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ RSpec.describe "UserBlock", type: :request do
|
|||
sign_out blocker
|
||||
delete "/user_blocks/#{blocked.id}", params: { user_block: { blocked_id: blocked.id } }
|
||||
expect(response.media_type).to eq "application/json"
|
||||
expect(response.status).to eq 401
|
||||
expect(response).to have_http_status :unauthorized
|
||||
expect(response.parsed_body["result"]).to eq "not-logged-in"
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ RSpec.describe "Videos", type: :request do
|
|||
it "redirects to the article's edit page for the logged in user" do
|
||||
stub_request(:get, %r{dw71fyauz7yz9\.cloudfront\.net/}).to_return(status: 200, body: "", headers: {})
|
||||
post "/videos", params: { article: { video: "https://www.something.com/something.mp4" } }
|
||||
expect(response.status).to eq(302)
|
||||
expect(response).to have_http_status(:found)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ RSpec.configure do |config|
|
|||
end
|
||||
end
|
||||
|
||||
# rubocop:disable Style/TopLevelMethodDefinition
|
||||
# adapted from <https://medium.com/doctolib-engineering/hunting-flaky-tests-2-waiting-for-ajax-bd76d79d9ee9>
|
||||
def wait_for_javascript
|
||||
max_time = Capybara::Helpers.monotonic_time + Capybara.default_max_wait_time
|
||||
|
|
@ -43,4 +42,3 @@ def wait_for_javascript
|
|||
|
||||
raise "wait_for_javascript timeout" unless finished
|
||||
end
|
||||
# rubocop:enable Style/TopLevelMethodDefinition
|
||||
|
|
|
|||
|
|
@ -17,14 +17,15 @@ RSpec.describe "Views an article", type: :system do
|
|||
expect(page).to have_content(article.title)
|
||||
end
|
||||
|
||||
# rubocop:disable Rspec/Capybara/SpecificMatcher
|
||||
it "lets moderators visit /mod", js: true do
|
||||
visit "/#{user.username}/#{article.slug}/mod"
|
||||
|
||||
expect(page).to have_selector('button[data-category="thumbsdown"][data-reactable-type="Article"]')
|
||||
expect(page).to have_selector('button[data-category="vomit"][data-reactable-type="Article"]')
|
||||
expect(page).to have_selector('button[data-category="vomit"][data-reactable-type="User"]')
|
||||
expect(page).to have_selector("button.level-rating-button")
|
||||
expect(page).to have_button(class: "level-rating-button")
|
||||
end
|
||||
# rubocop:enable Rspec/Capybara/SpecificMatcher
|
||||
|
||||
it "shows hidden comments on /mod" do
|
||||
commenter = create(:user)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ RSpec.describe "User visits a podcast page", type: :system do
|
|||
end
|
||||
|
||||
it "displays podcast episodes", js: true do
|
||||
expect(page).to have_selector("a.crayons-card", visible: :visible, count: 2)
|
||||
expect(page).to have_link(class: "crayons-card", visible: :visible, count: 2)
|
||||
end
|
||||
|
||||
it "displays podcast publish_at" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue