diff --git a/Gemfile b/Gemfile index 29dd4f67a3..4d6b2b0210 100644 --- a/Gemfile +++ b/Gemfile @@ -49,8 +49,8 @@ gem 'paypal-sdk-merchant', '1.117.2' gem 'stripe' gem 'devise' -gem 'devise-i18n' gem 'devise-encryptable' +gem 'devise-i18n' gem 'devise-token_authenticatable' gem 'jwt', '~> 2.3' gem 'oauth2', '~> 1.4.7' # Used for Stripe Connect @@ -82,8 +82,8 @@ gem 'rack-rewrite' gem 'rack-ssl', require: 'rack/ssl' gem 'roadie-rails' -gem 'puma' gem 'hiredis' +gem 'puma' gem 'redis', '>= 4.0', require: ['redis', 'redis/connection/hiredis'] gem 'sidekiq' gem 'sidekiq-scheduler' @@ -138,6 +138,7 @@ group :test, :development do gem 'awesome_print' gem 'bullet' gem 'capybara' + gem 'cuprite' gem 'database_cleaner', require: false gem "factory_bot_rails", '6.2.0', require: false gem 'fuubar', '~> 2.5.1' @@ -151,7 +152,6 @@ group :test, :development do gem 'shoulda-matchers' gem 'timecop' gem 'webdrivers' - gem 'cuprite' end group :test do diff --git a/app/constraints/split_checkout_constraint.rb b/app/constraints/split_checkout_constraint.rb index e0b0a18eda..3e0f732b85 100644 --- a/app/constraints/split_checkout_constraint.rb +++ b/app/constraints/split_checkout_constraint.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class SplitCheckoutConstraint def matches?(request) Flipper.enabled? :split_checkout, current_user(request) diff --git a/app/controllers/admin/enterprise_fees_controller.rb b/app/controllers/admin/enterprise_fees_controller.rb index ad17c5d90d..f14612a2cd 100644 --- a/app/controllers/admin/enterprise_fees_controller.rb +++ b/app/controllers/admin/enterprise_fees_controller.rb @@ -36,12 +36,12 @@ module Admin def bulk_update @flat_percent_value = enterprise_fee_bulk_params.dig('collection_attributes', '0', 'calculator_attributes', 'preferred_flat_percent') - - unless @flat_percent_value.nil? || Float(@flat_percent_value, exception: false) - flash[:error] = I18n.t(:calculator_preferred_value_error) - return redirect_to redirect_path + + unless @flat_percent_value.nil? || Float(@flat_percent_value, exception: false) + flash[:error] = I18n.t(:calculator_preferred_value_error) + return redirect_to redirect_path end - + @enterprise_fee_set = Sets::EnterpriseFeeSet.new(enterprise_fee_bulk_params) if @enterprise_fee_set.save diff --git a/app/controllers/api/v0/exchange_products_controller.rb b/app/controllers/api/v0/exchange_products_controller.rb index 9257266918..8b16fdbdd4 100644 --- a/app/controllers/api/v0/exchange_products_controller.rb +++ b/app/controllers/api/v0/exchange_products_controller.rb @@ -75,7 +75,10 @@ module Api def render_paginated_products results = products - @pagy, results = pagy(results, items: params[:per_page] || DEFAULT_PER_PAGE) if pagination_required? + if pagination_required? + @pagy, results = pagy(results, + items: params[:per_page] || DEFAULT_PER_PAGE) + end serialized_products = ActiveModel::ArraySerializer.new( results, diff --git a/app/controllers/api/v0/orders_controller.rb b/app/controllers/api/v0/orders_controller.rb index 1b0548ada9..81e425d571 100644 --- a/app/controllers/api/v0/orders_controller.rb +++ b/app/controllers/api/v0/orders_controller.rb @@ -15,7 +15,10 @@ module Api orders = SearchOrders.new(params, current_api_user).orders - @pagy, orders = pagy(orders, items: params[:per_page] || default_per_page) if pagination_required? + if pagination_required? + @pagy, orders = pagy(orders, + items: params[:per_page] || default_per_page) + end render json: { orders: serialized_orders(orders), diff --git a/app/controllers/concerns/checkout_callbacks.rb b/app/controllers/concerns/checkout_callbacks.rb index bc50a80b09..ff8d207add 100644 --- a/app/controllers/concerns/checkout_callbacks.rb +++ b/app/controllers/concerns/checkout_callbacks.rb @@ -14,7 +14,7 @@ module CheckoutCallbacks prepend_before_action :require_distributor_chosen before_action :load_order, :associate_user, :load_saved_addresses - before_action :load_shipping_methods, :load_countries, if: -> { params[:step] == "details"} + before_action :load_shipping_methods, :load_countries, if: -> { params[:step] == "details" } before_action :ensure_order_not_completed before_action :ensure_checkout_allowed @@ -47,7 +47,11 @@ module CheckoutCallbacks def load_countries @countries = available_countries.map { |c| [c.name, c.id] } - @countries_with_states = available_countries.map { |c| [c.id, c.states.map { |s| [s.name, s.id] }] } + @countries_with_states = available_countries.map { |c| + [c.id, c.states.map { |s| + [s.name, s.id] + }] + } end def redirect_to_shop? diff --git a/app/controllers/concerns/request_timeouts.rb b/app/controllers/concerns/request_timeouts.rb index 6653872aa7..691cba2a3d 100644 --- a/app/controllers/concerns/request_timeouts.rb +++ b/app/controllers/concerns/request_timeouts.rb @@ -4,7 +4,10 @@ module RequestTimeouts extend ActiveSupport::Concern included do - rescue_from Rack::Timeout::RequestTimeoutException, with: :timeout_response if defined? Rack::Timeout + if defined? Rack::Timeout + rescue_from Rack::Timeout::RequestTimeoutException, + with: :timeout_response + end end private diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index 63b2405aa4..290ba402fd 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -30,7 +30,7 @@ class SplitCheckoutController < ::BaseController render operations: cable_car. replace("#checkout", partial("split_checkout/checkout")). replace("#flashes", partial("shared/flashes", locals: { flashes: flash })), - status: :unprocessable_entity + status: :unprocessable_entity end end diff --git a/app/helpers/tax_helper.rb b/app/helpers/tax_helper.rb index 0a3e471071..af81743929 100644 --- a/app/helpers/tax_helper.rb +++ b/app/helpers/tax_helper.rb @@ -7,8 +7,8 @@ module TaxHelper I18n.t(:tax_amount_included, amount: amount) elsif !taxable.additional_tax_total.zero? Spree::Money.new(taxable.additional_tax_total, currency: taxable.currency) - else - Spree::Money.new(0.00, currency: taxable.currency) if display_zero + elsif display_zero + Spree::Money.new(0.00, currency: taxable.currency) end end diff --git a/app/mailers/producer_mailer.rb b/app/mailers/producer_mailer.rb index 66a47d91c9..4a22ef801d 100644 --- a/app/mailers/producer_mailer.rb +++ b/app/mailers/producer_mailer.rb @@ -78,6 +78,7 @@ class ProducerMailer < Spree::BaseMailer def set_customer_data(line_items) return unless @coordinator.preferred_show_customer_names_to_suppliers + line_items.map do |line_item| { sku: line_item.variant.sku, diff --git a/app/models/concerns/calculated_adjustments.rb b/app/models/concerns/calculated_adjustments.rb index af55dfa5b2..ffee86c178 100644 --- a/app/models/concerns/calculated_adjustments.rb +++ b/app/models/concerns/calculated_adjustments.rb @@ -67,8 +67,6 @@ module CalculatedAdjustments calculator.compute(calculable) end - private - def order_object_for(target) # Temporary method for adjustments transition. if target.is_a? Spree::Order diff --git a/app/models/concerns/searchable.rb b/app/models/concerns/searchable.rb index 9891372b59..265bc738ff 100644 --- a/app/models/concerns/searchable.rb +++ b/app/models/concerns/searchable.rb @@ -25,15 +25,15 @@ module Searchable class_methods do def ransackable_associations(*_args) - self.whitelisted_search_associations.map(&:to_s) + whitelisted_search_associations.map(&:to_s) end def ransackable_attributes(*_args) - (DEFAULT_SEARCHABLE_ATTRIBUTES | self.whitelisted_search_attributes).map(&:to_s) + (DEFAULT_SEARCHABLE_ATTRIBUTES | whitelisted_search_attributes).map(&:to_s) end def ransackable_scopes(*_args) - self.whitelisted_search_scopes.map(&:to_s) + whitelisted_search_scopes.map(&:to_s) end private diff --git a/app/models/concerns/set_unused_address_fields.rb b/app/models/concerns/set_unused_address_fields.rb index cb6f563f25..7e21a819b3 100644 --- a/app/models/concerns/set_unused_address_fields.rb +++ b/app/models/concerns/set_unused_address_fields.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'active_support/concern' -module SetUnusedAddressFields +module SetUnusedAddressFields extend ActiveSupport::Concern included do - self.before_validation :set_unused_address_fields + before_validation :set_unused_address_fields end def set_unused_address_fields diff --git a/app/models/customer.rb b/app/models/customer.rb index fc030bd1a1..96aed9dd2b 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -2,7 +2,7 @@ class Customer < ApplicationRecord include SetUnusedAddressFields - + acts_as_taggable searchable_attributes :name, :email, :code diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 1d2af37a91..664ae384ef 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -59,7 +59,8 @@ class Enterprise < ApplicationRecord delegate :latitude, :longitude, :city, :state_name, to: :address accepts_nested_attributes_for :address - accepts_nested_attributes_for :business_address, reject_if: :business_address_empty?, allow_destroy: true + accepts_nested_attributes_for :business_address, reject_if: :business_address_empty?, + allow_destroy: true accepts_nested_attributes_for :producer_properties, allow_destroy: true, reject_if: lambda { |pp| pp[:property_name].blank? @@ -213,8 +214,9 @@ class Enterprise < ApplicationRecord def business_address_empty?(attributes) attributes_exists = attributes['id'].present? - attributes_empty = attributes.slice(:company, :address1, :city, :phone, :zipcode).values.all?(&:blank?) - attributes.merge!(_destroy: 1) if attributes_exists and attributes_empty + attributes_empty = attributes.slice(:company, :address1, :city, :phone, + :zipcode).values.all?(&:blank?) + attributes.merge!(_destroy: 1) if attributes_exists && attributes_empty !attributes_exists && attributes_empty end diff --git a/app/models/spree/address.rb b/app/models/spree/address.rb index cff38fab0e..9bd500a41d 100644 --- a/app/models/spree/address.rb +++ b/app/models/spree/address.rb @@ -14,7 +14,7 @@ module Spree has_many :shipments validates :address1, :city, :country, :phone, presence: true - validates :company, presence: true, unless: -> { first_name.blank? || last_name.blank?} + validates :company, presence: true, unless: -> { first_name.blank? || last_name.blank? } validates :firstname, :lastname, presence: true, unless: -> { company.present? } validates :zipcode, presence: true, if: :require_zipcode? diff --git a/app/models/spree/adjustment.rb b/app/models/spree/adjustment.rb index 34044dcc31..06131597db 100644 --- a/app/models/spree/adjustment.rb +++ b/app/models/spree/adjustment.rb @@ -101,7 +101,7 @@ module Spree return amount if immutable? && !force if calculable.nil? && adjustable.nil? - self.delete + delete return 0.0 end diff --git a/app/models/spree/gateway/stripe_sca.rb b/app/models/spree/gateway/stripe_sca.rb index c623f4190d..48ad11364f 100644 --- a/app/models/spree/gateway/stripe_sca.rb +++ b/app/models/spree/gateway/stripe_sca.rb @@ -14,7 +14,7 @@ module Spree VOIDABLE_STATES = [ "requires_payment_method", "requires_capture", "requires_confirmation", "requires_action" - ] + ].freeze preference :enterprise_id, :integer @@ -87,7 +87,8 @@ module Spree if voidable?(payment_intent_response) provider.void(response_code, gateway_options) else - provider.refund(refundable_amount(payment_intent_response), response_code, gateway_options) + provider.refund(refundable_amount(payment_intent_response), response_code, + gateway_options) end end diff --git a/app/models/spree/image.rb b/app/models/spree/image.rb index db664b0006..e508395729 100644 --- a/app/models/spree/image.rb +++ b/app/models/spree/image.rb @@ -56,7 +56,7 @@ module Spree def no_attachment_errors return if attachment.errors.empty? - if errors.all? {|e| e.type == "Paperclip::Errors::NotIdentifiedByImageMagickError"} + if errors.all? { |e| e.type == "Paperclip::Errors::NotIdentifiedByImageMagickError" } attachment.errors.clear errors.add :base, I18n.t('spree.admin.products.image_upload_error') else diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index e081e45559..8bb09d4e5d 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -24,14 +24,13 @@ module Spree order.update_totals order.payment_required? } - go_to_state :confirmation, if: ->(order) { + go_to_state :confirmation, if: ->(_order) { Flipper.enabled? :split_checkout } go_to_state :complete end - attr_accessor :use_billing - attr_accessor :checkout_processing + attr_accessor :use_billing, :checkout_processing token_resource diff --git a/app/models/spree/user.rb b/app/models/spree/user.rb index c25634777f..542e43a0b9 100644 --- a/app/models/spree/user.rb +++ b/app/models/spree/user.rb @@ -3,7 +3,7 @@ module Spree class User < ApplicationRecord include SetUnusedAddressFields - + searchable_attributes :email devise :database_authenticatable, :token_authenticatable, :registerable, :recoverable, diff --git a/app/models/subscription.rb b/app/models/subscription.rb index 8c219b6c3a..304b7e71d9 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -2,7 +2,7 @@ class Subscription < ApplicationRecord include SetUnusedAddressFields - + ALLOWED_PAYMENT_METHOD_TYPES = ["Spree::PaymentMethod::Check", "Spree::Gateway::StripeConnect", "Spree::Gateway::StripeSCA"].freeze diff --git a/app/services/checkout/params.rb b/app/services/checkout/params.rb index 51d0dcb780..209b3cc2e4 100644 --- a/app/services/checkout/params.rb +++ b/app/services/checkout/params.rb @@ -56,7 +56,8 @@ module Checkout def set_basic_details [:firstname, :lastname, :phone].each do |attr| - @order_params[:ship_address_attributes][attr] = @order_params[:bill_address_attributes][attr] + @order_params[:ship_address_attributes][attr] = + @order_params[:bill_address_attributes][attr] end end end diff --git a/app/services/image_importer.rb b/app/services/image_importer.rb index c6d2982426..8fc243e755 100644 --- a/app/services/image_importer.rb +++ b/app/services/image_importer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ImageImporter def import(url, product) attach(download(url), product) diff --git a/app/services/products_renderer.rb b/app/services/products_renderer.rb index 8da554f79f..c977f9cf02 100644 --- a/app/services/products_renderer.rb +++ b/app/services/products_renderer.rb @@ -4,7 +4,7 @@ require 'open_food_network/scope_product_to_hub' class ProductsRenderer include Pagy::Backend - + class NoProducts < RuntimeError; end DEFAULT_PER_PAGE = 10 diff --git a/app/services/search_orders.rb b/app/services/search_orders.rb index d59b4de6f3..6ff7afcf3d 100644 --- a/app/services/search_orders.rb +++ b/app/services/search_orders.rb @@ -24,7 +24,7 @@ class SearchOrders def search_query base_query = ::Permissions::Order.new(current_user).editable_orders.not_empty - .or(::Permissions::Order.new(current_user).editable_orders.finalized) + .or(::Permissions::Order.new(current_user).editable_orders.finalized) return base_query unless params[:shipping_method_id] diff --git a/lib/active_merchant/billing/gateways/stripe_payment_intents_decorator.rb b/lib/active_merchant/billing/gateways/stripe_payment_intents_decorator.rb index 4ab64d3fa4..711589f0cc 100644 --- a/lib/active_merchant/billing/gateways/stripe_payment_intents_decorator.rb +++ b/lib/active_merchant/billing/gateways/stripe_payment_intents_decorator.rb @@ -2,7 +2,7 @@ ActiveMerchant::Billing::StripePaymentIntentsGateway.class_eval do CREATE_INTENT_ATTRIBUTES = - %i[description statement_descriptor receipt_email save_payment_method].freeze + %i[description statement_descriptor receipt_email save_payment_method].freeze def create_intent(money, payment_method, options = {}) post = {} @@ -33,7 +33,7 @@ ActiveMerchant::Billing::StripePaymentIntentsGateway.class_eval do def refund(money, intent_id, options = {}) intent = commit(:get, "payment_intents/#{intent_id}", nil, options) - charge_id = intent.params.dig('charges', 'data')[0].dig('id') + charge_id = intent.params.dig('charges', 'data')[0]['id'] super(money, charge_id, options) end diff --git a/lib/spree/responder.rb b/lib/spree/responder.rb index 2714599530..51ae950317 100644 --- a/lib/spree/responder.rb +++ b/lib/spree/responder.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class Responder < ::ActionController::Responder #:nodoc: + class Responder < ::ActionController::Responder # :nodoc: attr_accessor :on_success, :on_failure def initialize(controller, resources, options = {}) diff --git a/lib/tasks/import_product_images.rake b/lib/tasks/import_product_images.rake index 16b46e376d..7ebfc62c8f 100644 --- a/lib/tasks/import_product_images.rake +++ b/lib/tasks/import_product_images.rake @@ -4,7 +4,7 @@ namespace :ofn do namespace :import do desc "Importing images for products from CSV" task :product_images, [:filename] => [:environment] do |_task, args| - COLUMNS = [:producer, :name, :image_url] + COLUMNS = [:producer, :name, :image_url].freeze puts "Warning: use only with trusted URLs. This script will download whatever it can, including local secrets, and expose the file as an image file." @@ -15,7 +15,7 @@ namespace :ofn do csv.each.with_index do |entry, index| puts "#{index} #{entry[:producer]}, #{entry[:name]}" - enterprise = Enterprise.find_by_name! entry[:producer] + enterprise = Enterprise.find_by! name: entry[:producer] product = Spree::Product.where(supplier: enterprise, name: entry[:name], diff --git a/spec/controllers/api/v0/orders_controller_spec.rb b/spec/controllers/api/v0/orders_controller_spec.rb index bf7d5ce527..42d75da5ab 100644 --- a/spec/controllers/api/v0/orders_controller_spec.rb +++ b/spec/controllers/api/v0/orders_controller_spec.rb @@ -130,7 +130,7 @@ module Api it 'can sort orders by total' do get :index, params: { q: { completed_at_not_null: true, s: 'total desc' } }, - as: :json + as: :json expect(json_response['orders']).to eq serialized_orders([order4, order2, order1, order3]) end diff --git a/spec/controllers/spree/admin/orders/payments/payments_controller_refunds_spec.rb b/spec/controllers/spree/admin/orders/payments/payments_controller_refunds_spec.rb index dccb39edc7..9d9f1ce373 100644 --- a/spec/controllers/spree/admin/orders/payments/payments_controller_refunds_spec.rb +++ b/spec/controllers/spree/admin/orders/payments/payments_controller_refunds_spec.rb @@ -202,7 +202,8 @@ describe Spree::Admin::PaymentsController, type: :controller do context "when a partial refund has already been issued" do before do - stub_payment_intent_get_request(response: { intent_status: "succeeded", amount_refunded: 200 }) + stub_payment_intent_get_request(response: { intent_status: "succeeded", + amount_refunded: 200 }) stub_request(:post, "https://api.stripe.com/v1/charges/ch_1234/refunds"). with(basic_auth: ["sk_test_12345", ""]). to_return(status: 200, @@ -228,7 +229,8 @@ describe Spree::Admin::PaymentsController, type: :controller do stub_request(:post, "https://api.stripe.com/v1/payment_intents/pi_123/cancel"). with(basic_auth: ["sk_test_12345", ""]). to_return(status: 200, - body: JSON.generate(id: 'pi_123', object: 'payment_intent', status: 'canceled') ) + body: JSON.generate(id: 'pi_123', object: 'payment_intent', + status: 'canceled') ) end it "voids the payment" do diff --git a/spec/features/admin/order_spec.rb b/spec/features/admin/order_spec.rb index 24587456d2..8cad382463 100644 --- a/spec/features/admin/order_spec.rb +++ b/spec/features/admin/order_spec.rb @@ -148,7 +148,7 @@ describe ' expect(page).to_not have_content "Loading..." within("tr.stock-item", text: order.products.first.name) do - expect(page).to have_text("#{max_quantity}") + expect(page).to have_text(max_quantity.to_s) end expect(order.reload.line_items.first.quantity).to eq(max_quantity) end diff --git a/spec/features/consumer/shopping/products_spec.rb b/spec/features/consumer/shopping/products_spec.rb index b23bef7c27..d49fe56621 100644 --- a/spec/features/consumer/shopping/products_spec.rb +++ b/spec/features/consumer/shopping/products_spec.rb @@ -49,13 +49,13 @@ describe "As a consumer I want to view products", js: true do login_as_admin_and_visit spree.edit_admin_product_path(product) expect(page.find("div[id^='taTextElement']")['innerHTML']).to include('external site') - fill_in 'product_name', with: product.name + "_update" + fill_in 'product_name', with: "#{product.name}_update" click_button 'Update' # -- check back consumer product view visit shop_path - expect(page).to have_content(product.name + "_update") - click_link(product.name + "_update") + expect(page).to have_content("#{product.name}_update") + click_link("#{product.name}_update") expect(page).to have_selector '.reveal-modal' modal_should_be_open_for product diff --git a/spec/helpers/checkout_helper_spec.rb b/spec/helpers/checkout_helper_spec.rb index 920c05f896..41bacae7bc 100644 --- a/spec/helpers/checkout_helper_spec.rb +++ b/spec/helpers/checkout_helper_spec.rb @@ -68,17 +68,15 @@ describe CheckoutHelper, type: :helper do } let!(:order_tax_adjustment) { create(:adjustment, - originator: tax_rate, - adjustable: fee_adjustment, - order: order - ) + originator: tax_rate, + adjustable: fee_adjustment, + order: order) } let!(:line_item_fee_adjustment_tax_adjustment) { create(:adjustment, - originator: tax_rate, - adjustable: line_item_fee_adjustment, - order: order - ) + originator: tax_rate, + adjustable: line_item_fee_adjustment, + order: order) } it "removes tax rate adjustments" do diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb index e3a22d4ab2..ad1480c754 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -140,18 +140,22 @@ describe ProducerMailer, type: :mailer do it "displays last name for each order" do product_name = order.line_items.first.product.name last_name = order.billing_address.lastname - expect(body_as_html(mail).find("table.order-summary.customer-order tr", text: product_name)).to have_selector("td", text: last_name) + expect(body_as_html(mail).find("table.order-summary.customer-order tr", + text: product_name)).to have_selector("td", text: last_name) end it "displays first name for each order" do product_name = order.line_items.first.product.name first_name = order.billing_address.firstname - expect(body_as_html(mail).find("table.order-summary.customer-order tr", text: product_name)).to have_selector("td", text: first_name) + expect(body_as_html(mail).find("table.order-summary.customer-order tr", + text: product_name)).to have_selector("td", text: first_name) end it "it orders list via last name" do - create(:order, :with_line_item, distributor: d1, order_cycle: order_cycle, state: 'complete', bill_address: FactoryBot.create(:address, last_name: "Abby")) - create(:order, :with_line_item, distributor: d1, order_cycle: order_cycle, state: 'complete', bill_address: FactoryBot.create(:address, last_name: "maggie")) + create(:order, :with_line_item, distributor: d1, order_cycle: order_cycle, state: 'complete', + bill_address: FactoryBot.create(:address, last_name: "Abby")) + create(:order, :with_line_item, distributor: d1, order_cycle: order_cycle, state: 'complete', + bill_address: FactoryBot.create(:address, last_name: "maggie")) expect(mail.body.encoded).to match(/.*Abby.*Doe.*maggie/m) end end @@ -162,7 +166,9 @@ describe ProducerMailer, type: :mailer do end it "does not add customer names table" do - expect { body_as_html(mail).find(".order-summary.customer-order") }.to raise_error(Capybara::ElementNotFound) + expect { + body_as_html(mail).find(".order-summary.customer-order") + }.to raise_error(Capybara::ElementNotFound) end end diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index d05dbbce83..2dde510c6e 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -79,7 +79,7 @@ module Spree expect { line_item.delete adjustment.reload.update_adjustment! - }.to change{ Spree::Adjustment.count }.by -1 + }.to change{ Spree::Adjustment.count }.by(-1) end end end diff --git a/spec/support/request/checkout_request_helper.rb b/spec/support/request/checkout_request_helper.rb index 7170032bc5..f842610c20 100644 --- a/spec/support/request/checkout_request_helper.rb +++ b/spec/support/request/checkout_request_helper.rb @@ -33,19 +33,18 @@ module CheckoutRequestsHelper end def fill_out_form(shipping_method_name, payment_method_name, save_default_addresses: true) - within "#shipping" do choose shipping_method_name end - + within "#payment" do choose payment_method_name end fill_out_details - + within "#billing" do - check "Save as default billing address" if save_default_addresses + check "Save as default billing address" if save_default_addresses end fill_out_billing_address diff --git a/spec/system/admin/bulk_order_management_spec.rb b/spec/system/admin/bulk_order_management_spec.rb index e870fafb11..4575db79c2 100644 --- a/spec/system/admin/bulk_order_management_spec.rb +++ b/spec/system/admin/bulk_order_management_spec.rb @@ -99,7 +99,7 @@ describe ' expect(page).to have_selector "th.variant", text: "PRODUCT: UNIT", visible: true expect(page).to have_selector "td.variant", text: li1.product.name, visible: true expect(page).to have_selector "td.variant", - text: (li2.product.name + ": " + li2.variant.options_text), visible: true + text: "#{li2.product.name}: #{li2.variant.options_text}", visible: true end it "displays a field for quantity" do @@ -808,7 +808,7 @@ describe ' before :each do visit_bulk_order_management within "tr#li_#{li3.id}" do - find("a", text: li3.product.name + ": " + li3.variant.options_text).click + find("a", text: "#{li3.product.name}: #{li3.variant.options_text}").click end end diff --git a/spec/system/admin/configuration/shipping_categories_spec.rb b/spec/system/admin/configuration/shipping_categories_spec.rb index be1461d365..cc5bbc0f87 100644 --- a/spec/system/admin/configuration/shipping_categories_spec.rb +++ b/spec/system/admin/configuration/shipping_categories_spec.rb @@ -6,14 +6,14 @@ describe "Shipping Categories" do include AuthenticationHelper context 'user adds a new shipping category with temperature control' do - it 'user sees new shipping category with temperature control' do + it 'user sees new shipping category with temperature control' do login_as_admin_and_visit spree.admin_shipping_categories_path click_link "New Shipping Category" - + fill_in "shipping_category_name", with: "freeze" check "shipping_category_temperature_controlled" click_button "Create" - + expect(page).to have_content("successfully created!") expect(page).to have_content("freeze") row = find('tr', text: 'freeze') diff --git a/spec/system/admin/enterprises/business_address_form_spec.rb b/spec/system/admin/enterprises/business_address_form_spec.rb index 38f01a1ab0..a2e59f39e8 100644 --- a/spec/system/admin/enterprises/business_address_form_spec.rb +++ b/spec/system/admin/enterprises/business_address_form_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "system_helper" describe "Business Address" do @@ -21,7 +23,7 @@ describe "Business Address" do click_link "Business Details" end end - + before do go_to_business_details end @@ -109,7 +111,7 @@ describe "Business Address" do fill_in 'enterprise_business_address_attributes_phone', with: '0123456789' click_button "Update" - + go_to_business_details click_button "Reset Form" @@ -126,9 +128,9 @@ describe "Business Address" do fill_in 'enterprise_business_address_attributes_phone', with: '0123456789' click_button "Update" - + go_to_business_details - + fill_in 'enterprise_business_address_attributes_company', with: '' fill_in 'enterprise_business_address_attributes_address1', with: '' fill_in 'enterprise_business_address_attributes_city', with: '' diff --git a/spec/system/admin/enterprises/images_spec.rb b/spec/system/admin/enterprises/images_spec.rb index 072af5b008..66b6d90737 100644 --- a/spec/system/admin/enterprises/images_spec.rb +++ b/spec/system/admin/enterprises/images_spec.rb @@ -18,9 +18,10 @@ describe "Managing enterprise images" do end describe "images for an enterprise" do - - let(:alert_text_logo) {'The logo will be removed immediately after you confirm'.strip} - let(:alert_text_promo) {'The promo image will be removed immediately after you confirm.'.strip} + let(:alert_text_logo) { 'The logo will be removed immediately after you confirm'.strip } + let(:alert_text_promo) { + 'The promo image will be removed immediately after you confirm.'.strip + } def go_to_images within(".side_menu") do diff --git a/spec/system/admin/order_cycles/complex_creating_specific_time_spec.rb b/spec/system/admin/order_cycles/complex_creating_specific_time_spec.rb index a473b54416..e16d86796f 100644 --- a/spec/system/admin/order_cycles/complex_creating_specific_time_spec.rb +++ b/spec/system/admin/order_cycles/complex_creating_specific_time_spec.rb @@ -11,7 +11,7 @@ describe ' include WebHelper let(:order_cycle_opening_time) { 1.day.from_now(Time.zone.now) } - let(:order_cycle_closing_time) { 2.day.from_now(Time.zone.now) } + let(:order_cycle_closing_time) { 2.days.from_now(Time.zone.now) } it "creating an order cycle with full interface", js: true do # Given coordinating, supplying and distributing enterprises with some products with variants @@ -54,7 +54,7 @@ describe ' # If I fill in the basic fields find('#order_cycle_orders_open_at').click # select date - select_date_from_datepicker Time.at(order_cycle_opening_time) + select_date_from_datepicker Time.zone.at(order_cycle_opening_time) # select time within(".flatpickr-calendar.open .flatpickr-time") do find('.flatpickr-hour').set('%02d' % order_cycle_opening_time.hour) @@ -65,7 +65,7 @@ describe ' find('#order_cycle_orders_close_at').click # select date - select_date_from_datepicker Time.at(order_cycle_closing_time) + select_date_from_datepicker Time.zone.at(order_cycle_closing_time) # select time within(".flatpickr-calendar.open .flatpickr-time") do find('.flatpickr-hour').set('%02d' % order_cycle_closing_time.hour) @@ -136,9 +136,9 @@ describe ' expect(page).to have_input "oc#{oc.id}[name]", value: "Plums & Avos" expect(page).to have_input "oc#{oc.id}[orders_open_at]", - value: Time.at(order_cycle_opening_time), visible: false + value: Time.zone.at(order_cycle_opening_time), visible: false expect(page).to have_input "oc#{oc.id}[orders_close_at]", - value: Time.at(order_cycle_closing_time), visible: false + value: Time.zone.at(order_cycle_closing_time), visible: false expect(page).to have_content "My coordinator" expect(page).to have_selector 'td.producers', text: 'My supplier' diff --git a/spec/system/admin/order_cycles/simple_spec.rb b/spec/system/admin/order_cycles/simple_spec.rb index 22a97ca84e..48f90a189b 100644 --- a/spec/system/admin/order_cycles/simple_spec.rb +++ b/spec/system/admin/order_cycles/simple_spec.rb @@ -507,11 +507,11 @@ describe ' # If I fill in the basic fields find('#order_cycle_orders_open_at').click - select_datetime_from_datepicker Time.at(Time.zone.local(2040, 10, 17, 0o6, 0o0, 0o0)) + select_datetime_from_datepicker Time.zone.at(Time.zone.local(2040, 10, 17, 0o6, 0o0, 0o0)) # hide the datetimepicker find("body").send_keys(:escape) find('#order_cycle_orders_close_at').click - select_datetime_from_datepicker Time.at(Time.zone.local(2040, 10, 24, 17, 0o0, 0o0)) + select_datetime_from_datepicker Time.zone.at(Time.zone.local(2040, 10, 24, 17, 0o0, 0o0)) # hide the datetimepicker find("body").send_keys(:escape) fill_in 'order_cycle_outgoing_exchange_0_pickup_instructions', with: 'pickup instructions' @@ -661,7 +661,7 @@ describe ' order_cycle = create(:simple_order_cycle, name: "Translusent Berries") login_as_admin_and_visit admin_order_cycles_path find("#oc#{order_cycle.id}_orders_close_at").click - datetime = Time.at(Time.zone.local(2040, 10, 17, 0o6, 0o0, 0o0)) + datetime = Time.zone.at(Time.zone.local(2040, 10, 17, 0o6, 0o0, 0o0)) input = find(".flatpickr-calendar.open .flatpickr-minute") input.send_keys datetime.strftime("%M").to_s.strip expect(page).to have_content "You have unsaved changes" diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index 5bf94f0842..2507a7a3a0 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -26,20 +26,31 @@ describe ' order_cycle: order_cycle, state: 'complete', payment_state: 'balance_due') end - - let!(:order_cycle2) { create(:simple_order_cycle, name: 'Two', orders_close_at: 2.weeks.from_now) } - let!(:order_cycle3) { create(:simple_order_cycle, name: 'Three', orders_close_at: 3.weeks.from_now) } - let!(:order_cycle4) { create(:simple_order_cycle, name: 'Four', orders_close_at: 4.weeks.from_now) } - let!(:order2) { create(:order_with_credit_payment, user: user, distributor: distributor2, - order_cycle: order_cycle2, completed_at: 2.day.ago) } - let!(:order3) { create(:order_with_credit_payment, user: user, distributor: distributor3, - order_cycle: order_cycle3) } - let!(:order4) { create(:order_with_credit_payment, user: user, distributor: distributor4, - order_cycle: order_cycle4) } + let!(:order_cycle2) { + create(:simple_order_cycle, name: 'Two', orders_close_at: 2.weeks.from_now) + } + let!(:order_cycle3) { + create(:simple_order_cycle, name: 'Three', orders_close_at: 3.weeks.from_now) + } + let!(:order_cycle4) { + create(:simple_order_cycle, name: 'Four', orders_close_at: 4.weeks.from_now) + } + + let!(:order2) { + create(:order_with_credit_payment, user: user, distributor: distributor2, + order_cycle: order_cycle2, completed_at: 2.days.ago) + } + let!(:order3) { + create(:order_with_credit_payment, user: user, distributor: distributor3, + order_cycle: order_cycle3) + } + let!(:order4) { + create(:order_with_credit_payment, user: user, distributor: distributor4, + order_cycle: order_cycle4) + } it "order cycles appear in descending order by close date on orders page" do - login_as_admin_and_visit 'admin/orders' open_select2('#s2id_q_order_cycle_id_in') @@ -49,7 +60,6 @@ describe ' end it "filter by multiple order cycles" do - login_as_admin_and_visit 'admin/orders' select2_select 'Two', from: 'q_order_cycle_id_in' @@ -64,12 +74,11 @@ describe ' end it "filter by distributors" do - login_as_admin_and_visit 'admin/orders' - select2_select "#{distributor2.name}", from: 'q_distributor_id_in' - select2_select "#{distributor4.name}", from: 'q_distributor_id_in' - + select2_select distributor2.name.to_s, from: 'q_distributor_id_in' + select2_select distributor4.name.to_s, from: 'q_distributor_id_in' + page.find('.filter-actions .button.icon-search').click # Order 2 and 4 should show, but not 3 @@ -79,10 +88,8 @@ describe ' end it "filter by complete date" do - login_as_admin_and_visit 'admin/orders' - find('#q_completed_at_gteq').click select_date_from_datepicker order3.completed_at.yesterday find('#q_completed_at_lteq').click @@ -90,7 +97,6 @@ describe ' page.find('.filter-actions .button.icon-search').click - # Order 3 and 4 should show, but not 2 expect(page).to_not have_content order2.number expect(page).to have_content order3.number @@ -98,11 +104,10 @@ describe ' end context "select/unselect all orders" do - before do login_as_admin_and_visit spree.admin_orders_path end - + it "by clicking on the checkbox in the table header" do # select all orders page.find("#listing_orders thead th:first-child input[type=checkbox]").click @@ -155,7 +160,8 @@ describe ' context "with incomplete order" do it "can edit order" do - incomplete_order = create(:order_with_line_items, distributor: distributor, order_cycle: order_cycle, line_items_count: 1) + incomplete_order = create(:order_with_line_items, distributor: distributor, + order_cycle: order_cycle, line_items_count: 1) login_as_admin_and_visit spree.admin_orders_path uncheck 'Only show complete orders' @@ -169,7 +175,8 @@ describe ' context "test the 'Only show the complete orders' checkbox" do it "display or not incomplete order" do - incomplete_order = create(:order_with_line_items, distributor: distributor, order_cycle: order_cycle, line_items_count: 1) + incomplete_order = create(:order_with_line_items, distributor: distributor, + order_cycle: order_cycle, line_items_count: 1) complete_order = create( :order_with_line_items, distributor: distributor, diff --git a/spec/system/consumer/authentication_spec.rb b/spec/system/consumer/authentication_spec.rb index 142df9353a..3d06ef7855 100644 --- a/spec/system/consumer/authentication_spec.rb +++ b/spec/system/consumer/authentication_spec.rb @@ -163,7 +163,7 @@ describe "Authentication", js: true do it "Loggin by typing login/ redirects to /#/login" do visit "/login" uri = URI.parse(current_url) - expect(uri.path + "#" + uri.fragment).to eq('/#/login') + expect("#{uri.path}##{uri.fragment}").to eq('/#/login') end describe "with user locales" do diff --git a/spec/system/consumer/shopping/checkout_spec.rb b/spec/system/consumer/shopping/checkout_spec.rb index b2eec21a14..3da2c1a802 100644 --- a/spec/system/consumer/shopping/checkout_spec.rb +++ b/spec/system/consumer/shopping/checkout_spec.rb @@ -313,7 +313,7 @@ describe "As a consumer I want to check out my cart", js: true do it "checks out successfully" do visit checkout_path - + expect(page).to have_content "Shipping info" find(:xpath, '//*[@id="shipping"]/ng-form/dd').click find("input[value='#{shipping_with_fee.id}'").click diff --git a/spec/system/consumer/shopping/shopping_spec.rb b/spec/system/consumer/shopping/shopping_spec.rb index 05ca0c6966..0d0e8c7229 100644 --- a/spec/system/consumer/shopping/shopping_spec.rb +++ b/spec/system/consumer/shopping/shopping_spec.rb @@ -29,7 +29,7 @@ describe "As a consumer I want to shop with a distributor", js: true do it "shows a distributor with images" do # Given the distributor has a logo - distributor.logo = File.new(Rails.root + 'app/assets/images/logo-white.png') + distributor.logo = File.new(Rails.root.join("app/assets/images/logo-white.png")) distributor.save! # Then we should see the distributor and its logo diff --git a/spec/system/first_system_spec.rb b/spec/system/first_system_spec.rb index dd148a253b..f5241fcfac 100644 --- a/spec/system/first_system_spec.rb +++ b/spec/system/first_system_spec.rb @@ -14,7 +14,7 @@ describe "Visit Admin", js: true do fill_in "Email", with: user.email fill_in "Password", with: user.password - + click_login_button expect(page).to have_content "DASHBOARD" expect(page).to have_current_path spree.admin_dashboard_path diff --git a/spec/system/support/capybara_setup.rb b/spec/system/support/capybara_setup.rb index dea6cfa57c..6abf0653d0 100644 --- a/spec/system/support/capybara_setup.rb +++ b/spec/system/support/capybara_setup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Usually, especially when using Selenium, developers tend to increase the max wait time. # With Cuprite, there is no need for that. # We use a Capybara default value here explicitly. diff --git a/spec/system/support/precompile_assets.rb b/spec/system/support/precompile_assets.rb index 519ecb0fca..95a9f4dc8d 100644 --- a/spec/system/support/precompile_assets.rb +++ b/spec/system/support/precompile_assets.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.configure do |config| # Skip assets precompilcation if we exclude system specs. # For example, you can run all non-system tests via the following command: @@ -19,5 +21,3 @@ RSpec.configure do |config| end end end - -