ReadyResponder/ReadyResponder

View on GitHub
spec/controllers/inspections_controller_spec.rb

Summary

Maintainability
A
1 hr
Test Coverage

Block has too many lines. [121/25]
Open

RSpec.describe InspectionsController, type: :controller do
  let(:active_person) { create(:person, firstname: 'Aaon' ) }
  let(:inactive_person) { create(:inactive_person, firstname: 'Aaby' ) }
  let(:item) { create(:item) }
  let!(:inspections) { create_list(:inspection, 3, item_id: item.id) }

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Block has too many lines. [32/25]
Open

  describe '#update' do
    let(:inspection_params) do
      {
        id: inspection.id,
        inspection: { inspection_date: Time.now.strftime('%Y-%m-%d %H:%M'), status: 'Incomplete' }

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Block has too many lines. [32/25]
Open

  describe '#create' do
    let!(:inspection_params) do
      {
        item_id: item.id,
        inspection: { inspection_date: Time.now.strftime('%Y-%m-%d %H:%M'), status: 'Passed' }

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    context 'with a successful update' do
      it 'updates the inspection' do
        expect { subject }.to change { inspection.reload.status }.from('Passed').to('Incomplete')
      end

Severity: Minor
Found in spec/controllers/inspections_controller_spec.rb and 1 other location - About 40 mins to fix
spec/controllers/item_types_controller_spec.rb on lines 117..126

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 38.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 3 locations. Consider refactoring.
Open

  describe '#show' do
    it 'assigns an inspection & renders' do
      get :show, params: { id: inspection.id }

      expect(assigns[:inspection]).to eq(inspection)
Severity: Minor
Found in spec/controllers/inspections_controller_spec.rb and 2 other locations - About 15 mins to fix
spec/controllers/item_types_controller_spec.rb on lines 19..24
spec/controllers/item_types_controller_spec.rb on lines 50..55

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 26.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Space inside parentheses detected.
Open

  let(:inactive_person) { create(:inactive_person, firstname: 'Aaby' ) }

Checks for spaces inside ordinary round parentheses.

Example:

# bad
f( 3)
g = (a + 3 )

# good
f(3)
g = (a + 3)

Line is too long. [94/80]
Open

        inspection: { inspection_date: Time.now.strftime('%Y-%m-%d %H:%M'), status: 'Passed' }

Avoid using {...} for multi-line blocks.
Open

    before {

Check for uses of braces or do/end around single line or multi-line blocks.

Example: EnforcedStyle: linecountbased (default)

# bad - single line block
items.each do |item| item / 5 end

# good - single line block
items.each { |item| item / 5 }

# bad - multi-line block
things.map { |thing|
  something = thing.some_method
  process(something)
}

# good - multi-line block
things.map do |thing|
  something = thing.some_method
  process(something)
end

Example: EnforcedStyle: semantic

# Prefer `do...end` over `{...}` for procedural blocks.

# return value is used/assigned
# bad
foo = map do |x|
  x
end
puts (map do |x|
  x
end)

# return value is not used out of scope
# good
map do |x|
  x
end

# Prefer `{...}` over `do...end` for functional blocks.

# return value is not used out of scope
# bad
each { |x|
  x
}

# return value is used/assigned
# good
foo = map { |x|
  x
}
map { |x|
  x
}.inspect

Example: EnforcedStyle: bracesforchaining

# bad
words.each do |word|
  word.flip.flop
end.join("-")

# good
words.each { |word|
  word.flip.flop
}.join("-")

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

      expect(assigns[:inspectors]).to eq([active_person, item.owner]), "Should assign only active persons as inspectors"

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Parenthesize the param change { Inspection.count } to make sure that the block will be associated with the change method call.
Open

        expect { subject }.to_not change { Inspection.count }

This cop checks for ambiguous block association with method when param passed without parentheses.

Example:

# bad
some_method a { |val| puts val }

Example:

# good
# With parentheses, there's no ambiguity.
some_method(a) { |val| puts val }

# good
# Operator methods require no disambiguation
foo == bar { |b| b.baz }

# good
# Lambda arguments require no disambiguation
foo = ->(bar) { bar.baz }

Line is too long. [120/80]
Open

      expect(assigns[:inspectors]).to eq([active_person, item.owner]), "Should assign only active persons as inspectors"

Line is too long. [98/80]
Open

        inspection: { inspection_date: Time.now.strftime('%Y-%m-%d %H:%M'), status: 'Incomplete' }

Missing magic comment # frozen_string_literal: true.
Open

require 'rails_helper'

This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

Example: EnforcedStyle: when_needed (default)

# The `when_needed` style will add the frozen string literal comment
# to files only when the `TargetRubyVersion` is set to 2.3+.
# bad
module Foo
  # ...
end

# good
# frozen_string_literal: true

module Foo
  # ...
end

Example: EnforcedStyle: always

# The `always` style will always add the frozen string literal comment
# to a file, regardless of the Ruby version or if `freeze` or `<<` are
# called on a string literal.
# bad
module Bar
  # ...
end

# good
# frozen_string_literal: true

module Bar
  # ...
end

Example: EnforcedStyle: never

# The `never` will enforce that the frozen string literal comment does
# not exist in a file.
# bad
# frozen_string_literal: true

module Baz
  # ...
end

# good
module Baz
  # ...
end

Space inside parentheses detected.
Open

  let(:active_person) { create(:person, firstname: 'Aaon' ) }

Checks for spaces inside ordinary round parentheses.

Example:

# bad
f( 3)
g = (a + 3 )

# good
f(3)
g = (a + 3)

Line is too long. [97/80]
Open

        expect { subject }.to change { inspection.reload.status }.from('Passed').to('Incomplete')

Parenthesize the param change { inspection.status } to make sure that the block will be associated with the change method call.
Open

        expect { subject }.to_not change { inspection.status }

This cop checks for ambiguous block association with method when param passed without parentheses.

Example:

# bad
some_method a { |val| puts val }

Example:

# good
# With parentheses, there's no ambiguity.
some_method(a) { |val| puts val }

# good
# Operator methods require no disambiguation
foo == bar { |b| b.baz }

# good
# Lambda arguments require no disambiguation
foo = ->(bar) { bar.baz }

Line is too long. [86/80]
Open

      expect(assigns[:inspectors]).to eq([inactive_person, active_person, item.owner])

Expression at 36, 15 should be on its own line.
Open

      subject }

This cop checks whether the end statement of a do..end block is on its own line.

Example:

# bad
blah do |i|
  foo(i) end

# good
blah do |i|
  foo(i)
end

# bad
blah { |i|
  foo(i) }

# good
blah { |i|
  foo(i)
}

There are no issues that match your filters.

Category
Status