diff --git a/.rubocop.yml b/.rubocop.yml index 6191b77..f171dcc 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -19,7 +19,7 @@ Style/TrailingCommaInArrayLiteral: Style/TrailingCommaInHashLiteral: EnforcedStyleForMultiline: no_comma -Layout/AlignParameters: +Layout/ParameterAlignment: EnforcedStyle: with_first_parameter # See https://github.com/rubocop-hq/rubocop/issues/4222 diff --git a/Gemfile b/Gemfile index 811fddf..27fde16 100644 --- a/Gemfile +++ b/Gemfile @@ -8,5 +8,5 @@ local_gemfile = "#{File.dirname(__FILE__)}/Gemfile.local" if File.exist?(local_gemfile) eval(File.read(local_gemfile)) # rubocop:disable Lint/Eval else - gem 'activerecord', '~> 5.2.4' + gem 'activerecord', '>= 5.2.4', '< 6.2' end \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 7bd8d8a..1a9c97d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -198,7 +198,7 @@ PLATFORMS ruby DEPENDENCIES - activerecord (~> 5.2.4) + activerecord (>= 5.2.4, < 6.2) ammeter (>= 1.1) bundler (>= 1.3) database_cleaner (>= 1.7) diff --git a/gemfiles/rails5.gemfile b/gemfiles/rails5.gemfile deleted file mode 100644 index 7583c62..0000000 --- a/gemfiles/rails5.gemfile +++ /dev/null @@ -1,6 +0,0 @@ -source "https://rubygems.org" - -gem 'rails', '~>5.1' -gem 'activerecord', '~> 5.2.4.3' - -gemspec path: '..' diff --git a/gemfiles/rails52.gemfile b/gemfiles/rails52.gemfile index 28481fd..c21e0c5 100644 --- a/gemfiles/rails52.gemfile +++ b/gemfiles/rails52.gemfile @@ -1,6 +1,6 @@ source "https://rubygems.org" -gem 'rails', '~>5.2' +gem 'rails', '~> 5.2' gem 'activerecord', '~> 5.2.4.3' gemspec path: '..' diff --git a/gemfiles/rails6.gemfile b/gemfiles/rails6.gemfile index f833f0c..6747b65 100644 --- a/gemfiles/rails6.gemfile +++ b/gemfiles/rails6.gemfile @@ -1,6 +1,6 @@ source "https://rubygems.org" -gem 'rails', '~>6.0' -gem 'activerecord', '~> 6.0' +gem 'rails', '~> 6.0', ' < 6.1' +gem 'activerecord', '~> 6.0', '< 6.1' gemspec path: '..' diff --git a/gemfiles/rails61.gemfile b/gemfiles/rails61.gemfile index aa243cc..2f7f0c9 100644 --- a/gemfiles/rails61.gemfile +++ b/gemfiles/rails61.gemfile @@ -1,6 +1,6 @@ source "https://rubygems.org" -gem 'rails', '~>6.1' +gem 'rails', '~> 6.1' gem 'activerecord', '~> 6.1' gemspec path: '..' diff --git a/lib/metka/generic_parser.rb b/lib/metka/generic_parser.rb index 9f20aa0..d045b9f 100644 --- a/lib/metka/generic_parser.rb +++ b/lib/metka/generic_parser.rb @@ -25,7 +25,7 @@ def call(value) gsub_quote_pattern!(tag_list, value, double_quote_pattern) gsub_quote_pattern!(tag_list, value, single_quote_pattern) - tag_list.merge value.split(Regexp.new delimiter).map(&:strip).reject(&:empty?) + tag_list.merge value.split(Regexp.new(delimiter)).map(&:strip).reject(&:empty?) when Enumerable tag_list.merge value.reject(&:empty?) end @@ -46,7 +46,7 @@ def delimiter end def single_quote_pattern - @single_quote_pattern[delimiter] ||= /(\A|#{delimiter})\s*'(.*?)'\s*(?=#{delimiter}\s*|\z)/ + @single_quote_pattern[delimiter] ||= /(\A|#{delimiter})\s*'(.*?)'\s*(?=#{delimiter}\s*|\z)/ end def double_quote_pattern diff --git a/lib/metka/model.rb b/lib/metka/model.rb index 8147768..96a285b 100644 --- a/lib/metka/model.rb +++ b/lib/metka/model.rb @@ -43,10 +43,10 @@ def included(base) base.class_eval do columns.each do |column| - scope "with_all_#{column}", ->(tags) { tagged_with(tags, on: [ column ]) } - scope "with_any_#{column}", ->(tags) { tagged_with(tags, on: [ column ], any: true) } - scope "without_all_#{column}", ->(tags) { tagged_with(tags, on: [ column ], exclude: true) } - scope "without_any_#{column}", ->(tags) { tagged_with(tags, on: [ column ], any: true, exclude: true) } + scope "with_all_#{column}", ->(tags) { tagged_with(tags, on: [column]) } + scope "with_any_#{column}", ->(tags) { tagged_with(tags, on: [column], any: true) } + scope "without_all_#{column}", ->(tags) { tagged_with(tags, on: [column], exclude: true) } + scope "without_any_#{column}", ->(tags) { tagged_with(tags, on: [column], any: true, exclude: true) } end unless respond_to?(:tagged_with) @@ -66,7 +66,7 @@ def included(base) prepared_unnest = columns.map { |column| "#{table_name}.#{column}" }.join(' || ') subquery = all.select("UNNEST(#{prepared_unnest}) AS tag_name") - unscoped.from(subquery).group(:tag_name).pluck(:tag_name, 'COUNT(*) AS taggings_count') + unscoped.from(subquery).group(:tag_name).pluck(:tag_name, Arel.sql('COUNT(*) AS taggings_count')) end columns.each do |column| diff --git a/lib/metka/query_builder.rb b/lib/metka/query_builder.rb index 70509bb..9e53f8c 100644 --- a/lib/metka/query_builder.rb +++ b/lib/metka/query_builder.rb @@ -10,11 +10,11 @@ class QueryBuilder def call(model, columns, tags, options) strategy = options_to_strategy(options) - query = join(options[:join_operator]) do + query = join(options[:join_operator]) { columns.map do |column| build_query(strategy, model, column, tags) end - end + } if options[:exclude].present? Arel::Nodes::Not.new(query) @@ -43,11 +43,13 @@ def join(operator, &block) end end - # @param nodes [Array, Arel::Node] - # @return [Arel::Node] + # @param nodes [Array, Arel::Nodes::Node] + # @return [Arel::Nodes::Node] def join_or(nodes) + node_base_klass = defined?(::Arel::Nodes::Node) ? ::Arel::Nodes::Node : ::Arel::Node + case nodes - when ::Arel::Node + when node_base_klass nodes when Array l, *r = nodes diff --git a/lib/metka/query_builder/base_query.rb b/lib/metka/query_builder/base_query.rb index a25246b..fee9453 100644 --- a/lib/metka/query_builder/base_query.rb +++ b/lib/metka/query_builder/base_query.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'singleton' module Metka diff --git a/spec/dummy/app/models/materialized_view_multitag_post.rb b/spec/dummy/app/models/materialized_view_multitag_post.rb index 340f2a9..500f7ec 100644 --- a/spec/dummy/app/models/materialized_view_multitag_post.rb +++ b/spec/dummy/app/models/materialized_view_multitag_post.rb @@ -3,7 +3,7 @@ # This class use materialized view strategy with aggregation by multiple tagged columns # You can find out more here: lib/generators/metka/strategies/materialized_view/materialized_view_generator.rb class MaterializedViewMultitagPost < ActiveRecord::Base - include Metka::Model(columns: %w(tags categories)) + include Metka::Model(columns: %w[tags categories]) belongs_to :user end diff --git a/spec/dummy/app/models/post.rb b/spec/dummy/app/models/post.rb index e616f34..35af1ba 100644 --- a/spec/dummy/app/models/post.rb +++ b/spec/dummy/app/models/post.rb @@ -2,7 +2,7 @@ # This class use ActiveRecord Strategy class Post < ActiveRecord::Base - include Metka::Model(columns: %w(tags categories)) + include Metka::Model(columns: %w[tags categories]) belongs_to :user end diff --git a/spec/dummy/app/models/tagged_materialized_view_post.rb b/spec/dummy/app/models/tagged_materialized_view_post.rb index de1e755..04108d4 100644 --- a/spec/dummy/app/models/tagged_materialized_view_post.rb +++ b/spec/dummy/app/models/tagged_materialized_view_post.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true class TaggedMaterializedViewPost < ActiveRecord::Base - end diff --git a/spec/dummy/app/models/tagged_view_post.rb b/spec/dummy/app/models/tagged_view_post.rb index 3fdb328..95b1c30 100644 --- a/spec/dummy/app/models/tagged_view_post.rb +++ b/spec/dummy/app/models/tagged_view_post.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true class TaggedViewPost < ActiveRecord::Base - end diff --git a/spec/dummy/app/models/tagged_with_tags_and_categories_materialized_view_multitag_post.rb b/spec/dummy/app/models/tagged_with_tags_and_categories_materialized_view_multitag_post.rb index fb659f4..6dcb00b 100644 --- a/spec/dummy/app/models/tagged_with_tags_and_categories_materialized_view_multitag_post.rb +++ b/spec/dummy/app/models/tagged_with_tags_and_categories_materialized_view_multitag_post.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true class TaggedWithTagsAndCategoriesMaterializedViewMultitagPost < ActiveRecord::Base - end diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb index b2aaea9..0d3bcdb 100644 --- a/spec/dummy/config/environments/test.rb +++ b/spec/dummy/config/environments/test.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true Rails.application.configure do - config.logger = ENV['LOG'] ? Logger.new(STDOUT) : nil + config.logger = ENV['LOG'] ? Logger.new($stdout) : nil config.active_record.dump_schema_after_migration = false end diff --git a/spec/dummy/db/migrate/02_create_posts.rb b/spec/dummy/db/migrate/02_create_posts.rb index f655f3c..ba5c7ce 100644 --- a/spec/dummy/db/migrate/02_create_posts.rb +++ b/spec/dummy/db/migrate/02_create_posts.rb @@ -3,10 +3,10 @@ class CreatePosts < ActiveRecord::Migration[5.0] def change create_table :posts do |t| - t.string :title + t.string :title t.integer :user_id, null: false - t.string :tags, array: true - t.string :categories, array: true + t.string :tags, array: true + t.string :categories, array: true t.timestamps end end diff --git a/spec/dummy/db/migrate/03_create_view_posts.rb b/spec/dummy/db/migrate/03_create_view_posts.rb index 8eb742b..b91b129 100644 --- a/spec/dummy/db/migrate/03_create_view_posts.rb +++ b/spec/dummy/db/migrate/03_create_view_posts.rb @@ -3,9 +3,9 @@ class CreateViewPosts < ActiveRecord::Migration[5.0] def change create_table :view_posts do |t| - t.string :title + t.string :title t.integer :user_id, null: false - t.string :tags, array: true + t.string :tags, array: true t.timestamps end end diff --git a/spec/dummy/db/migrate/04_create_materialized_view_posts.rb b/spec/dummy/db/migrate/04_create_materialized_view_posts.rb index f3eb09a..a5a987c 100644 --- a/spec/dummy/db/migrate/04_create_materialized_view_posts.rb +++ b/spec/dummy/db/migrate/04_create_materialized_view_posts.rb @@ -3,9 +3,9 @@ class CreateMaterializedViewPosts < ActiveRecord::Migration[5.0] def change create_table :materialized_view_posts do |t| - t.string :title + t.string :title t.integer :user_id, null: false - t.string :tags, array: true + t.string :tags, array: true t.timestamps end diff --git a/spec/dummy/db/migrate/05_create_materialized_view_multitag_posts.rb b/spec/dummy/db/migrate/05_create_materialized_view_multitag_posts.rb index f7ee46f..0d95f51 100644 --- a/spec/dummy/db/migrate/05_create_materialized_view_multitag_posts.rb +++ b/spec/dummy/db/migrate/05_create_materialized_view_multitag_posts.rb @@ -3,10 +3,10 @@ class CreateMaterializedViewMultitagPosts < ActiveRecord::Migration[5.0] def change create_table :materialized_view_multitag_posts do |t| - t.string :title + t.string :title t.integer :user_id, null: false - t.string :tags, array: true - t.string :categories, array: true + t.string :tags, array: true + t.string :categories, array: true t.timestamps end end diff --git a/spec/generators/strategies/materialized_view_generator_spec.rb b/spec/generators/strategies/materialized_view_generator_spec.rb index 2f1f320..ee583e4 100644 --- a/spec/generators/strategies/materialized_view_generator_spec.rb +++ b/spec/generators/strategies/materialized_view_generator_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -require 'generators/metka/strategies/materialized_view/materialized_view_generator.rb' +require 'generators/metka/strategies/materialized_view/materialized_view_generator' RSpec.describe Metka::Generators::Strategies::MaterializedViewGenerator, type: :generator do destination File.expand_path('../../tmp', __dir__) @@ -52,4 +52,3 @@ end end end - diff --git a/spec/metka/generic_parser_spec.rb b/spec/metka/generic_parser_spec.rb index 9c79cad..e64ac11 100644 --- a/spec/metka/generic_parser_spec.rb +++ b/spec/metka/generic_parser_spec.rb @@ -1,4 +1,3 @@ -# coding: utf-8 # frozen_string_literal: true require 'spec_helper' diff --git a/spec/metka/model/tagged_without_any_spec.rb b/spec/metka/model/tagged_without_any_spec.rb index 5e84fd2..3dd3ef5 100644 --- a/spec/metka/model/tagged_without_any_spec.rb +++ b/spec/metka/model/tagged_without_any_spec.rb @@ -5,9 +5,9 @@ RSpec.describe Metka::Model, :db do let!(:user) { User.create(name: Faker::Name.name) } - let!(:first_post) { Post.create(user_id: user.id, tags: ['ruby', 'elixir', 'crystal'], categories: ['ruby', 'programming']) } + let!(:first_post) { Post.create(user_id: user.id, tags: ['ruby', 'elixir', 'crystal'], categories: ['ruby', 'programming']) } let!(:second_post) { Post.create(user_id: user.id, tags: ['ruby', 'rails', 'react'], categories: ['programming', 'backend']) } - let!(:third_post) { Post.create(user_id: user.id, tags: ['php', 'yii2', 'angular'], categories: []) } + let!(:third_post) { Post.create(user_id: user.id, tags: ['php', 'yii2', 'angular'], categories: []) } context 'when use default join operator' do it 'should return collection without tag ruby' do diff --git a/spec/metka/model_spec.rb b/spec/metka/model_spec.rb index 752a6ae..017a069 100644 --- a/spec/metka/model_spec.rb +++ b/spec/metka/model_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe Metka::Model, :db do - let!(:tag_list) { 'ruby, rails, crystal' } + let!(:tag_list) { 'ruby, rails, crystal' } let!(:category_list) { 'programming, backend, frontend' } - let!(:user) { User.create(name: Faker::Name.name) } - let!(:user1) { User.create!(name: Faker::Name.name, tags: %w[developer senior]) } - let!(:user2) { User.create!(name: Faker::Name.name, tags: ['junior']) } - let!(:post) { Post.new(user_id: user.id)} + let!(:user) { User.create(name: Faker::Name.name) } + let!(:user1) { User.create!(name: Faker::Name.name, tags: %w[developer senior]) } + let!(:user2) { User.create!(name: Faker::Name.name, tags: ['junior']) } + let!(:post) { Post.new(user_id: user.id) } let!(:post_two) { Post.new(user_id: user.id)} before do diff --git a/spec/metka/post_spec.rb b/spec/metka/post_spec.rb index 116f98c..f777d5d 100644 --- a/spec/metka/post_spec.rb +++ b/spec/metka/post_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe Metka::Post, :model do - let!(:tag1) { 'tag1' } - let!(:tag2) { 'tag2' } - let!(:category1) { 'category1' } - let!(:category2) { 'category2' } + let!(:tag1) { 'tag1' } + let!(:tag2) { 'tag2' } + let!(:category1) { 'category1' } + let!(:category2) { 'category2' } let!(:shared_tag) { 'sharedtag' } let!(:unused_tag) { 'tag3' } - let!(:user) { User.create(name: Faker::Name.name) } + let!(:user) { User.create(name: Faker::Name.name) } let(:tagged_model) { Post } diff --git a/spec/metka/tagged_materialized_view_post_spec.rb b/spec/metka/tagged_materialized_view_post_spec.rb index 5bae163..a3ff890 100644 --- a/spec/metka/tagged_materialized_view_post_spec.rb +++ b/spec/metka/tagged_materialized_view_post_spec.rb @@ -3,10 +3,10 @@ require 'spec_helper' RSpec.describe Metka::TaggedMaterializedViewPost, :model do - let!(:tag1) { 'tag1' } - let!(:tag2) { 'tag2' } + let!(:tag1) { 'tag1' } + let!(:tag2) { 'tag2' } let!(:unused_tag) { 'tag3' } - let!(:user) { User.create(name: Faker::Name.name) } + let!(:user) { User.create(name: Faker::Name.name) } let(:tagged_model) { TaggedMaterializedViewPost } @@ -32,32 +32,32 @@ end it 'increases the counter on post with tag addition' do - expect{ MaterializedViewPost.create(user_id: user.id, tag_list: tag2) } - .to change{ tagged_model.find_by(tag_name: tag2).taggings_count } + expect { MaterializedViewPost.create(user_id: user.id, tag_list: tag2) } + .to change { tagged_model.find_by(tag_name: tag2).taggings_count } .by(1) end it 'decreases the counter on post with tag removal' do - expect{ materialized_view_post_1.delete } - .to change{ tagged_model.find_by(tag_name: tag1).taggings_count } + expect { materialized_view_post_1.delete } + .to change { tagged_model.find_by(tag_name: tag1).taggings_count } .by(-1) end it 'increases the counter on post tags expansion via update' do expect { materialized_view_post_1.update(tag_list: [tag1, tag2]) } - .to change{ tagged_model.find_by(tag_name: tag2).taggings_count } + .to change { tagged_model.find_by(tag_name: tag2).taggings_count } .by(1) end it 'decreases the counter on post tags narrowing via update' do expect { materialized_view_post_2.update(tag_list: tag2) } - .to change{ tagged_model.find_by(tag_name: tag1).taggings_count } + .to change { tagged_model.find_by(tag_name: tag1).taggings_count } .by(-1) end it 'decreases the counter on post tags nullify' do - expect{ materialized_view_post_1.update(tag_list: nil) } - .to change{ tagged_model.find_by(tag_name: tag1).taggings_count } + expect { materialized_view_post_1.update(tag_list: nil) } + .to change { tagged_model.find_by(tag_name: tag1).taggings_count } .by(-1) end end diff --git a/spec/metka/tagged_view_post_spec.rb b/spec/metka/tagged_view_post_spec.rb index 15c416b..d50b02e 100644 --- a/spec/metka/tagged_view_post_spec.rb +++ b/spec/metka/tagged_view_post_spec.rb @@ -3,10 +3,10 @@ require 'spec_helper' RSpec.describe Metka::TaggedViewPost, :model do - let!(:tag1) { 'tag1' } - let!(:tag2) { 'tag2' } + let!(:tag1) { 'tag1' } + let!(:tag2) { 'tag2' } let!(:unused_tag) { 'tag3' } - let!(:user) { User.create(name: Faker::Name.name) } + let!(:user) { User.create(name: Faker::Name.name) } let(:tagged_model) { TaggedViewPost } @@ -32,32 +32,32 @@ end it 'increases the counter on post with tag addition' do - expect{ ViewPost.create(user_id: user.id, tag_list: tag2) } - .to change{ tagged_model.find_by(tag_name: tag2).taggings_count } + expect { ViewPost.create(user_id: user.id, tag_list: tag2) } + .to change { tagged_model.find_by(tag_name: tag2).taggings_count } .by(1) end it 'decreases the counter on post with tag removal' do - expect{ view_post_1.delete } - .to change{ tagged_model.find_by(tag_name: tag1).taggings_count } + expect { view_post_1.delete } + .to change { tagged_model.find_by(tag_name: tag1).taggings_count } .by(-1) end it 'increases the counter on post tags expansion via update' do expect { view_post_1.update(tag_list: [tag1, tag2]) } - .to change{ tagged_model.find_by(tag_name: tag2).taggings_count } + .to change { tagged_model.find_by(tag_name: tag2).taggings_count } .by(1) end it 'decreases the counter on post tags narrowing via update' do expect { view_post_2.update(tag_list: tag2) } - .to change{ tagged_model.find_by(tag_name: tag1).taggings_count } + .to change { tagged_model.find_by(tag_name: tag1).taggings_count } .by(-1) end it 'decreases the counter on post tags nullify' do - expect{ view_post_1.update(tag_list: nil) } - .to change{ tagged_model.find_by(tag_name: tag1).taggings_count } + expect { view_post_1.update(tag_list: nil) } + .to change { tagged_model.find_by(tag_name: tag1).taggings_count } .by(-1) end end diff --git a/spec/metka/tagged_with_tags_and_categories_materialized_view_multitag_post_spec.rb b/spec/metka/tagged_with_tags_and_categories_materialized_view_multitag_post_spec.rb index 9a994e3..e068302 100644 --- a/spec/metka/tagged_with_tags_and_categories_materialized_view_multitag_post_spec.rb +++ b/spec/metka/tagged_with_tags_and_categories_materialized_view_multitag_post_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe Metka::TaggedWithTagsAndCategoriesMaterializedViewMultitagPost, :model do - let!(:tag1) { 'tag1' } - let!(:tag2) { 'tag2' } - let!(:category1) { 'category1' } - let!(:category2) { 'category2' } + let!(:tag1) { 'tag1' } + let!(:tag2) { 'tag2' } + let!(:category1) { 'category1' } + let!(:category2) { 'category2' } let!(:shared_tag) { 'sharedtag' } let!(:unused_tag) { 'tag3' } - let!(:user) { User.create(name: Faker::Name.name) } + let!(:user) { User.create(name: Faker::Name.name) } let(:tagged_model) { TaggedWithTagsAndCategoriesMaterializedViewMultitagPost } @@ -56,44 +56,44 @@ end it 'increases the counter on post with tag addition' do - expect{ MaterializedViewMultitagPost.create(user_id: user.id, tag_list: tag2, category_list: category1) } - .to change{ tagged_model.find_by(tag_name: tag2).taggings_count } + expect { MaterializedViewMultitagPost.create(user_id: user.id, tag_list: tag2, category_list: category1) } + .to change { tagged_model.find_by(tag_name: tag2).taggings_count } .by(1) - .and change{ tagged_model.find_by(tag_name: category1).taggings_count } + .and change { tagged_model.find_by(tag_name: category1).taggings_count } .by(1) end it 'decreases the counter on post with tag removal' do - expect{ materialized_view_multitag_post_1.delete } - .to change{ tagged_model.find_by(tag_name: tag1).taggings_count } + expect { materialized_view_multitag_post_1.delete } + .to change { tagged_model.find_by(tag_name: tag1).taggings_count } .by(-1) - .and change{ tagged_model.find_by(tag_name: shared_tag).taggings_count } + .and change { tagged_model.find_by(tag_name: shared_tag).taggings_count } .by(-1) - .and change{ tagged_model.find_by(tag_name: category1)&.taggings_count.to_i } + .and change { tagged_model.find_by(tag_name: category1)&.taggings_count.to_i } .by(-1) - .and change{ tagged_model.find_by(tag_name: category2).taggings_count } + .and change { tagged_model.find_by(tag_name: category2).taggings_count } .by(-1) end it 'increases the counter on post tags expansion via update' do - expect{ materialized_view_multitag_post_1.update(tag_list: [tag1, tag2]) } - .to change{ tagged_model.find_by(tag_name: tag2).taggings_count } + expect { materialized_view_multitag_post_1.update(tag_list: [tag1, tag2]) } + .to change { tagged_model.find_by(tag_name: tag2).taggings_count } .by(1) - .and change{ tagged_model.find_by(tag_name: shared_tag).taggings_count } + .and change { tagged_model.find_by(tag_name: shared_tag).taggings_count } .by(-1) end it 'decreases the counter on post tags narrowing via update' do - expect{ materialized_view_multitag_post_2.update(category_list: category2) } - .to change{ tagged_model.find_by(tag_name: shared_tag).taggings_count } + expect { materialized_view_multitag_post_2.update(category_list: category2) } + .to change { tagged_model.find_by(tag_name: shared_tag).taggings_count } .by(-1) end it 'decreases the counter on post tags nullify' do - expect{ materialized_view_multitag_post_1.update(tag_list: nil) } - .to change{ tagged_model.find_by(tag_name: tag1).taggings_count } + expect { materialized_view_multitag_post_1.update(tag_list: nil) } + .to change { tagged_model.find_by(tag_name: tag1).taggings_count } .by(-1) - .and change{ tagged_model.find_by(tag_name: shared_tag).taggings_count } + .and change { tagged_model.find_by(tag_name: shared_tag).taggings_count } .by(-1) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9d618f2..99ab983 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,8 +7,7 @@ require File.expand_path('dummy/config/environment', __dir__) require 'database_cleaner' -require './spec/support/database_cleaner.rb' - +require './spec/support/database_cleaner' require 'ammeter/init' require 'faker' diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index b8e6866..88dbfdc 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.configure do |config| config.before(:suite) do DatabaseCleaner.clean_with(:truncation)