main
Washington Botelho 2022-05-17 23:29:08 -03:00
parent 2f8f719fc4
commit 5c3cc117a6
7 changed files with 47 additions and 42 deletions

View File

@ -1,6 +1,6 @@
# This configuration was generated by # This configuration was generated by
# `rubocop --auto-gen-config` # `rubocop --auto-gen-config`
# on 2022-04-21 22:55:24 UTC using RuboCop version 1.28.1. # on 2022-05-18 01:29:38 UTC using RuboCop version 1.29.1.
# The point is for the user to remove these configuration records # The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base. # one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new # Note that changes in the inspected code, or installation of new
@ -13,12 +13,19 @@ Gemspec/RequiredRubyVersion:
Exclude: Exclude:
- 'rating.gemspec' - 'rating.gemspec'
# Offense count: 4
# Configuration parameters: AllowComments, AllowEmptyLambdas.
Lint/EmptyBlock:
Exclude:
- 'spec/factories/global.rb'
- 'spec/factories/toy.rb'
- 'spec/support/db/migrate/create_globals_table.rb'
- 'spec/support/db/migrate/create_toys_table.rb'
# Offense count: 1 # Offense count: 1
# This cop supports safe auto-correction (--auto-correct). Lint/NoReturnInBeginEndBlocks:
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns. Exclude:
# URISchemes: http, https - 'lib/rating/config.rb'
Layout/LineLength:
Max: 139
# Offense count: 3 # Offense count: 3
# This cop supports unsafe auto-correction (--auto-correct-all). # This cop supports unsafe auto-correction (--auto-correct-all).
@ -39,13 +46,24 @@ Metrics/ParameterLists:
Max: 6 Max: 6
# Offense count: 1 # Offense count: 1
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers. # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, normalcase, non_integer # SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339 # AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
Naming/VariableNumber: Naming/VariableNumber:
Exclude: Exclude:
- 'spec/rails_helper.rb' - 'spec/rails_helper.rb'
# Offense count: 9
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: be, be_nil
RSpec/BeNil:
Exclude:
- 'spec/models/extension/unscoped_rating_spec.rb'
- 'spec/models/extension/where_spec.rb'
- 'spec/models/rate/create_spec.rb'
- 'spec/models/rate/rate_for_spec.rb'
# Offense count: 2 # Offense count: 2
# Configuration parameters: Prefixes. # Configuration parameters: Prefixes.
# Prefixes: when, with, without # Prefixes: when, with, without
@ -84,11 +102,6 @@ RSpec/LetSetup:
RSpec/MessageSpies: RSpec/MessageSpies:
EnforcedStyle: receive EnforcedStyle: receive
# Offense count: 2
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 12
# Offense count: 7 # Offense count: 7
# Configuration parameters: IgnoreSharedExamples. # Configuration parameters: IgnoreSharedExamples.
RSpec/NamedSubject: RSpec/NamedSubject:
@ -111,16 +124,8 @@ Rails/ApplicationRecord:
- 'lib/rating/models/rating/rating.rb' - 'lib/rating/models/rating/rating.rb'
# Offense count: 2 # Offense count: 2
# This cop supports unsafe auto-correction (--auto-correct-all).
# Configuration parameters: Include.
# Include: **/Rakefile, **/*.rake
Rails/RakeEnvironment:
Exclude:
- 'Rakefile'
# Offense count: 1
# This cop supports safe auto-correction (--auto-correct). # This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns. Rails/RedundantPresenceValidationOnBelongsTo:
# URISchemes: http, https Exclude:
Layout/LineLength: - 'lib/rating/models/rating/rate.rb'
Max: 139 - 'lib/rating/models/rating/rating.rb'

View File

@ -93,8 +93,8 @@ module Rating
resource_rating_avg = values.rating_avg resource_rating_avg = values.rating_avg
resource_rating_count = values.rating_count.to_f resource_rating_count = values.rating_count.to_f
(resource_rating_count / (resource_rating_count + count_avg)) * resource_rating_avg + ((resource_rating_count / (resource_rating_count + count_avg)) * resource_rating_avg) +
(count_avg / (resource_rating_count + count_avg)) * resource_type_rating_avg ((count_avg / (resource_rating_count + count_avg)) * resource_type_rating_avg)
end end
def execute_sql(sql) def execute_sql(sql)

View File

@ -10,11 +10,11 @@ RSpec.describe Rating::Extension, ':rated?' do
before { author.rate resource, 1 } before { author.rate resource, 1 }
context 'when has no rate for the given resource' do context 'when has no rate for the given resource' do
specify { expect(author.rated?(create(:article))).to eq false } it { expect(author.rated?(create(:article))).to be false }
end end
context 'when has rate for the given resource' do context 'when has rate for the given resource' do
specify { expect(author.rated?(resource)).to eq true } it { expect(author.rated?(resource)).to be true }
end end
end end
@ -24,11 +24,11 @@ RSpec.describe Rating::Extension, ':rated?' do
before { author.rate resource, 1, scope: category } before { author.rate resource, 1, scope: category }
context 'when has no rate for the given resource' do context 'when has no rate for the given resource' do
specify { expect(author.rated?(resource, scope: create(:category))).to eq false } it { expect(author.rated?(resource, scope: create(:category))).to be false }
end end
context 'when has rate for the given resource' do context 'when has rate for the given resource' do
specify { expect(author.rated?(resource, scope: category)).to eq true } it { expect(author.rated?(resource, scope: category)).to be true }
end end
end end
@ -37,11 +37,11 @@ RSpec.describe Rating::Extension, ':rated?' do
before { author.rate resource, 1, extra_scopes: { scope_1: 'scope_1' } } before { author.rate resource, 1, extra_scopes: { scope_1: 'scope_1' } }
context 'when has no rate for the given resource with given extra scopes' do context 'when has no rate for the given resource with given extra scopes' do
specify { expect(author.rated?(resource, extra_scopes: { scope_1: 'missing' })).to eq false } it { expect(author.rated?(resource, extra_scopes: { scope_1: 'missing' })).to be false }
end end
context 'when has rate for the given resource with given extra scopes' do context 'when has rate for the given resource with given extra scopes' do
specify { expect(author.rated?(resource, extra_scopes: { scope_1: 'scope_1' })).to eq true } it { expect(author.rated?(resource, extra_scopes: { scope_1: 'scope_1' })).to be true }
end end
end end
end end

View File

@ -34,7 +34,7 @@ RSpec.describe Rating::Extension, 'unscoped_rating' do
expect(rating.average.to_s).to eq '5.0' expect(rating.average.to_s).to eq '5.0'
expect(rating.estimate.to_s).to eq '5.0' expect(rating.estimate.to_s).to eq '5.0'
expect(rating.resource).to eq resource expect(rating.resource).to eq resource
expect(rating.scopeable).to eq nil expect(rating.scopeable).to be(nil)
expect(rating.sum).to eq 5 expect(rating.sum).to eq 5
expect(rating.total).to eq 1 expect(rating.total).to eq 1
end end
@ -57,7 +57,7 @@ RSpec.describe Rating::Extension, 'unscoped_rating' do
expect(rating.average.to_s).to eq '2.6666666666666667' expect(rating.average.to_s).to eq '2.6666666666666667'
expect(rating.estimate.to_s).to eq '2.6666666666666667' expect(rating.estimate.to_s).to eq '2.6666666666666667'
expect(rating.resource).to eq resource expect(rating.resource).to eq resource
expect(rating.scopeable).to eq nil expect(rating.scopeable).to be(nil)
expect(rating.sum).to eq 8 expect(rating.sum).to eq 8
expect(rating.total).to eq 3 expect(rating.total).to eq 3
end end
@ -91,7 +91,7 @@ RSpec.describe Rating::Extension, 'unscoped_rating' do
expect(rating.average.to_s).to eq '2.6666666666666667' expect(rating.average.to_s).to eq '2.6666666666666667'
expect(rating.estimate.to_s).to eq '2.6666666666666667' expect(rating.estimate.to_s).to eq '2.6666666666666667'
expect(rating.resource).to eq resource expect(rating.resource).to eq resource
expect(rating.scopeable).to eq nil expect(rating.scopeable).to be(nil)
expect(rating.sum).to eq 8 expect(rating.sum).to eq 8
expect(rating.total).to eq 3 expect(rating.total).to eq 3
end end

View File

@ -26,7 +26,7 @@ RSpec.describe Rating::Extension, 'unscoped_rating' do
expect(rating.average.to_s).to eq '3.0' expect(rating.average.to_s).to eq '3.0'
expect(rating.estimate.to_s).to eq '3.0' expect(rating.estimate.to_s).to eq '3.0'
expect(rating.resource).to eq resource expect(rating.resource).to eq resource
expect(rating.scopeable).to eq nil expect(rating.scopeable).to be(nil)
expect(rating.sum).to eq 9 expect(rating.sum).to eq 9
expect(rating.total).to eq 3 expect(rating.total).to eq 3
end end

View File

@ -155,7 +155,7 @@ RSpec.describe Rating::Rate, ':create' do
rate = described_class.last rate = described_class.last
expect(rate.author).to eq author expect(rate.author).to eq author
expect(rate.comment).to eq nil expect(rate.comment).to be(nil)
expect(rate.resource).to eq article expect(rate.resource).to eq article
expect(rate.value).to eq 3 expect(rate.value).to eq 3
end end
@ -168,7 +168,7 @@ RSpec.describe Rating::Rate, ':create' do
rate = described_class.last rate = described_class.last
expect(rate.author).to eq author expect(rate.author).to eq author
expect(rate.comment).to eq nil expect(rate.comment).to be(nil)
expect(rate.resource).to eq article expect(rate.resource).to eq article
expect(rate.value).to eq 3 expect(rate.value).to eq 3
end end

View File

@ -8,7 +8,7 @@ RSpec.describe Rating::Rate, ':rate_for' do
context 'with no scopeable' do context 'with no scopeable' do
context 'when rate does not exist' do context 'when rate does not exist' do
it { expect(described_class.rate_for(author: author, resource: article)).to eq nil } it { expect(described_class.rate_for(author: author, resource: article)).to be(nil) }
end end
context 'when rate exists' do context 'when rate exists' do
@ -27,7 +27,7 @@ RSpec.describe Rating::Rate, ':rate_for' do
context 'when rate does not exist' do context 'when rate does not exist' do
it do it do
expect(described_class.rate_for(author: author, resource: article, scopeable: category)).to eq nil expect(described_class.rate_for(author: author, resource: article, scopeable: category)).to be(nil)
end end
end end
@ -99,7 +99,7 @@ RSpec.describe Rating::Rate, ':rate_for' do
scopeable: category scopeable: category
) )
expect(result).to eq nil expect(result).to be(nil)
end end
end end
end end