lint
parent
038a0d20cb
commit
286b03be63
69
.rubocop.yml
69
.rubocop.yml
|
@ -2,62 +2,47 @@ require: rubocop-rspec
|
||||||
|
|
||||||
inherit_from: .rubocop_todo.yml
|
inherit_from: .rubocop_todo.yml
|
||||||
|
|
||||||
AllCops:
|
|
||||||
Exclude:
|
|
||||||
- generators/rating/templates/**/*
|
|
||||||
|
|
||||||
Rails:
|
Rails:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
Lint/Debugger:
|
Layout/AlignParameters:
|
||||||
|
EnforcedStyle: with_fixed_indentation
|
||||||
|
|
||||||
|
Layout/EmptyLinesAroundArguments:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
Metrics/AbcSize:
|
Rails/ApplicationRecord:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
Metrics/ClassLength:
|
RSpec/DescribeMethod:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
Metrics/CyclomaticComplexity:
|
RSpec/ExampleLength:
|
||||||
|
Max: 10
|
||||||
|
|
||||||
|
RSpec/FilePath:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
RSpec/MultipleExpectations:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
RSpec/NestedGroups:
|
||||||
|
Max: 5
|
||||||
|
|
||||||
Metrics/LineLength:
|
Metrics/LineLength:
|
||||||
Enabled: false
|
Max: 120
|
||||||
|
|
||||||
Metrics/MethodLength:
|
Naming/VariableNumber:
|
||||||
Enabled: false
|
EnforcedStyle: snake_case
|
||||||
|
|
||||||
Metrics/PerceivedComplexity:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
Rails/HasAndBelongsToMany:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
Rails/HttpPositionalArguments:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
Style/IfUnlessModifier:
|
|
||||||
MaxLineLength: 0
|
|
||||||
|
|
||||||
Style/PercentLiteralDelimiters:
|
|
||||||
PreferredDelimiters:
|
|
||||||
'%i': '[]'
|
|
||||||
'%I': '[]'
|
|
||||||
'%r': ()
|
|
||||||
'%w': '[]'
|
|
||||||
'%W': '[]'
|
|
||||||
|
|
||||||
Style/AlignParameters:
|
|
||||||
EnforcedStyle: with_fixed_indentation
|
|
||||||
|
|
||||||
Style/Documentation:
|
Style/Documentation:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
Style/Encoding:
|
Style/PercentLiteralDelimiters:
|
||||||
Enabled: false
|
PreferredDelimiters:
|
||||||
|
'%': '()'
|
||||||
Style/SpaceBeforeComma:
|
'%i': '[]'
|
||||||
Enabled: false
|
'%I': '[]'
|
||||||
|
'%r': '()'
|
||||||
Style/SpaceBeforeFirstArg:
|
'%w': '[]'
|
||||||
Enabled: false
|
'%W': '[]'
|
||||||
|
|
|
@ -16,8 +16,8 @@ RSpec.describe Rating::Extension, ':order_by_rating' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'filtering by :average' do
|
context 'when filtering by :average' do
|
||||||
context 'as asc' do
|
context 'with as asc' do
|
||||||
it 'works' do
|
it 'works' do
|
||||||
expect(Article.order_by_rating(:average, :asc)).to eq [
|
expect(Article.order_by_rating(:average, :asc)).to eq [
|
||||||
article_3,
|
article_3,
|
||||||
|
@ -35,7 +35,7 @@ RSpec.describe Rating::Extension, ':order_by_rating' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'as desc' do
|
context 'with as desc' do
|
||||||
it 'works' do
|
it 'works' do
|
||||||
expect(Article.order_by_rating(:average, :desc)).to eq [
|
expect(Article.order_by_rating(:average, :desc)).to eq [
|
||||||
article_1,
|
article_1,
|
||||||
|
@ -54,8 +54,8 @@ RSpec.describe Rating::Extension, ':order_by_rating' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'filtering by :estimate' do
|
context 'when filtering by :estimate' do
|
||||||
context 'as asc' do
|
context 'with as asc' do
|
||||||
it 'works' do
|
it 'works' do
|
||||||
expect(Article.order_by_rating(:estimate, :asc)).to eq [
|
expect(Article.order_by_rating(:estimate, :asc)).to eq [
|
||||||
article_3,
|
article_3,
|
||||||
|
@ -73,7 +73,7 @@ RSpec.describe Rating::Extension, ':order_by_rating' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'as desc' do
|
context 'with as desc' do
|
||||||
it 'works' do
|
it 'works' do
|
||||||
expect(Article.order_by_rating(:estimate, :desc)).to eq [
|
expect(Article.order_by_rating(:estimate, :desc)).to eq [
|
||||||
article_1,
|
article_1,
|
||||||
|
@ -92,7 +92,7 @@ RSpec.describe Rating::Extension, ':order_by_rating' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'filtering by :sum' do
|
context 'when filtering by :sum' do
|
||||||
context 'as asc' do
|
context 'as asc' do
|
||||||
it 'works' do
|
it 'works' do
|
||||||
expect(Article.order_by_rating(:sum, :asc)).to eq [
|
expect(Article.order_by_rating(:sum, :asc)).to eq [
|
||||||
|
@ -111,7 +111,7 @@ RSpec.describe Rating::Extension, ':order_by_rating' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'as desc' do
|
context 'with as desc' do
|
||||||
it 'works' do
|
it 'works' do
|
||||||
expect(Article.order_by_rating(:sum, :desc)).to eq [
|
expect(Article.order_by_rating(:sum, :desc)).to eq [
|
||||||
article_1,
|
article_1,
|
||||||
|
@ -130,8 +130,8 @@ RSpec.describe Rating::Extension, ':order_by_rating' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'filtering by :total' do
|
context 'when filtering by :total' do
|
||||||
context 'as asc' do
|
context 'with as asc' do
|
||||||
it 'works' do
|
it 'works' do
|
||||||
result = Article.order_by_rating(:total, :asc)
|
result = Article.order_by_rating(:total, :asc)
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ RSpec.describe Rating::Extension, ':order_by_rating' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'as desc' do
|
context 'with as desc' do
|
||||||
it 'works' do
|
it 'works' do
|
||||||
result = Article.order_by_rating(:total, :desc)
|
result = Article.order_by_rating(:total, :desc)
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,13 @@ RSpec.describe Rating::Extension, ':rated?' do
|
||||||
|
|
||||||
context 'with no scopeable' do
|
context 'with no scopeable' do
|
||||||
context 'when has no rate for the given resource' do
|
context 'when has no rate for the given resource' do
|
||||||
before { allow(author).to receive(:rate_for).with(article, scope: nil) { nil } }
|
before { allow(author).to receive(:rate_for).with(article, scope: nil).and_return nil }
|
||||||
|
|
||||||
specify { expect(author.rated?(article)).to eq false }
|
specify { expect(author.rated?(article)).to eq false }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when has rate for the given resource' do
|
context 'when has rate for the given resource' do
|
||||||
before { allow(author).to receive(:rate_for).with(article, scope: nil) { double } }
|
before { allow(author).to receive(:rate_for).with(article, scope: nil).and_return double }
|
||||||
|
|
||||||
specify { expect(author.rated?(article)).to eq true }
|
specify { expect(author.rated?(article)).to eq true }
|
||||||
end
|
end
|
||||||
|
@ -24,13 +24,13 @@ RSpec.describe Rating::Extension, ':rated?' do
|
||||||
let!(:category) { build :category }
|
let!(:category) { build :category }
|
||||||
|
|
||||||
context 'when has no rate for the given resource' do
|
context 'when has no rate for the given resource' do
|
||||||
before { allow(author).to receive(:rate_for).with(article, scope: category) { nil } }
|
before { allow(author).to receive(:rate_for).with(article, scope: category).and_return nil }
|
||||||
|
|
||||||
specify { expect(author.rated?(article, scope: category)).to eq false }
|
specify { expect(author.rated?(article, scope: category)).to eq false }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when has rate for the given resource' do
|
context 'when has rate for the given resource' do
|
||||||
before { allow(author).to receive(:rate_for).with(article, scope: category) { double } }
|
before { allow(author).to receive(:rate_for).with(article, scope: category).and_return double }
|
||||||
|
|
||||||
specify { expect(author.rated?(article, scope: category)).to eq true }
|
specify { expect(author.rated?(article, scope: category)).to eq true }
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,25 +19,21 @@ RSpec.describe Rating::Extension, ':rated' do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when destroy author' do
|
context 'when destroy author' do
|
||||||
before do
|
it 'destroys rates of that author' do
|
||||||
expect(Rating::Rate.where(author: author_1).count).to eq 4
|
expect(Rating::Rate.where(author: author_1).count).to eq 4
|
||||||
|
|
||||||
author_1.destroy!
|
author_1.destroy!
|
||||||
end
|
|
||||||
|
|
||||||
it 'destroys rates of that author' do
|
|
||||||
expect(Rating::Rate.where(author: author_1).count).to eq 0
|
expect(Rating::Rate.where(author: author_1).count).to eq 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when destroy resource rated by author' do
|
context 'when destroy resource rated by author' do
|
||||||
before do
|
it 'destroys rates of that resource' do
|
||||||
expect(Rating::Rate.where(resource: article_1).count).to eq 4
|
expect(Rating::Rate.where(resource: article_1).count).to eq 4
|
||||||
|
|
||||||
article_1.destroy!
|
article_1.destroy!
|
||||||
end
|
|
||||||
|
|
||||||
it 'destroys rates of that resource' do
|
|
||||||
expect(Rating::Rate.where(resource: article_1).count).to eq 0
|
expect(Rating::Rate.where(resource: article_1).count).to eq 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,26 +7,26 @@ RSpec.describe Rating::Rating, ':averager_data' do
|
||||||
include_context 'with_database_records'
|
include_context 'with_database_records'
|
||||||
|
|
||||||
context 'with no scopeable' do
|
context 'with no scopeable' do
|
||||||
subject { described_class.averager_data article_1, nil }
|
subject(:result) { described_class.averager_data article_1, nil }
|
||||||
|
|
||||||
it 'returns the values average of given resource type' do
|
it 'returns the values average of given resource type' do
|
||||||
expect(subject.as_json['rating_avg']).to eq 30.5
|
expect(result.as_json['rating_avg']).to eq 30.5
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the average of number of records for the given resource type' do
|
it 'returns the average of number of records for the given resource type' do
|
||||||
expect(subject.as_json['count_avg']).to eq 1.3333333333333333
|
expect(result.as_json['count_avg']).to eq 1.3333333333333333
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with scopeable' do
|
context 'with scopeable' do
|
||||||
subject { described_class.averager_data article_1, category }
|
subject(:result) { described_class.averager_data article_1, category }
|
||||||
|
|
||||||
it 'returns the values average of given resource type' do
|
it 'returns the values average of given resource type' do
|
||||||
expect(subject.as_json['rating_avg']).to eq 1.5
|
expect(result.as_json['rating_avg']).to eq 1.5
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the average of number of records for the given resource type' do
|
it 'returns the average of number of records for the given resource type' do
|
||||||
expect(subject.as_json['count_avg']).to eq 2
|
expect(result.as_json['count_avg']).to eq 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,42 +7,42 @@ RSpec.describe Rating::Rating, ':data' do
|
||||||
include_context 'with_database_records'
|
include_context 'with_database_records'
|
||||||
|
|
||||||
context 'with no scopeable' do
|
context 'with no scopeable' do
|
||||||
subject { described_class.data article_1, nil }
|
subject(:result) { described_class.data article_1, nil }
|
||||||
|
|
||||||
it 'returns the average of value for a resource' do
|
it 'returns the average of value for a resource' do
|
||||||
expect(subject[:average]).to eq 50.5
|
expect(result[:average]).to eq 50.5
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the sum of values for a resource' do
|
it 'returns the sum of values for a resource' do
|
||||||
expect(subject[:sum]).to eq 101
|
expect(result[:sum]).to eq 101
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the count of votes for a resource' do
|
it 'returns the count of votes for a resource' do
|
||||||
expect(subject[:total]).to eq 2
|
expect(result[:total]).to eq 2
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the estimate for a resource' do
|
it 'returns the estimate for a resource' do
|
||||||
expect(subject[:estimate]).to eq 42.50000000000001
|
expect(result[:estimate]).to eq 42.50000000000001
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with scopeable' do
|
context 'with scopeable' do
|
||||||
subject { described_class.data article_1, category }
|
subject(:result) { described_class.data article_1, category }
|
||||||
|
|
||||||
it 'returns the average of value for a resource' do
|
it 'returns the average of value for a resource' do
|
||||||
expect(subject[:average]).to eq 1.5
|
expect(result[:average]).to eq 1.5
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the sum of values for a resource' do
|
it 'returns the sum of values for a resource' do
|
||||||
expect(subject[:sum]).to eq 3
|
expect(result[:sum]).to eq 3
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the count of votes for a resource' do
|
it 'returns the count of votes for a resource' do
|
||||||
expect(subject[:total]).to eq 2
|
expect(result[:total]).to eq 2
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the estimate for a resource' do
|
it 'returns the estimate for a resource' do
|
||||||
expect(subject[:estimate]).to eq 1.5
|
expect(result[:estimate]).to eq 1.5
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,34 +7,34 @@ RSpec.describe Rating::Rating, ':values_data' do
|
||||||
include_context 'with_database_records'
|
include_context 'with_database_records'
|
||||||
|
|
||||||
context 'with no scopeable' do
|
context 'with no scopeable' do
|
||||||
subject { described_class.values_data article_1, nil }
|
subject(:result) { described_class.values_data article_1, nil }
|
||||||
|
|
||||||
it 'returns the average of value for a resource' do
|
it 'returns the average of value for a resource' do
|
||||||
expect(subject.as_json['rating_avg']).to eq 50.5
|
expect(result.as_json['rating_avg']).to eq 50.5
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the sum of values for a resource' do
|
it 'returns the sum of values for a resource' do
|
||||||
expect(subject.as_json['rating_sum']).to eq 101
|
expect(result.as_json['rating_sum']).to eq 101
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the count of votes for a resource' do
|
it 'returns the count of votes for a resource' do
|
||||||
expect(subject.as_json['rating_count']).to eq 2
|
expect(result.as_json['rating_count']).to eq 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with scopeable' do
|
context 'with scopeable' do
|
||||||
subject { described_class.values_data article_1, category }
|
subject(:result) { described_class.values_data article_1, category }
|
||||||
|
|
||||||
it 'returns the average of value for a resource' do
|
it 'returns the average of value for a resource' do
|
||||||
expect(subject.as_json['rating_avg']).to eq 1.5
|
expect(result.as_json['rating_avg']).to eq 1.5
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the sum of values for a resource' do
|
it 'returns the sum of values for a resource' do
|
||||||
expect(subject.as_json['rating_sum']).to eq 3
|
expect(result.as_json['rating_sum']).to eq 3
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the count of votes for a resource' do
|
it 'returns the count of votes for a resource' do
|
||||||
expect(subject.as_json['rating_count']).to eq 2
|
expect(result.as_json['rating_count']).to eq 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
RSpec.shared_context 'with_database_records' do
|
RSpec.shared_context 'with_database_records' do
|
||||||
let!(:category) { create :category }
|
let!(:category) { create :category }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue