Migrate to GitHub Actions
parent
5e23b3b06b
commit
c4c079fe90
|
@ -0,0 +1,38 @@
|
||||||
|
name: Test
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
ruby:
|
||||||
|
- 2.7
|
||||||
|
- '3.0'
|
||||||
|
- '3.1'
|
||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: mysql:8
|
||||||
|
env:
|
||||||
|
MYSQL_DATABASE: rating_test
|
||||||
|
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||||
|
ports:
|
||||||
|
- 3306:3306
|
||||||
|
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: ruby/setup-ruby@v1
|
||||||
|
with:
|
||||||
|
ruby-version: ${{ matrix.ruby }}
|
||||||
|
bundler-cache: true
|
||||||
|
- name: 'Runs tests'
|
||||||
|
run: bundle exec rake spec
|
||||||
|
- name: 'Runs tests with config enabled'
|
||||||
|
run: bundle exec rake spec_config
|
||||||
|
- name: 'Runs tests with config enabled for extra scopes'
|
||||||
|
run: bundle exec rake spec_config_with_extra_scopes
|
|
@ -0,0 +1,17 @@
|
||||||
|
name: RuboCop
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Set up Ruby
|
||||||
|
uses: ruby/setup-ruby@v1
|
||||||
|
with:
|
||||||
|
ruby-version: 2.7
|
||||||
|
bundler-cache: true # 'bundle install' and cache
|
||||||
|
- name: Run RuboCop
|
||||||
|
run: bundle exec rubocop --parallel
|
|
@ -1,17 +1,18 @@
|
||||||
require:
|
require:
|
||||||
- rubocop-performance
|
- rubocop-performance
|
||||||
|
- rubocop-rails
|
||||||
- rubocop-rspec
|
- rubocop-rspec
|
||||||
|
|
||||||
inherit_from: .rubocop_todo.yml
|
inherit_from: .rubocop_todo.yml
|
||||||
|
|
||||||
Layout/AlignArguments:
|
Layout/ArgumentAlignment:
|
||||||
EnforcedStyle: with_fixed_indentation
|
EnforcedStyle: with_fixed_indentation
|
||||||
|
|
||||||
Layout/AlignHash:
|
Layout/HashAlignment:
|
||||||
EnforcedColonStyle: table
|
EnforcedColonStyle: table
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
Layout/AlignParameters:
|
Layout/ParameterAlignment:
|
||||||
EnforcedStyle: with_fixed_indentation
|
EnforcedStyle: with_fixed_indentation
|
||||||
|
|
||||||
Layout/EmptyLinesAroundArguments:
|
Layout/EmptyLinesAroundArguments:
|
||||||
|
|
|
@ -0,0 +1,126 @@
|
||||||
|
# This configuration was generated by
|
||||||
|
# `rubocop --auto-gen-config`
|
||||||
|
# on 2022-04-21 22:55:24 UTC using RuboCop version 1.28.1.
|
||||||
|
# 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: 1
|
||||||
|
# Configuration parameters: Include.
|
||||||
|
# Include: **/*.gemspec
|
||||||
|
Gemspec/RequiredRubyVersion:
|
||||||
|
Exclude:
|
||||||
|
- 'rating.gemspec'
|
||||||
|
|
||||||
|
# Offense count: 1
|
||||||
|
# This cop supports safe auto-correction (--auto-correct).
|
||||||
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
|
||||||
|
# URISchemes: http, https
|
||||||
|
Layout/LineLength:
|
||||||
|
Max: 139
|
||||||
|
|
||||||
|
# Offense count: 3
|
||||||
|
# This cop supports unsafe auto-correction (--auto-correct-all).
|
||||||
|
Lint/NonDeterministicRequireOrder:
|
||||||
|
Exclude:
|
||||||
|
- 'spec/rails_helper.rb'
|
||||||
|
- 'spec/support/factory_bot.rb'
|
||||||
|
- 'spec/support/migrate.rb'
|
||||||
|
|
||||||
|
# Offense count: 1
|
||||||
|
# Configuration parameters: CountComments, CountAsOne.
|
||||||
|
Metrics/ClassLength:
|
||||||
|
Max: 106
|
||||||
|
|
||||||
|
# Offense count: 2
|
||||||
|
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
|
||||||
|
Metrics/ParameterLists:
|
||||||
|
Max: 6
|
||||||
|
|
||||||
|
# Offense count: 1
|
||||||
|
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers.
|
||||||
|
# SupportedStyles: snake_case, normalcase, non_integer
|
||||||
|
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
|
||||||
|
Naming/VariableNumber:
|
||||||
|
Exclude:
|
||||||
|
- 'spec/rails_helper.rb'
|
||||||
|
|
||||||
|
# Offense count: 2
|
||||||
|
# Configuration parameters: Prefixes.
|
||||||
|
# Prefixes: when, with, without
|
||||||
|
RSpec/ContextWording:
|
||||||
|
Exclude:
|
||||||
|
- 'spec/models/extension/order_by_rating_spec.rb'
|
||||||
|
- 'spec/support/shared_context/with_database_records.rb'
|
||||||
|
|
||||||
|
# Offense count: 15
|
||||||
|
RSpec/DescribeMethod:
|
||||||
|
Exclude:
|
||||||
|
- 'spec/models/extension/after_create_spec.rb'
|
||||||
|
- 'spec/models/extension/order_by_rating_spec.rb'
|
||||||
|
- 'spec/models/extension/rate_for_spec.rb'
|
||||||
|
- 'spec/models/extension/rate_spec.rb'
|
||||||
|
- 'spec/models/extension/rated_question_spec.rb'
|
||||||
|
- 'spec/models/extension/rated_spec.rb'
|
||||||
|
- 'spec/models/extension/rates_spec.rb'
|
||||||
|
- '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'
|
||||||
|
- 'spec/models/rating/averager_data_spec.rb'
|
||||||
|
- 'spec/models/rating/data_spec.rb'
|
||||||
|
- 'spec/models/rating/update_rating_spec.rb'
|
||||||
|
- 'spec/models/rating/values_data_spec.rb'
|
||||||
|
|
||||||
|
# Offense count: 6
|
||||||
|
RSpec/LetSetup:
|
||||||
|
Exclude:
|
||||||
|
- 'spec/support/shared_context/with_database_records.rb'
|
||||||
|
|
||||||
|
# Offense count: 12
|
||||||
|
# Configuration parameters: .
|
||||||
|
# SupportedStyles: have_received, receive
|
||||||
|
RSpec/MessageSpies:
|
||||||
|
EnforcedStyle: receive
|
||||||
|
|
||||||
|
# Offense count: 2
|
||||||
|
# Configuration parameters: AllowSubject.
|
||||||
|
RSpec/MultipleMemoizedHelpers:
|
||||||
|
Max: 12
|
||||||
|
|
||||||
|
# Offense count: 7
|
||||||
|
# Configuration parameters: IgnoreSharedExamples.
|
||||||
|
RSpec/NamedSubject:
|
||||||
|
Exclude:
|
||||||
|
- 'spec/config/rate_table_spec.rb'
|
||||||
|
- 'spec/config/rating_table_spec.rb'
|
||||||
|
- 'spec/config/validations_spec.rb'
|
||||||
|
- 'spec/models/rate_spec.rb'
|
||||||
|
|
||||||
|
# Offense count: 2
|
||||||
|
RSpec/RepeatedExampleGroupDescription:
|
||||||
|
Exclude:
|
||||||
|
- 'spec/models/extension/rated_spec.rb'
|
||||||
|
|
||||||
|
# Offense count: 2
|
||||||
|
# This cop supports safe auto-correction (--auto-correct).
|
||||||
|
Rails/ApplicationRecord:
|
||||||
|
Exclude:
|
||||||
|
- 'lib/rating/models/rating/rate.rb'
|
||||||
|
- 'lib/rating/models/rating/rating.rb'
|
||||||
|
|
||||||
|
# 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).
|
||||||
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
|
||||||
|
# URISchemes: http, https
|
||||||
|
Layout/LineLength:
|
||||||
|
Max: 139
|
|
@ -1 +0,0 @@
|
||||||
2.6.5
|
|
180
Gemfile.lock
180
Gemfile.lock
|
@ -7,118 +7,126 @@ PATH
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
actionpack (6.0.2.1)
|
actionpack (7.0.2.3)
|
||||||
actionview (= 6.0.2.1)
|
actionview (= 7.0.2.3)
|
||||||
activesupport (= 6.0.2.1)
|
activesupport (= 7.0.2.3)
|
||||||
rack (~> 2.0, >= 2.0.8)
|
rack (~> 2.0, >= 2.2.0)
|
||||||
rack-test (>= 0.6.3)
|
rack-test (>= 0.6.3)
|
||||||
rails-dom-testing (~> 2.0)
|
rails-dom-testing (~> 2.0)
|
||||||
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
||||||
actionview (6.0.2.1)
|
actionview (7.0.2.3)
|
||||||
activesupport (= 6.0.2.1)
|
activesupport (= 7.0.2.3)
|
||||||
builder (~> 3.1)
|
builder (~> 3.1)
|
||||||
erubi (~> 1.4)
|
erubi (~> 1.4)
|
||||||
rails-dom-testing (~> 2.0)
|
rails-dom-testing (~> 2.0)
|
||||||
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
||||||
activemodel (6.0.2.1)
|
activemodel (7.0.2.3)
|
||||||
activesupport (= 6.0.2.1)
|
activesupport (= 7.0.2.3)
|
||||||
activerecord (6.0.2.1)
|
activerecord (7.0.2.3)
|
||||||
activemodel (= 6.0.2.1)
|
activemodel (= 7.0.2.3)
|
||||||
activesupport (= 6.0.2.1)
|
activesupport (= 7.0.2.3)
|
||||||
activesupport (6.0.2.1)
|
activesupport (7.0.2.3)
|
||||||
concurrent-ruby (~> 1.0, >= 1.0.2)
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
||||||
i18n (>= 0.7, < 2)
|
i18n (>= 1.6, < 2)
|
||||||
minitest (~> 5.1)
|
minitest (>= 5.1)
|
||||||
tzinfo (~> 1.1)
|
tzinfo (~> 2.0)
|
||||||
zeitwerk (~> 2.2)
|
ast (2.4.2)
|
||||||
ast (2.4.0)
|
|
||||||
builder (3.2.4)
|
builder (3.2.4)
|
||||||
byebug (11.0.1)
|
concurrent-ruby (1.1.10)
|
||||||
coderay (1.1.2)
|
|
||||||
concurrent-ruby (1.1.5)
|
|
||||||
crass (1.0.6)
|
crass (1.0.6)
|
||||||
database_cleaner (1.7.0)
|
database_cleaner (2.0.1)
|
||||||
diff-lcs (1.3)
|
database_cleaner-active_record (~> 2.0.0)
|
||||||
erubi (1.9.0)
|
database_cleaner-active_record (2.0.1)
|
||||||
factory_bot (5.1.1)
|
activerecord (>= 5.a)
|
||||||
activesupport (>= 4.2.0)
|
database_cleaner-core (~> 2.0.0)
|
||||||
factory_bot_rails (5.1.1)
|
database_cleaner-core (2.0.1)
|
||||||
factory_bot (~> 5.1.0)
|
diff-lcs (1.5.0)
|
||||||
railties (>= 4.2.0)
|
erubi (1.10.0)
|
||||||
i18n (1.8.2)
|
factory_bot (6.2.1)
|
||||||
|
activesupport (>= 5.0.0)
|
||||||
|
factory_bot_rails (6.2.0)
|
||||||
|
factory_bot (~> 6.2.0)
|
||||||
|
railties (>= 5.0.0)
|
||||||
|
i18n (1.10.0)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
jaro_winkler (1.5.4)
|
loofah (2.16.0)
|
||||||
loofah (2.4.0)
|
|
||||||
crass (~> 1.0.2)
|
crass (~> 1.0.2)
|
||||||
nokogiri (>= 1.5.9)
|
nokogiri (>= 1.5.9)
|
||||||
method_source (0.9.2)
|
method_source (1.0.0)
|
||||||
mini_portile2 (2.4.0)
|
mini_portile2 (2.8.0)
|
||||||
minitest (5.14.0)
|
minitest (5.15.0)
|
||||||
mysql2 (0.5.3)
|
mysql2 (0.5.3)
|
||||||
nokogiri (1.10.7)
|
nokogiri (1.13.4)
|
||||||
mini_portile2 (~> 2.4.0)
|
mini_portile2 (~> 2.8.0)
|
||||||
parallel (1.19.1)
|
racc (~> 1.4)
|
||||||
parser (2.7.0.2)
|
parallel (1.22.1)
|
||||||
ast (~> 2.4.0)
|
parser (3.1.2.0)
|
||||||
pry (0.12.2)
|
ast (~> 2.4.1)
|
||||||
coderay (~> 1.1.0)
|
racc (1.6.0)
|
||||||
method_source (~> 0.9.0)
|
rack (2.2.3)
|
||||||
pry-byebug (3.7.0)
|
|
||||||
byebug (~> 11.0)
|
|
||||||
pry (~> 0.10)
|
|
||||||
rack (2.1.1)
|
|
||||||
rack-test (1.1.0)
|
rack-test (1.1.0)
|
||||||
rack (>= 1.0, < 3)
|
rack (>= 1.0, < 3)
|
||||||
rails-dom-testing (2.0.3)
|
rails-dom-testing (2.0.3)
|
||||||
activesupport (>= 4.2.0)
|
activesupport (>= 4.2.0)
|
||||||
nokogiri (>= 1.6)
|
nokogiri (>= 1.6)
|
||||||
rails-html-sanitizer (1.3.0)
|
rails-html-sanitizer (1.4.2)
|
||||||
loofah (~> 2.3)
|
loofah (~> 2.3)
|
||||||
railties (6.0.2.1)
|
railties (7.0.2.3)
|
||||||
actionpack (= 6.0.2.1)
|
actionpack (= 7.0.2.3)
|
||||||
activesupport (= 6.0.2.1)
|
activesupport (= 7.0.2.3)
|
||||||
method_source
|
method_source
|
||||||
rake (>= 0.8.7)
|
rake (>= 12.2)
|
||||||
thor (>= 0.20.3, < 2.0)
|
thor (~> 1.0)
|
||||||
rainbow (3.0.0)
|
zeitwerk (~> 2.5)
|
||||||
rake (13.0.1)
|
rainbow (3.1.1)
|
||||||
rspec-core (3.9.1)
|
rake (13.0.6)
|
||||||
rspec-support (~> 3.9.1)
|
regexp_parser (2.3.0)
|
||||||
rspec-expectations (3.9.0)
|
rexml (3.2.5)
|
||||||
|
rspec-core (3.11.0)
|
||||||
|
rspec-support (~> 3.11.0)
|
||||||
|
rspec-expectations (3.11.0)
|
||||||
diff-lcs (>= 1.2.0, < 2.0)
|
diff-lcs (>= 1.2.0, < 2.0)
|
||||||
rspec-support (~> 3.9.0)
|
rspec-support (~> 3.11.0)
|
||||||
rspec-mocks (3.9.1)
|
rspec-mocks (3.11.1)
|
||||||
diff-lcs (>= 1.2.0, < 2.0)
|
diff-lcs (>= 1.2.0, < 2.0)
|
||||||
rspec-support (~> 3.9.0)
|
rspec-support (~> 3.11.0)
|
||||||
rspec-rails (3.9.0)
|
rspec-rails (5.1.1)
|
||||||
actionpack (>= 3.0)
|
actionpack (>= 5.2)
|
||||||
activesupport (>= 3.0)
|
activesupport (>= 5.2)
|
||||||
railties (>= 3.0)
|
railties (>= 5.2)
|
||||||
rspec-core (~> 3.9.0)
|
rspec-core (~> 3.10)
|
||||||
rspec-expectations (~> 3.9.0)
|
rspec-expectations (~> 3.10)
|
||||||
rspec-mocks (~> 3.9.0)
|
rspec-mocks (~> 3.10)
|
||||||
rspec-support (~> 3.9.0)
|
rspec-support (~> 3.10)
|
||||||
rspec-support (3.9.2)
|
rspec-support (3.11.0)
|
||||||
rubocop (0.79.0)
|
rubocop (1.28.1)
|
||||||
jaro_winkler (~> 1.5.1)
|
|
||||||
parallel (~> 1.10)
|
parallel (~> 1.10)
|
||||||
parser (>= 2.7.0.1)
|
parser (>= 3.1.0.0)
|
||||||
rainbow (>= 2.2.2, < 4.0)
|
rainbow (>= 2.2.2, < 4.0)
|
||||||
|
regexp_parser (>= 1.8, < 3.0)
|
||||||
|
rexml
|
||||||
|
rubocop-ast (>= 1.17.0, < 2.0)
|
||||||
ruby-progressbar (~> 1.7)
|
ruby-progressbar (~> 1.7)
|
||||||
unicode-display_width (>= 1.4.0, < 1.7)
|
unicode-display_width (>= 1.4.0, < 3.0)
|
||||||
rubocop-performance (1.5.2)
|
rubocop-ast (1.17.0)
|
||||||
rubocop (>= 0.71.0)
|
parser (>= 3.1.1.0)
|
||||||
rubocop-rspec (1.37.1)
|
rubocop-performance (1.13.3)
|
||||||
rubocop (>= 0.68.1)
|
rubocop (>= 1.7.0, < 2.0)
|
||||||
ruby-progressbar (1.10.1)
|
rubocop-ast (>= 0.4.0)
|
||||||
shoulda-matchers (4.2.0)
|
rubocop-rails (2.14.2)
|
||||||
activesupport (>= 4.2.0)
|
activesupport (>= 4.2.0)
|
||||||
thor (1.0.1)
|
rack (>= 1.1)
|
||||||
thread_safe (0.3.6)
|
rubocop (>= 1.7.0, < 2.0)
|
||||||
tzinfo (1.2.6)
|
rubocop-rspec (2.10.0)
|
||||||
thread_safe (~> 0.1)
|
rubocop (~> 1.19)
|
||||||
unicode-display_width (1.6.1)
|
ruby-progressbar (1.11.0)
|
||||||
zeitwerk (2.2.2)
|
shoulda-matchers (5.1.0)
|
||||||
|
activesupport (>= 5.2.0)
|
||||||
|
thor (1.2.1)
|
||||||
|
tzinfo (2.0.4)
|
||||||
|
concurrent-ruby (~> 1.0)
|
||||||
|
unicode-display_width (2.1.0)
|
||||||
|
zeitwerk (2.5.4)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
|
@ -127,10 +135,10 @@ DEPENDENCIES
|
||||||
database_cleaner
|
database_cleaner
|
||||||
factory_bot_rails
|
factory_bot_rails
|
||||||
mysql2
|
mysql2
|
||||||
pry-byebug
|
|
||||||
rating!
|
rating!
|
||||||
rspec-rails
|
rspec-rails
|
||||||
rubocop-performance
|
rubocop-performance
|
||||||
|
rubocop-rails
|
||||||
rubocop-rspec
|
rubocop-rspec
|
||||||
shoulda-matchers
|
shoulda-matchers
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ module Rating
|
||||||
scope: ::Rating::Config.validations['rate']['scope'].map(&:to_sym),
|
scope: ::Rating::Config.validations['rate']['scope'].map(&:to_sym),
|
||||||
}
|
}
|
||||||
|
|
||||||
def self.create(author:, extra_scopes:, metadata:, resource:, scopeable: nil, value:)
|
def self.create(author:, extra_scopes:, metadata:, resource:, value:, scopeable: nil)
|
||||||
attributes = { author: author, resource: resource, scopeable: scopeable }.merge(extra_scopes)
|
attributes = { author: author, resource: resource, scopeable: scopeable }.merge(extra_scopes)
|
||||||
record = find_or_initialize_by(attributes)
|
record = find_or_initialize_by(attributes)
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ module Rating
|
||||||
record
|
record
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.rate_for(author:, extra_scopes: {}, resource:, scopeable: nil)
|
def self.rate_for(author:, resource:, extra_scopes: {}, scopeable: nil)
|
||||||
find_by extra_scopes.merge(author: author, resource: resource, scopeable: scopeable)
|
find_by extra_scopes.merge(author: author, resource: resource, scopeable: scopeable)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,9 @@ Gem::Specification.new do |spec|
|
||||||
spec.add_development_dependency 'database_cleaner'
|
spec.add_development_dependency 'database_cleaner'
|
||||||
spec.add_development_dependency 'factory_bot_rails'
|
spec.add_development_dependency 'factory_bot_rails'
|
||||||
spec.add_development_dependency 'mysql2'
|
spec.add_development_dependency 'mysql2'
|
||||||
spec.add_development_dependency 'pry-byebug'
|
|
||||||
spec.add_development_dependency 'rspec-rails'
|
spec.add_development_dependency 'rspec-rails'
|
||||||
spec.add_development_dependency 'rubocop-performance'
|
spec.add_development_dependency 'rubocop-performance'
|
||||||
|
spec.add_development_dependency 'rubocop-rails'
|
||||||
spec.add_development_dependency 'rubocop-rspec'
|
spec.add_development_dependency 'rubocop-rspec'
|
||||||
spec.add_development_dependency 'shoulda-matchers'
|
spec.add_development_dependency 'shoulda-matchers'
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :rating_rate, class: Rating::Rate do
|
factory :rating_rate, class: 'Rating::Rate' do
|
||||||
value { 100 }
|
value { 100 }
|
||||||
|
|
||||||
author { create :author }
|
author { create :author }
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :rating_rating, class: Rating::Rating do
|
factory :rating_rating, class: 'Rating::Rating' do
|
||||||
average { 100 }
|
average { 100 }
|
||||||
estimate { 100 }
|
estimate { 100 }
|
||||||
sum { 100 }
|
sum { 100 }
|
||||||
|
|
|
@ -8,7 +8,8 @@ RSpec.describe Rating::Extension, ':rate_for' do
|
||||||
|
|
||||||
context 'with no scopeable' do
|
context 'with no scopeable' do
|
||||||
it 'delegates to rate object' do
|
it 'delegates to rate object' do
|
||||||
expect(Rating::Rate).to receive(:rate_for).with author: author, extra_scopes: {}, resource: article, scopeable: nil
|
expect(Rating::Rate).to receive(:rate_for).with author: author, extra_scopes: {}, resource: article,
|
||||||
|
scopeable: nil
|
||||||
|
|
||||||
author.rate_for article
|
author.rate_for article
|
||||||
end
|
end
|
||||||
|
@ -18,7 +19,8 @@ RSpec.describe Rating::Extension, ':rate_for' do
|
||||||
let!(:category) { build :category }
|
let!(:category) { build :category }
|
||||||
|
|
||||||
it 'delegates to rate object' do
|
it 'delegates to rate object' do
|
||||||
expect(Rating::Rate).to receive(:rate_for).with author: author, extra_scopes: {}, resource: article, scopeable: category
|
expect(Rating::Rate).to receive(:rate_for).with author: author, extra_scopes: {}, resource: article,
|
||||||
|
scopeable: category
|
||||||
|
|
||||||
author.rate_for article, scope: category
|
author.rate_for article, scope: category
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,7 +51,12 @@ RSpec.describe Rating::Extension, ':rate' do
|
||||||
context 'with extra_scopes' do
|
context 'with extra_scopes' do
|
||||||
it 'delegates to rate object' do
|
it 'delegates to rate object' do
|
||||||
expect(Rating::Rate).to receive(:create).with(
|
expect(Rating::Rate).to receive(:create).with(
|
||||||
author: author, extra_scopes: { scope_1: 'scope_1' }, metadata: { comment: 'comment' }, resource: article, scopeable: nil, value: 3
|
author: author,
|
||||||
|
extra_scopes: { scope_1: 'scope_1' },
|
||||||
|
metadata: { comment: 'comment' },
|
||||||
|
resource: article,
|
||||||
|
scopeable: nil,
|
||||||
|
value: 3
|
||||||
)
|
)
|
||||||
|
|
||||||
author.rate article, 3, extra_scopes: { scope_1: 'scope_1' }, metadata: { comment: 'comment' }
|
author.rate article, 3, extra_scopes: { scope_1: 'scope_1' }, metadata: { comment: 'comment' }
|
||||||
|
|
|
@ -4,14 +4,13 @@ ENV['RAILS_ENV'] ||= 'test'
|
||||||
|
|
||||||
require 'active_record/railtie'
|
require 'active_record/railtie'
|
||||||
require 'mysql2'
|
require 'mysql2'
|
||||||
require 'pry-byebug'
|
|
||||||
require 'rating'
|
require 'rating'
|
||||||
|
|
||||||
client = Mysql2::Client.new(host: :localhost, username: :root)
|
client = Mysql2::Client.new(host: '127.0.0.1', username: :root)
|
||||||
|
|
||||||
client.query 'DROP DATABASE IF EXISTS rating_test;'
|
client.query 'DROP DATABASE IF EXISTS rating_test;'
|
||||||
client.query 'CREATE DATABASE IF NOT EXISTS rating_test;'
|
client.query 'CREATE DATABASE IF NOT EXISTS rating_test;'
|
||||||
|
|
||||||
ActiveRecord::Base.establish_connection adapter: :mysql2, database: :rating_test, username: :root
|
ActiveRecord::Base.establish_connection adapter: :mysql2, database: :rating_test, username: :root, host: '127.0.0.1'
|
||||||
|
|
||||||
Dir[File.expand_path('support/**/*.rb', __dir__)].each { |file| require file }
|
Dir[File.expand_path('support/**/*.rb', __dir__)].each { |file| require file }
|
||||||
|
|
Loading…
Reference in New Issue