mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #8409 from luisAzcuaga/task/rubocop
[6055] Task: Run rubocop over existing todo
This commit is contained in:
6
Gemfile
6
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
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SplitCheckoutConstraint
|
||||
def matches?(request)
|
||||
Flipper.enabled? :split_checkout, current_user(request)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class Customer < ApplicationRecord
|
||||
include SetUnusedAddressFields
|
||||
|
||||
|
||||
acts_as_taggable
|
||||
|
||||
searchable_attributes :name, :email, :code
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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?
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ module Spree
|
||||
return amount if immutable? && !force
|
||||
|
||||
if calculable.nil? && adjustable.nil?
|
||||
self.delete
|
||||
delete
|
||||
return 0.0
|
||||
end
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
module Spree
|
||||
class User < ApplicationRecord
|
||||
include SetUnusedAddressFields
|
||||
|
||||
|
||||
searchable_attributes :email
|
||||
|
||||
devise :database_authenticatable, :token_authenticatable, :registerable, :recoverable,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class Subscription < ApplicationRecord
|
||||
include SetUnusedAddressFields
|
||||
|
||||
|
||||
ALLOWED_PAYMENT_METHOD_TYPES = ["Spree::PaymentMethod::Check",
|
||||
"Spree::Gateway::StripeConnect",
|
||||
"Spree::Gateway::StripeSCA"].freeze
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ImageImporter
|
||||
def import(url, product)
|
||||
attach(download(url), product)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 = {})
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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('<a href="http://google.fr" target="_blank">external site</a>')
|
||||
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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: ''
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user