Merge branch 'master' into pagy_upgrade

This commit is contained in:
piyush828-design
2025-04-28 11:23:44 +05:30
committed by GitHub
40 changed files with 151 additions and 83 deletions

View File

@@ -221,16 +221,6 @@ Metrics/PerceivedComplexity:
- 'app/models/spree/ability.rb'
- 'app/models/spree/order/checkout.rb'
# Offense count: 7
Naming/AccessorMethodName:
Exclude:
- 'app/mailers/producer_mailer.rb'
- 'app/models/spree/order.rb'
- 'app/services/checkout/post_checkout_actions.rb'
- 'lib/spree/core/controller_helpers/common.rb'
- 'spec/support/request/shop_workflow.rb'
- 'spec/support/request/web_helper.rb'
# Offense count: 1
# Configuration parameters: ForbiddenDelimiters.
# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$))

View File

@@ -25,6 +25,6 @@ class BaseController < ApplicationController
def set_order_cycle
return if @order_cycles.count != 1
current_order(true).set_order_cycle! @order_cycles.first
current_order(true).assign_order_cycle! @order_cycles.first
end
end

View File

@@ -26,7 +26,7 @@ module OrderCompletion
# Builds an order setting the token and distributor of the one specified
def build_new_order(distributor, token)
new_order = current_order(true)
new_order.set_distributor!(distributor)
new_order.assign_distributor!(distributor)
new_order.tokenized_permission.token = token
new_order.tokenized_permission.save!
end

View File

@@ -25,7 +25,7 @@ module OrderStockCheck
Alert.raise_with_record("Notice: order cycle closed during checkout completion", current_order)
current_order.empty!
current_order.set_order_cycle! nil
current_order.assign_order_cycle! nil
flash[:info] = I18n.t('order_cycle_closed')
respond_to do |format|

View File

@@ -11,7 +11,7 @@ class ShopController < BaseController
def order_cycle
if request.post?
if oc = OrderCycle.with_distributor(@distributor).active.find_by(id: params[:order_cycle_id])
current_order(true).set_order_cycle! oc
current_order(true).assign_order_cycle! oc
@current_order_cycle = oc
render json: @current_order_cycle, serializer: Api::OrderCycleSerializer
else

View File

@@ -37,7 +37,7 @@ class ProducerMailer < ApplicationMailer
@receival_instructions = @order_cycle.receival_instructions_for(@producer)
@total = total_from_line_items(line_items)
@tax_total = tax_total_from_line_items(line_items)
@customer_line_items = set_customer_data(line_items)
@customer_line_items = customer_data(line_items)
end
def subject
@@ -76,7 +76,7 @@ class ProducerMailer < ApplicationMailer
Spree::Money.new line_items.to_a.sum(&:included_tax)
end
def set_customer_data(line_items)
def customer_data(line_items)
return unless @coordinator.show_customer_names_to_suppliers?
@display_business_name = false

View File

@@ -560,7 +560,7 @@ module Spree
end
end
def set_order_cycle!(order_cycle)
def assign_order_cycle!(order_cycle)
return if self.order_cycle == order_cycle
self.order_cycle = order_cycle
@@ -573,7 +573,7 @@ module Spree
line_items.includes(variant: :stock_items).find_each(&:cap_quantity_at_stock!)
end
def set_distributor!(distributor)
def assign_distributor!(distributor)
self.distributor = distributor
self.order_cycle = nil unless order_cycle&.has_distributor? distributor
save!

View File

@@ -8,7 +8,7 @@ module Checkout
end
def success(params, current_user)
set_customer_terms_and_conditions_accepted_at(params)
assign_customer_terms_and_conditions_accepted_at(params)
save_order_addresses_as_user_default(params, current_user)
end
@@ -27,7 +27,7 @@ module Checkout
user_default_address_setter.set_default_ship_address if params[:order][:default_ship_address]
end
def set_customer_terms_and_conditions_accepted_at(params)
def assign_customer_terms_and_conditions_accepted_at(params)
return unless params[:order]
return unless params[:order][:terms_and_conditions_accepted]

View File

@@ -13,7 +13,7 @@ module Orders
def reset_distributor
if order.distributor && order.distributor != distributor
order.empty!
order.set_order_cycle! nil
order.assign_order_cycle! nil
end
order.distributor = distributor
end

View File

@@ -13,7 +13,7 @@
%col{ style: "width: 15%" }
%thead
%tr
%th= sort_link [:spree, @search], :email, t(".user"), {}, {title: "users_email_title"}
%th= sort_link [:spree, @search], :email, t(".user"), title: "users_email_title"
%th= sort_link [:spree, @search], :enterprise_limit, t(".enterprise_limit")
%th.actions
%tbody

View File

@@ -10,7 +10,7 @@ module Spree
helper_method :title=
helper_method :accurate_title
layout :get_layout
layout :pick_layout
before_action :set_user_language
@@ -65,7 +65,7 @@ module Spree
# Returns which layout to render.
# The layout to render can be set inside Spree configuration with the +:layout+ option.
# Default layout is: +app/views/spree/layouts/spree_application+
def get_layout
def pick_layout
Spree::Config[:layout]
end
end

View File

@@ -19,7 +19,7 @@ RSpec.describe EnterprisesController, type: :controller do
}
before do
order.set_distributor! current_distributor
order.assign_distributor! current_distributor
order.line_items << line_item
end

View File

@@ -64,7 +64,7 @@ RSpec.describe PaymentGateways::StripeController, type: :controller do
expect(controller).to receive(:current_order).and_return(order).at_least(:once)
expect(order_cycle).to receive(:closed?).and_return(true)
expect(order).to receive(:empty!)
expect(order).to receive(:set_order_cycle!).with(nil)
expect(order).to receive(:assign_order_cycle!).with(nil)
get :confirm, params: { payment_intent: "pi_123" }

View File

@@ -796,7 +796,7 @@ RSpec.describe Spree::Order do
describe "setting the distributor" do
it "sets the distributor when no order cycle is set" do
d = create(:distributor_enterprise)
subject.set_distributor! d
subject.assign_distributor! d
expect(subject.distributor).to eq(d)
end
@@ -806,7 +806,7 @@ RSpec.describe Spree::Order do
create(:exchange, order_cycle: oc, sender: oc.coordinator, receiver: d, incoming: false)
subject.order_cycle = oc
subject.set_distributor! d
subject.assign_distributor! d
expect(subject.distributor).to eq(d)
expect(subject.order_cycle).to eq(oc)
@@ -817,7 +817,7 @@ RSpec.describe Spree::Order do
oc = create(:simple_order_cycle)
subject.order_cycle = oc
subject.set_distributor! d
subject.assign_distributor! d
expect(subject.distributor).to eq(d)
expect(subject.order_cycle).to be_nil
@@ -825,8 +825,8 @@ RSpec.describe Spree::Order do
it "clears the distributor when setting to nil" do
d = create(:distributor_enterprise)
subject.set_distributor! d
subject.set_distributor! nil
subject.assign_distributor! d
subject.assign_distributor! nil
expect(subject.distributor).to be_nil
end
@@ -853,16 +853,16 @@ RSpec.describe Spree::Order do
it "empties the cart when changing the order cycle" do
expect(subject).to receive(:empty!)
subject.set_order_cycle! oc
subject.assign_order_cycle! oc
end
it "doesn't empty the cart if the order cycle is not different" do
expect(subject).not_to receive(:empty!)
subject.set_order_cycle! subject.order_cycle
subject.assign_order_cycle! subject.order_cycle
end
it "sets the order cycle when no distributor is set" do
subject.set_order_cycle! oc
subject.assign_order_cycle! oc
expect(subject.order_cycle).to eq(oc)
end
@@ -871,7 +871,7 @@ RSpec.describe Spree::Order do
create(:exchange, order_cycle: oc, sender: oc.coordinator, receiver: d, incoming: false)
subject.distributor = d
subject.set_order_cycle! oc
subject.assign_order_cycle! oc
expect(subject.order_cycle).to eq(oc)
expect(subject.distributor).to eq(d)
@@ -881,7 +881,7 @@ RSpec.describe Spree::Order do
d = create(:distributor_enterprise)
subject.distributor = d
subject.set_order_cycle! oc
subject.assign_order_cycle! oc
expect(subject.order_cycle).to eq(oc)
expect(subject.distributor).to be_nil
@@ -889,10 +889,10 @@ RSpec.describe Spree::Order do
it "clears the order cycle when setting to nil" do
d = create(:distributor_enterprise)
subject.set_order_cycle! oc
subject.assign_order_cycle! oc
subject.distributor = d
subject.set_order_cycle! nil
subject.assign_order_cycle! nil
expect(subject.order_cycle).to be_nil
expect(subject.distributor).to eq(d)

View File

@@ -49,7 +49,7 @@ RSpec.describe "Concurrent checkouts", concurrency: true do
order.next # => payment
order.next # => confirmation
set_order(order)
pick_order(order)
login_as(order.user)
end

View File

@@ -34,7 +34,7 @@ RSpec.describe "checking out an order with a paypal express payment method", typ
expect(order.next).to be true # => address
expect(order.next).to be true # => delivery
expect(order.next).to be true # => payment
set_order order
pick_order order
stub_paypal_confirm
end

View File

@@ -31,7 +31,7 @@ RSpec.describe 'checkout endpoints', type: :request do
allow(order_cycle_distributed_variants).to receive(:distributes_order_variants?)
.and_return(true)
set_order order
pick_order order
end
context "when getting the cart `/checkout/cart`" do

View File

@@ -93,7 +93,7 @@ RSpec.describe "checking out an order with a Stripe SCA payment method", type: :
Stripe.api_key = "sk_test_12345"
order.update(distributor_id: enterprise.id, order_cycle_id: order_cycle.id)
order.reload.update_totals
set_order order
pick_order order
# Authorizes the payment
stub_request(:post, "https://api.stripe.com/v1/payment_intents")

View File

@@ -33,7 +33,7 @@ module ShopWorkflow
order_cycle.exchanges.outgoing.first.enterprise_fees << enterprise_fee
end
def set_order(order)
def pick_order(order)
allow_any_instance_of(ApplicationController).to receive(:session).and_return(
order_id: order.id, access_token: order.token
)

View File

@@ -33,7 +33,7 @@ module WebHelper
page.execute_script("I18n.locale = '#{locale}'")
end
def get_i18n_locale
def pick_i18n_locale
page.evaluate_script("I18n.locale;")
end

View File

@@ -66,4 +66,35 @@ RSpec.describe "Zones" do
click_button "Update"
expect(page).to have_content("successfully updated!")
end
context "pagination" do
before do
login_as_admin
# creates 16 zones
16.times { create(:zone) }
visit spree.admin_zones_path
end
it "displays pagination" do
# table displays 15 entries
within('tbody') do
expect(page).to have_css('tr', count: 15)
end
within ".pagination" do
expect(page).not_to have_content "Previous"
expect(page).to have_content "Next"
click_on "2"
end
# table displays 1 entry
within('tbody') do
expect(page).to have_css('tr', count: 1)
end
within ".pagination" do
expect(page).to have_content "Previous"
expect(page).not_to have_content "Next"
end
end
end
end

View File

@@ -19,13 +19,13 @@ RSpec.describe 'Multilingual' do
end
it 'can switch language by params' do
expect(get_i18n_locale).to eq 'en'
expect(pick_i18n_locale).to eq 'en'
expect(get_i18n_translation('spree_admin_overview_enterprises_header')).to eq 'My Enterprises'
expect(page).to have_content 'My Enterprises'
expect(admin_user.locale).to be_nil
visit spree.admin_dashboard_path(locale: 'es')
expect(get_i18n_locale).to eq 'es'
expect(pick_i18n_locale).to eq 'es'
expect(get_i18n_translation('spree_admin_overview_enterprises_header'))
.to eq 'Mis Organizaciones'
expect(page).to have_content 'Mis Organizaciones'
@@ -35,7 +35,7 @@ RSpec.describe 'Multilingual' do
it 'fallbacks to default_locale' do
visit spree.admin_dashboard_path(locale: 'it')
expect(get_i18n_locale).to eq 'en'
expect(pick_i18n_locale).to eq 'en'
expect(get_i18n_translation('spree_admin_overview_enterprises_header')).to eq 'My Enterprises'
expect(page).to have_content 'My Enterprises'
expect(admin_user.locale).to be_nil

View File

@@ -503,22 +503,41 @@ RSpec.describe '
context "pagination" do
before do
# creates 15 orders additional to the 4 orders
15.times { create(:order_ready_to_ship) }
login_as_admin
visit spree.admin_orders_path
end
it "displays pagination options" do
# displaying 4 orders (one order per table row)
# displaying 15 orders (one order per table row)
within('tbody') do
expect(page).to have_css('tr', count: 4)
expect(page).to have_css('tr', count: 15)
end
# pagination options also refer 4 order
expect(page).to have_content "4 Results found. Viewing 1 to 4."
# pagination options refers 19 orders
expect(page).to have_content "19 Results found. Viewing 1 to 15."
page.find(".per-page-dropdown .ts-control .item").click # toggling the pagination dropdown
expect(page).to have_content "15 per page"
expect(page).to have_content "50 per page"
expect(page).to have_content "100 per page"
end
it "changes pagination and displays entries" do
within ".pagination" do
expect(page).not_to have_css('button.page.prev')
expect(page).to have_css('button.page.next')
click_on "2"
end
# table displays 4 entries
within('tbody') do
expect(page).to have_css('tr', count: 4)
end
expect(page).to have_content "19 Results found. Viewing 16 to 19."
within ".pagination" do
expect(page).to have_css('button.page.prev')
expect(page).not_to have_css('button.page.next')
end
end
end
context "with a capturable order" do

View File

@@ -128,6 +128,34 @@ RSpec.describe "Managing users" do
}.to change { user.reload.show_api_key_view }.to(false)
end
end
context "pagination" do
before do
# creates 8 more users
8.times { create(:user) }
expect(Spree::User.count).to eq 11
visit spree.admin_users_path
end
it "displays pagination" do
# table displays 10 entries
within('tbody') do
expect(page).to have_css('tr', count: 10)
end
within ".pagination" do
expect(page).not_to have_content "Previous"
expect(page).to have_content "Next"
click_on "2"
end
# table displays 1 entry
within('tbody') do
expect(page).to have_css('tr', count: 1)
end
within ".pagination" do
expect(page).to have_content "Previous"
expect(page).not_to have_content "Next"
end
end
end
end
describe "creating a user" do

View File

@@ -11,7 +11,7 @@ RSpec.describe "Checkout" do
before do
variant.semantic_links << SemanticLink.new(semantic_id: "https://product")
set_order order
pick_order order
login_as create(:user)
end

View File

@@ -69,7 +69,7 @@ RSpec.describe "As a consumer, I want to checkout my order" do
before do
add_enterprise_fee enterprise_fee
set_order order
pick_order order
distributor.shipping_methods.push(shipping_methods)
end

View File

@@ -74,7 +74,7 @@ RSpec.describe "As a consumer, I want to checkout my order" do
before do
add_enterprise_fee enterprise_fee
set_order order
pick_order order
distributor.shipping_methods.push(shipping_methods)
end

View File

@@ -45,7 +45,7 @@ RSpec.describe "As a consumer, I want to checkout my order" do
before do
add_enterprise_fee enterprise_fee
set_order order
pick_order order
distributor.shipping_methods.push(free_shipping_with_required_address)
end

View File

@@ -39,7 +39,7 @@ RSpec.describe "As a consumer, I want to checkout my order" do
before do
add_enterprise_fee enterprise_fee
set_order order
pick_order order
distributor.shipping_methods.push(free_shipping_with_required_address)
end

View File

@@ -86,7 +86,7 @@ RSpec.describe "As a consumer, I want to see adjustment breakdown" do
describe "for a customer with shipping address within the tax zone" do
before do
set_order order_within_zone
pick_order order_within_zone
login_as(user_within_zone)
end
@@ -200,7 +200,7 @@ RSpec.describe "As a consumer, I want to see adjustment breakdown" do
describe "for a customer with shipping address outside the tax zone" do
before do
set_order order_outside_zone
pick_order order_outside_zone
login_as(user_outside_zone)
end

View File

@@ -92,7 +92,7 @@ RSpec.describe "As a consumer, I want to see adjustment breakdown" do
describe "for a customer with shipping address within the tax zone" do
before do
set_order order_within_zone
pick_order order_within_zone
login_as(user_within_zone)
end
@@ -211,7 +211,7 @@ RSpec.describe "As a consumer, I want to see adjustment breakdown" do
describe "for a customer with shipping address outside the tax zone" do
before do
set_order order_outside_zone
pick_order order_outside_zone
login_as(user_outside_zone)
end

View File

@@ -25,19 +25,19 @@ RSpec.describe 'Multilingual' do
context 'can switch language by params' do
it 'in root path' do
visit root_path
expect(get_i18n_locale).to eq 'en'
expect(pick_i18n_locale).to eq 'en'
expect(get_i18n_translation('label_shops')).to eq 'Shops'
expect(cookies_name).not_to include('locale')
expect(page).to have_content 'SHOPS'
visit root_path(locale: 'es')
expect(get_i18n_locale).to eq 'es'
expect(pick_i18n_locale).to eq 'es'
expect(get_i18n_translation('label_shops')).to eq 'Tiendas'
expect_menu_and_cookie_in_es
# it is not in the list of available of available_locales
visit root_path(locale: 'it')
expect(get_i18n_locale).to eq 'es'
expect(pick_i18n_locale).to eq 'es'
expect(get_i18n_translation('label_shops')).to eq 'Tiendas'
expect_menu_and_cookie_in_es
end
@@ -51,7 +51,7 @@ RSpec.describe 'Multilingual' do
let(:order) { create(:order, order_cycle:, distributor:) }
before do
set_order order
pick_order order
add_product_to_cart order, product, quantity: 1
end
@@ -124,7 +124,7 @@ RSpec.describe 'Multilingual' do
create(:order_ready_for_confirmation, distributor:)
}
before do
set_order order
pick_order order
login_as user
end

View File

@@ -33,7 +33,7 @@ RSpec.describe "full-page cart" do
let(:order) { create(:order, order_cycle:, distributor:) }
before do
set_order order
pick_order order
end
describe "continue shopping" do

View File

@@ -25,7 +25,7 @@ RSpec.describe "As a consumer I want to check out my cart" do
after { Warden.test_reset! }
before do
set_order order
pick_order order
add_product_to_cart order, product
end

View File

@@ -42,7 +42,7 @@ RSpec.describe "Check out with Paypal" do
before do
distributor.shipping_methods << free_shipping
set_order order
pick_order order
add_product_to_cart order, product
end

View File

@@ -36,7 +36,7 @@ RSpec.describe "Check out with Stripe" do
before do
stripe_enable
set_order order
pick_order order
add_product_to_cart order, product
distributor.shipping_methods << [shipping_with_fee, free_shipping]
end
@@ -205,7 +205,7 @@ RSpec.describe "Check out with Stripe" do
new_order = create(:order, user:, order_cycle:,
distributor:, bill_address_id: nil,
ship_address_id: nil)
set_order(new_order)
pick_order(new_order)
add_product_to_cart(new_order, product, quantity: 10)
stub_payment_intents_post_request order: new_order
stub_successful_capture_request order: new_order

View File

@@ -38,7 +38,7 @@ RSpec.describe "As a consumer I want to view products" do
let(:order) { create(:order, distributor:) }
before do
set_order order
pick_order order
end
describe "supplier's name is displayed" do

View File

@@ -27,7 +27,7 @@ RSpec.describe "As a consumer I want to shop with a distributor" do
let(:order) { create(:order, distributor:) }
before do
set_order order
pick_order order
end
it "shows a distributor with images" do
@@ -461,7 +461,7 @@ RSpec.describe "As a consumer I want to shop with a distributor" do
before do
add_variant_to_order_cycle(exchange, variant)
set_order_cycle(order, oc1)
set_order(order)
pick_order(order)
visit shop_path
end

View File

@@ -21,7 +21,7 @@ RSpec.describe "As a consumer, I want to check unit price information for a prod
let(:user) { create(:user, password: "password", password_confirmation: "password") }
before do
set_order order
pick_order order
exchange1.update_attribute :pickup_time, "monday"
add_variant_to_order_cycle(exchange1, variant)
end

View File

@@ -142,7 +142,7 @@ RSpec.describe 'White label setting' do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
pick_order(order)
end
it_behaves_like "hides the OFN navigation when needed only"
@@ -176,7 +176,7 @@ RSpec.describe 'White label setting' do
context "when the user has a complete order" do
before do
set_order(complete_order)
pick_order(complete_order)
end
shared_examples "hides the OFN navigation when needed only for the order confirmation" do
@@ -225,7 +225,7 @@ RSpec.describe 'White label setting' do
context "when the preference is set to false" do
before do
distributor.update_attribute(:hide_ofn_navigation, false)
set_order(order)
pick_order(order)
allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor).
and_return(distributor)
end
@@ -288,7 +288,7 @@ RSpec.describe 'White label setting' do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
pick_order(order)
visit main_app.cart_path
end
@@ -299,7 +299,7 @@ RSpec.describe 'White label setting' do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
pick_order(order)
visit checkout_path
end
@@ -347,7 +347,7 @@ RSpec.describe 'White label setting' do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
pick_order(order)
visit main_app.cart_path
end
@@ -358,7 +358,7 @@ RSpec.describe 'White label setting' do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
pick_order(order)
visit checkout_path
end
@@ -399,7 +399,7 @@ RSpec.describe 'White label setting' do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
pick_order(order)
visit main_app.cart_path
end
@@ -410,7 +410,7 @@ RSpec.describe 'White label setting' do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
pick_order(order)
visit checkout_path
end