Fix rubocop complaints (#5769)

* Fix rubocop complaints

* Fix broken specs
This commit is contained in:
rhymes 2020-01-27 22:58:23 +01:00 committed by Ben Halpern
parent 5444c53df2
commit 0927c81a93
3 changed files with 58 additions and 27 deletions

View file

@ -1,4 +1,4 @@
# This is a workaround I found in this GH issue:
# Workaround for erb_lint warnings:
# https://github.com/openstreetmap/openstreetmap-website/issues/2472
require:
- rubocop-performance
@ -7,13 +7,13 @@ require:
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-01-07 09:14:55 +0100 using RuboCop version 0.79.0.
# on 2020-01-27 18:38:25 +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: 230
# Offense count: 236
Metrics/AbcSize:
Max: 75
@ -27,14 +27,13 @@ Metrics/BlockLength:
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/jobs/comments/calculate_score_job_spec.rb'
- 'spec/labor/badge_rewarder_spec.rb'
- 'spec/models/comment_spec.rb'
- 'spec/models/notification_spec.rb'
- 'spec/requests/api/v0/articles_spec.rb'
- 'spec/requests/display_ad_events_spec.rb'
# Offense count: 466
# Offense count: 500
# Configuration parameters: AggregateFailuresByDefault.
RSpec/MultipleExpectations:
Max: 8
@ -77,7 +76,7 @@ Style/GuardClause:
Exclude:
- 'app/models/article.rb'
# Offense count: 3394
# Offense count: 3566
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https

View file

@ -16,7 +16,8 @@ RSpec.describe ArticleDecorator, type: :decorator do
it "returns the article url without a canonical_url" do
article.canonical_url = ""
expect(article.decorate.processed_canonical_url). to eq("https://#{ApplicationConfig['APP_DOMAIN']}#{article.path}")
expected_url = "https://#{ApplicationConfig['APP_DOMAIN']}#{article.path}"
expect(article.decorate.processed_canonical_url).to eq(expected_url)
end
end
@ -36,26 +37,24 @@ RSpec.describe ArticleDecorator, type: :decorator do
end
describe "#description_and_tags" do
it "creates proper description when description is not present and body is present and short, and tags are present" do
paragraphs = Faker::Hipster.paragraph(sentence_count: 40)
it "creates proper description when it is not present and body is present and short, and tags are present" do
body_markdown = "---\ntitle: Title\npublished: false\ndescription:\ntags: heytag\n---\n\nHey this is the article"
expect(create_article(body_markdown: body_markdown).description_and_tags).to eq("Hey this is the article. Tagged with heytag.")
expected_result = "Hey this is the article. Tagged with heytag."
expect(create_article(body_markdown: body_markdown).description_and_tags).to eq(expected_result)
end
it "creates proper description when description is not present and body is present and short, and tags are not present" do
paragraphs = Faker::Hipster.paragraph(sentence_count: 40)
it "creates proper description when it is not present and body is present and short, and tags are not present" do
body_markdown = "---\ntitle: Title\npublished: false\ndescription:\ntags:\n---\n\nHey this is the article"
expect(create_article(body_markdown: body_markdown).description_and_tags).to eq("Hey this is the article.")
end
it "creates proper description when description is not present and body is present and long, and tags are present" do
it "creates proper description when it is not present and body is present and long, and tags are present" do
paragraphs = Faker::Hipster.paragraph(sentence_count: 40)
body_markdown = "---\ntitle: Title\npublished: false\ndescription:\ntags: heytag\n---\n\n#{paragraphs}"
expect(create_article(body_markdown: body_markdown).description_and_tags).to end_with("... Tagged with heytag.")
end
it "creates proper description when description is not present and body is not present and long, and tags are present" do
it "creates proper description when it is not present and body is not present and long, and tags are present" do
body_markdown = "---\ntitle: Title\npublished: false\ndescription:\ntags: heytag\n---\n\n"
created_article = create_article(body_markdown: body_markdown)
expect(created_article.description_and_tags).to eq("A post by #{created_article.user.name}. Tagged with heytag.")

View file

@ -44,37 +44,60 @@ RSpec.describe UserDecorator, type: :decorator do
Moderator::BanishUser.call(admin: user, user: user)
expect(user.decorate.fully_banished?).to eq(true)
end
end
describe "#config_body_class" do
it "creates proper body class with defaults" do
expect(user.decorate.config_body_class).to eq("default default-article-body pro-status-#{user.pro?} trusted-status-#{user.trusted} #{user.config_navbar}-navbar-config")
expected_result = %W[
default default-article-body pro-status-#{user.pro?}
trusted-status-#{user.trusted} #{user.config_navbar}-navbar-config
].join(" ")
expect(user.decorate.config_body_class).to eq(expected_result)
end
it "creates proper body class with sans serif config" do
user.config_font = "sans_serif"
expect(user.decorate.config_body_class).to eq("default sans-serif-article-body pro-status-#{user.pro?} trusted-status-#{user.trusted} #{user.config_navbar}-navbar-config")
expected_result = %W[
default sans-serif-article-body pro-status-#{user.pro?}
trusted-status-#{user.trusted} #{user.config_navbar}-navbar-config
].join(" ")
expect(user.decorate.config_body_class).to eq(expected_result)
end
it "creates proper body class with night theme" do
user.config_theme = "night_theme"
expect(user.decorate.config_body_class).to eq("night-theme default-article-body pro-status-#{user.pro?} trusted-status-#{user.trusted} #{user.config_navbar}-navbar-config")
expected_result = %W[
night-theme default-article-body pro-status-#{user.pro?}
trusted-status-#{user.trusted} #{user.config_navbar}-navbar-config
].join(" ")
expect(user.decorate.config_body_class).to eq(expected_result)
end
it "creates proper body class with pink theme" do
user.config_theme = "pink_theme"
expect(user.decorate.config_body_class).to eq("pink-theme default-article-body pro-status-#{user.pro?} trusted-status-#{user.trusted} #{user.config_navbar}-navbar-config")
expected_result = %W[
pink-theme default-article-body pro-status-#{user.pro?}
trusted-status-#{user.trusted} #{user.config_navbar}-navbar-config
].join(" ")
expect(user.decorate.config_body_class).to eq(expected_result)
end
it "creates proper body class with minimal light theme" do
user.config_theme = "minimal_light_theme"
expect(user.decorate.config_body_class).to eq("minimal-light-theme default-article-body pro-status-#{user.pro?} trusted-status-#{user.trusted} #{user.config_navbar}-navbar-config")
expected_result = %W[
minimal-light-theme default-article-body pro-status-#{user.pro?}
trusted-status-#{user.trusted} #{user.config_navbar}-navbar-config
].join(" ")
expect(user.decorate.config_body_class).to eq(expected_result)
end
it "works with static navbar" do
user.config_navbar = "static"
expect(user.decorate.config_body_class).to eq("default default-article-body pro-status-#{user.pro?} trusted-status-#{user.trusted} static-navbar-config")
expected_result = %W[
default default-article-body pro-status-#{user.pro?}
trusted-status-#{user.trusted} static-navbar-config
].join(" ")
expect(user.decorate.config_body_class).to eq(expected_result)
end
context "when user with roles" do
@ -82,12 +105,22 @@ RSpec.describe UserDecorator, type: :decorator do
it "creates proper body class with pro user" do
user.add_role(:pro)
expect(user.decorate.config_body_class).to eq("default default-article-body pro-status-#{user.pro?} trusted-status-#{user.trusted} #{user.config_navbar}-navbar-config")
expected_result = %W[
default default-article-body pro-status-true
trusted-status-#{user.trusted} default-navbar-config
].join(" ")
expect(user.decorate.config_body_class).to eq(expected_result)
end
it "creates proper body class with trusted user" do
user.add_role(:trusted)
expect(user.decorate.config_body_class).to eq("default default-article-body pro-status-#{user.pro?} trusted-status-#{user.trusted} #{user.config_navbar}-navbar-config")
expected_result = %W[
default default-article-body pro-status-#{user.pro?}
trusted-status-true default-navbar-config
].join(" ")
expect(user.decorate.config_body_class).to eq(expected_result)
end
end
end
@ -95,17 +128,17 @@ RSpec.describe UserDecorator, type: :decorator do
describe "#dark_theme?" do
it "determines dark theme if night theme" do
user.config_theme = "night_theme"
expect(user.decorate.dark_theme?).to eq(true)
expect(user.decorate.dark_theme?).to be(true)
end
it "determines dark theme if ten x hacker" do
user.config_theme = "ten_x_hacker_theme"
expect(user.decorate.dark_theme?).to eq(true)
expect(user.decorate.dark_theme?).to be(true)
end
it "determines not dark theme if not one of the dark themes" do
user.config_theme = "default"
expect(user.decorate.dark_theme?).to eq(false)
expect(user.decorate.dark_theme?).to be(false)
end
end
end