diff --git a/.rubocop.yml b/.rubocop.yml index 7e692d4f3..dcb020c0e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,8 +4,8 @@ require: - rubocop-performance AllCops: - TargetRailsVersion: 6.0 - TargetRubyVersion: 3.0 + TargetRailsVersion: 7.0 + TargetRubyVersion: 3.1 Exclude: - 'bin/**/*' - 'db/schema.rb' @@ -105,5 +105,8 @@ Naming/MemoizedInstanceVariableName: RSpec/FilePath: Enabled: false +RSpec/SpecFilePathFormat: + Enabled: false + Rails/BulkChangeTable: Enabled: false diff --git a/Gemfile b/Gemfile index 4c56719c1..3b74175d1 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ gem 'browser', '~> 5.3.1' gem 'devise', '~>4.9.2' gem 'devise-i18n', '~>1.11.0' gem 'factory_bot_rails', '~> 6.2.0' -gem 'faker', '~> 3.2.0' +gem 'faker', '~> 3.5.1' gem 'font-awesome-rails', '~> 4.7.0.8' gem 'http', '~> 5.1.1' gem 'jbuilder', '~> 2.11.5' @@ -74,10 +74,10 @@ end group :test do gem 'rails-controller-testing', '~> 1.0.5' - gem 'rubocop', '~> 1.50.2', require: false + gem 'rubocop', '~> 1.61', require: false gem 'rubocop-performance' gem 'rubocop-rails' - gem 'rubocop-rspec' + gem 'rubocop-rspec', '~> 2.25' gem 'simplecov', require: false gem 'simplecov-lcov', '~> 0.8.0', require: false gem 'terminal-notifier-guard' diff --git a/Gemfile.lock b/Gemfile.lock index e9f5069cf..1372c10cf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -135,7 +135,7 @@ GEM factory_bot_rails (6.2.0) factory_bot (~> 6.2.0) railties (>= 5.0.0) - faker (3.2.3) + faker (3.5.1) i18n (>= 1.8.11, < 2) faraday (2.12.2) faraday-net_http (>= 2.0, < 3.5) @@ -210,6 +210,7 @@ GEM activerecord kaminari-core (= 1.2.2) kaminari-core (1.2.2) + language_server-protocol (3.17.0.3) libv8-node (16.19.0.1-x86_64-linux) listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) @@ -396,7 +397,6 @@ GEM http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) - rexml (3.4.0) rouge (4.5.1) rspec (3.13.0) rspec-core (~> 3.13.0) @@ -419,28 +419,37 @@ GEM rspec-mocks (~> 3.13) rspec-support (~> 3.13) rspec-support (3.13.2) - rubocop (1.50.2) + rubocop (1.69.2) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.0, < 2.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.36.2, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) + unicode-display_width (>= 2.4.0, < 4.0) rubocop-ast (1.37.0) parser (>= 3.3.1.0) + rubocop-capybara (2.21.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.26.1) + rubocop (~> 1.61) rubocop-performance (1.23.0) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rails (2.25.1) + rubocop-rails (2.28.0) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 1.33.0, < 2.0) + rubocop (>= 1.52.0, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rspec (3.0.0) + rubocop-rspec (2.31.0) rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + rubocop-rspec_rails (~> 2.28) + rubocop-rspec_rails (2.29.1) + rubocop (~> 1.61) ruby-progressbar (1.13.0) rufus-scheduler (3.9.2) fugit (~> 1.1, >= 1.11.1) @@ -518,7 +527,9 @@ GEM concurrent-ruby (~> 1.0) uglifier (4.2.1) execjs (>= 0.3.0, < 3) - unicode-display_width (2.6.0) + unicode-display_width (3.1.3) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) uniform_notifier (1.16.0) uri (1.0.2) validates_timeliness (7.0.0) @@ -564,7 +575,7 @@ DEPENDENCIES devise-i18n (~> 1.11.0) dotenv-rails (~> 2.8.1) factory_bot_rails (~> 6.2.0) - faker (~> 3.2.0) + faker (~> 3.5.1) font-awesome-rails (~> 4.7.0.8) foreman guard-livereload (~> 2.5.2) @@ -598,10 +609,10 @@ DEPENDENCIES redis-rails (~> 5.0.2) rest-client (~> 2.1.0) rspec-rails - rubocop (~> 1.50.2) + rubocop (~> 1.61) rubocop-performance rubocop-rails - rubocop-rspec + rubocop-rspec (~> 2.25) sassc-rails (~> 2.1.2) sentry-rails (~> 5.9) sentry-ruby (~> 5.9) diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index 6decfedf6..9afce5b31 100644 --- a/app/controllers/activities_controller.rb +++ b/app/controllers/activities_controller.rb @@ -22,6 +22,28 @@ def index @price_lists_json = PriceList.unarchived.to_json(only: %i[id name]) end + def show # rubocop:disable Metrics/AbcSize, Metrics/MethodLength + @activity = Activity.includes(:price_list, + { orders: [{ order_rows: :product }, :user, :created_by] }).find(params[:id]) + authorize @activity + + @price_list = @activity.price_list + @bartenders = @activity.bartenders + @orders = @activity.orders + + @credit_mutations = @activity.credit_mutations + @credit_mutations_total = @activity.credit_mutations_total + + @revenue_by_category = @activity.revenue_by_category + @revenue_with_cash = @activity.revenue_with_cash + @revenue_with_pin = @activity.revenue_with_pin + @revenue_with_credit = @activity.revenue_with_credit + @cash_total = @activity.cash_total + @revenue_total = @activity.revenue_total + + @count_per_product = @activity.count_per_product + end + def create @activity = Activity.new(permitted_attributes.merge(created_by: current_user)) authorize @activity @@ -61,28 +83,6 @@ def destroy redirect_to Activity end - def show # rubocop:disable Metrics/AbcSize, Metrics/MethodLength - @activity = Activity.includes(:price_list, - { orders: [{ order_rows: :product }, :user, :created_by] }).find(params[:id]) - authorize @activity - - @price_list = @activity.price_list - @bartenders = @activity.bartenders - @orders = @activity.orders - - @credit_mutations = @activity.credit_mutations - @credit_mutations_total = @activity.credit_mutations_total - - @revenue_by_category = @activity.revenue_by_category - @revenue_with_cash = @activity.revenue_with_cash - @revenue_with_pin = @activity.revenue_with_pin - @revenue_with_credit = @activity.revenue_with_credit - @cash_total = @activity.cash_total - @revenue_total = @activity.revenue_total - - @count_per_product = @activity.count_per_product - end - def order_screen # rubocop:disable Metrics/MethodLength, Metrics/AbcSize authorize Activity diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 73496787d..ca5521a48 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -78,7 +78,7 @@ def allowed_filters end def send_insufficient_credit_mail?(user, old_credit) - return if user.nil? + return false if user.nil? user.provider == 'amber_oauth2' && user.credit.negative? && old_credit.positive? end diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb index 4f6ed90e6..c4e2d3b9f 100644 --- a/app/controllers/payments_controller.rb +++ b/app/controllers/payments_controller.rb @@ -3,7 +3,7 @@ class PaymentsController < ApplicationController after_action :verify_authorized, only: %i[index create add] def index - @payments = Payment.all.order(created_at: :desc) + @payments = Payment.order(created_at: :desc) authorize @payments end diff --git a/app/controllers/price_lists_controller.rb b/app/controllers/price_lists_controller.rb index 31783b5ed..5223025f2 100644 --- a/app/controllers/price_lists_controller.rb +++ b/app/controllers/price_lists_controller.rb @@ -8,7 +8,7 @@ def index authorize PriceList price_lists = policy_scope(PriceList.order(created_at: :desc)) - products = Product.all.order(:id).includes(:product_prices) + products = Product.order(:id).includes(:product_prices) @price_list = PriceList.new diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 13c0d17c3..c7fb5eadc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,10 +1,10 @@ module ApplicationHelper # TODO: Spec this method # :nocov: - def nav_link(name = nil, options = nil, html_options = nil, &block) + def nav_link(name = nil, options = nil, html_options = nil, &) options&.merge!(class: 'active') { |_, v1, v2| [v1, v2].join ' ' } if current_page?(name) - link_to(name, options, html_options, &block) + link_to(name, options, html_options, &) end def flash_class(level) diff --git a/app/models/activity.rb b/app/models/activity.rb index 12433222a..14c69c630 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -12,19 +12,19 @@ class Activity < ApplicationRecord validates_datetime :end_time, after: :start_time validate :activity_not_locked - scope :upcoming, (lambda { + scope :upcoming, lambda { where('(start_time < ? and end_time > ?) or start_time > ?', Time.zone.now, Time.zone.now, Time.zone.now).order(:start_time, :end_time) - }) + } - scope :current, (lambda { + scope :current, lambda { where('(start_time < ? and end_time > ?)', Time.zone.now, Time.zone.now).order(:start_time, :end_time) - }) + } - scope :not_locked, (lambda { + scope :not_locked, lambda { where('end_time >= ? AND locked_by_id IS NULL', 2.months.ago) - }) + } delegate :products, to: :price_list diff --git a/app/models/credit_mutation.rb b/app/models/credit_mutation.rb index 6a2f48bb2..7bd71f7de 100644 --- a/app/models/credit_mutation.rb +++ b/app/models/credit_mutation.rb @@ -8,9 +8,9 @@ class CreditMutation < ApplicationRecord validate :activity_not_locked - scope :linked_to_activity, (lambda { + scope :linked_to_activity, lambda { where.not(activity: nil) - }) + } before_destroy -> { throw(:abort) } diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 43afe14b4..a688e69b9 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -1,7 +1,7 @@ class Invoice < ApplicationRecord has_secure_token - enum status: { pending: 0, sent: 1, paid: 3 } + enum :status, { pending: 0, sent: 1, paid: 3 } belongs_to :user belongs_to :activity diff --git a/app/models/order.rb b/app/models/order.rb index 9a4318f78..2ab5062be 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -15,7 +15,7 @@ class Order < ApplicationRecord before_create :can_user_create_order? before_destroy -> { throw(:abort) } - scope :orders_for, (->(user) { where(user: user) }) + scope :orders_for, ->(user) { where(user: user) } def can_user_create_order? throw(:abort) unless user.nil? || user.can_order(activity) diff --git a/app/models/payment.rb b/app/models/payment.rb index 8a5982dec..b993348c9 100644 --- a/app/models/payment.rb +++ b/app/models/payment.rb @@ -6,7 +6,7 @@ class << self undef_method :open end # See: https://docs.mollie.com/payments/status-changes - enum status: { open: 0, pending: 1, paid: 2, failed: 3, canceled: 4, expired: 5 } + enum :status, { open: 0, pending: 1, paid: 2, failed: 3, canceled: 4, expired: 5 } COMPLETE_STATUSES = %w[paid failed canceled expired].freeze belongs_to :user, optional: true @@ -18,7 +18,7 @@ class << self validate :user_xor_invoice validate :user_amount - scope :not_completed, (-> { where.not(status: COMPLETE_STATUSES) }) + scope :not_completed, -> { where.not(status: COMPLETE_STATUSES) } after_save :process_complete_payment! diff --git a/app/models/price_list.rb b/app/models/price_list.rb index dff0a3006..42e050344 100644 --- a/app/models/price_list.rb +++ b/app/models/price_list.rb @@ -5,7 +5,7 @@ class PriceList < ApplicationRecord validates :name, presence: true - scope :unarchived, (-> { where(archived_at: nil) }) + scope :unarchived, -> { where(archived_at: nil) } def product_price_for(product) @product_price ||= ProductPrice.includes(:product).where(price_list: self) diff --git a/app/models/product.rb b/app/models/product.rb index 8082251ac..43cf21bf2 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,6 +1,6 @@ class Product < ApplicationRecord - enum category: { beer: 0, low_alcohol_beer: 9, craft_beer: 6, non_alcoholic: 1, distilled: 2, whiskey: 8, wine: 3, food: 4, tobacco: 5, - donation: 7 } + enum :category, { beer: 0, low_alcohol_beer: 9, craft_beer: 6, non_alcoholic: 1, distilled: 2, whiskey: 8, wine: 3, food: 4, tobacco: 5, + donation: 7 } has_many :product_prices, dependent: :destroy has_many :price_lists, through: :product_prices, dependent: :restrict_with_error diff --git a/app/models/role.rb b/app/models/role.rb index 55d9a47a2..accda5999 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -1,5 +1,5 @@ class Role < ApplicationRecord - enum role_type: { treasurer: 0, main_bartender: 1, renting_manager: 2 } + enum :role_type, { treasurer: 0, main_bartender: 1, renting_manager: 2 } validates :role_type, :group_uid, presence: true has_many :roles_users, class_name: 'RolesUsers', dependent: :destroy, inverse_of: :role diff --git a/app/models/user.rb b/app/models/user.rb index 086e3d444..f7862ce68 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,11 +12,11 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength validates :uid, uniqueness: true, allow_blank: true validate :no_deactivation_when_nonzero_credit - scope :in_amber, (-> { where(provider: 'amber_oauth2') }) - scope :manual, (-> { where(provider: nil) }) - scope :active, (-> { where(deactivated: false) }) - scope :inactive, (-> { where(deactivated: true) }) - scope :treasurer, (-> { joins(:roles).merge(Role.treasurer) }) + scope :in_amber, -> { where(provider: 'amber_oauth2') } + scope :manual, -> { where(provider: nil) } + scope :active, -> { where(deactivated: false) } + scope :inactive, -> { where(deactivated: true) } + scope :treasurer, -> { joins(:roles).merge(Role.treasurer) } attr_accessor :current_activity @@ -53,7 +53,7 @@ def can_order(activity = nil) if activity.nil? !insufficient_credit else - !insufficient_credit or activity.orders.select { |order| order.user_id == id }.any? + !insufficient_credit or activity.orders.any? { |order| order.user_id == id } end end @@ -113,15 +113,15 @@ def self.full_name_from_attributes(first_name, last_name_prefix, last_name, nick end def self.calculate_credits - credits = User.all.left_outer_joins(:credit_mutations).group(:id).sum('amount') + credits = User.left_outer_joins(:credit_mutations).group(:id).sum('amount') costs = User.calculate_spendings credits.each_with_object({}) { |(id, credit), h| h[id] = credit - costs.fetch(id, 0) } end def self.calculate_spendings(from: '01-01-1970', to: Time.zone.now) - User.all.joins(:order_rows) - .where('orders.created_at >= ? AND orders.created_at < ?', from, to) + User.joins(:order_rows) + .where(orders: { created_at: from...to }) .group(:id).sum('product_count * price_per_product') end diff --git a/config/initializers/wicked_pdf.rb b/config/initializers/wicked_pdf.rb index e3b693e0f..1b5c0e317 100644 --- a/config/initializers/wicked_pdf.rb +++ b/config/initializers/wicked_pdf.rb @@ -8,7 +8,8 @@ # # https://github.com/mileszs/wicked_pdf/blob/master/README.md -WickedPdf.config = { +WickedPdf.configure do |c| + # Path to the wkhtmltopdf executable: This usually isn't needed if using # one of the wkhtmltopdf-binary family of gems. # exe_path: '/usr/local/bin/wkhtmltopdf', @@ -17,5 +18,5 @@ # Layout file to be used for all PDFs # (but can be overridden in `render :pdf` calls) - layout: 'pdf.html.erb' -} + c.layout = 'pdf.html.erb' +end diff --git a/db/migrate/20180107182815_add_functional_name_to_role.rb b/db/migrate/20180107182815_add_functional_name_to_role.rb index d553e4c21..3f0742978 100644 --- a/db/migrate/20180107182815_add_functional_name_to_role.rb +++ b/db/migrate/20180107182815_add_functional_name_to_role.rb @@ -3,7 +3,7 @@ def up remove_index :roles, column: %i[name group_uid] add_column :roles, :role_type, :integer - Role.all.each do |role| + Role.find_each do |role| name = role.read_attribute(:name) case name when 'Treasurer' @@ -21,7 +21,7 @@ def down remove_index :roles, column: %i[role_type group_uid] add_column :roles, :name, :string - Role.all.each do |role| + Role.find_each do |role| if role.treasurer? role.update(name: 'Treasurer') elsif role.main_bartender? diff --git a/db/seeds.rb b/db/seeds.rb index 3043c9a22..9a5534757 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,4 +1,4 @@ -require_relative './seeds/products' +require_relative 'seeds/products' # rubocop:disable Rails/Output p 'Seeding products...' @@ -6,9 +6,8 @@ p 'Seeding price lists...' price_lists_names = %w[BSA Inkoopprijs Extern] -price_lists = [] -price_lists_names.each do |name| - price_lists << FactoryBot.create(:price_list, :with_all_products, name: name) +price_lists = price_lists_names.map do |name| + FactoryBot.create(:price_list, :with_all_products, name: name) end p 'Seeding users...' diff --git a/db/seeds/products.rb b/db/seeds/products.rb index 8d8862fe7..1bc4014c7 100644 --- a/db/seeds/products.rb +++ b/db/seeds/products.rb @@ -1,6 +1,4 @@ def seed_products # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity - products = [] - # rubocop:disable Style/WordArray products_beer = ['Bier (glas)', 'Bier (pul)', 'Bier (pitcher)', '12+1'] products_low_alcohol_beer = ['Alcoholarm bier', 'Radler 0.0'] @@ -14,8 +12,8 @@ def seed_products # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metri products_donation = ['Donatie'] # rubocop:enable Style/WordArray - products_beer.each do |name| - products << Product.create(name: name, category: :beer) + products = products_beer.map do |name| + Product.create(name: name, category: :beer) end products_low_alcohol_beer.each do |name| diff --git a/lib/omniauth/strategies/amber_oauth2.rb b/lib/omniauth/strategies/amber_oauth2.rb index 991439f8a..12790ee81 100644 --- a/lib/omniauth/strategies/amber_oauth2.rb +++ b/lib/omniauth/strategies/amber_oauth2.rb @@ -46,7 +46,7 @@ def full_name(raw_info) end def groups_from_json(json) - json.map { |group| group['id'] } + json.pluck('id') end end end diff --git a/spec/controllers/activities_controller/create_invoices_spec.rb b/spec/controllers/activities_controller/create_invoices_spec.rb index 95ee573cb..f321e6f11 100644 --- a/spec/controllers/activities_controller/create_invoices_spec.rb +++ b/spec/controllers/activities_controller/create_invoices_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ActivitiesController, type: :controller do +describe ActivitiesController do describe 'POST create_invoices' do let(:activity) { create(:activity) } let(:request) do diff --git a/spec/controllers/activities_controller/create_spec.rb b/spec/controllers/activities_controller/create_spec.rb index 91c31f2c3..adf986bf5 100644 --- a/spec/controllers/activities_controller/create_spec.rb +++ b/spec/controllers/activities_controller/create_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ActivitiesController, type: :controller do +describe ActivitiesController do describe 'POST create' do let(:activity) do build(:activity, price_list: create(:price_list)) diff --git a/spec/controllers/activities_controller/destroy_spec.rb b/spec/controllers/activities_controller/destroy_spec.rb index 7333ef35c..c5ee6b3ce 100644 --- a/spec/controllers/activities_controller/destroy_spec.rb +++ b/spec/controllers/activities_controller/destroy_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ActivitiesController, type: :controller do +describe ActivitiesController do describe 'DELETE destroy' do let(:activity) do create(:activity, price_list: create(:price_list)) diff --git a/spec/controllers/activities_controller/index_spec.rb b/spec/controllers/activities_controller/index_spec.rb index ca837556f..99569c6a8 100644 --- a/spec/controllers/activities_controller/index_spec.rb +++ b/spec/controllers/activities_controller/index_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ActivitiesController, type: :controller do +describe ActivitiesController do describe 'GET index' do let(:unlocked_activities) { create(:activity) } let(:locked_activities) { create_list(:activity, 2, :locked) } diff --git a/spec/controllers/activities_controller/lock_spec.rb b/spec/controllers/activities_controller/lock_spec.rb index e12c328db..dee50bec9 100644 --- a/spec/controllers/activities_controller/lock_spec.rb +++ b/spec/controllers/activities_controller/lock_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ActivitiesController, type: :controller do +describe ActivitiesController do describe 'POST lock' do let(:activity) { create(:activity) } let(:request) do diff --git a/spec/controllers/activities_controller/product_totals_spec.rb b/spec/controllers/activities_controller/product_totals_spec.rb index 1b5838c3a..b08efc0f2 100644 --- a/spec/controllers/activities_controller/product_totals_spec.rb +++ b/spec/controllers/activities_controller/product_totals_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ActivitiesController, type: :controller do +describe ActivitiesController do describe 'GET product_totals' do let(:activity) { create(:activity) } let(:params) { { id: activity.id } } diff --git a/spec/controllers/activities_controller/update_spec.rb b/spec/controllers/activities_controller/update_spec.rb index f9bf95e37..824f7cf9c 100644 --- a/spec/controllers/activities_controller/update_spec.rb +++ b/spec/controllers/activities_controller/update_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ActivitiesController, type: :controller do +describe ActivitiesController do describe 'PUT update' do let(:activity) do create(:activity, price_list: create(:price_list)) diff --git a/spec/controllers/credit_mutations_controller/create_spec.rb b/spec/controllers/credit_mutations_controller/create_spec.rb index df987739f..3713edce3 100644 --- a/spec/controllers/credit_mutations_controller/create_spec.rb +++ b/spec/controllers/credit_mutations_controller/create_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe CreditMutationsController, type: :controller do +describe CreditMutationsController do describe 'POST create' do let(:user) { create(:user) } let(:credit_mutation) do @@ -9,58 +9,58 @@ let(:credit_mutation_with_activity) do build(:credit_mutation, activity: create(:activity), user: user) end - let(:request1) do + let(:without_activty) do post :create, params: { credit_mutation: credit_mutation.attributes, format: :json } end - let(:request2) do + let(:with_activty) do post :create, params: { credit_mutation: credit_mutation_with_activity.attributes, format: :json } end context 'when as treasurer' do it 'creates a new credit_mutation' do sign_in create(:user, :treasurer) - expect { request1 }.to(change(CreditMutation, :count).by(1)) + expect { without_activty }.to(change(CreditMutation, :count).by(1)) end it 'creates a new credit_mutation linked to an activity' do sign_in create(:user, :treasurer) - expect { request2 }.to(change(CreditMutation, :count).by(1)) + expect { with_activty }.to(change(CreditMutation, :count).by(1)) end end context 'when as renting-manager' do it 'creates a new credit_mutation' do sign_in create(:user, :renting_manager) - expect { request1 }.not_to change(CreditMutation, :count) + expect { without_activty }.not_to change(CreditMutation, :count) end it 'creates a new credit_mutation linked to an activity' do sign_in create(:user, :renting_manager) - expect { request2 }.not_to change(CreditMutation, :count) + expect { with_activty }.not_to change(CreditMutation, :count) end end context 'when as main-bartender' do it 'creates a new credit_mutation' do sign_in create(:user, :main_bartender) - expect { request1 }.not_to change(CreditMutation, :count) + expect { without_activty }.not_to change(CreditMutation, :count) end it 'creates a new credit_mutation linked to an activity' do sign_in create(:user, :main_bartender) - expect { request2 }.to(change(CreditMutation, :count).by(1)) + expect { with_activty }.to(change(CreditMutation, :count).by(1)) end end context 'when as user' do it 'creates a new credit_mutation' do sign_in create(:user) - expect { request1 }.not_to change(CreditMutation, :count) + expect { without_activty }.not_to change(CreditMutation, :count) end it 'creates a new credit_mutation linked to an activity' do sign_in create(:user) - expect { request2 }.not_to change(CreditMutation, :count) + expect { with_activty }.not_to change(CreditMutation, :count) end end end diff --git a/spec/controllers/credit_mutations_controller/index_spec.rb b/spec/controllers/credit_mutations_controller/index_spec.rb index 088cedf93..c1bd79338 100644 --- a/spec/controllers/credit_mutations_controller/index_spec.rb +++ b/spec/controllers/credit_mutations_controller/index_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe CreditMutationsController, type: :controller do +describe CreditMutationsController do describe 'GET index' do let(:credit_mutation) { create(:credit_mutation, user: create(:user)) } let(:credit_mutation_with_activity) { create(:credit_mutation, activity: create(:activity), user: create(:user)) } diff --git a/spec/controllers/invoices_controller/create_spec.rb b/spec/controllers/invoices_controller/create_spec.rb index 892eec3f2..e5e962270 100644 --- a/spec/controllers/invoices_controller/create_spec.rb +++ b/spec/controllers/invoices_controller/create_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe InvoicesController, type: :controller do +describe InvoicesController do describe 'POST create' do let(:invoice) do build(:invoice, user: create(:user), activity: create(:activity, :locked)) diff --git a/spec/controllers/invoices_controller/index_spec.rb b/spec/controllers/invoices_controller/index_spec.rb index ab7fad4e9..8ae1b7282 100644 --- a/spec/controllers/invoices_controller/index_spec.rb +++ b/spec/controllers/invoices_controller/index_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe InvoicesController, type: :controller do +describe InvoicesController do describe 'GET index' do let(:invoices) { create_list(:invoice, 2) } diff --git a/spec/controllers/invoices_controller/pay_spec.rb b/spec/controllers/invoices_controller/pay_spec.rb index d7c129311..2e1e13797 100644 --- a/spec/controllers/invoices_controller/pay_spec.rb +++ b/spec/controllers/invoices_controller/pay_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe InvoicesController, type: :controller do +describe InvoicesController do describe 'GET /:id/pay' do let(:invoice) { create(:invoice, :with_rows) } let(:id) { invoice.id } diff --git a/spec/controllers/invoices_controller/show_spec.rb b/spec/controllers/invoices_controller/show_spec.rb index a18763cd2..eabe49b9c 100644 --- a/spec/controllers/invoices_controller/show_spec.rb +++ b/spec/controllers/invoices_controller/show_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe InvoicesController, type: :controller do +describe InvoicesController do describe 'GET show' do let(:invoice) { create(:invoice) } diff --git a/spec/controllers/orders_controller/create_spec.rb b/spec/controllers/orders_controller/create_spec.rb index d863db985..838a63d67 100644 --- a/spec/controllers/orders_controller/create_spec.rb +++ b/spec/controllers/orders_controller/create_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe OrdersController, type: :controller do +describe OrdersController do describe 'POST create' do let(:activity) { create(:activity) } let(:locked_activity) { create(:activity) } diff --git a/spec/controllers/orders_controller/destroy_spec.rb b/spec/controllers/orders_controller/destroy_spec.rb index 6a5ef5beb..fc081ff17 100644 --- a/spec/controllers/orders_controller/destroy_spec.rb +++ b/spec/controllers/orders_controller/destroy_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe OrdersController, type: :controller do +describe OrdersController do describe 'DELETE destroy' do let(:activity) { create(:activity) } let(:locked_activity) { create(:activity) } diff --git a/spec/controllers/orders_controller/index_spec.rb b/spec/controllers/orders_controller/index_spec.rb index 46974cc6e..83f5d8d24 100644 --- a/spec/controllers/orders_controller/index_spec.rb +++ b/spec/controllers/orders_controller/index_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe OrdersController, type: :controller do +describe OrdersController do describe 'GET index' do let(:alice) { create(:user, :treasurer) } let(:bob) { create(:user, :renting_manager) } diff --git a/spec/controllers/orders_controller/update_spec.rb b/spec/controllers/orders_controller/update_spec.rb index 1da12b7ad..679c1a5fd 100644 --- a/spec/controllers/orders_controller/update_spec.rb +++ b/spec/controllers/orders_controller/update_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe OrdersController, type: :controller do +describe OrdersController do describe 'PUT update' do let(:activity) { create(:activity) } let(:locked_activity) { create(:activity) } diff --git a/spec/controllers/payments_controller/callback_spec.rb b/spec/controllers/payments_controller/callback_spec.rb index 45405575d..e3743d288 100644 --- a/spec/controllers/payments_controller/callback_spec.rb +++ b/spec/controllers/payments_controller/callback_spec.rb @@ -1,7 +1,7 @@ # rubocop:disable RSpec/AnyInstance require 'rails_helper' -describe PaymentsController, type: :controller do +describe PaymentsController do describe 'GET callback' do let(:user) { create(:user) } let(:payment) do @@ -16,8 +16,7 @@ before do allow_any_instance_of(Payment).to receive(:mollie_payment).and_return(mollie) - allow(mollie).to receive(:status).and_return(:paid) - allow(mollie).to receive(:paid?).and_return(true) + allow(mollie).to receive_messages(status: :paid, paid?: true) request payment.reload @@ -34,8 +33,7 @@ before do allow_any_instance_of(Payment).to receive(:mollie_payment).and_return(mollie) - allow(mollie).to receive(:status).and_return(:open) - allow(mollie).to receive(:paid?).and_return(false) + allow(mollie).to receive_messages(status: :open, paid?: false) request payment.reload diff --git a/spec/controllers/payments_controller/create_spec.rb b/spec/controllers/payments_controller/create_spec.rb index 7390e17e0..39cac1f5e 100644 --- a/spec/controllers/payments_controller/create_spec.rb +++ b/spec/controllers/payments_controller/create_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe PaymentsController, type: :controller do +describe PaymentsController do describe 'POST create' do let(:user) { create(:user) } let(:eve) { create(:user) } @@ -14,10 +14,8 @@ let(:mollie) { instance_double(Mollie::Payment) } before do - allow(Mollie::Payment).to receive(:create).and_return(mollie) - allow(Mollie::Payment).to receive(:get).and_return(mollie) - allow(mollie).to receive(:id).and_return(1) - allow(mollie).to receive(:checkout_url).and_return('https://example.com') + allow(Mollie::Payment).to receive_messages(create: mollie, get: mollie) + allow(mollie).to receive_messages(id: 1, checkout_url: 'https://example.com') end context 'when with incorrect amount' do diff --git a/spec/controllers/payments_controller/index_spec.rb b/spec/controllers/payments_controller/index_spec.rb index 495c5ec7d..060186916 100644 --- a/spec/controllers/payments_controller/index_spec.rb +++ b/spec/controllers/payments_controller/index_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe PaymentsController, type: :controller do +describe PaymentsController do describe 'GET index' do let(:payments) { create_list(:payment, 2) } diff --git a/spec/controllers/price_lists_controller/archive_spec.rb b/spec/controllers/price_lists_controller/archive_spec.rb index d50a8d4d8..a2c34ed79 100644 --- a/spec/controllers/price_lists_controller/archive_spec.rb +++ b/spec/controllers/price_lists_controller/archive_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe PriceListsController, type: :controller do +describe PriceListsController do describe 'POST /:id/archive' do let(:price_list) do create(:price_list) diff --git a/spec/controllers/price_lists_controller/create_spec.rb b/spec/controllers/price_lists_controller/create_spec.rb index d95fd49b4..ae98266dc 100644 --- a/spec/controllers/price_lists_controller/create_spec.rb +++ b/spec/controllers/price_lists_controller/create_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe PriceListsController, type: :controller do +describe PriceListsController do describe 'POST create' do let(:price_list) do build(:price_list) diff --git a/spec/controllers/price_lists_controller/index_spec.rb b/spec/controllers/price_lists_controller/index_spec.rb index dbf3f234a..d429acf3e 100644 --- a/spec/controllers/price_lists_controller/index_spec.rb +++ b/spec/controllers/price_lists_controller/index_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe PriceListsController, type: :controller do +describe PriceListsController do describe 'GET index' do let(:archived_price_lists) { create_list(:price_list, 3, :archived) } let(:unarchived_price_lists) { create_list(:price_list, 3) } @@ -15,8 +15,8 @@ sign_in create(:user, :treasurer) get :index - expect(assigns(:price_lists_json)).to eq PriceList.all.order(created_at: :desc).to_json(except: %i[created_at updated_at - deleted_at]) + expect(assigns(:price_lists_json)).to eq PriceList.order(created_at: :desc).to_json(except: %i[created_at updated_at + deleted_at]) end end diff --git a/spec/controllers/price_lists_controller/unarchive_spec.rb b/spec/controllers/price_lists_controller/unarchive_spec.rb index 796728f49..bd244ee83 100644 --- a/spec/controllers/price_lists_controller/unarchive_spec.rb +++ b/spec/controllers/price_lists_controller/unarchive_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe PriceListsController, type: :controller do +describe PriceListsController do describe 'POST /:id/unarchive' do let(:price_list) do create(:price_list) diff --git a/spec/controllers/price_lists_controller/update_spec.rb b/spec/controllers/price_lists_controller/update_spec.rb index 7cb136db8..1362057c6 100644 --- a/spec/controllers/price_lists_controller/update_spec.rb +++ b/spec/controllers/price_lists_controller/update_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe PriceListsController, type: :controller do +describe PriceListsController do describe 'PUT update' do let(:price_list) do create(:price_list) diff --git a/spec/controllers/products_controller/create_spec.rb b/spec/controllers/products_controller/create_spec.rb index 51101e35b..cd580a19e 100644 --- a/spec/controllers/products_controller/create_spec.rb +++ b/spec/controllers/products_controller/create_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ProductsController, type: :controller do +describe ProductsController do describe 'POST create' do let(:product) do build(:product) diff --git a/spec/controllers/products_controller/update_spec.rb b/spec/controllers/products_controller/update_spec.rb index 8c5c6de7d..3371fc44f 100644 --- a/spec/controllers/products_controller/update_spec.rb +++ b/spec/controllers/products_controller/update_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ProductsController, type: :controller do +describe ProductsController do describe 'PUT update' do let(:product) do create(:product, product_prices: [create(:product_price)]) diff --git a/spec/controllers/users_controller/create_spec.rb b/spec/controllers/users_controller/create_spec.rb index b2de00877..736b06cd8 100644 --- a/spec/controllers/users_controller/create_spec.rb +++ b/spec/controllers/users_controller/create_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe UsersController, type: :controller do +describe UsersController do describe 'POST create' do let(:user) do build(:user, :manual) diff --git a/spec/controllers/users_controller/index_spec.rb b/spec/controllers/users_controller/index_spec.rb index 4d2b37dba..396dedf7c 100644 --- a/spec/controllers/users_controller/index_spec.rb +++ b/spec/controllers/users_controller/index_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe UsersController, type: :controller do +describe UsersController do describe 'GET index' do let(:alice) { create(:user, :treasurer, :manual) } let(:bob) { create(:user, :renting_manager, :manual) } diff --git a/spec/controllers/users_controller/show_spec.rb b/spec/controllers/users_controller/show_spec.rb index b1b383987..052111bb3 100644 --- a/spec/controllers/users_controller/show_spec.rb +++ b/spec/controllers/users_controller/show_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe UsersController, type: :controller do +describe UsersController do describe 'GET show' do let(:amber) { create(:user, :from_amber) } let(:eve) { create(:user, :manual) } diff --git a/spec/controllers/users_controller/update_spec.rb b/spec/controllers/users_controller/update_spec.rb index 3d3d6a2ef..3878087e6 100644 --- a/spec/controllers/users_controller/update_spec.rb +++ b/spec/controllers/users_controller/update_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe UsersController, type: :controller do +describe UsersController do describe 'PUT update' do let(:user) do create(:user, :manual) diff --git a/spec/factories/activity.rb b/spec/factories/activity.rb index fccee20b6..e04846358 100644 --- a/spec/factories/activity.rb +++ b/spec/factories/activity.rb @@ -3,7 +3,7 @@ title { Faker::Book.title } start_time { Faker::Time.between(from: 1.day.ago, to: Time.zone.today).beginning_of_hour } end_time { Faker::Time.between(from: 1.day.from_now, to: 2.days.from_now).beginning_of_hour } - association :created_by, factory: :user + created_by factory: %i[user] price_list trait :locked do @@ -22,7 +22,7 @@ end trait :manually_locked do - association :locked_by, factory: :user + locked_by factory: %i[user] end end end diff --git a/spec/factories/credit_mutation.rb b/spec/factories/credit_mutation.rb index 84bd9ea7a..857036e58 100644 --- a/spec/factories/credit_mutation.rb +++ b/spec/factories/credit_mutation.rb @@ -2,7 +2,7 @@ factory :credit_mutation do description { Faker::Space.agency } user - association :created_by, factory: :user + created_by factory: %i[user] amount { rand(0..100) } end end diff --git a/spec/factories/invoices.rb b/spec/factories/invoices.rb index 221d5d7fa..c29d801c2 100644 --- a/spec/factories/invoices.rb +++ b/spec/factories/invoices.rb @@ -3,11 +3,11 @@ user created_at { Faker::Time.between(from: 1.day.ago, to: 2.days.ago) } - association :activity, factory: %i[activity manually_locked] + activity factory: %i[activity manually_locked] trait :with_rows do after(:create) do |invoice, _evaluator| - create :invoice_row, invoice: invoice + create(:invoice_row, invoice: invoice) end end end diff --git a/spec/factories/order.rb b/spec/factories/order.rb index 12c4f2a17..85ae84a8e 100644 --- a/spec/factories/order.rb +++ b/spec/factories/order.rb @@ -2,7 +2,7 @@ factory :order do activity user - association :created_by, factory: :user + created_by factory: %i[user] trait :cash do after(:build) do |order| @@ -24,7 +24,7 @@ end after(:create) do |order, evaluator| - create :order_row, order: order, product: evaluator.products.sample, product_count: 1 + create(:order_row, order: order, product: evaluator.products.sample, product_count: 1) end end diff --git a/spec/factories/price_list.rb b/spec/factories/price_list.rb index 2044f8c6d..fa89b9b04 100644 --- a/spec/factories/price_list.rb +++ b/spec/factories/price_list.rb @@ -22,7 +22,7 @@ after(:create) do |price_list, evaluator| if evaluator.with_all_products - Product.all.each do |product| + Product.find_each do |product| create(:product_price, price_list: price_list, product: product) end elsif evaluator.with_specific_products diff --git a/spec/factories/user.rb b/spec/factories/user.rb index 5ead18872..2dedf1802 100644 --- a/spec/factories/user.rb +++ b/spec/factories/user.rb @@ -2,7 +2,7 @@ factory :user do name { Faker::Movies::StarWars.character } - sequence(:email) { |n| Faker::Internet.safe_email(name: "#{Faker::Internet.user_name}#{n}") } + sequence(:email) { |n| Faker::Internet.email(name: "#{Faker::Internet.user_name}#{n}") } trait(:treasurer) do after :create do |user, _evaluator| diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 265fded40..196e21907 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe ApplicationHelper, type: :helper do +RSpec.describe ApplicationHelper do describe '#flash_class' do it { expect(flash_class('notice')).to eq 'alert-info' } it { expect(flash_class('success')).to eq 'alert-success' } diff --git a/spec/helpers/slack_helper_spec.rb b/spec/helpers/slack_helper_spec.rb index d7a620859..15c4ee174 100644 --- a/spec/helpers/slack_helper_spec.rb +++ b/spec/helpers/slack_helper_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe SlackHelper, type: :helper do +RSpec.describe SlackHelper do include described_class describe '#ping' do diff --git a/spec/jobs/activity_invoice_job_spec.rb b/spec/jobs/activity_invoice_job_spec.rb index 133be2b5a..1c8090ca2 100644 --- a/spec/jobs/activity_invoice_job_spec.rb +++ b/spec/jobs/activity_invoice_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe ActivityInvoiceJob, type: :job do +RSpec.describe ActivityInvoiceJob do describe '#perform' do let(:activity) { create(:activity) } let(:manual_users) { create_list(:user, 3) } diff --git a/spec/jobs/credit_insufficient_notification_job_spec.rb b/spec/jobs/credit_insufficient_notification_job_spec.rb index 267a69f7d..52789f88b 100644 --- a/spec/jobs/credit_insufficient_notification_job_spec.rb +++ b/spec/jobs/credit_insufficient_notification_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe CreditInsufficientNotificationJob, type: :job do +RSpec.describe CreditInsufficientNotificationJob do describe '#perform' do let(:user) { create(:user, name: 'Buddy Normal') } let(:negative_user) { create(:user, name: 'Bro Negative', email: 'user@csvalpha.nl') } diff --git a/spec/jobs/health_check_job_spec.rb b/spec/jobs/health_check_job_spec.rb index 1527ab322..6c80078ea 100644 --- a/spec/jobs/health_check_job_spec.rb +++ b/spec/jobs/health_check_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe HealthCheckJob, type: :job do +RSpec.describe HealthCheckJob do describe '#perform' do let(:job) { described_class.perform_now(:test) } let(:hc_id) { 'test-id' } diff --git a/spec/jobs/new_credit_mutation_notification_job_spec.rb b/spec/jobs/new_credit_mutation_notification_job_spec.rb index fae445826..8fc3d9275 100644 --- a/spec/jobs/new_credit_mutation_notification_job_spec.rb +++ b/spec/jobs/new_credit_mutation_notification_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe NewCreditMutationNotificationJob, type: :job do +RSpec.describe NewCreditMutationNotificationJob do describe '#perform' do let(:user) { create(:user, name: 'Buddy Normal', email: 'bahamas@example.com') } let(:emails) { ActionMailer::Base.deliveries } diff --git a/spec/jobs/slack_message_job_spec.rb b/spec/jobs/slack_message_job_spec.rb index c9c47e494..642cb20d7 100644 --- a/spec/jobs/slack_message_job_spec.rb +++ b/spec/jobs/slack_message_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe SlackMessageJob, type: :job do +RSpec.describe SlackMessageJob do describe '#perform' do let(:job) { described_class.new } diff --git a/spec/models/activity_spec.rb b/spec/models/activity_spec.rb index 82aa7fe8e..b26ab2c87 100644 --- a/spec/models/activity_spec.rb +++ b/spec/models/activity_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Activity, type: :model do +RSpec.describe Activity do subject(:activity) { build_stubbed(:activity) } describe '#valid' do @@ -344,7 +344,7 @@ create(:order, created_by: bartender, activity: activity) end - it { expect(activity.bartenders).to match_array [bartender] } + it { expect(activity.bartenders).to contain_exactly(bartender) } end end diff --git a/spec/models/credit_mutation_spec.rb b/spec/models/credit_mutation_spec.rb index 5885c2478..b706d74dd 100644 --- a/spec/models/credit_mutation_spec.rb +++ b/spec/models/credit_mutation_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe CreditMutation, type: :model do +RSpec.describe CreditMutation do subject(:mutation) { build_stubbed(:credit_mutation) } describe '#valid' do diff --git a/spec/models/invoice_row_spec.rb b/spec/models/invoice_row_spec.rb index 1b35dd55c..831b9eff9 100644 --- a/spec/models/invoice_row_spec.rb +++ b/spec/models/invoice_row_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe InvoiceRow, type: :model do +RSpec.describe InvoiceRow do subject(:invoice_row) { build_stubbed(:invoice_row) } describe '#valid' do diff --git a/spec/models/invoice_spec.rb b/spec/models/invoice_spec.rb index 7f7f46f54..05e8b11a6 100644 --- a/spec/models/invoice_spec.rb +++ b/spec/models/invoice_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Invoice, type: :model do +RSpec.describe Invoice do subject(:invoice) { build_stubbed(:invoice) } describe '#valid' do diff --git a/spec/models/order_row_spec.rb b/spec/models/order_row_spec.rb index 5feceb257..1a4e9a9d6 100644 --- a/spec/models/order_row_spec.rb +++ b/spec/models/order_row_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe OrderRow, type: :model do +RSpec.describe OrderRow do subject(:order_row) { create(:order_row) } describe '#valid' do diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb index 3a913153b..e5000c029 100644 --- a/spec/models/order_spec.rb +++ b/spec/models/order_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Order, type: :model do +RSpec.describe Order do subject(:order) { build_stubbed(:order) } describe '#valid' do diff --git a/spec/models/payment_spec.rb b/spec/models/payment_spec.rb index 3dd15d5ad..05ee3ac7b 100644 --- a/spec/models/payment_spec.rb +++ b/spec/models/payment_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Payment, type: :model do +RSpec.describe Payment do subject(:payment) { build_stubbed(:payment) } describe '#valid' do diff --git a/spec/models/price_list_spec.rb b/spec/models/price_list_spec.rb index 4547d7015..3ed1632ef 100644 --- a/spec/models/price_list_spec.rb +++ b/spec/models/price_list_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe PriceList, type: :model do +RSpec.describe PriceList do subject(:price_list) { build_stubbed(:price_list) } describe '#valid' do diff --git a/spec/models/product_price_spec.rb b/spec/models/product_price_spec.rb index 906abc00b..bdf837c26 100644 --- a/spec/models/product_price_spec.rb +++ b/spec/models/product_price_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe ProductPrice, type: :model do +RSpec.describe ProductPrice do subject(:product_price) { build_stubbed(:product_price) } describe '#valid' do diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb index e8d5c8fb2..a4fcedaed 100644 --- a/spec/models/product_spec.rb +++ b/spec/models/product_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Product, type: :model do +RSpec.describe Product do subject(:product) { build(:product) } describe '#valid' do diff --git a/spec/models/role_spec.rb b/spec/models/role_spec.rb index 7e16e5980..c3d981d20 100644 --- a/spec/models/role_spec.rb +++ b/spec/models/role_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Role, type: :model do +RSpec.describe Role do subject(:role) { build_stubbed(:role) } describe '#valid' do diff --git a/spec/models/roles_users_spec.rb b/spec/models/roles_users_spec.rb index 3da1b85f5..1d2a3241f 100644 --- a/spec/models/roles_users_spec.rb +++ b/spec/models/roles_users_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe RolesUsers, type: :model do +RSpec.describe RolesUsers do subject(:roles_users) { build_stubbed(:roles_users) } describe '#valid' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 98f7e89f0..fa5ee3d7c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe User, type: :model do +RSpec.describe User do subject(:user) { build_stubbed(:user) } describe '#valid' do @@ -114,7 +114,7 @@ create(:roles_users, role: role, user: user) end - it { expect(user.roles).to match_array [role] } + it { expect(user.roles).to contain_exactly(role) } end context 'when with a destroyed role' do @@ -128,7 +128,7 @@ roles_users.destroy end - it { expect(user.roles).not_to match_array [role] } + it { expect(user.roles).not_to contain_exactly(role) } end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 8866ea435..f89ed97e9 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -22,7 +22,7 @@ # directory. Alternatively, in the individual `*_spec.rb` files, manually # require only the support files necessary. # -Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } +Rails.root.glob('spec/support/**/*.rb').each { |f| require f } # Checks for pending migration and applies them before tests are run. # If you are not using ActiveRecord, you can remove this line.