Merge pull request #3569 from luisramos0/delete-more-overrides

Delete some more dead overrides and more dead code
This commit is contained in:
Pau Pérez Fabregat
2019-03-12 17:48:12 +01:00
committed by GitHub
26 changed files with 19 additions and 641 deletions

View File

@@ -1864,17 +1864,9 @@ Style/HashSyntax:
- 'app/models/spree/product_decorator.rb'
- 'app/models/spree/taxon_decorator.rb'
- 'app/models/spree/user_decorator.rb'
- 'app/overrides/add_distributor_details_js_to_product.rb'
- 'app/overrides/add_distributor_details_to_product.rb'
- 'app/overrides/add_distributor_to_add_to_cart_form.rb'
- 'app/overrides/add_enterprise_fees_to_admin_configurations_menu.rb'
- 'app/overrides/add_source_to_product.rb'
- 'app/overrides/remove_search_bar.rb'
- 'app/overrides/remove_side_bar.rb'
- 'app/overrides/replace_checkout_payment_button.rb'
- 'app/overrides/replace_order_details_steps_data.rb'
- 'app/overrides/replace_payment_name_with_description.rb'
- 'app/overrides/replace_shipping_address_form_with_distributor_details.rb'
- 'app/overrides/set_auth_token_in_backend.rb'
- 'app/overrides/set_auth_token_in_frontend.rb'
- 'app/presenters/variant_presenter.rb'

View File

@@ -1,21 +0,0 @@
module AddToCartHelper
def product_out_of_stock
!@product.has_stock? && !Spree::Config[:allow_backorders]
end
def distributor_available_for?(order, product)
DistributionChangeValidator.new(order).distributor_available_for?(product)
end
def order_cycle_available_for?(order, product)
DistributionChangeValidator.new(order).order_cycle_available_for?(product)
end
def available_distributors_for(order, product)
DistributionChangeValidator.new(order).available_distributors_for(product)
end
def available_order_cycles_for(order, product)
DistributionChangeValidator.new(order).available_order_cycles_for(product)
end
end

View File

@@ -5,10 +5,6 @@ module Spree
order.nil? || order.line_items.empty?
end
def alternative_available_distributors(order)
DistributionChangeValidator.new(order).available_distributors(Enterprise.all) - [order.distributor]
end
def last_completed_order
spree_current_user.orders.complete.last
end

View File

@@ -39,13 +39,6 @@ class OrderCycle < ActiveRecord::Base
scope :by_name, order('name')
scope :distributing_product, lambda { |product|
joins(:exchanges).
merge(Exchange.outgoing).
merge(Exchange.with_product(product)).
select('DISTINCT order_cycles.*')
}
scope :with_distributor, lambda { |distributor|
joins(:exchanges).merge(Exchange.outgoing).merge(Exchange.to_enterprise(distributor))
}
@@ -156,7 +149,6 @@ class OrderCycle < ActiveRecord::Base
end
def distributed_variants
# TODO: only used in DistributionChangeValidator, can we remove?
self.exchanges.outgoing.map(&:variants).flatten.uniq.reject(&:deleted?)
end

View File

@@ -1,5 +0,0 @@
Deface::Override.new(:virtual_path => "spree/shared/_order_details",
:replace => "div.row.steps-data",
:partial => "spree/shared/order_details_steps_data",
:name => "replace_order_details_steps_data",
:original => '1a68aa5db3fee7f7bbb2b6b826749aeb69168cee')

View File

@@ -1,5 +0,0 @@
Deface::Override.new(:virtual_path => "spree/payments/_payment",
:replace => "code[erb-loud]:contains('content_tag(:span, payment.payment_method.name)')",
:text => "<%= content_tag( :span, ( payment.payment_method.description || payment.payment_method.name ).html_safe ) %>",
:name => "replace_payment_name_with_description",
:original => 'dff62efcadc0f9e6513b0f81a51ebbda035f78f6')

View File

@@ -13,12 +13,6 @@ class CartService
def populate(from_hash, overwrite = false)
@distributor, @order_cycle = distributor_and_order_cycle
# Refactor: We may not need this validation - we can't change distribution here, so
# this validation probably can't fail
if !distribution_can_supply_products_in_cart(@distributor, @order_cycle)
errors.add(:base, I18n.t(:spree_order_populator_error))
return false
end
@order.with_lock do
variants = read_variants from_hash
@@ -116,10 +110,6 @@ class CartService
[@order.distributor, @order.order_cycle]
end
def distribution_can_supply_products_in_cart(distributor, order_cycle)
DistributionChangeValidator.new(@order).can_change_to_distribution?(distributor, order_cycle)
end
def varies_from_cart(variant_data)
li = line_item_for_variant_id variant_data[:variant_id]

View File

@@ -25,10 +25,6 @@
%tfoot#edit-cart
= render 'spree/orders/form/cart_actions_row' if @order.cart?
/ This is the fees row which we want to replace with the pop-over
-# - unless @order.adjustments.eligible.blank?
-# = render "spree/orders/adjustments"
%tr
%td.text-right{colspan:"3"}
= t :orders_form_subtotal

View File

@@ -1,12 +1,4 @@
%tr.line-item{class: "variant-#{variant.id}"}
/ removed image thumbnail on shopping cart & checkout to simplify
/ %td.cart-item-image{"data-hook" => "cart_item_image"}
/ - if variant.images.length == 0
/ = link_to small_image(variant.product), variant.product
/ - else
/ = link_to image_tag(variant.images.first.attachment.url(:small)), variant.product
%td.cart-item-description{'data-hook' => "cart_item_description"}
%div.item-thumb-image{"data-hook" => "cart_item_image"}
@@ -24,11 +16,6 @@
%td.text-right.cart-item-price{"data-hook" => "cart_item_price"}
= line_item.single_display_amount_with_adjustments.to_html
-# Now in a template in app/assets/javascripts/templates !
-# %price-breakdown{"price-breakdown" => "_", variant: "variant",
-# "price-breakdown-append-to-body" => "true",
-# "price-breakdown-placement" => "left",
-# "price-breakdown-animation" => true}
%td.text-center.cart-item-quantity{"data-hook" => "cart_item_quantity"}
= item_form.number_field :quantity, :min => 0, "ofn-on-hand" => variant.on_hand, "ng-model" => "line_item_#{line_item.id}", :class => "line_item_quantity", :size => 5
%td.cart-item-total.text-right{"data-hook" => "cart_item_total"}

View File

@@ -1,18 +0,0 @@
.add-to-cart
- order = current_order(false)
- if product_out_of_stock
= content_tag('strong', t(:out_of_stock))
- elsif !distributor_available_for?(order, @product)
= render 'add_to_cart_distributor_unavailable'
- elsif !order_cycle_available_for?(order, @product)
= render 'add_to_cart_order_cycle_unavailable'
- else
= render 'add_to_cart_quantity_fields', product: @product
%br
= button_tag :class => 'large primary', :id => 'add-to-cart-button', :type => :submit do
= t(:add_to_cart)

View File

@@ -1,3 +0,0 @@
.distributor
= t :products_cart_distributor_choice
= select_tag "distributor_id", options_from_collection_for_select([Enterprise.new]+distributor_collection, "id", "name", current_distributor.andand.id)

View File

@@ -1,7 +0,0 @@
= hidden_field_tag "distributor_id", distributor.id
.distributor-fixed
- if changing_distributor
= t :products_cart_distributor_change, name: distributor.name
- else
= t :products_cart_distributor_is, name: distributor.name

View File

@@ -1,2 +0,0 @@
.error-distributor
= t :products_distributor_error, link: link_to(current_distributor.name, root_path)

View File

@@ -1,3 +0,0 @@
%div
= t :products_oc
= select_tag "order_cycle_id", options_from_collection_for_select([OrderCycle.new(name: t(:none))]+order_cycle_collection, "id", "name", current_order_cycle.andand.id)

View File

@@ -1,7 +0,0 @@
= hidden_field_tag "order_cycle_id", order_cycle.id
.order-cycle-fixed
- if changing_order_cycle
= t :products_oc_change, name: order_cycle.name
- else
= t :products_oc_is, name: order_cycle.name

View File

@@ -1,2 +0,0 @@
.error-distributor
= t :products_oc_error, link: = link_to((current_order_cycle.andand.name || t(:products_oc_current)), root_path)

View File

@@ -1,9 +0,0 @@
%div(class = "columns alpha two")
%div
= t :products_quantity
= number_field_tag (product.has_variants? ? :quantity : "variants[#{product.master.id}]"), 1, :class => 'title', :in => 1..product.on_hand
- if product.group_buy
%div(class = "columns alpha three")
%div
= t :products_max_quantity
= number_field_tag (product.has_variants? ? :max_quantity : "variant_attributes[#{product.master.id}][max_quantity]"), 1, :class => 'title max_quantity', :in => 1..product.on_hand

View File

@@ -1,9 +0,0 @@
%fieldset#product-distributor-details.columns.five.omega
%legend
= t :products_distributor
.distributor-details
- order = current_order(false)
- if order.andand.distributor.present?
= render 'enterprises/distributor_details', :distributor => order.distributor
- else
= t :products_distributor_info

View File

@@ -1,29 +0,0 @@
%div{:data-hook => "product_source"}
%h6.product-section-title= t(:supplier)
%table#product-source.table-display{:width => "100%"}
%tbody
- if @product.supplier
%tr.odd
%td= link_to @product.supplier.name, [main_app, @product.supplier]
- if false
%br/
%h6.product-section-title= t(:distributors)
%table#product-source.table-display{:width => "100%"}
%tbody
- order = current_order(false)
- validator = DistributionChangeValidator.new(order)
- Enterprise.distributing_products(@product).each do |distributor|
- if !order.nil? && distributor == order.distributor
%tr.odd
%td
%b= link_to(distributor.name, [main_app, distributor])
%td
%b= t(:current)
- elsif order.nil? || validator.can_change_to_distributor?(distributor)
%tr.even
%td= link_to distributor.name, [main_app, distributor]
%td= t(:available)
- else
%tr.even
%td= link_to distributor.name, [main_app, distributor]
%td

View File

@@ -1,48 +0,0 @@
<div class="row steps-data">
<% if order.has_step?("address") %>
<div class="columns alpha six">
<h6><%= "Customer Details" %> <%= link_to "(#{t(:edit)})", checkout_state_path(:address) unless @order.completed? %></h6>
<div class="address">
<%= "#{t(:name)}: #{order.bill_address.full_name}" %><br />
<%= "#{t(:address)}: #{order.bill_address.address1}, #{order.bill_address.city}" %>
</div>
<br/>
<div class="row steps-data">
<% order.payments.each do |payment| %>
<div <% if payment.payment_method.name.include? "EFT" %>id="eft-payment-alert"<% end %>>
<h6><%= t(:payment_information) %> <%= link_to "(#{t(:edit)})", checkout_state_path(:payment) unless @order.completed? %></h6>
<div class="payment-info">
<% if payment.payment_method.name.include? "PayPal" %>
<div class="flash notice"><% t(:order_payment_paypal_successful) %></div>
<% elsif payment.payment_method.name.include? "EFT" %>
<span><%= payment.payment_method.description.html_safe %></span>
<% elsif order.credit_cards.empty? == false %>
<span class="cc-type">
<%= image_tag "credit_cards/icons/#{order.credit_cards.first.cc_type}.png" %>
<%= t(:ending_in)%> <%= order.credit_cards.first.last_digits %>
</span>
<br />
<span class="full-name">
<%= order.credit_cards.first.first_name %>
<%= order.credit_cards.first.last_name %>
</span>
<% elsif payment.payment_method.type == "Spree::PaymentMethod::Check" %>
<span><%= payment.payment_method.description %></span>
<% end %>
</div>
</div>
<% end %>
</div>
</div>
<div class="columns alpha six">
<h6><% t(:order_hub_info) %></h6>
<div class="address">
<%= render 'enterprises/distributor_details', :distributor => order.distributor %>
</div>
</div>
<% end %>
</div>

View File

@@ -4,67 +4,16 @@ class DistributionChangeValidator
@order = order
end
def can_change_to_distributor?(distributor)
# Distributor may not be changed once an item has been added to the cart/order, unless all items are available from the specified distributor
@order.line_items.empty? || all_available_distributors.include?(distributor)
end
def can_change_to_distribution?(distributor, order_cycle)
(@order.line_item_variants - variants_available_for_distribution(distributor, order_cycle)).empty?
end
def variants_available_for_distribution(distributor, order_cycle)
product_distribution_variants = distributor.andand.product_distribution_variants || []
order_cycle_variants = order_cycle.andand.variants_distributed_by(distributor) || []
product_distribution_variants = []
product_distribution_variants = distributor.product_distribution_variants if distributor
order_cycle_variants = []
order_cycle_variants = order_cycle.variants_distributed_by(distributor) if order_cycle
product_distribution_variants + order_cycle_variants
end
def distributor_available_for?(product)
@order.nil? || available_distributors_for(product).present?
end
def order_cycle_available_for?(product)
@order.nil? || !product_requires_order_cycle(product) || available_order_cycles_for(product).present?
end
def available_distributors_for(product)
distributors = Enterprise.distributing_products(product)
if @order.andand.line_items.present?
distributors = available_distributors(distributors)
end
distributors
end
def available_order_cycles_for(product)
order_cycles = OrderCycle.distributing_product(product)
if @order.andand.line_items.present?
order_cycles = available_order_cycles(order_cycles)
end
order_cycles
end
def product_requires_order_cycle(product)
product.product_distributions.blank?
end
def all_available_distributors
@all_available_distributors ||= (available_distributors(Enterprise.all) || [])
end
def available_distributors enterprises
enterprises.select do |e|
(@order.line_item_variants - e.distributed_variants).empty?
end
end
def available_order_cycles order_cycles
order_cycles.select do |oc|
(@order.line_item_variants - oc.distributed_variants).empty?
end
end
end

View File

@@ -13,252 +13,45 @@ describe DistributionChangeValidator do
order.should_receive(:line_item_variants) { [1] }
subject.should_receive(:variants_available_for_distribution).
with(distributor, order_cycle) { [] }
subject.can_change_to_distribution?(distributor, order_cycle).should be false
expect(subject.can_change_to_distribution?(distributor, order_cycle)).to be false
end
it "returns true when all variants are available for the specified distribution" do
order.should_receive(:line_item_variants) { [1] }
subject.should_receive(:variants_available_for_distribution).
with(distributor, order_cycle) { [1] }
subject.can_change_to_distribution?(distributor, order_cycle).should be true
expect(subject.can_change_to_distribution?(distributor, order_cycle)).to be true
end
end
describe "finding variants that are available through a particular distribution" do
it "finds variants distributed by product distribution" do
v = double(:variant)
d = double(:distributor, product_distribution_variants: [v])
oc = double(:order_cycle, variants_distributed_by: [])
variant = double(:variant)
distributor = double(:distributor, product_distribution_variants: [variant])
order_cycle = double(:order_cycle, variants_distributed_by: [])
subject.variants_available_for_distribution(d, oc).should == [v]
expect(subject.variants_available_for_distribution(distributor, order_cycle)).to eq [variant]
end
it "finds variants distributed by product distribution when order cycle is nil" do
v = double(:variant)
d = double(:distributor, product_distribution_variants: [v])
variant = double(:variant)
distributor = double(:distributor, product_distribution_variants: [variant])
subject.variants_available_for_distribution(d, nil).should == [v]
expect(subject.variants_available_for_distribution(distributor, nil)).to eq [variant]
end
it "finds variants distributed by order cycle" do
v = double(:variant)
d = double(:distributor, product_distribution_variants: [])
oc = double(:order_cycle)
variant = double(:variant)
distributor = double(:distributor, product_distribution_variants: [])
order_cycle = double(:order_cycle)
oc.should_receive(:variants_distributed_by).with(d) { [v] }
order_cycle.should_receive(:variants_distributed_by).with(distributor) { [variant] }
subject.variants_available_for_distribution(d, oc).should == [v]
expect(subject.variants_available_for_distribution(distributor, order_cycle)).to eq [variant]
end
it "returns an empty array when distributor and order cycle are both nil" do
subject.variants_available_for_distribution(nil, nil).should == []
end
end
describe "finding distributors which have the same variants" do
let(:variant1) { double(:variant) }
let(:variant2) { double(:variant) }
let(:variant3) { double(:variant) }
let(:variant4) { double(:variant) }
let(:variant5) { double(:variant) }
it "matches enterprises which offer all products within the order" do
line_item_variants = [variant1, variant3, variant5]
order.stub(:line_item_variants) { line_item_variants }
enterprise = double(:enterprise)
enterprise.stub(:distributed_variants) { line_item_variants } # Exactly the same variants as the order
subject.available_distributors([enterprise]).should == [enterprise]
end
it "does not match enterprises with no products available" do
line_item_variants = [variant1, variant3, variant5]
order.stub(:line_item_variants) { line_item_variants }
enterprise = double(:enterprise)
enterprise.stub(:distributed_variants) { [] } # No variants
subject.available_distributors([enterprise]).should_not include enterprise
end
it "does not match enterprises with only some of the same variants in the order available" do
line_item_variants = [variant1, variant3, variant5]
order.stub(:line_item_variants) { line_item_variants }
enterprise_with_some_variants = double(:enterprise)
enterprise_with_some_variants.stub(:distributed_variants) { [variant1, variant3] } # Only some variants
enterprise_with_some_plus_extras = double(:enterprise)
enterprise_with_some_plus_extras.stub(:distributed_variants) { [variant1, variant2, variant3, variant4] } # Only some variants, plus extras
subject.available_distributors([enterprise_with_some_variants]).should_not include enterprise_with_some_variants
subject.available_distributors([enterprise_with_some_plus_extras]).should_not include enterprise_with_some_plus_extras
end
it "matches enterprises which offer all products in the order, plus additional products" do
line_item_variants = [variant1, variant3, variant5]
order.stub(:line_item_variants) { line_item_variants }
enterprise = double(:enterprise)
enterprise.stub(:distributed_variants) { [variant1, variant2, variant3, variant4, variant5] } # Excess variants
subject.available_distributors([enterprise]).should == [enterprise]
end
it "matches no enterprises when none are provided" do
subject.available_distributors([]).should == []
end
end
describe "finding order cycles which have the same variants" do
let(:variant1) { double(:variant) }
let(:variant2) { double(:variant) }
let(:variant3) { double(:variant) }
let(:variant4) { double(:variant) }
let(:variant5) { double(:variant) }
it "matches order cycles which offer all products within the order" do
line_item_variants = [variant1, variant3, variant5]
order.stub(:line_item_variants) { line_item_variants }
order_cycle = double(:order_cycle)
order_cycle.stub(:distributed_variants) { line_item_variants } # Exactly the same variants as the order
subject.available_order_cycles([order_cycle]).should == [order_cycle]
end
it "does not match order cycles with no products available" do
line_item_variants = [variant1, variant3, variant5]
order.stub(:line_item_variants) { line_item_variants }
order_cycle = double(:order_cycle)
order_cycle.stub(:distributed_variants) { [] } # No variants
subject.available_order_cycles([order_cycle]).should_not include order_cycle
end
it "does not match order cycles with only some of the same variants in the order available" do
line_item_variants = [variant1, variant3, variant5]
order.stub(:line_item_variants) { line_item_variants }
order_cycle_with_some_variants = double(:order_cycle)
order_cycle_with_some_variants.stub(:distributed_variants) { [variant1, variant3] } # Only some variants
order_cycle_with_some_plus_extras = double(:order_cycle)
order_cycle_with_some_plus_extras.stub(:distributed_variants) { [variant1, variant2, variant3, variant4] } # Only some variants, plus extras
subject.available_order_cycles([order_cycle_with_some_variants]).should_not include order_cycle_with_some_variants
subject.available_order_cycles([order_cycle_with_some_plus_extras]).should_not include order_cycle_with_some_plus_extras
end
it "matches order cycles which offer all products in the order, plus additional products" do
line_item_variants = [variant1, variant3, variant5]
order.stub(:line_item_variants) { line_item_variants }
order_cycle = double(:order_cycle)
order_cycle.stub(:distributed_variants) { [variant1, variant2, variant3, variant4, variant5] } # Excess variants
subject.available_order_cycles([order_cycle]).should == [order_cycle]
end
it "matches no order cycles when none are provided" do
subject.available_order_cycles([]).should == []
end
end
describe "checking if a distributor is available for a product" do
it "returns true when order is nil" do
subject = DistributionChangeValidator.new(nil)
subject.distributor_available_for?(product).should be true
end
it "returns true when there's an distributor that can cover the new product" do
subject.stub(:available_distributors_for).and_return([1])
subject.distributor_available_for?(product).should be true
end
it "returns false when there's no distributor that can cover the new product" do
subject.stub(:available_distributors_for).and_return([])
subject.distributor_available_for?(product).should be false
end
end
describe "checking if an order cycle is available for a product" do
it "returns true when the order is nil" do
subject = DistributionChangeValidator.new(nil)
subject.order_cycle_available_for?(product).should be true
end
it "returns true when the product doesn't require an order cycle" do
subject.stub(:product_requires_order_cycle).and_return(false)
subject.order_cycle_available_for?(product).should be true
end
it "returns true when there's an order cycle that can cover the product" do
subject.stub(:product_requires_order_cycle).and_return(true)
subject.stub(:available_order_cycles_for).and_return([1])
subject.order_cycle_available_for?(product).should be true
end
it "returns false otherwise" do
subject.stub(:product_requires_order_cycle).and_return(true)
subject.stub(:available_order_cycles_for).and_return([])
subject.order_cycle_available_for?(product).should be false
end
end
describe "finding available distributors for a product" do
it "returns enterprises distributing the product when there's no order" do
subject = DistributionChangeValidator.new(nil)
Enterprise.stub(:distributing_products).and_return([1, 2, 3])
subject.should_receive(:available_distributors).never
subject.available_distributors_for(product).should == [1, 2, 3]
end
it "returns enterprises distributing the product when there's no order items" do
order.stub(:line_items) { [] }
Enterprise.stub(:distributing_products).and_return([1, 2, 3])
subject.should_receive(:available_distributors).never
subject.available_distributors_for(product).should == [1, 2, 3]
end
it "filters by available distributors when there are order items" do
order.stub(:line_items) { [1, 2, 3] }
Enterprise.stub(:distributing_products).and_return([1, 2, 3])
subject.should_receive(:available_distributors).and_return([2])
subject.available_distributors_for(product).should == [2]
end
end
describe "finding available order cycles for a product" do
it "returns order cycles distributing the product when there's no order" do
subject = DistributionChangeValidator.new(nil)
OrderCycle.stub(:distributing_product).and_return([1, 2, 3])
subject.should_receive(:available_order_cycles).never
subject.available_order_cycles_for(product).should == [1, 2, 3]
end
it "returns order cycles distributing the product when there's no order items" do
order.stub(:line_items) { [] }
OrderCycle.stub(:distributing_product).and_return([1, 2, 3])
subject.should_receive(:available_order_cycles).never
subject.available_order_cycles_for(product).should == [1, 2, 3]
end
it "filters by available order cycles when there are order items" do
order.stub(:line_items) { [1, 2, 3] }
OrderCycle.stub(:distributing_product).and_return([1, 2, 3])
subject.should_receive(:available_order_cycles).and_return([2])
subject.available_order_cycles_for(product).should == [2]
end
end
describe "determining if a product requires an order cycle" do
it "returns true when the product does not have any product distributions" do
product.stub(:product_distributions).and_return([])
subject.product_requires_order_cycle(product).should be true
end
it "returns false otherwise" do
product.stub(:product_distributions).and_return([1])
subject.product_requires_order_cycle(product).should be false
expect(subject.variants_available_for_distribution(nil, nil)).to eq []
end
end
end

View File

@@ -81,38 +81,6 @@ describe OrderCycle do
OrderCycle.accessible_by(user).should_not include(oc_not_accessible)
end
describe "finding order cycles distributing a product" do
it "returns order cycles distributing the product's master variant" do
p = create(:product)
d = create(:distributor_enterprise)
oc = create(:simple_order_cycle, distributors: [d], variants: [p.master])
p.reload
OrderCycle.distributing_product(p).should == [oc]
end
it "returns order cycles distributing another variant" do
p = create(:product)
v = create(:variant, product: p)
d = create(:distributor_enterprise)
oc = create(:simple_order_cycle, distributors: [d], variants: [v])
p.reload
OrderCycle.distributing_product(p).should == [oc]
end
it "does not return order cycles supplying but not distributing a product" do
p = create(:product)
s = create(:supplier_enterprise)
oc = create(:simple_order_cycle)
ex = create(:exchange, order_cycle: oc, sender: s, receiver: oc.coordinator, incoming: true)
ex.variants << p.master
p.reload
OrderCycle.distributing_product(p).should == []
end
end
it "finds the most recently closed order cycles" do
oc1 = create(:simple_order_cycle, orders_close_at: 2.hours.ago)
oc2 = create(:simple_order_cycle, orders_close_at: 1.hour.ago)

View File

@@ -23,47 +23,6 @@ describe ProductDistribution do
describe "adjusting orders" do
context "integration" do
let(:distributor) { create(:distributor_enterprise) }
let(:product) { create(:product, name: 'Pear') }
let(:enterprise_fee) { create(:enterprise_fee, calculator: build(:calculator), enterprise: distributor) }
let!(:product_distribution) { create(:product_distribution, product: product, distributor: distributor, enterprise_fee: enterprise_fee) }
let(:order) { create(:order, distributor: distributor) }
it "creates an adjustment for product distributions" do
enterprise_fee.calculator.preferred_amount = 1.23
enterprise_fee.calculator.save!
# When I add the product to the order, an adjustment should be made
expect do
cart_service = CartService.new order
cart_service.populate products: {product.id => product.master.id}, quantity: 1, distributor_id: distributor.id
# Normally the controller would fire this event when the order's contents are changed
fire_order_contents_changed_event(order.user, order)
end.to change(Spree::Adjustment, :count).by(1)
# And it should have the correct data
order.reload
adjustments = order.adjustments.where(:originator_type => 'EnterpriseFee')
expect(adjustments.count).to eq 1
adjustment = adjustments.first
expect(adjustment.source).to eq order.line_items.last
expect(adjustment.originator).to eq enterprise_fee
expect(adjustment.label).to eq "Product distribution by #{distributor.name} for Pear"
expect(adjustment.amount).to eq 1.23
# TODO ROB this has an intermittent failure
# And it should have some associated metadata
md = adjustment.metadata
expect(md.enterprise).to eq distributor
expect(md.fee_name).to eq enterprise_fee.name
expect(md.fee_type).to eq enterprise_fee.fee_type
expect(md.enterprise_role).to eq 'distributor'
end
end
describe "finding our adjustment for a line item" do
it "returns nil when not present" do
line_item = build(:line_item)

View File

@@ -458,42 +458,6 @@ describe Spree::Order do
end
end
context "validating distributor changes" do
it "checks that a distributor is available when changing" do
set_feature_toggle :order_cycles, false
order_enterprise = FactoryBot.create(:enterprise, id: 1, :name => "Order Enterprise")
subject.distributor = order_enterprise
product1 = FactoryBot.create(:product)
product2 = FactoryBot.create(:product)
product3 = FactoryBot.create(:product)
variant11 = FactoryBot.create(:variant, product: product1)
variant12 = FactoryBot.create(:variant, product: product1)
variant21 = FactoryBot.create(:variant, product: product2)
variant31 = FactoryBot.create(:variant, product: product3)
variant32 = FactoryBot.create(:variant, product: product3)
# Product Distributions
# Order Enterprise sells product 1 and product 3
FactoryBot.create(:product_distribution, product: product1, distributor: order_enterprise)
FactoryBot.create(:product_distribution, product: product3, distributor: order_enterprise)
# Build the current order
line_item1 = FactoryBot.create(:line_item, order: subject, variant: variant11)
line_item2 = FactoryBot.create(:line_item, order: subject, variant: variant12)
line_item3 = FactoryBot.create(:line_item, order: subject, variant: variant31)
subject.reload
subject.line_items = [line_item1,line_item2,line_item3]
test_enterprise = FactoryBot.create(:enterprise, id: 2, :name => "Test Enterprise")
# Test Enterprise sells only product 1
FactoryBot.create(:product_distribution, product: product1, distributor: test_enterprise)
subject.distributor = test_enterprise
subject.should_not be_valid
subject.errors.messages.should == {:base => ["Distributor or order cycle cannot supply the products in your cart"]}
end
end
describe "scopes" do
describe "not_state" do
before do

View File

@@ -51,37 +51,6 @@ describe CartService do
end
end
describe "populate" do
before do
expect(cart_service).to receive(:distributor_and_order_cycle).
and_return([distributor, order_cycle])
end
it "checks that distribution can supply all products in the cart" do
expect(cart_service).to receive(:distribution_can_supply_products_in_cart).
with(distributor, order_cycle).and_return(false)
expect(cart_service.populate(params)).to be false
expect(cart_service.errors.to_a).to eq(["That distributor or order cycle can't supply all the products in your cart. Please choose another."])
end
it "locks the order" do
allow(cart_service).to receive(:distribution_can_supply_products_in_cart).and_return(true)
expect(order).to receive(:with_lock)
cart_service.populate(params, true)
end
it "attempts cart add with max_quantity" do
allow(cart_service).to receive(:distribution_can_supply_products_in_cart).and_return true
params = { variants: { "1" => { quantity: 1, max_quantity: 2 } } }
allow(order).to receive(:with_lock).and_yield
allow(cart_service).to receive(:varies_from_cart) { true }
allow(cart_service).to receive(:variants_removed) { [] }
expect(cart_service).to receive(:attempt_cart_add).with("1", 1, 2).and_return true
cart_service.populate(params, true)
end
end
describe "varies_from_cart" do
let(:variant) { double(:variant, id: 123) }
@@ -236,15 +205,6 @@ describe CartService do
end
describe "validations" do
describe "determining if distributor can supply products in cart" do
it "delegates to DistributionChangeValidator" do
dcv = double(:dcv)
expect(dcv).to receive(:can_change_to_distribution?).with(distributor, order_cycle).and_return(true)
expect(DistributionChangeValidator).to receive(:new).with(order).and_return(dcv)
expect(cart_service.send(:distribution_can_supply_products_in_cart, distributor, order_cycle)).to be true
end
end
describe "checking order cycle is provided for a variant, OR is not needed" do
let(:variant) { double(:variant) }