mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Fix Style/HashSyntax
This commit is contained in:
@@ -97,31 +97,31 @@ describe Admin::BulkLineItemsController, type: :controller do
|
||||
let(:distributor1) { create(:distributor_enterprise) }
|
||||
let(:distributor2) { create(:distributor_enterprise) }
|
||||
let(:coordinator) { create(:distributor_enterprise) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator:) }
|
||||
let!(:order1) {
|
||||
FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete',
|
||||
FactoryBot.create(:order, order_cycle:, state: 'complete',
|
||||
completed_at: Time.zone.now, distributor: distributor1,
|
||||
billing_address: FactoryBot.create(:address) )
|
||||
}
|
||||
let!(:line_item1) {
|
||||
FactoryBot.create(:line_item_with_shipment, order: order1,
|
||||
product: FactoryBot.create(:product,
|
||||
supplier: supplier))
|
||||
supplier:))
|
||||
}
|
||||
let!(:line_item2) {
|
||||
FactoryBot.create(:line_item_with_shipment, order: order1,
|
||||
product: FactoryBot.create(:product,
|
||||
supplier: supplier))
|
||||
supplier:))
|
||||
}
|
||||
let!(:order2) {
|
||||
FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete',
|
||||
FactoryBot.create(:order, order_cycle:, state: 'complete',
|
||||
completed_at: Time.zone.now, distributor: distributor2,
|
||||
billing_address: FactoryBot.create(:address) )
|
||||
}
|
||||
let!(:line_item3) {
|
||||
FactoryBot.create(:line_item_with_shipment, order: order2,
|
||||
product: FactoryBot.create(:product,
|
||||
supplier: supplier))
|
||||
supplier:))
|
||||
}
|
||||
|
||||
context "producer enterprise" do
|
||||
@@ -191,9 +191,9 @@ describe Admin::BulkLineItemsController, type: :controller do
|
||||
let(:supplier) { create(:supplier_enterprise) }
|
||||
let(:distributor1) { create(:distributor_enterprise) }
|
||||
let(:coordinator) { create(:distributor_enterprise) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator:) }
|
||||
let!(:order1) {
|
||||
FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete',
|
||||
FactoryBot.create(:order, order_cycle:, state: 'complete',
|
||||
completed_at: Time.zone.now,
|
||||
distributor: distributor1,
|
||||
billing_address: FactoryBot.create(:address) )
|
||||
@@ -201,7 +201,7 @@ describe Admin::BulkLineItemsController, type: :controller do
|
||||
let!(:line_item1) {
|
||||
line_item1 = FactoryBot.create(:line_item_with_shipment,
|
||||
order: order1,
|
||||
product: FactoryBot.create(:product, supplier: supplier))
|
||||
product: FactoryBot.create(:product, supplier:))
|
||||
# make sure shipment is available through db reloads of this line_item
|
||||
line_item1.tap(&:save!)
|
||||
}
|
||||
@@ -281,7 +281,7 @@ describe Admin::BulkLineItemsController, type: :controller do
|
||||
context "hub enterprise" do
|
||||
before do
|
||||
allow(controller).to receive_messages spree_current_user: distributor1.owner
|
||||
put :update, params: params, xhr: true
|
||||
put :update, params:, xhr: true
|
||||
end
|
||||
|
||||
it "updates the line item" do
|
||||
@@ -300,16 +300,16 @@ describe Admin::BulkLineItemsController, type: :controller do
|
||||
let(:supplier) { create(:supplier_enterprise) }
|
||||
let(:distributor1) { create(:distributor_enterprise) }
|
||||
let(:coordinator) { create(:distributor_enterprise) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator:) }
|
||||
let!(:order1) {
|
||||
FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete',
|
||||
FactoryBot.create(:order, order_cycle:, state: 'complete',
|
||||
completed_at: Time.zone.now, distributor: distributor1,
|
||||
billing_address: FactoryBot.create(:address) )
|
||||
}
|
||||
let!(:line_item1) {
|
||||
FactoryBot.create(:line_item_with_shipment, order: order1,
|
||||
product: FactoryBot.create(:product,
|
||||
supplier: supplier))
|
||||
supplier:))
|
||||
}
|
||||
let(:params) { { id: line_item1.id, order_id: order1.number } }
|
||||
|
||||
@@ -348,20 +348,20 @@ describe Admin::BulkLineItemsController, type: :controller do
|
||||
let(:outgoing_exchange) { order_cycle.exchanges.outgoing.first }
|
||||
|
||||
let!(:order) {
|
||||
create(:order_with_line_items, line_items_count: 2, distributor: distributor,
|
||||
order_cycle: order_cycle)
|
||||
create(:order_with_line_items, line_items_count: 2, distributor:,
|
||||
order_cycle:)
|
||||
}
|
||||
let(:line_item1) { order.line_items.first }
|
||||
let(:line_item2) { order.line_items.last }
|
||||
|
||||
let!(:zone) { create(:zone_with_member) }
|
||||
let(:tax_included) { true }
|
||||
let(:tax_rate5) { create(:tax_rate, amount: 0.05, zone: zone, included_in_price: tax_included) }
|
||||
let(:tax_rate5) { create(:tax_rate, amount: 0.05, zone:, included_in_price: tax_included) }
|
||||
let(:tax_rate10) {
|
||||
create(:tax_rate, amount: 0.10, zone: zone, included_in_price: tax_included)
|
||||
create(:tax_rate, amount: 0.10, zone:, included_in_price: tax_included)
|
||||
}
|
||||
let(:tax_rate15) {
|
||||
create(:tax_rate, amount: 0.15, zone: zone, included_in_price: tax_included)
|
||||
create(:tax_rate, amount: 0.15, zone:, included_in_price: tax_included)
|
||||
}
|
||||
let(:tax_cat5) { create(:tax_category, tax_rates: [tax_rate5]) }
|
||||
let(:tax_cat10) { create(:tax_category, tax_rates: [tax_rate10]) }
|
||||
@@ -395,7 +395,7 @@ describe Admin::BulkLineItemsController, type: :controller do
|
||||
order.recreate_all_fees!
|
||||
order.create_tax_charge!
|
||||
order.update_order!
|
||||
order.payments << create(:payment, payment_method: payment_method, amount: order.total,
|
||||
order.payments << create(:payment, payment_method:, amount: order.total,
|
||||
state: "completed")
|
||||
|
||||
allow(controller).to receive(:spree_current_user) { distributor.owner }
|
||||
|
||||
@@ -22,7 +22,7 @@ module Admin
|
||||
end
|
||||
|
||||
context "json" do
|
||||
let!(:customer) { create(:customer, enterprise: enterprise, created_manually: true) }
|
||||
let!(:customer) { create(:customer, enterprise:, created_manually: true) }
|
||||
|
||||
context "where I manage the enterprise" do
|
||||
before do
|
||||
@@ -35,13 +35,13 @@ module Admin
|
||||
let(:params) { { format: :json, enterprise_id: enterprise.id } }
|
||||
|
||||
it "scopes @collection to customers of that enterprise" do
|
||||
get :index, params: params
|
||||
get(:index, params:)
|
||||
expect(assigns(:collection)).to eq [customer]
|
||||
end
|
||||
|
||||
it "serializes the data" do
|
||||
expect(ActiveModel::ArraySerializer).to receive(:new)
|
||||
get :index, params: params
|
||||
get :index, params:
|
||||
end
|
||||
|
||||
it 'calls CustomersWithBalance' do
|
||||
@@ -51,42 +51,42 @@ module Admin
|
||||
|
||||
expect(customers_with_balance).to receive(:query) { Customer.none }
|
||||
|
||||
get :index, params: params
|
||||
get :index, params:
|
||||
end
|
||||
|
||||
it 'serializes using CustomerWithBalanceSerializer' do
|
||||
expect(Api::Admin::CustomerWithBalanceSerializer).to receive(:new)
|
||||
|
||||
get :index, params: params
|
||||
get :index, params:
|
||||
end
|
||||
|
||||
context 'when the customer has no orders' do
|
||||
it 'includes the customer balance in the response' do
|
||||
get :index, params: params
|
||||
get(:index, params:)
|
||||
expect(json_response.first["balance"]).to eq("$0.00")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the customer has complete orders' do
|
||||
let(:order) { create(:order, customer: customer, state: 'complete') }
|
||||
let!(:line_item) { create(:line_item, order: order, price: 10.0) }
|
||||
let(:order) { create(:order, customer:, state: 'complete') }
|
||||
let!(:line_item) { create(:line_item, order:, price: 10.0) }
|
||||
|
||||
it 'includes the customer balance in the response' do
|
||||
order.update_order!
|
||||
get :index, params: params
|
||||
get(:index, params:)
|
||||
expect(json_response.first["balance"]).to eq("$-10.00")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the customer has canceled orders' do
|
||||
let(:order) { create(:order, customer: customer) }
|
||||
let(:order) { create(:order, customer:) }
|
||||
let!(:variant) { create(:variant, price: 10.0) }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(Spree::Payment).to receive(:completed?).and_return(true)
|
||||
|
||||
order.contents.add(variant)
|
||||
order.payments << create(:payment, order: order, amount: order.total)
|
||||
order.payments << create(:payment, order:, amount: order.total)
|
||||
order.reload
|
||||
|
||||
order.process_payments!
|
||||
@@ -94,24 +94,24 @@ module Admin
|
||||
end
|
||||
|
||||
it 'includes the customer balance in the response' do
|
||||
get :index, params: params
|
||||
get(:index, params:)
|
||||
expect(json_response.first["balance"]).to eq("$10.00")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the customer has cart orders' do
|
||||
let(:order) { create(:order, customer: customer, state: 'cart') }
|
||||
let!(:line_item) { create(:line_item, order: order, price: 10.0) }
|
||||
let(:order) { create(:order, customer:, state: 'cart') }
|
||||
let!(:line_item) { create(:line_item, order:, price: 10.0) }
|
||||
|
||||
it 'includes the customer balance in the response' do
|
||||
get :index, params: params
|
||||
get(:index, params:)
|
||||
expect(json_response.first["balance"]).to eq("$0.00")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the customer has an order with a void payment' do
|
||||
let(:order) { create(:order_with_totals, customer: customer, state: 'complete') }
|
||||
let!(:payment) { create(:payment, order: order, amount: order.total) }
|
||||
let(:order) { create(:order_with_totals, customer:, state: 'complete') }
|
||||
let!(:payment) { create(:payment, order:, amount: order.total) }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(Spree::Payment).to receive(:completed?).and_return(true)
|
||||
@@ -122,7 +122,7 @@ module Admin
|
||||
|
||||
it 'includes the customer balance in the response' do
|
||||
expect(order.payment_total).to eq(0)
|
||||
get :index, params: params
|
||||
get(:index, params:)
|
||||
expect(json_response.first["balance"]).to eq('$-10.00')
|
||||
end
|
||||
end
|
||||
@@ -154,7 +154,7 @@ module Admin
|
||||
let(:another_enterprise) { create(:distributor_enterprise) }
|
||||
|
||||
context "json" do
|
||||
let!(:customer) { create(:customer, enterprise: enterprise) }
|
||||
let!(:customer) { create(:customer, enterprise:) }
|
||||
|
||||
context "where I manage the customer's enterprise" do
|
||||
render_views
|
||||
@@ -236,7 +236,7 @@ module Admin
|
||||
let(:another_enterprise) { create(:distributor_enterprise) }
|
||||
|
||||
context "json" do
|
||||
let!(:customer) { create(:customer, enterprise: enterprise) }
|
||||
let!(:customer) { create(:customer, enterprise:) }
|
||||
|
||||
context "where I manage the customer's enterprise" do
|
||||
render_views
|
||||
|
||||
@@ -246,7 +246,7 @@ describe Admin::EnterprisesController, type: :controller do
|
||||
|
||||
describe "tag rules" do
|
||||
let(:enterprise) { create(:distributor_enterprise) }
|
||||
let!(:tag_rule) { create(:filter_order_cycles_tag_rule, enterprise: enterprise) }
|
||||
let!(:tag_rule) { create(:filter_order_cycles_tag_rule, enterprise:) }
|
||||
|
||||
before do
|
||||
controller_login_as_enterprise_user [enterprise]
|
||||
|
||||
@@ -10,10 +10,10 @@ describe Admin::InventoryItemsController, type: :controller do
|
||||
let(:enterprise) { create(:distributor_enterprise) }
|
||||
let(:variant) { create(:variant) }
|
||||
let(:inventory_item) {
|
||||
create(:inventory_item, enterprise: enterprise, variant: variant, visible: true)
|
||||
create(:inventory_item, enterprise:, variant:, visible: true)
|
||||
}
|
||||
let(:params) {
|
||||
{ format: format,
|
||||
{ format:,
|
||||
inventory_item: { enterprise_id: enterprise.id, variant_id: variant.id, visible: false } }
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ describe Admin::InventoryItemsController, type: :controller do
|
||||
context "with unacceptable data" do
|
||||
render_views
|
||||
let!(:bad_params) {
|
||||
{ format: format,
|
||||
{ format:,
|
||||
inventory_item: { enterprise_id: enterprise.id, variant_id: variant.id,
|
||||
visible: nil } }
|
||||
}
|
||||
@@ -83,9 +83,9 @@ describe Admin::InventoryItemsController, type: :controller do
|
||||
let(:enterprise) { create(:distributor_enterprise) }
|
||||
let(:variant) { create(:variant) }
|
||||
let(:inventory_item) {
|
||||
create(:inventory_item, enterprise: enterprise, variant: variant, visible: true)
|
||||
create(:inventory_item, enterprise:, variant:, visible: true)
|
||||
}
|
||||
let(:params) { { format: format, id: inventory_item.id, inventory_item: { visible: false } } }
|
||||
let(:params) { { format:, id: inventory_item.id, inventory_item: { visible: false } } }
|
||||
|
||||
context "where I don't manage the inventory item enterprise" do
|
||||
before do
|
||||
@@ -129,7 +129,7 @@ describe Admin::InventoryItemsController, type: :controller do
|
||||
context "with unacceptable data" do
|
||||
render_views
|
||||
let!(:bad_params) {
|
||||
{ format: format, id: inventory_item.id, inventory_item: { visible: nil } }
|
||||
{ format:, id: inventory_item.id, inventory_item: { visible: nil } }
|
||||
}
|
||||
|
||||
it "returns an error message" do
|
||||
|
||||
@@ -19,7 +19,7 @@ describe Admin::InvoiceSettingsController, type: :controller do
|
||||
|
||||
it "disables invoices" do
|
||||
expect {
|
||||
post :update, params: params
|
||||
post :update, params:
|
||||
}.to change {
|
||||
Spree::Config[:enable_invoices?]
|
||||
}.to(false)
|
||||
@@ -27,7 +27,7 @@ describe Admin::InvoiceSettingsController, type: :controller do
|
||||
|
||||
it "changes the invoice style" do
|
||||
expect {
|
||||
post :update, params: params
|
||||
post :update, params:
|
||||
}.to change {
|
||||
Spree::Config[:invoice_style2?]
|
||||
}.to(true)
|
||||
|
||||
@@ -20,7 +20,7 @@ describe Admin::MatomoSettingsController, type: :controller do
|
||||
|
||||
it "changes Matomo settings" do
|
||||
expect {
|
||||
post :update, params: params
|
||||
post :update, params:
|
||||
}.to change {
|
||||
[
|
||||
Spree::Config[:matomo_url],
|
||||
|
||||
@@ -46,7 +46,7 @@ module Admin
|
||||
let(:q) { { orders_close_at_gt: 45.days.ago } }
|
||||
|
||||
it "loads order cycles closed after specified date, and orders w/o a close_at date" do
|
||||
get :index, as: :json, params: { q: q }
|
||||
get :index, as: :json, params: { q: }
|
||||
expect(assigns(:collection)).to_not include oc1
|
||||
expect(assigns(:collection)).to include oc2, oc3, oc4
|
||||
end
|
||||
@@ -55,7 +55,7 @@ module Admin
|
||||
before { q.merge!(id_not_in: [oc2.id, oc4.id]) }
|
||||
|
||||
it "loads order cycles that meet all conditions" do
|
||||
get :index, format: :json, params: { q: q }
|
||||
get :index, format: :json, params: { q: }
|
||||
expect(assigns(:collection)).to_not include oc1, oc2, oc4
|
||||
expect(assigns(:collection)).to include oc3
|
||||
end
|
||||
@@ -221,16 +221,16 @@ module Admin
|
||||
let!(:p) { create(:product) }
|
||||
let!(:v) { p.variants.first }
|
||||
let!(:incoming_exchange) {
|
||||
create(:exchange, order_cycle: order_cycle, sender: producer, receiver: coordinator,
|
||||
create(:exchange, order_cycle:, sender: producer, receiver: coordinator,
|
||||
incoming: true, variants: [v])
|
||||
}
|
||||
let!(:outgoing_exchange) {
|
||||
create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: coordinator,
|
||||
create(:exchange, order_cycle:, sender: coordinator, receiver: coordinator,
|
||||
incoming: false, variants: [v])
|
||||
}
|
||||
let!(:subscription) { create(:subscription, shop: coordinator, schedule: schedule) }
|
||||
let!(:subscription) { create(:subscription, shop: coordinator, schedule:) }
|
||||
let!(:subscription_line_item) {
|
||||
create(:subscription_line_item, subscription: subscription, variant: v)
|
||||
create(:subscription_line_item, subscription:, variant: v)
|
||||
}
|
||||
|
||||
before do
|
||||
@@ -308,11 +308,11 @@ module Admin
|
||||
let(:hub) { create(:distributor_enterprise) }
|
||||
let(:v) { create(:variant) }
|
||||
let!(:incoming_exchange) {
|
||||
create(:exchange, order_cycle: order_cycle, sender: producer, receiver: coordinator,
|
||||
create(:exchange, order_cycle:, sender: producer, receiver: coordinator,
|
||||
incoming: true, variants: [v])
|
||||
}
|
||||
let!(:outgoing_exchange) {
|
||||
create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: hub,
|
||||
create(:exchange, order_cycle:, sender: coordinator, receiver: hub,
|
||||
incoming: false, variants: [v])
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ describe Admin::ProxyOrdersController, type: :controller do
|
||||
let!(:user) { create(:user, enterprise_limit: 10) }
|
||||
let!(:shop) { create(:distributor_enterprise) }
|
||||
let!(:order_cycle) { create(:simple_order_cycle, orders_close_at: 1.day.from_now) }
|
||||
let!(:subscription) { create(:subscription, shop: shop, with_items: true) }
|
||||
let!(:subscription) { create(:subscription, shop:, with_items: true) }
|
||||
let!(:proxy_order) {
|
||||
create(:proxy_order, subscription: subscription, order_cycle: order_cycle)
|
||||
create(:proxy_order, subscription:, order_cycle:)
|
||||
}
|
||||
|
||||
before do
|
||||
@@ -44,7 +44,7 @@ describe Admin::ProxyOrdersController, type: :controller do
|
||||
|
||||
context "when cancellation succeeds" do
|
||||
it 'renders the cancelled proxy_order as json' do
|
||||
get :cancel, params: params
|
||||
get(:cancel, params:)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['state']).to eq "canceled"
|
||||
expect(json_response['id']).to eq proxy_order.id
|
||||
@@ -56,7 +56,7 @@ describe Admin::ProxyOrdersController, type: :controller do
|
||||
before { order_cycle.update(orders_close_at: 1.day.ago) }
|
||||
|
||||
it "shows an error" do
|
||||
get :cancel, params: params
|
||||
get(:cancel, params:)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['errors']).to eq ['Could not cancel the order']
|
||||
end
|
||||
@@ -73,10 +73,10 @@ describe Admin::ProxyOrdersController, type: :controller do
|
||||
let!(:payment_method) { create(:payment_method) }
|
||||
let!(:shipping_method) { create(:shipping_method) }
|
||||
let!(:subscription) do
|
||||
create(:subscription, shipping_method: shipping_method, shop: shop, with_items: true)
|
||||
create(:subscription, shipping_method:, shop:, with_items: true)
|
||||
end
|
||||
let!(:proxy_order) {
|
||||
create(:proxy_order, subscription: subscription, order_cycle: order_cycle)
|
||||
create(:proxy_order, subscription:, order_cycle:)
|
||||
}
|
||||
let(:order) { proxy_order.initialise_order! }
|
||||
|
||||
@@ -115,7 +115,7 @@ describe Admin::ProxyOrdersController, type: :controller do
|
||||
|
||||
context "when resuming succeeds" do
|
||||
it 'renders the resumed proxy_order as json' do
|
||||
get :resume, params: params
|
||||
get(:resume, params:)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['state']).to eq "resumed"
|
||||
expect(json_response['id']).to eq proxy_order.id
|
||||
@@ -127,7 +127,7 @@ describe Admin::ProxyOrdersController, type: :controller do
|
||||
before { order_cycle.update(orders_close_at: 1.day.ago) }
|
||||
|
||||
it "shows an error" do
|
||||
get :resume, params: params
|
||||
get(:resume, params:)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['errors']).to eq ['Could not resume the order']
|
||||
end
|
||||
|
||||
@@ -35,8 +35,8 @@ describe Admin::ReportsController, type: :controller do
|
||||
|
||||
# orderA1 can only be accessed by supplier1, supplier3 and distributor1
|
||||
let(:orderA1) do
|
||||
order = create(:order, distributor: distributor1, bill_address: bill_address,
|
||||
ship_address: ship_address, special_instructions: instructions,
|
||||
order = create(:order, distributor: distributor1, bill_address:,
|
||||
ship_address:, special_instructions: instructions,
|
||||
order_cycle: ocA)
|
||||
order.line_items << create(:line_item, variant: product1.variants.first)
|
||||
order.line_items << create(:line_item, variant: product3.variants.first)
|
||||
@@ -46,8 +46,8 @@ describe Admin::ReportsController, type: :controller do
|
||||
end
|
||||
# orderA2 can only be accessed by supplier2 and distributor2
|
||||
let(:orderA2) do
|
||||
order = create(:order, distributor: distributor2, bill_address: bill_address,
|
||||
ship_address: ship_address, special_instructions: instructions,
|
||||
order = create(:order, distributor: distributor2, bill_address:,
|
||||
ship_address:, special_instructions: instructions,
|
||||
order_cycle: ocA)
|
||||
order.line_items << create(:line_item, variant: product2.variants.first)
|
||||
order.finalize!
|
||||
@@ -56,8 +56,8 @@ describe Admin::ReportsController, type: :controller do
|
||||
end
|
||||
# orderB1 can only be accessed by supplier1, supplier3 and distributor1
|
||||
let(:orderB1) do
|
||||
order = create(:order, distributor: distributor1, bill_address: bill_address,
|
||||
ship_address: ship_address, special_instructions: instructions,
|
||||
order = create(:order, distributor: distributor1, bill_address:,
|
||||
ship_address:, special_instructions: instructions,
|
||||
order_cycle: ocB)
|
||||
order.line_items << create(:line_item, variant: product1.variants.first)
|
||||
order.line_items << create(:line_item, variant: product3.variants.first)
|
||||
@@ -67,8 +67,8 @@ describe Admin::ReportsController, type: :controller do
|
||||
end
|
||||
# orderB2 can only be accessed by supplier2 and distributor2
|
||||
let(:orderB2) do
|
||||
order = create(:order, distributor: distributor2, bill_address: bill_address,
|
||||
ship_address: ship_address, special_instructions: instructions,
|
||||
order = create(:order, distributor: distributor2, bill_address:,
|
||||
ship_address:, special_instructions: instructions,
|
||||
order_cycle: ocB)
|
||||
order.line_items << create(:line_item, variant: product2.variants.first)
|
||||
order.finalize!
|
||||
|
||||
@@ -22,13 +22,13 @@ describe Admin::SchedulesController, type: :controller do
|
||||
|
||||
it "scopes @collection to schedules containing order_cycles " \
|
||||
"coordinated by enterprises I manage" do
|
||||
get :index, params: params
|
||||
get(:index, params:)
|
||||
expect(assigns(:collection)).to eq [coordinated_schedule]
|
||||
end
|
||||
|
||||
it "serializes the data" do
|
||||
expect(ActiveModel::ArraySerializer).to receive(:new)
|
||||
get :index, params: params
|
||||
get :index, params:
|
||||
end
|
||||
|
||||
context "and there is a schedule of an OC coordinated by _another_ enterprise " \
|
||||
@@ -46,7 +46,7 @@ describe Admin::SchedulesController, type: :controller do
|
||||
|
||||
it "scopes @collection to schedules containing order_cycles " \
|
||||
"coordinated by the first enterprise" do
|
||||
get :index, params: params
|
||||
get(:index, params:)
|
||||
expect(assigns(:collection)).to eq [coordinated_schedule]
|
||||
end
|
||||
end
|
||||
@@ -107,8 +107,8 @@ describe Admin::SchedulesController, type: :controller do
|
||||
it "allows me to add/remove only order cycles I coordinate to/from the schedule" do
|
||||
order_cycle_ids = [coordinated_order_cycle2.id, uncoordinated_order_cycle2.id,
|
||||
uncoordinated_order_cycle3.id]
|
||||
spree_put :update, format: :json, id: coordinated_schedule.id,
|
||||
order_cycle_ids: order_cycle_ids
|
||||
spree_put(:update, format: :json, id: coordinated_schedule.id,
|
||||
order_cycle_ids:)
|
||||
expect(assigns(:schedule)).to eq coordinated_schedule
|
||||
# coordinated_order_cycle2 is added, uncoordinated_order_cycle is NOT removed
|
||||
expect(coordinated_schedule.reload.order_cycles).to include coordinated_order_cycle2,
|
||||
|
||||
@@ -35,7 +35,7 @@ describe Admin::StripeAccountsController, type: :controller do
|
||||
end
|
||||
|
||||
context "when the specified stripe account exists" do
|
||||
let(:stripe_account) { create(:stripe_account, enterprise: enterprise) }
|
||||
let(:stripe_account) { create(:stripe_account, enterprise:) }
|
||||
|
||||
before do
|
||||
# So that we can stub #deauthorize_and_destroy
|
||||
@@ -96,7 +96,7 @@ describe Admin::StripeAccountsController, type: :controller do
|
||||
end
|
||||
|
||||
it "redirects to unauthorized" do
|
||||
get :status, params: params
|
||||
get(:status, params:)
|
||||
expect(response).to redirect_to unauthorized_path
|
||||
end
|
||||
end
|
||||
@@ -108,7 +108,7 @@ describe Admin::StripeAccountsController, type: :controller do
|
||||
|
||||
context "when Stripe is not enabled" do
|
||||
it "returns with a status of 'stripe_disabled'" do
|
||||
get :status, params: params
|
||||
get(:status, params:)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response["status"]).to eq "stripe_disabled"
|
||||
end
|
||||
@@ -119,7 +119,7 @@ describe Admin::StripeAccountsController, type: :controller do
|
||||
|
||||
context "when no stripe account is associated with the specified enterprise" do
|
||||
it "returns with a status of 'account_missing'" do
|
||||
get :status, params: params
|
||||
get(:status, params:)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response["status"]).to eq "account_missing"
|
||||
end
|
||||
@@ -127,7 +127,7 @@ describe Admin::StripeAccountsController, type: :controller do
|
||||
|
||||
context "when a stripe account is associated with the specified enterprise" do
|
||||
let!(:account) {
|
||||
create(:stripe_account, stripe_user_id: "acc_123", enterprise: enterprise)
|
||||
create(:stripe_account, stripe_user_id: "acc_123", enterprise:)
|
||||
}
|
||||
|
||||
context "but access has been revoked or does not exist on stripe's servers" do
|
||||
@@ -137,7 +137,7 @@ describe Admin::StripeAccountsController, type: :controller do
|
||||
end
|
||||
|
||||
it "returns with a status of 'access_revoked'" do
|
||||
get :status, params: params
|
||||
get(:status, params:)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response["status"]).to eq "access_revoked"
|
||||
end
|
||||
@@ -159,7 +159,7 @@ describe Admin::StripeAccountsController, type: :controller do
|
||||
end
|
||||
|
||||
it "returns with a status of 'connected'" do
|
||||
get :status, params: params
|
||||
get(:status, params:)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response["status"]).to eq "connected"
|
||||
# serializes required attrs
|
||||
|
||||
@@ -84,7 +84,7 @@ describe Admin::StripeConnectSettingsController, type: :controller do
|
||||
before { allow(controller).to receive(:spree_current_user) { user } }
|
||||
|
||||
it "does not allow access" do
|
||||
get :update, params: params
|
||||
get(:update, params:)
|
||||
expect(response).to redirect_to unauthorized_path
|
||||
end
|
||||
end
|
||||
@@ -97,7 +97,7 @@ describe Admin::StripeConnectSettingsController, type: :controller do
|
||||
|
||||
it "sets global config to the specified values" do
|
||||
expect(Spree::Config.stripe_connect_enabled).to be true
|
||||
get :update, params: params
|
||||
get(:update, params:)
|
||||
expect(Spree::Config.stripe_connect_enabled).to be false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,7 @@ describe Admin::SubscriptionLineItemsController, type: :controller do
|
||||
let(:unmanaged_shop) { create(:enterprise) }
|
||||
let!(:product) { create(:product) }
|
||||
let!(:variant) {
|
||||
create(:variant, product: product, unit_value: '100', price: 15.00)
|
||||
create(:variant, product:, unit_value: '100', price: 15.00)
|
||||
}
|
||||
let!(:outgoing_exchange) {
|
||||
order_cycle.exchanges.create(sender: shop, receiver: shop, variants: [variant],
|
||||
|
||||
@@ -18,7 +18,7 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
|
||||
context 'as a regular user' do
|
||||
it 'redirects to unauthorized' do
|
||||
get :index, params: params
|
||||
get(:index, params:)
|
||||
expect(response).to redirect_to unauthorized_path
|
||||
end
|
||||
end
|
||||
@@ -28,10 +28,10 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
let!(:not_enabled_shop) { create(:distributor_enterprise, owner: user) }
|
||||
|
||||
context "where I manage a shop that is set up for subscriptions" do
|
||||
let!(:subscription) { create(:subscription, shop: shop) }
|
||||
let!(:subscription) { create(:subscription, shop:) }
|
||||
|
||||
it 'renders the index page with appropriate data' do
|
||||
get :index, params: params
|
||||
get(:index, params:)
|
||||
expect(response).to render_template 'index'
|
||||
expect(assigns(:collection)).to eq [] # No collection loaded
|
||||
expect(assigns(:shops)).to eq [shop] # Shops are loaded
|
||||
@@ -40,7 +40,7 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
|
||||
context "where I don't manage a shop that is set up for subscriptions" do
|
||||
it 'renders the setup_explanation page' do
|
||||
get :index, params: params
|
||||
get(:index, params:)
|
||||
expect(response).to render_template 'setup_explanation'
|
||||
expect(assigns(:collection)).to eq [] # No collection loaded
|
||||
expect(assigns(:shop)).to eq shop # First SO enabled shop is loaded
|
||||
@@ -51,11 +51,11 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
|
||||
context 'json' do
|
||||
let(:params) { { format: :json } }
|
||||
let!(:subscription) { create(:subscription, shop: shop) }
|
||||
let!(:subscription) { create(:subscription, shop:) }
|
||||
|
||||
context 'as a regular user' do
|
||||
it 'redirects to unauthorized' do
|
||||
get :index, params: params
|
||||
get(:index, params:)
|
||||
expect(response).to redirect_to unauthorized_path
|
||||
end
|
||||
end
|
||||
@@ -66,7 +66,7 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
let!(:subscription2) { create(:subscription, shop: shop2) }
|
||||
|
||||
it 'renders the collection as json' do
|
||||
get :index, params: params
|
||||
get(:index, params:)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response.count).to be 2
|
||||
expect(json_response.map{ |so| so['id'] }).to include subscription.id, subscription2.id
|
||||
@@ -76,7 +76,7 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
before { params.merge!(q: { shop_id_eq: shop2.id }) }
|
||||
|
||||
it "restricts the list of subscriptions" do
|
||||
get :index, params: params
|
||||
get(:index, params:)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response.count).to be 1
|
||||
ids = json_response.map{ |so| so['id'] }
|
||||
@@ -207,7 +207,7 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
|
||||
context 'where the specified variants are available from the shop' do
|
||||
let!(:exchange) {
|
||||
create(:exchange, order_cycle: order_cycle, incoming: false, receiver: shop,
|
||||
create(:exchange, order_cycle:, incoming: false, receiver: shop,
|
||||
variants: [variant])
|
||||
}
|
||||
|
||||
@@ -240,11 +240,11 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
let!(:shipping_method) { create(:shipping_method, distributors: [shop]) }
|
||||
let!(:subscription) {
|
||||
create(:subscription,
|
||||
shop: shop,
|
||||
shop:,
|
||||
customer: customer1,
|
||||
schedule: schedule,
|
||||
payment_method: payment_method,
|
||||
shipping_method: shipping_method)
|
||||
schedule:,
|
||||
payment_method:,
|
||||
shipping_method:)
|
||||
}
|
||||
|
||||
before do
|
||||
@@ -280,11 +280,11 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
let!(:shipping_method) { create(:shipping_method, distributors: [shop]) }
|
||||
let!(:subscription) {
|
||||
create(:subscription,
|
||||
shop: shop,
|
||||
customer: customer,
|
||||
schedule: schedule,
|
||||
payment_method: payment_method,
|
||||
shipping_method: shipping_method,
|
||||
shop:,
|
||||
customer:,
|
||||
schedule:,
|
||||
payment_method:,
|
||||
shipping_method:,
|
||||
subscription_line_items: [create(:subscription_line_item, variant: variant1,
|
||||
quantity: 2)])
|
||||
}
|
||||
@@ -418,9 +418,9 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
let!(:user) { create(:user, enterprise_limit: 10) }
|
||||
let!(:shop) { create(:distributor_enterprise) }
|
||||
let!(:order_cycle) { create(:simple_order_cycle, orders_close_at: 1.day.from_now) }
|
||||
let!(:subscription) { create(:subscription, shop: shop, with_items: true) }
|
||||
let!(:subscription) { create(:subscription, shop:, with_items: true) }
|
||||
let!(:proxy_order) {
|
||||
create(:proxy_order, subscription: subscription, order_cycle: order_cycle)
|
||||
create(:proxy_order, subscription:, order_cycle:)
|
||||
}
|
||||
|
||||
before do
|
||||
@@ -454,7 +454,7 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
context "when at least one associated order is still 'open'" do
|
||||
let(:order_cycle) { subscription.order_cycles.first }
|
||||
let(:proxy_order) {
|
||||
create(:proxy_order, subscription: subscription, order_cycle: order_cycle)
|
||||
create(:proxy_order, subscription:, order_cycle:)
|
||||
}
|
||||
let!(:order) { proxy_order.initialise_order! }
|
||||
|
||||
@@ -525,7 +525,7 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
describe 'pause' do
|
||||
let!(:user) { create(:user, enterprise_limit: 10) }
|
||||
let!(:shop) { create(:distributor_enterprise) }
|
||||
let!(:subscription) { create(:subscription, shop: shop, with_items: true) }
|
||||
let!(:subscription) { create(:subscription, shop:, with_items: true) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { user }
|
||||
@@ -558,7 +558,7 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
context "when at least one associated order is still 'open'" do
|
||||
let(:order_cycle) { subscription.order_cycles.first }
|
||||
let(:proxy_order) {
|
||||
create(:proxy_order, subscription: subscription, order_cycle: order_cycle)
|
||||
create(:proxy_order, subscription:, order_cycle:)
|
||||
}
|
||||
let!(:order) { proxy_order.initialise_order! }
|
||||
|
||||
@@ -630,7 +630,7 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
let!(:user) { create(:user, enterprise_limit: 10) }
|
||||
let!(:shop) { create(:distributor_enterprise) }
|
||||
let!(:subscription) {
|
||||
create(:subscription, shop: shop, paused_at: Time.zone.now, with_items: true)
|
||||
create(:subscription, shop:, paused_at: Time.zone.now, with_items: true)
|
||||
}
|
||||
|
||||
before do
|
||||
@@ -664,7 +664,7 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
context "when at least one order in an open order cycle is 'complete'" do
|
||||
let(:order_cycle) { subscription.order_cycles.first }
|
||||
let(:proxy_order) {
|
||||
create(:proxy_order, subscription: subscription, order_cycle: order_cycle)
|
||||
create(:proxy_order, subscription:, order_cycle:)
|
||||
}
|
||||
let!(:order) { proxy_order.initialise_order! }
|
||||
|
||||
@@ -750,7 +750,7 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { user }
|
||||
controller.instance_variable_set(:@subscription, Subscription.new(shop: shop))
|
||||
controller.instance_variable_set(:@subscription, Subscription.new(shop:))
|
||||
end
|
||||
|
||||
it "assigns data to instance variables" do
|
||||
|
||||
@@ -8,8 +8,8 @@ describe Admin::TagRulesController, type: :controller do
|
||||
let(:format) { :json }
|
||||
|
||||
let(:enterprise) { create(:distributor_enterprise) }
|
||||
let!(:tag_rule) { create(:filter_order_cycles_tag_rule, enterprise: enterprise) }
|
||||
let(:params) { { format: format, id: tag_rule.id } }
|
||||
let!(:tag_rule) { create(:filter_order_cycles_tag_rule, enterprise:) }
|
||||
let(:params) { { format:, id: tag_rule.id } }
|
||||
|
||||
context "where I don't manage the tag rule enterprise" do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
@@ -10,9 +10,9 @@ describe Admin::VariantOverridesController, type: :controller do
|
||||
let(:hub) { create(:distributor_enterprise) }
|
||||
let(:variant) { create(:variant) }
|
||||
let!(:inventory_item) {
|
||||
create(:inventory_item, enterprise: hub, variant: variant, visible: true)
|
||||
create(:inventory_item, enterprise: hub, variant:, visible: true)
|
||||
}
|
||||
let!(:variant_override) { create(:variant_override, hub: hub, variant: variant) }
|
||||
let!(:variant_override) { create(:variant_override, hub:, variant:) }
|
||||
let(:variant_override_params) {
|
||||
[{ id: variant_override.id, price: 123.45, count_on_hand: 321, sku: "MySKU",
|
||||
on_demand: false }]
|
||||
@@ -43,7 +43,7 @@ describe Admin::VariantOverridesController, type: :controller do
|
||||
end
|
||||
|
||||
it 'only authorizes the updated variant overrides' do
|
||||
other_variant_override = create(:variant_override, hub: hub, variant: create(:variant))
|
||||
other_variant_override = create(:variant_override, hub:, variant: create(:variant))
|
||||
expect(controller).not_to receive(:authorize!).with(:update, other_variant_override)
|
||||
|
||||
put :bulk_update, as: format, params: { variant_overrides: variant_override_params }
|
||||
@@ -89,7 +89,7 @@ describe Admin::VariantOverridesController, type: :controller do
|
||||
context "and there is a variant override for a deleted variant" do
|
||||
let(:deleted_variant) { create(:variant) }
|
||||
let!(:variant_override_of_deleted_variant) {
|
||||
create(:variant_override, hub: hub, variant: deleted_variant)
|
||||
create(:variant_override, hub:, variant: deleted_variant)
|
||||
}
|
||||
|
||||
before { deleted_variant.update_attribute :deleted_at, Time.zone.now }
|
||||
@@ -114,18 +114,18 @@ describe Admin::VariantOverridesController, type: :controller do
|
||||
let(:hub) { create(:distributor_enterprise) }
|
||||
let(:producer) { create(:supplier_enterprise) }
|
||||
let(:product) { create(:product, supplier: producer) }
|
||||
let(:variant1) { create(:variant, product: product) }
|
||||
let(:variant2) { create(:variant, product: product) }
|
||||
let(:variant1) { create(:variant, product:) }
|
||||
let(:variant2) { create(:variant, product:) }
|
||||
let!(:variant_override1) {
|
||||
create(:variant_override, hub: hub, variant: variant1, count_on_hand: 5, default_stock: 7,
|
||||
create(:variant_override, hub:, variant: variant1, count_on_hand: 5, default_stock: 7,
|
||||
resettable: true)
|
||||
}
|
||||
let!(:variant_override2) {
|
||||
create(:variant_override, hub: hub, variant: variant2, count_on_hand: 2, default_stock: 1,
|
||||
create(:variant_override, hub:, variant: variant2, count_on_hand: 2, default_stock: 1,
|
||||
resettable: false)
|
||||
}
|
||||
|
||||
let(:params) { { format: format, hub_id: hub.id } }
|
||||
let(:params) { { format:, hub_id: hub.id } }
|
||||
|
||||
context "where I don't manage the variant override hub" do
|
||||
before do
|
||||
@@ -135,7 +135,7 @@ describe Admin::VariantOverridesController, type: :controller do
|
||||
end
|
||||
|
||||
it "redirects to unauthorized" do
|
||||
put :bulk_reset, params: params
|
||||
put(:bulk_reset, params:)
|
||||
expect(response).to redirect_to unauthorized_path
|
||||
end
|
||||
end
|
||||
@@ -148,7 +148,7 @@ describe Admin::VariantOverridesController, type: :controller do
|
||||
context "where the producer has not granted create_variant_overrides permission " \
|
||||
"to the hub" do
|
||||
it "restricts access" do
|
||||
put :bulk_reset, params: params
|
||||
put(:bulk_reset, params:)
|
||||
expect(response).to redirect_to unauthorized_path
|
||||
end
|
||||
end
|
||||
@@ -160,7 +160,7 @@ describe Admin::VariantOverridesController, type: :controller do
|
||||
}
|
||||
|
||||
it "loads data" do
|
||||
put :bulk_reset, params: params
|
||||
put(:bulk_reset, params:)
|
||||
expect(assigns[:hubs]).to eq [hub]
|
||||
expect(assigns[:producers]).to eq [producer]
|
||||
expect(assigns[:hub_permissions]).to eq Hash[hub.id, [producer.id]]
|
||||
@@ -170,7 +170,7 @@ describe Admin::VariantOverridesController, type: :controller do
|
||||
it "updates stock to default values where reset is enabled" do
|
||||
expect(variant_override1.reload.count_on_hand).to eq 5 # reset enabled
|
||||
expect(variant_override2.reload.count_on_hand).to eq 2 # reset disabled
|
||||
put :bulk_reset, params: params
|
||||
put(:bulk_reset, params:)
|
||||
expect(variant_override1.reload.count_on_hand).to eq 7 # reset enabled
|
||||
expect(variant_override2.reload.count_on_hand).to eq 2 # reset disabled
|
||||
end
|
||||
@@ -180,7 +180,7 @@ describe Admin::VariantOverridesController, type: :controller do
|
||||
before { hub.owner.update_attribute(:enterprise_limit, 2) }
|
||||
let(:hub2) { create(:distributor_enterprise, owner: hub.owner) }
|
||||
let(:product) { create(:product, supplier: producer) }
|
||||
let(:variant3) { create(:variant, product: product) }
|
||||
let(:variant3) { create(:variant, product:) }
|
||||
let!(:variant_override3) {
|
||||
create(:variant_override, hub: hub2, variant: variant3, count_on_hand: 1,
|
||||
default_stock: 13, resettable: true)
|
||||
@@ -192,7 +192,7 @@ describe Admin::VariantOverridesController, type: :controller do
|
||||
|
||||
it "does not reset count_on_hand for variant_overrides not in params" do
|
||||
expect {
|
||||
put :bulk_reset, params: params
|
||||
put :bulk_reset, params:
|
||||
}.to_not change{ variant_override3.reload.count_on_hand }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,7 +27,7 @@ module Api
|
||||
end
|
||||
|
||||
describe "#update" do
|
||||
let(:customer) { create(:customer, user: user) }
|
||||
let(:customer) { create(:customer, user:) }
|
||||
let(:params) { { format: :json, id: customer.id, customer: { code: '123' } } }
|
||||
|
||||
context "as a user who is not associated with the customer" do
|
||||
|
||||
@@ -78,7 +78,7 @@ describe Api::V0::EnterprisesController, type: :controller do
|
||||
let(:enterprise_manager) { create(:user) }
|
||||
|
||||
before do
|
||||
enterprise_manager.enterprise_roles.build(enterprise: enterprise).save
|
||||
enterprise_manager.enterprise_roles.build(enterprise:).save
|
||||
allow(controller).to receive(:spree_current_user) { enterprise_manager }
|
||||
end
|
||||
|
||||
@@ -90,7 +90,7 @@ describe Api::V0::EnterprisesController, type: :controller do
|
||||
end
|
||||
|
||||
it "I can update enterprise logo image" do
|
||||
api_post :update_image, logo: logo, id: enterprise.id
|
||||
api_post :update_image, logo:, id: enterprise.id
|
||||
expect(response.status).to eq 200
|
||||
expect(response.content_type).to eq "text/html"
|
||||
expect(response.body).to match /logo\.png$/
|
||||
|
||||
@@ -22,7 +22,7 @@ module Api
|
||||
let!(:product3) { create(:product, primary_taxon: taxon2) }
|
||||
let!(:product4) { create(:product, primary_taxon: taxon3, properties: [property3]) }
|
||||
let!(:user) { create(:user) }
|
||||
let(:customer) { create(:customer, user: user, enterprise: distributor) }
|
||||
let(:customer) { create(:customer, user:, enterprise: distributor) }
|
||||
|
||||
before do
|
||||
exchange.variants << product1.variants.first
|
||||
@@ -95,9 +95,9 @@ module Api
|
||||
let!(:supplier) { create(:supplier_enterprise, properties: [supplier_property]) }
|
||||
|
||||
before do
|
||||
product1.update!(supplier: supplier)
|
||||
product2.update!(supplier: supplier)
|
||||
product3.update!(supplier: supplier, inherits_properties: false)
|
||||
product1.update!(supplier:)
|
||||
product2.update!(supplier:)
|
||||
product3.update!(supplier:, inherits_properties: false)
|
||||
end
|
||||
|
||||
it "filter out the product that don't inherits from supplier properties" do
|
||||
@@ -248,16 +248,16 @@ module Api
|
||||
context "with custom taxon ordering applied and duplicate product names in the order cycle" do
|
||||
let!(:supplier) { create(:supplier_enterprise) }
|
||||
let!(:product5) {
|
||||
create(:product, name: "Duplicate name", primary_taxon: taxon3, supplier: supplier)
|
||||
create(:product, name: "Duplicate name", primary_taxon: taxon3, supplier:)
|
||||
}
|
||||
let!(:product6) {
|
||||
create(:product, name: "Duplicate name", primary_taxon: taxon3, supplier: supplier)
|
||||
create(:product, name: "Duplicate name", primary_taxon: taxon3, supplier:)
|
||||
}
|
||||
let!(:product7) {
|
||||
create(:product, name: "Duplicate name", primary_taxon: taxon2, supplier: supplier)
|
||||
create(:product, name: "Duplicate name", primary_taxon: taxon2, supplier:)
|
||||
}
|
||||
let!(:product8) {
|
||||
create(:product, name: "Duplicate name", primary_taxon: taxon2, supplier: supplier)
|
||||
create(:product, name: "Duplicate name", primary_taxon: taxon2, supplier:)
|
||||
}
|
||||
|
||||
before do
|
||||
|
||||
@@ -12,7 +12,7 @@ module Api
|
||||
|
||||
let!(:distributor) { create(:distributor_enterprise) }
|
||||
let!(:coordinator) { create(:distributor_enterprise) }
|
||||
let!(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) }
|
||||
let!(:order_cycle) { create(:simple_order_cycle, coordinator:) }
|
||||
|
||||
describe '#index' do
|
||||
let!(:distributor2) { create(:distributor_enterprise) }
|
||||
@@ -20,18 +20,18 @@ module Api
|
||||
let!(:supplier) { create(:supplier_enterprise) }
|
||||
let!(:order_cycle2) { create(:simple_order_cycle, coordinator: coordinator2) }
|
||||
let!(:order1) do
|
||||
create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now,
|
||||
distributor: distributor, billing_address: create(:address, lastname: "c"),
|
||||
create(:order, order_cycle:, state: 'complete', completed_at: Time.zone.now,
|
||||
distributor:, billing_address: create(:address, lastname: "c"),
|
||||
total: 5.0)
|
||||
end
|
||||
let!(:order2) do
|
||||
create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now,
|
||||
create(:order, order_cycle:, state: 'complete', completed_at: Time.zone.now,
|
||||
distributor: distributor2, billing_address: create(:address, lastname: "a"),
|
||||
total: 10.0)
|
||||
end
|
||||
let!(:order3) do
|
||||
create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now,
|
||||
distributor: distributor, billing_address: create(:address, lastname: "b"),
|
||||
create(:order, order_cycle:, state: 'complete', completed_at: Time.zone.now,
|
||||
distributor:, billing_address: create(:address, lastname: "b"),
|
||||
total: 1.0 )
|
||||
end
|
||||
let!(:order4) do
|
||||
@@ -42,19 +42,19 @@ module Api
|
||||
let!(:order5) { create(:order, state: 'cart', completed_at: nil) }
|
||||
let!(:line_item1) do
|
||||
create(:line_item_with_shipment, order: order1,
|
||||
product: create(:product, supplier: supplier))
|
||||
product: create(:product, supplier:))
|
||||
end
|
||||
let!(:line_item2) do
|
||||
create(:line_item_with_shipment, order: order2,
|
||||
product: create(:product, supplier: supplier))
|
||||
product: create(:product, supplier:))
|
||||
end
|
||||
let!(:line_item3) do
|
||||
create(:line_item_with_shipment, order: order2,
|
||||
product: create(:product, supplier: supplier))
|
||||
product: create(:product, supplier:))
|
||||
end
|
||||
let!(:line_item4) do
|
||||
create(:line_item_with_shipment, order: order3,
|
||||
product: create(:product, supplier: supplier))
|
||||
product: create(:product, supplier:))
|
||||
end
|
||||
|
||||
context 'as a regular user' do
|
||||
@@ -152,8 +152,8 @@ module Api
|
||||
|
||||
context "with an order without billing address" do
|
||||
let!(:order7) {
|
||||
create(:order_with_line_items, billing_address: nil, order_cycle: order_cycle,
|
||||
distributor: distributor)
|
||||
create(:order_with_line_items, billing_address: nil, order_cycle:,
|
||||
distributor:)
|
||||
}
|
||||
|
||||
it 'can show orders without bill address' do
|
||||
@@ -200,7 +200,7 @@ module Api
|
||||
|
||||
describe "#show" do
|
||||
let!(:order) {
|
||||
create(:completed_order_with_totals, order_cycle: order_cycle, distributor: distributor )
|
||||
create(:completed_order_with_totals, order_cycle:, distributor: )
|
||||
}
|
||||
|
||||
context "Resource not found" do
|
||||
@@ -253,7 +253,7 @@ module Api
|
||||
|
||||
context "as distributor owner" do
|
||||
let!(:order) {
|
||||
create(:completed_order_with_fees, order_cycle: order_cycle, distributor: distributor )
|
||||
create(:completed_order_with_fees, order_cycle:, distributor: )
|
||||
}
|
||||
|
||||
before { allow(controller).to receive(:spree_current_user) { order.distributor.owner } }
|
||||
@@ -318,13 +318,13 @@ module Api
|
||||
}
|
||||
let!(:order) {
|
||||
create(:order_with_totals_and_distribution,
|
||||
user: user, distributor: distributor, order_cycle: order_cycle,
|
||||
user:, distributor:, order_cycle:,
|
||||
state: 'complete', payment_state: 'balance_due')
|
||||
}
|
||||
|
||||
before do
|
||||
order.finalize!
|
||||
order.payments << create(:check_payment, order: order, amount: order.total)
|
||||
order.payments << create(:check_payment, order:, amount: order.total)
|
||||
allow(controller).to receive(:spree_current_user) { order.distributor.owner }
|
||||
end
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ describe Api::V0::ProductsController, type: :controller do
|
||||
|
||||
let(:supplier) { create(:supplier_enterprise) }
|
||||
let(:supplier2) { create(:supplier_enterprise) }
|
||||
let!(:product) { create(:product, supplier: supplier) }
|
||||
let!(:product) { create(:product, supplier:) }
|
||||
let!(:other_product) { create(:product) }
|
||||
let(:product_other_supplier) { create(:product, supplier: supplier2) }
|
||||
let(:product_with_image) { create(:product_with_image, supplier: supplier) }
|
||||
let(:product_with_image) { create(:product_with_image, supplier:) }
|
||||
let(:all_attributes) { ["id", "name", "variants"] }
|
||||
let(:variants_attributes) {
|
||||
["id", "options_text", "unit_value", "unit_description", "unit_to_display", "on_demand",
|
||||
@@ -210,7 +210,7 @@ describe Api::V0::ProductsController, type: :controller do
|
||||
describe '#bulk_products' do
|
||||
context "as an enterprise user" do
|
||||
let!(:taxon) { create(:taxon) }
|
||||
let!(:product2) { create(:product, supplier: supplier, primary_taxon: taxon) }
|
||||
let!(:product2) { create(:product, supplier:, primary_taxon: taxon) }
|
||||
let!(:product3) { create(:product, supplier: supplier2, primary_taxon: taxon) }
|
||||
let!(:product4) { create(:product, supplier: supplier2) }
|
||||
let(:current_api_user) { supplier_enterprise_user(supplier) }
|
||||
@@ -271,7 +271,7 @@ describe Api::V0::ProductsController, type: :controller do
|
||||
|
||||
def supplier_enterprise_user(enterprise)
|
||||
user = create(:user)
|
||||
user.enterprise_roles.create(enterprise: enterprise)
|
||||
user.enterprise_roles.create(enterprise:)
|
||||
user
|
||||
end
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ describe Api::V0::ReportsController, type: :controller do
|
||||
describe "packing report" do
|
||||
context "as an enterprise user with full order permissions (distributor)" do
|
||||
let!(:distributor) { create(:distributor_enterprise) }
|
||||
let!(:order) { create(:completed_order_with_totals, distributor: distributor) }
|
||||
let!(:order) { create(:completed_order_with_totals, distributor:) }
|
||||
let(:current_user) { distributor.owner }
|
||||
|
||||
it "renders results" do
|
||||
|
||||
@@ -75,7 +75,7 @@ describe Api::V0::ShipmentsController, type: :controller do
|
||||
hub = create(:distributor_enterprise)
|
||||
order.update_attribute(:distributor, hub)
|
||||
shipment.shipping_method.distributors << hub
|
||||
variant_override = create(:variant_override, hub: hub, variant: variant)
|
||||
variant_override = create(:variant_override, hub:, variant:)
|
||||
|
||||
spree_post :create, params
|
||||
|
||||
@@ -202,7 +202,7 @@ describe Api::V0::ShipmentsController, type: :controller do
|
||||
}
|
||||
let!(:order_cycle) { create(:order_cycle, distributors: [distributor]) }
|
||||
let!(:order) {
|
||||
create(:completed_order_with_totals, order_cycle: order_cycle, distributor: distributor)
|
||||
create(:completed_order_with_totals, order_cycle:, distributor:)
|
||||
}
|
||||
let(:shipping_fee) { order.reload.shipment.adjustments.first }
|
||||
|
||||
@@ -240,7 +240,7 @@ describe Api::V0::ShipmentsController, type: :controller do
|
||||
}
|
||||
let!(:order_cycle) { create(:order_cycle, distributors: [distributor]) }
|
||||
let!(:order) {
|
||||
create(:completed_order_with_totals, order_cycle: order_cycle, distributor: distributor)
|
||||
create(:completed_order_with_totals, order_cycle:, distributor:)
|
||||
}
|
||||
let(:new_shipping_rate) {
|
||||
order.shipment.shipping_rates.select{ |sr| sr.shipping_method == shipping_method2 }.first
|
||||
@@ -341,7 +341,7 @@ describe Api::V0::ShipmentsController, type: :controller do
|
||||
it 'adds a variant override to the shipment' do
|
||||
hub = create(:distributor_enterprise)
|
||||
order.update_attribute(:distributor, hub)
|
||||
variant_override = create(:variant_override, hub: hub, variant: variant)
|
||||
variant_override = create(:variant_override, hub:, variant:)
|
||||
|
||||
spree_put :add, params
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@ module Api
|
||||
render_views
|
||||
|
||||
let(:taxonomy) { create(:taxonomy) }
|
||||
let(:taxon) { create(:taxon, name: "Ruby", taxonomy: taxonomy) }
|
||||
let(:taxon2) { create(:taxon, name: "Rails", taxonomy: taxonomy) }
|
||||
let(:taxon) { create(:taxon, name: "Ruby", taxonomy:) }
|
||||
let(:taxon2) { create(:taxon, name: "Rails", taxonomy:) }
|
||||
let(:attributes) { [:id, :name] }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { current_api_user }
|
||||
|
||||
taxon2.children << create(:taxon, name: "3.2.2", taxonomy: taxonomy)
|
||||
taxon2.children << create(:taxon, name: "3.2.2", taxonomy:)
|
||||
taxon.children << taxon2
|
||||
taxonomy.root.children << taxon
|
||||
end
|
||||
|
||||
@@ -6,8 +6,8 @@ describe Api::V0::TaxonsController do
|
||||
render_views
|
||||
|
||||
let(:taxonomy) { create(:taxonomy) }
|
||||
let(:taxon) { create(:taxon, name: "Ruby", taxonomy: taxonomy) }
|
||||
let(:taxon2) { create(:taxon, name: "Rails", taxonomy: taxonomy) }
|
||||
let(:taxon) { create(:taxon, name: "Ruby", taxonomy:) }
|
||||
let(:taxon2) { create(:taxon, name: "Rails", taxonomy:) }
|
||||
let(:attributes) {
|
||||
["id", "name", "pretty_name", "permalink", "position", "parent_id", "taxonomy_id"]
|
||||
}
|
||||
@@ -15,7 +15,7 @@ describe Api::V0::TaxonsController do
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { current_api_user }
|
||||
|
||||
taxon2.children << create(:taxon, name: "3.2.2", taxonomy: taxonomy)
|
||||
taxon2.children << create(:taxon, name: "3.2.2", taxonomy:)
|
||||
taxon.children << taxon2
|
||||
taxonomy.root.children << taxon
|
||||
end
|
||||
|
||||
@@ -88,7 +88,7 @@ describe Api::V0::VariantsController, type: :controller do
|
||||
context "as an enterprise user" do
|
||||
let(:current_api_user) { create(:user, enterprises: [supplier]) }
|
||||
let(:supplier_other) { create(:supplier_enterprise) }
|
||||
let!(:product) { create(:product, supplier: supplier) }
|
||||
let!(:product) { create(:product, supplier:) }
|
||||
let(:variant) { product.variants.first }
|
||||
let(:product_other) { create(:product, supplier: supplier_other) }
|
||||
let(:variant_other) { product_other.variants.first }
|
||||
@@ -102,7 +102,7 @@ describe Api::V0::VariantsController, type: :controller do
|
||||
end
|
||||
|
||||
context "with more than one variants" do
|
||||
let(:variant_to_delete) { create(:variant, product: product) }
|
||||
let(:variant_to_delete) { create(:variant, product:) }
|
||||
|
||||
it "deletes a variant" do
|
||||
api_delete :destroy, id: variant_to_delete.id
|
||||
@@ -127,7 +127,7 @@ describe Api::V0::VariantsController, type: :controller do
|
||||
|
||||
let(:product) { create(:product) }
|
||||
let(:variant) { product.variants.first }
|
||||
let!(:variant2) { create(:variant, product: product) }
|
||||
let!(:variant2) { create(:variant, product:) }
|
||||
|
||||
context "deleted variants" do
|
||||
before do
|
||||
|
||||
@@ -31,7 +31,7 @@ describe BaseController, type: :controller do
|
||||
end
|
||||
|
||||
it "uses the last incomplete order" do
|
||||
last_cart = create(:order, user: user, created_by: user, state: "cart", completed_at: nil)
|
||||
last_cart = create(:order, user:, created_by: user, state: "cart", completed_at: nil)
|
||||
allow(controller).to receive(:spree_current_user).and_return(user)
|
||||
|
||||
expect {
|
||||
@@ -46,12 +46,12 @@ describe BaseController, type: :controller do
|
||||
# And we used to override that logic to delete old incomplete orders.
|
||||
# Now we are checking here that none of that is happening.
|
||||
|
||||
last_cart = create(:order, user: user, created_by: user, state: "cart", completed_at: nil)
|
||||
last_cart = create(:order, user:, created_by: user, state: "cart", completed_at: nil)
|
||||
last_cart.line_items << create(:line_item)
|
||||
|
||||
current_cart = create(
|
||||
:order,
|
||||
user: user,
|
||||
user:,
|
||||
created_by: user,
|
||||
state: "cart",
|
||||
completed_at: nil,
|
||||
@@ -69,12 +69,12 @@ describe BaseController, type: :controller do
|
||||
end
|
||||
|
||||
it "doesn't recover old orders after checkout, a new empty one is created" do
|
||||
last_cart = create(:order, user: user, created_by: user, state: "cart", completed_at: nil)
|
||||
last_cart = create(:order, user:, created_by: user, state: "cart", completed_at: nil)
|
||||
last_cart.line_items << create(:line_item)
|
||||
|
||||
just_completed_order = create(
|
||||
:order,
|
||||
user: user,
|
||||
user:,
|
||||
created_by: user,
|
||||
state: "complete",
|
||||
completed_at: Time.zone.now,
|
||||
|
||||
@@ -50,11 +50,11 @@ describe CartController, type: :controller do
|
||||
|
||||
let(:hub) { create(:distributor_enterprise, with_payment_and_shipping: true) }
|
||||
let!(:variant_override_in_the_order) {
|
||||
create(:variant_override, hub: hub, variant: variant_in_the_order, price: 55.55,
|
||||
create(:variant_override, hub:, variant: variant_in_the_order, price: 55.55,
|
||||
count_on_hand: 20, default_stock: nil, resettable: false)
|
||||
}
|
||||
let!(:variant_override_not_in_the_order) {
|
||||
create(:variant_override, hub: hub, variant: variant_not_in_the_order, count_on_hand: 7,
|
||||
create(:variant_override, hub:, variant: variant_not_in_the_order, count_on_hand: 7,
|
||||
default_stock: nil, resettable: false)
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ describe CartController, type: :controller do
|
||||
}
|
||||
let!(:order) { subject.current_order(true) }
|
||||
let!(:line_item) {
|
||||
create(:line_item, order: order, variant: variant_in_the_order, quantity: 2, max_quantity: 3)
|
||||
create(:line_item, order:, variant: variant_in_the_order, quantity: 2, max_quantity: 3)
|
||||
}
|
||||
|
||||
before do
|
||||
|
||||
@@ -59,7 +59,7 @@ describe EnterprisesController, type: :controller do
|
||||
orders_close_at: 4.days.from_now)
|
||||
}
|
||||
let!(:oc3_exchange) { order_cycle3.exchanges.outgoing.to_enterprise(distributor).first }
|
||||
let(:customer) { create(:customer, user: user, enterprise: distributor) }
|
||||
let(:customer) { create(:customer, user:, enterprise: distributor) }
|
||||
|
||||
it "shows order cycles allowed by the rules" do
|
||||
create(:filter_order_cycles_tag_rule,
|
||||
@@ -114,7 +114,7 @@ describe EnterprisesController, type: :controller do
|
||||
|
||||
describe "when an out of stock item is in the cart" do
|
||||
let(:variant) { create(:variant, on_demand: false, on_hand: 10) }
|
||||
let(:line_item) { create(:line_item, variant: variant) }
|
||||
let(:line_item) { create(:line_item, variant:) }
|
||||
let(:order_cycle) {
|
||||
create(:simple_order_cycle, distributors: [current_distributor], variants: [variant])
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ describe LineItemsController, type: :controller do
|
||||
|
||||
context "listing bought items" do
|
||||
let!(:completed_order) do
|
||||
order = create(:completed_order_with_totals, user: user, distributor: distributor,
|
||||
order_cycle: order_cycle, line_items_count: 1)
|
||||
order = create(:completed_order_with_totals, user:, distributor:,
|
||||
order_cycle:, line_items_count: 1)
|
||||
break unless order.next! while !order.completed?
|
||||
order
|
||||
end
|
||||
@@ -34,7 +34,7 @@ describe LineItemsController, type: :controller do
|
||||
context "on a completed order" do
|
||||
let(:item) do
|
||||
order = create(:completed_order_with_totals)
|
||||
item = create(:line_item, order: order)
|
||||
item = create(:line_item, order:)
|
||||
break unless order.next! while !order.completed?
|
||||
item
|
||||
end
|
||||
@@ -52,7 +52,7 @@ describe LineItemsController, type: :controller do
|
||||
|
||||
context "where the item's order is not associated with the user" do
|
||||
it "denies deletion" do
|
||||
delete :destroy, params: params
|
||||
delete(:destroy, params:)
|
||||
expect(response.status).to eq 403
|
||||
end
|
||||
end
|
||||
@@ -65,7 +65,7 @@ describe LineItemsController, type: :controller do
|
||||
|
||||
context "without an order cycle or distributor" do
|
||||
it "denies deletion" do
|
||||
delete :destroy, params: params
|
||||
delete(:destroy, params:)
|
||||
expect(response.status).to eq 403
|
||||
end
|
||||
end
|
||||
@@ -75,7 +75,7 @@ describe LineItemsController, type: :controller do
|
||||
|
||||
context "where changes are not allowed" do
|
||||
it "denies deletion" do
|
||||
delete :destroy, params: params
|
||||
delete(:destroy, params:)
|
||||
expect(response.status).to eq 403
|
||||
end
|
||||
end
|
||||
@@ -84,20 +84,20 @@ describe LineItemsController, type: :controller do
|
||||
before { distributor.update!(allow_order_changes: true) }
|
||||
|
||||
it "deletes the line item" do
|
||||
delete :destroy, params: params
|
||||
delete(:destroy, params:)
|
||||
expect(response.status).to eq 204
|
||||
expect { item.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
context "after a payment is captured" do
|
||||
let(:payment) {
|
||||
create(:check_payment, :completed, amount: order.total, order: order)
|
||||
create(:check_payment, :completed, amount: order.total, order:)
|
||||
}
|
||||
before { payment.capture! }
|
||||
|
||||
it 'updates the payment state' do
|
||||
expect(order.payment_state).to eq 'paid'
|
||||
delete :destroy, params: params
|
||||
delete(:destroy, params:)
|
||||
order.reload
|
||||
expect(order.payment_state).to eq 'credit_owed'
|
||||
end
|
||||
@@ -114,7 +114,7 @@ describe LineItemsController, type: :controller do
|
||||
create(:tax_rate, included_in_price: true,
|
||||
calculator: Calculator::DefaultTax.new,
|
||||
amount: 0.25,
|
||||
zone: zone)
|
||||
zone:)
|
||||
end
|
||||
let(:shipping_tax_category) { create(:tax_category, tax_rates: [shipping_tax_rate]) }
|
||||
let(:shipping_fee) { 3 }
|
||||
@@ -122,8 +122,8 @@ describe LineItemsController, type: :controller do
|
||||
let(:distributor_with_taxes) { create(:distributor_enterprise_with_tax) }
|
||||
let(:order) {
|
||||
create(:completed_order_with_fees, distributor: distributor_with_taxes,
|
||||
shipping_fee: shipping_fee, payment_fee: payment_fee,
|
||||
shipping_tax_category: shipping_tax_category)
|
||||
shipping_fee:, payment_fee:,
|
||||
shipping_tax_category:)
|
||||
}
|
||||
|
||||
before do
|
||||
@@ -166,15 +166,15 @@ describe LineItemsController, type: :controller do
|
||||
Calculator::PriceSack.new(preferred_minimal_amount: 15, preferred_normal_amount: 22,
|
||||
preferred_discount_amount: 11)
|
||||
}
|
||||
let(:enterprise_fee) { create(:enterprise_fee, calculator: calculator) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee, calculator:) }
|
||||
let!(:exchange) {
|
||||
create(:exchange, incoming: true, sender: variant1.product.supplier,
|
||||
receiver: order_cycle.coordinator, variants: [variant1, variant2],
|
||||
enterprise_fees: [enterprise_fee])
|
||||
}
|
||||
let!(:order) do
|
||||
order = create(:completed_order_with_totals, user: user, distributor: distributor,
|
||||
order_cycle: order_cycle, line_items_count: 2)
|
||||
order = create(:completed_order_with_totals, user:, distributor:,
|
||||
order_cycle:, line_items_count: 2)
|
||||
order.reload.line_items.first.update(variant_id: variant1.id)
|
||||
order.line_items.last.update(variant_id: variant2.id)
|
||||
break unless order.next! while !order.completed?
|
||||
@@ -187,7 +187,7 @@ describe LineItemsController, type: :controller do
|
||||
expect(order.reload.adjustment_total).to eq calculator.preferred_discount_amount
|
||||
|
||||
allow(controller).to receive_messages spree_current_user: user
|
||||
delete :destroy, params: params
|
||||
delete(:destroy, params:)
|
||||
expect(response.status).to eq 204
|
||||
|
||||
expect(order.reload.adjustment_total).to eq calculator.preferred_normal_amount
|
||||
|
||||
Reference in New Issue
Block a user