Auto-correct rubocop offences for standing-orders

This commit is contained in:
Rob Harrington
2017-11-17 13:38:38 +11:00
parent 26a325e6e0
commit 03f1980b1b
34 changed files with 192 additions and 185 deletions

View File

@@ -87,7 +87,7 @@ module Admin
end
else
respond_to do |format|
format.json { render :json => {:success => false} }
format.json { render :json => {:success => false} }
end
end
end

View File

@@ -28,6 +28,7 @@ module Admin
end
private
def collection
return Schedule.where("1=0") unless json_request?
permissions.visible_schedules

View File

@@ -80,7 +80,7 @@ module Admin
def collection
if request.format.json?
permissions.editable_standing_orders.ransack(params[:q]).result
.preload([:shop,:customer,:schedule,:standing_line_items,:ship_address,:bill_address,proxy_orders: {order: :order_cycle}])
.preload([:shop, :customer, :schedule, :standing_line_items, :ship_address, :bill_address, proxy_orders: {order: :order_cycle}])
else
StandingOrder.where("1=0")
end
@@ -125,7 +125,7 @@ module Admin
return if params[:open_orders] == 'cancel'
@open_orders_to_keep = @standing_order.proxy_orders.placed_and_open.pluck(:id)
return if @open_orders_to_keep.empty? || params[:open_orders] == 'keep'
return render json: { errors: { open_orders: t('admin.standing_orders.confirm_cancel_open_orders_msg') } }, status: :conflict
render json: { errors: { open_orders: t('admin.standing_orders.confirm_cancel_open_orders_msg') } }, status: :conflict
end
def strip_banned_attrs

View File

@@ -25,7 +25,7 @@ class StandingOrderForm
validate :standing_line_items_available?
validate :credit_card_ok?
def initialize(standing_order, params={}, fee_calculator=nil)
def initialize(standing_order, params = {}, fee_calculator = nil)
@standing_order = standing_order
@params = params
@fee_calculator = fee_calculator
@@ -44,9 +44,8 @@ class StandingOrderForm
end
def json_errors
errors.messages.inject({}) do |errors, (k,v)|
errors.messages.each_with_object({}) do |(k, v), errors|
errors[k] = v.map { |msg| build_msg_from(k, msg) }
errors
end
end
@@ -142,7 +141,7 @@ class StandingOrderForm
def validate_price_estimates
item_attributes = params[:standing_line_items_attributes]
return unless item_attributes.present?
return if item_attributes.blank?
if fee_calculator
item_attributes.each do |item_attrs|
if variant = Spree::Variant.find_by_id(item_attrs[:variant_id])
@@ -167,13 +166,13 @@ class StandingOrderForm
end
def relevant_address_attrs
["firstname","lastname","address1","zipcode","city","state_id","country_id","phone"]
["firstname", "lastname", "address1", "zipcode", "city", "state_id", "country_id", "phone"]
end
def addresses_match?(order_address, standing_order_address)
relevant_address_attrs.all? do |attr|
order_address[attr] == standing_order_address.send("#{attr}_was") ||
order_address[attr] == standing_order_address[attr]
order_address[attr] == standing_order_address[attr]
end
end
@@ -256,15 +255,15 @@ class StandingOrderForm
def variant_ids_for_shop_and_schedule
Spree::Variant.joins(exchanges: { order_cycle: :schedules})
.where(id: standing_line_items.map(&:variant_id))
.where(schedules: { id: schedule}, exchanges: { incoming: false, receiver_id: shop })
.merge(OrderCycle.not_closed)
.select('DISTINCT spree_variants.id')
.pluck(:id)
.where(id: standing_line_items.map(&:variant_id))
.where(schedules: { id: schedule}, exchanges: { incoming: false, receiver_id: shop })
.merge(OrderCycle.not_closed)
.select('DISTINCT spree_variants.id')
.pluck(:id)
end
def build_msg_from(k, msg)
return msg[1..-1] if msg.starts_with?("^")
errors.full_message(k,msg)
errors.full_message(k, msg)
end
end

View File

@@ -14,9 +14,9 @@ class StandingOrderConfirmJob
def proxy_orders
ProxyOrder.not_canceled.where('confirmed_at IS NULL AND placed_at IS NOT NULL')
.joins(:order_cycle).merge(recently_closed_order_cycles)
.joins(:standing_order).merge(StandingOrder.not_canceled.not_paused)
.joins(:order).merge(Spree::Order.complete)
.joins(:order_cycle).merge(recently_closed_order_cycles)
.joins(:standing_order).merge(StandingOrder.not_canceled.not_paused)
.joins(:order).merge(Spree::Order.complete)
end
def recently_closed_order_cycles

View File

@@ -13,8 +13,8 @@ class StandingOrderPlacementJob
def proxy_orders
# Loads proxy orders for open order cycles that have not been placed yet
ProxyOrder.not_canceled.where(placed_at: nil)
.joins(:order_cycle).merge(OrderCycle.active)
.joins(:standing_order).merge(StandingOrder.not_canceled.not_paused)
.joins(:order_cycle).merge(OrderCycle.active)
.joins(:standing_order).merge(StandingOrder.not_canceled.not_paused)
end
def process(order)
@@ -66,7 +66,7 @@ class StandingOrderPlacementJob
def log_completion_issue(order)
line1 = "StandingOrderPlacementError: Cannot process order #{order.number} due to errors"
line2 = "Errors: #{order.errors.full_messages.join(", ")}"
line2 = "Errors: #{order.errors.full_messages.join(', ')}"
Rails.logger.info("#{line1}\n#{line2}")
end
end

View File

@@ -27,7 +27,7 @@ class ProxyOrder < ActiveRecord::Base
def cancel
return false unless order_cycle.orders_close_at.andand > Time.zone.now
transaction do
self.update_column(:canceled_at, Time.zone.now)
update_column(:canceled_at, Time.zone.now)
order.send('cancel') if order
true
end
@@ -36,7 +36,7 @@ class ProxyOrder < ActiveRecord::Base
def resume
return false unless order_cycle.orders_close_at.andand > Time.zone.now
transaction do
self.update_column(:canceled_at, nil)
update_column(:canceled_at, nil)
order.send('resume') if order
true
end
@@ -44,13 +44,13 @@ class ProxyOrder < ActiveRecord::Base
def initialise_order!
return order if order.present?
create_order!({
create_order!(
customer_id: standing_order.customer_id,
email: standing_order.customer.email,
order_cycle_id: order_cycle_id,
distributor_id: standing_order.shop_id,
shipping_method_id: standing_order.shipping_method_id,
})
shipping_method_id: standing_order.shipping_method_id
)
order.update_attribute(:user, standing_order.customer.user)
standing_order.standing_line_items.each do |sli|
order.line_items.build(variant_id: sli.variant_id, quantity: sli.quantity, skip_stock_check: true)
@@ -67,6 +67,6 @@ class ProxyOrder < ActiveRecord::Base
def placed_and_open?
order.andand.state == 'complete' &&
order_cycle.orders_close_at > Time.now
order_cycle.orders_close_at > Time.now
end
end

View File

@@ -118,7 +118,7 @@ Spree::Product.class_eval do
}
scope :stockable_by, lambda { |enterprise|
return where('1=0') unless enterprise.present?
return where('1=0') if enterprise.blank?
permitted_producer_ids = EnterpriseRelationship.joins(:parent).permitting(enterprise)
.with_permission(:add_to_order_cycle).where(enterprises: { is_primary_producer: true }).pluck(:parent_id)
return where('spree_products.supplier_id IN (?)', [enterprise.id] | permitted_producer_ids)

View File

@@ -44,9 +44,9 @@ Spree::Variant.class_eval do
scope :in_schedule, lambda { |schedule|
joins(exchanges: { order_cycle: :schedule}).
merge(Exchange.outgoing).
where(schedules: { id: schedule}).
select('DISTINCT spree_variants.*')
merge(Exchange.outgoing).
where(schedules: { id: schedule}).
select('DISTINCT spree_variants.*')
}
scope :for_distribution, lambda { |order_cycle, distributor|

View File

@@ -4,7 +4,7 @@ class StandingLineItem < ActiveRecord::Base
validates :standing_order, presence: true
validates :variant, presence: true
validates :quantity, { presence: true, numericality: { only_integer: true } }
validates :quantity, presence: true, numericality: { only_integer: true }
def total_estimate
(price_estimate || 0) * (quantity || 0)

View File

@@ -1,5 +1,5 @@
class StandingOrder < ActiveRecord::Base
ALLOWED_PAYMENT_METHOD_TYPES = ["Spree::PaymentMethod::Check", "Spree::Gateway::StripeConnect"]
ALLOWED_PAYMENT_METHOD_TYPES = ["Spree::PaymentMethod::Check", "Spree::Gateway::StripeConnect"].freeze
belongs_to :shop, class_name: 'Enterprise'
belongs_to :customer
@@ -35,7 +35,7 @@ class StandingOrder < ActiveRecord::Base
def cancel(keep_ids = [])
transaction do
self.update_column(:canceled_at, Time.zone.now)
update_column(:canceled_at, Time.zone.now)
proxy_orders.reject{ |o| keep_ids.include? o.id }.each(&:cancel)
true
end

View File

@@ -39,12 +39,12 @@ class Api::Admin::IndexOrderCycleSerializer < ActiveModel::Serializer
def producers
producers = object.suppliers.merge(visible_enterprises)
ActiveModel::ArraySerializer.new(producers, {each_serializer: Api::Admin::IdNameSerializer})
ActiveModel::ArraySerializer.new(producers, each_serializer: Api::Admin::IdNameSerializer)
end
def shops
shops = object.distributors.merge(visible_enterprises)
ActiveModel::ArraySerializer.new(shops, {each_serializer: Api::Admin::IdNameSerializer})
ActiveModel::ArraySerializer.new(shops, each_serializer: Api::Admin::IdNameSerializer)
end
def edit_path

View File

@@ -57,15 +57,15 @@ module OpenFoodNetwork
def last_used_bill_address
return nil unless allow_search_by_email?
Spree::Order.joins(:bill_address).order('id DESC')
.complete.where(email: email)
.first.andand.bill_address
.complete.where(email: email)
.first.andand.bill_address
end
def last_used_ship_address
return nil unless allow_search_by_email?
Spree::Order.complete.joins(:ship_address, :shipping_method).order('id DESC')
.where(email: email, spree_shipping_methods: { require_ship_address: true })
.first.andand.ship_address
.where(email: email, spree_shipping_methods: { require_ship_address: true })
.first.andand.ship_address
end
# Only allow search for address by email if a customer or user with the
@@ -76,7 +76,7 @@ module OpenFoodNetwork
def allow_search_by_email?
return false unless email.present? && (user.present? || customer.present?)
return false unless email == customer.andand.email || email == user.andand.email
return true
true
end
end
end

View File

@@ -36,7 +36,7 @@ module OpenFoodNetwork
end
def ensure_credit_card
return false unless saved_credit_card.present?
return false if saved_credit_card.blank?
payment.update_attributes(source: saved_credit_card)
end

View File

@@ -164,7 +164,7 @@ describe Admin::CustomersController, type: :controller do
end
context "when I don't manage the customer" do
before { params.merge!({customer_id: unmanaged_customer.id}) }
before { params.merge!(customer_id: unmanaged_customer.id) }
it "redirects to unauthorised" do
spree_get :addresses, params
@@ -173,7 +173,7 @@ describe Admin::CustomersController, type: :controller do
end
context "when no customer with a matching id exists" do
before { params.merge!({customer_id: 1}) }
before { params.merge!(customer_id: 1) }
it "redirects to unauthorised" do
spree_get :addresses, params
@@ -218,7 +218,7 @@ describe Admin::CustomersController, type: :controller do
end
context "when I don't manage the customer" do
before { params.merge!({customer_id: unmanaged_customer.id}) }
before { params.merge!(customer_id: unmanaged_customer.id) }
it "redirects to unauthorised" do
spree_get :cards, params
@@ -227,7 +227,7 @@ describe Admin::CustomersController, type: :controller do
end
context "when no customer with a matching id exists" do
before { params.merge!({customer_id: 1}) }
before { params.merge!(customer_id: 1) }
it "redirects to unauthorised" do
spree_get :cards, params

View File

@@ -180,7 +180,7 @@ module Admin
end
it "allows me to assign only schedules that already I coordinate to the order cycle" do
schedule_ids = [coordinated_schedule2.id, uncoordinated_schedule.id ]
schedule_ids = [coordinated_schedule2.id, uncoordinated_schedule.id]
spree_put :update, format: :json, id: coordinated_order_cycle.id, order_cycle: { schedule_ids: schedule_ids }
expect(assigns(:order_cycle)).to eq coordinated_order_cycle
# coordinated_order_cycle2 is added

View File

@@ -80,7 +80,7 @@ describe Admin::SchedulesController, type: :controller do
end
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 ]
order_cycle_ids = [coordinated_order_cycle2.id, uncoordinated_order_cycle2.id, uncoordinated_order_cycle3.id]
spree_put :update, format: :json, id: coordinated_schedule.id, schedule: { order_cycle_ids: order_cycle_ids }
expect(assigns(:schedule)).to eq coordinated_schedule
# coordinated_order_cycle2 is added, uncoordinated_order_cycle is NOT removed
@@ -198,7 +198,7 @@ describe Admin::SchedulesController, type: :controller do
before { allow(controller).to receive(:spree_current_user) { user } }
context "where I manage at least one of the schedule's coordinators" do
before { params.merge!({id: coordinated_schedule.id}) }
before { params.merge!(id: coordinated_schedule.id) }
it "allows me to destroy the schedule" do
expect { spree_delete :destroy, params }.to change(Schedule, :count).by(-1)
@@ -206,7 +206,7 @@ describe Admin::SchedulesController, type: :controller do
end
context "where I don't manage any of the schedule's coordinators" do
before { params.merge!({id: uncoordinated_schedule.id}) }
before { params.merge!(id: uncoordinated_schedule.id) }
it "prevents me from destroying the schedule" do
expect { spree_delete :destroy, params }.to_not change(Schedule, :count)

View File

@@ -13,7 +13,7 @@ describe Admin::StandingLineItemsController, type: :controller do
let!(:enterprise_fee) { create(:enterprise_fee, amount: 3.50) }
let!(:order_cycle) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.from_now, orders_close_at: 7.days.from_now) }
let!(:outgoing_exchange) { order_cycle.exchanges.create(sender: shop, receiver: shop, variants: [variant], enterprise_fees: [enterprise_fee]) }
let!(:schedule) { create(:schedule, order_cycles: [order_cycle])}
let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) }
let(:unmanaged_schedule) { create(:schedule, order_cycles: [create(:simple_order_cycle, coordinator: unmanaged_shop)]) }
context "json" do
@@ -30,7 +30,7 @@ describe Admin::StandingLineItemsController, type: :controller do
end
context "and an unmanaged shop_id is provided" do
before { params.merge!({ shop_id: unmanaged_shop.id }) }
before { params.merge!(shop_id: unmanaged_shop.id) }
it "returns an error" do
spree_post :build, params
@@ -39,7 +39,7 @@ describe Admin::StandingLineItemsController, type: :controller do
end
context "where a managed shop_id is provided" do
before { params.merge!({ shop_id: shop.id }) }
before { params.merge!(shop_id: shop.id) }
context "but the shop doesn't have permission to sell product in question" do
it "returns an error" do
@@ -66,7 +66,7 @@ describe Admin::StandingLineItemsController, type: :controller do
end
context "but an unmanaged schedule_id is provided" do
before { params.merge!({ schedule_id: unmanaged_schedule.id }) }
before { params.merge!(schedule_id: unmanaged_schedule.id) }
it "returns a serialized standing line item without a price estimate" do
spree_post :build, params
@@ -79,7 +79,7 @@ describe Admin::StandingLineItemsController, type: :controller do
end
context "and a managed schedule_id is provided" do
before { params.merge!({ schedule_id: schedule.id }) }
before { params.merge!(schedule_id: schedule.id) }
it "returns a serialized standing line item with a price estimate" do
spree_post :build, params

View File

@@ -130,7 +130,7 @@ describe Admin::StandingOrdersController, type: :controller do
context 'when I submit insufficient params' do
it 'returns errors' do
expect{ spree_post :create, params }.to_not change{StandingOrder.count}
expect{ spree_post :create, params }.to_not change{ StandingOrder.count }
json_response = JSON.parse(response.body)
expect(json_response['errors'].keys).to include 'schedule', 'customer', 'payment_method', 'shipping_method', 'begins_at'
end
@@ -145,18 +145,18 @@ describe Admin::StandingOrdersController, type: :controller do
let(:unmanaged_shipping_method) { create(:shipping_method, distributors: [unmanaged_enterprise]) }
before do
params[:standing_order].merge!({
params[:standing_order].merge!(
schedule_id: unmanaged_schedule.id,
customer_id: unmanaged_customer.id,
payment_method_id: unmanaged_payment_method.id,
shipping_method_id: unmanaged_shipping_method.id,
begins_at: 2.days.ago,
ends_at: 3.weeks.ago
})
)
end
it 'returns errors' do
expect{ spree_post :create, params }.to_not change{StandingOrder.count}
expect{ spree_post :create, params }.to_not change{ StandingOrder.count }
json_response = JSON.parse(response.body)
expect(json_response['errors'].keys).to include 'schedule', 'customer', 'payment_method', 'shipping_method', 'ends_at'
end
@@ -167,34 +167,34 @@ describe Admin::StandingOrdersController, type: :controller do
let(:variant) { create(:variant) }
before do
params[:standing_order].merge!({
params[:standing_order].merge!(
schedule_id: schedule.id,
customer_id: customer.id,
payment_method_id: payment_method.id,
shipping_method_id: shipping_method.id,
begins_at: 2.days.ago,
ends_at: 3.months.from_now
})
params.merge!({
)
params.merge!(
bill_address: address.attributes.except('id'),
ship_address: address.attributes.except('id'),
standing_line_items: [{ quantity: 2, variant_id: variant.id}]
})
)
end
context 'where the specified variants are not available from the shop' do
it 'returns an error' do
expect{ spree_post :create, params }.to_not change{StandingOrder.count}
expect{ spree_post :create, params }.to_not change{ StandingOrder.count }
json_response = JSON.parse(response.body)
expect(json_response['errors']['standing_line_items']).to eq ["#{variant.product.name} - #{variant.full_name} is not available from the selected schedule"]
end
end
context 'where the specified variants are available from the shop' do
let!(:exchange) { create(:exchange, order_cycle: order_cycle, incoming: false, receiver: shop, variants: [variant])}
let!(:exchange) { create(:exchange, order_cycle: order_cycle, incoming: false, receiver: shop, variants: [variant]) }
it 'creates standing line items for the standing order' do
expect{ spree_post :create, params }.to change{StandingOrder.count}.by(1)
expect{ spree_post :create, params }.to change{ StandingOrder.count }.by(1)
standing_order = StandingOrder.last
expect(standing_order.schedule).to eq schedule
expect(standing_order.customer).to eq customer
@@ -220,13 +220,14 @@ describe Admin::StandingOrdersController, type: :controller do
let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) }
let!(:payment_method) { create(:payment_method, distributors: [shop]) }
let!(:shipping_method) { create(:shipping_method, distributors: [shop]) }
let!(:standing_order) { create(:standing_order,
shop: shop,
customer: customer1,
schedule: schedule,
payment_method: payment_method,
shipping_method: shipping_method
) }
let!(:standing_order) {
create(:standing_order,
shop: shop,
customer: customer1,
schedule: schedule,
payment_method: payment_method,
shipping_method: shipping_method)
}
before do
allow(controller).to receive(:spree_current_user) { user }
@@ -251,15 +252,16 @@ describe Admin::StandingOrdersController, type: :controller do
let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) }
let!(:payment_method) { create(:payment_method, distributors: [shop]) }
let!(:shipping_method) { create(:shipping_method, distributors: [shop]) }
let!(:standing_order) { create(:standing_order,
shop: shop,
customer: customer,
schedule: schedule,
payment_method: payment_method,
shipping_method: shipping_method,
standing_line_items: [create(:standing_line_item, variant: variant1, quantity: 2)]
) }
let(:standing_line_item1) { standing_order.standing_line_items.first}
let!(:standing_order) {
create(:standing_order,
shop: shop,
customer: customer,
schedule: schedule,
payment_method: payment_method,
shipping_method: shipping_method,
standing_line_items: [create(:standing_line_item, variant: variant1, quantity: 2)])
}
let(:standing_line_item1) { standing_order.standing_line_items.first }
let(:params) { { format: :json, id: standing_order.id, standing_order: {} } }
context 'as an non-manager of the standing order shop' do
@@ -283,7 +285,7 @@ describe Admin::StandingOrdersController, type: :controller do
let!(:new_schedule) { create(:schedule, order_cycles: [order_cycle]) }
before do
params[:standing_order].merge!({ schedule_id: new_schedule.id, customer_id: new_customer.id})
params[:standing_order].merge!(schedule_id: new_schedule.id, customer_id: new_customer.id)
end
it 'does not alter customer_id or schedule_id' do
@@ -301,14 +303,14 @@ describe Admin::StandingOrdersController, type: :controller do
let(:unmanaged_shipping_method) { create(:shipping_method, distributors: [unmanaged_enterprise]) }
before do
params[:standing_order].merge!({
params[:standing_order].merge!(
payment_method_id: unmanaged_payment_method.id,
shipping_method_id: unmanaged_shipping_method.id,
})
shipping_method_id: unmanaged_shipping_method.id
)
end
it 'returns errors' do
expect{ spree_post :update, params }.to_not change{StandingOrder.count}
expect{ spree_post :update, params }.to_not change{ StandingOrder.count }
json_response = JSON.parse(response.body)
expect(json_response['errors'].keys).to include 'payment_method', 'shipping_method'
standing_order.reload
@@ -322,7 +324,10 @@ describe Admin::StandingOrdersController, type: :controller do
let!(:new_shipping_method) { create(:shipping_method, distributors: [shop]) }
before do
params[:standing_order].merge!({payment_method_id: new_payment_method.id, shipping_method_id: new_shipping_method.id})
params[:standing_order].merge!(
payment_method_id: new_payment_method.id,
shipping_method_id: new_shipping_method.id
)
end
it 'updates the standing order' do
@@ -344,7 +349,7 @@ describe Admin::StandingOrdersController, type: :controller do
context 'where the specified variants are not available from the shop' do
it 'returns an error' do
expect{ spree_post :update, params }.to_not change{standing_order.standing_line_items.count}
expect{ spree_post :update, params }.to_not change{ standing_order.standing_line_items.count }
json_response = JSON.parse(response.body)
expect(json_response['errors']['standing_line_items']).to eq ["#{product2.name} - #{variant2.full_name} is not available from the selected schedule"]
end
@@ -354,7 +359,7 @@ describe Admin::StandingOrdersController, type: :controller do
before { outgoing_exchange.update_attributes(variants: [variant1, variant2]) }
it 'creates standing line items for the standing order' do
expect{ spree_post :update, params }.to change{standing_order.standing_line_items.count}.by(1)
expect{ spree_post :update, params }.to change{ standing_order.standing_line_items.count }.by(1)
standing_order.reload
expect(standing_order.standing_line_items.count).to be 2
standing_line_item = standing_order.standing_line_items.last
@@ -419,7 +424,7 @@ describe Admin::StandingOrdersController, type: :controller do
end
context "when 'keep' has been provided as the 'open_orders' directive" do
before { params.merge!({ open_orders: 'keep'}) }
before { params.merge!(open_orders: 'keep') }
it 'renders the cancelled standing_order as json, and does not cancel the open order' do
spree_put :cancel, params
@@ -436,7 +441,7 @@ describe Admin::StandingOrdersController, type: :controller do
let(:mail_mock) { double(:mail) }
before do
params.merge!({ open_orders: 'cancel'})
params[:open_orders] = 'cancel'
allow(Spree::OrderMailer).to receive(:cancel_email) { mail_mock }
allow(mail_mock).to receive(:deliver)
end
@@ -518,7 +523,7 @@ describe Admin::StandingOrdersController, type: :controller do
end
context "when 'keep' has been provided as the 'open_orders' directive" do
before { params.merge!({ open_orders: 'keep'}) }
before { params.merge!(open_orders: 'keep') }
it 'renders the paused standing_order as json, and does not cancel the open order' do
spree_put :pause, params
@@ -535,7 +540,7 @@ describe Admin::StandingOrdersController, type: :controller do
let(:mail_mock) { double(:mail) }
before do
params.merge!({ open_orders: 'cancel'})
params[:open_orders] = 'cancel'
allow(Spree::OrderMailer).to receive(:cancel_email) { mail_mock }
allow(mail_mock).to receive(:deliver)
end

View File

@@ -31,7 +31,7 @@ describe Spree::Admin::PaymentsController, type: :controller do
context "where the request succeeds" do
before do
stub_request(:post, "https://sk_test_12345:@api.stripe.com/v1/charges/ch_1a2b3c/refunds").
to_return(:status => 200, :body => JSON.generate(id: 're_123', object: 'refund', status: 'succeeded') )
to_return(:status => 200, :body => JSON.generate(id: 're_123', object: 'refund', status: 'succeeded') )
end
it "voids the payment" do
@@ -49,7 +49,7 @@ describe Spree::Admin::PaymentsController, type: :controller do
context "where the request fails" do
before do
stub_request(:post, "https://sk_test_12345:@api.stripe.com/v1/charges/ch_1a2b3c/refunds").
to_return(:status => 200, :body => JSON.generate(error: { message: "Bup-bow!"}) )
to_return(:status => 200, :body => JSON.generate(error: { message: "Bup-bow!"}) )
end
it "does not void the payment" do

View File

@@ -193,7 +193,7 @@ feature "Product Import", js: true do
it "returns and error if nothing was uploaded" do
visit main_app.admin_product_import_path
expect(page).to have_content 'Select a spreadsheet to upload'
expect(page).to have_content 'Select a spreadsheet to upload'
click_button 'Import'
expect(flash_message).to eq I18n.t(:product_import_file_not_found_notice)

View File

@@ -281,15 +281,16 @@ feature 'Standing Orders' do
let!(:variant3_ex) { variant3_oc.exchanges.create(sender: shop, receiver: shop, variants: [variant3]) }
let!(:payment_method) { create(:payment_method, distributors: [shop]) }
let!(:shipping_method) { create(:shipping_method, distributors: [shop]) }
let!(:standing_order) { create(:standing_order,
shop: shop,
customer: customer,
schedule: schedule,
payment_method: payment_method,
shipping_method: shipping_method,
standing_line_items: [create(:standing_line_item, variant: variant1, quantity: 2)],
with_proxy_orders: true
) }
let!(:standing_order) {
create(:standing_order,
shop: shop,
customer: customer,
schedule: schedule,
payment_method: payment_method,
shipping_method: shipping_method,
standing_line_items: [create(:standing_line_item, variant: variant1, quantity: 2)],
with_proxy_orders: true)
}
it "passes the smoke test" do
visit edit_admin_standing_order_path(standing_order)

View File

@@ -9,8 +9,8 @@ describe StandingOrderForm do
let!(:variant2) { create(:variant, product: product2, unit_value: '1000', price: 6.00, option_values: []) }
let!(:variant3) { create(:variant, product: product2, unit_value: '1000', price: 2.50, option_values: [], count_on_hand: 1) }
let!(:enterprise_fee) { create(:enterprise_fee, amount: 1.75) }
let!(:order_cycle1) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 9.days.ago, orders_close_at: 2.day.ago) }
let!(:order_cycle2) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.day.ago, orders_close_at: 5.days.from_now) }
let!(:order_cycle1) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 9.days.ago, orders_close_at: 2.days.ago) }
let!(:order_cycle2) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.ago, orders_close_at: 5.days.from_now) }
let!(:order_cycle3) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 5.days.from_now, orders_close_at: 12.days.from_now) }
let!(:order_cycle4) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 12.days.from_now, orders_close_at: 19.days.from_now) }
let!(:outgoing_exchange1) { order_cycle1.exchanges.create(sender: shop, receiver: shop, variants: [variant1, variant2, variant3], enterprise_fees: [enterprise_fee]) }
@@ -23,22 +23,23 @@ describe StandingOrderForm do
let!(:address) { create(:address) }
let(:standing_order) { StandingOrder.new }
let!(:params) { {
shop_id: shop.id,
customer_id: customer.id,
schedule_id: schedule.id,
bill_address_attributes: address.clone.attributes,
ship_address_attributes: address.clone.attributes,
payment_method_id: payment_method.id,
shipping_method_id: shipping_method.id,
begins_at: 4.days.ago,
ends_at: 14.days.from_now,
standing_line_items_attributes: [
{variant_id: variant1.id, quantity: 1},
{variant_id: variant2.id, quantity: 2},
{variant_id: variant3.id, quantity: 3}
]
} }
let!(:params) {
{
shop_id: shop.id,
customer_id: customer.id,
schedule_id: schedule.id,
bill_address_attributes: address.clone.attributes,
ship_address_attributes: address.clone.attributes,
payment_method_id: payment_method.id,
shipping_method_id: shipping_method.id,
begins_at: 4.days.ago,
ends_at: 14.days.from_now,
standing_line_items_attributes: [
{variant_id: variant1.id, quantity: 1},
{variant_id: variant2.id, quantity: 2},
{variant_id: variant3.id, quantity: 3}
]
} }
let(:form) { StandingOrderForm.new(standing_order, params) }
@@ -450,7 +451,7 @@ describe StandingOrderForm do
context "but the shipping method is being changed to one that requires a ship_address" do
let(:new_shipping_method) { create(:shipping_method, require_ship_address: true) }
before { params.merge!({ shipping_method_id: new_shipping_method.id }) }
before { params.merge!(shipping_method_id: new_shipping_method.id) }
it "updates ship_address attrs" do
expect(form.save).to be true
@@ -511,7 +512,7 @@ describe StandingOrderForm do
before { variant.update_attribute(:count_on_hand, 2) }
context "when quantity is within available stock" do
let(:params) { { standing_line_items_attributes: [ { id: sli.id, quantity: 2} ] } }
let(:params) { { standing_line_items_attributes: [{ id: sli.id, quantity: 2}] } }
let(:form) { StandingOrderForm.new(standing_order, params) }
it "updates the line_item quantities and totals on all orders" do
@@ -524,7 +525,7 @@ describe StandingOrderForm do
end
context "when quantity is greater than available stock" do
let(:params) { { standing_line_items_attributes: [ { id: sli.id, quantity: 3} ] } }
let(:params) { { standing_line_items_attributes: [{ id: sli.id, quantity: 3}] } }
let(:form) { StandingOrderForm.new(standing_order, params) }
it "updates the line_item quantities and totals on all orders" do
@@ -537,7 +538,7 @@ describe StandingOrderForm do
end
context "where the quantity of the item on an initialised order has already been changed" do
let(:params) { { standing_line_items_attributes: [ { id: sli.id, quantity: 3} ] } }
let(:params) { { standing_line_items_attributes: [{ id: sli.id, quantity: 3}] } }
let(:form) { StandingOrderForm.new(standing_order, params) }
let(:changed_line_item) { order.line_items.find_by_variant_id(sli.variant_id) }
@@ -574,13 +575,13 @@ describe StandingOrderForm do
let(:unavailable_variant) { create(:variant) }
let(:shop) { create(:enterprise) }
let(:order_cycle) { create(:simple_order_cycle, variants: [variant], coordinator: shop, distributors: [shop]) }
let(:schedule) { create(:schedule, order_cycles: [order_cycle] )}
let(:schedule) { create(:schedule, order_cycles: [order_cycle] ) }
let(:standing_order) { create(:standing_order, schedule: schedule, shop: shop, with_items: true, with_proxy_orders: true) }
let(:order) { standing_order.proxy_orders.first.initialise_order! }
let(:form) { StandingOrderForm.new(standing_order, params) }
context "that is available from the selected schedule" do
let(:params) { { standing_line_items_attributes: [ { id: nil, variant_id: variant.id, quantity: 1} ] } }
let(:params) { { standing_line_items_attributes: [{ id: nil, variant_id: variant.id, quantity: 1}] } }
it "adds the line item and updates the total on all orders" do
expect(order.reload.total.to_f).to eq 59.97
@@ -592,7 +593,7 @@ describe StandingOrderForm do
end
context "that is not available from the selected schedule" do
let(:params) { { standing_line_items_attributes: [ { id: nil, variant_id: unavailable_variant.id, quantity: 1} ] } }
let(:params) { { standing_line_items_attributes: [{ id: nil, variant_id: unavailable_variant.id, quantity: 1}] } }
it "returns false and does not add the line item or update the total on orders" do
expect(order.reload.total.to_f).to eq 59.97
@@ -609,8 +610,8 @@ describe StandingOrderForm do
let(:standing_order) { create(:standing_order, with_items: true, with_proxy_orders: true) }
let(:order) { standing_order.proxy_orders.first.initialise_order! }
let(:sli) { standing_order.standing_line_items.first }
let(:variant) { sli.variant}
let(:params) { { standing_line_items_attributes: [ { id: sli.id, _destroy: true } ] } }
let(:variant) { sli.variant }
let(:params) { { standing_line_items_attributes: [{ id: sli.id, _destroy: true }] } }
let(:form) { StandingOrderForm.new(standing_order, params) }
context "that is not the last remaining item" do
@@ -625,8 +626,8 @@ describe StandingOrderForm do
context "that is the last remaining item" do
before do
standing_order.standing_line_items.where('variant_id != ?',variant.id).destroy_all
order.line_items.where('variant_id != ?',variant.id).destroy_all
standing_order.standing_line_items.where('variant_id != ?', variant.id).destroy_all
order.line_items.where('variant_id != ?', variant.id).destroy_all
standing_order.reload
order.reload
end
@@ -657,7 +658,7 @@ describe StandingOrderForm do
context "when line_item params are present" do
before do
params[:standing_line_items_attributes] = [ { id: 1, price_estimate: 2.50 }, { id: 2, price_estimate: 3.50 }]
params[:standing_line_items_attributes] = [{ id: 1, price_estimate: 2.50 }, { id: 2, price_estimate: 3.50 }]
end
context "when no fee calculator is present" do

View File

@@ -32,7 +32,7 @@ describe StandingOrderConfirmJob do
end
it "ignores cancelled proxy orders" do
proxy_order.update_attributes!(canceled_at: 5.minute.ago)
proxy_order.update_attributes!(canceled_at: 5.minutes.ago)
expect(proxy_orders).to_not include proxy_order
end
@@ -69,7 +69,7 @@ describe StandingOrderConfirmJob do
end
it "marks confirmable proxy_orders as processed by setting confirmed_at" do
expect{job.perform}.to change{proxy_order.reload.confirmed_at}
expect{ job.perform }.to change{ proxy_order.reload.confirmed_at }
expect(proxy_order.confirmed_at).to be_within(5.seconds).of Time.now
end
@@ -117,7 +117,7 @@ describe StandingOrderConfirmJob do
before { expect(payment_updater_mock).to receive(:update!) { :no_card } }
it "adds and error to the order" do
expect{job.send(:update_payment!)}.to change(order.errors, :count).from(0).to(1)
expect{ job.send(:update_payment!) }.to change(order.errors, :count).from(0).to(1)
expect(order.errors.full_messages).to include I18n.t("activerecord.errors.models.standing_order.no_card")
end
end
@@ -185,7 +185,7 @@ describe StandingOrderConfirmJob do
it "sends only a standing order confirm email, no regular confirmation emails" do
ActionMailer::Base.deliveries.clear
expect{job.send(:process!)}.to_not enqueue_job ConfirmOrderJob
expect{ job.send(:process!) }.to_not enqueue_job ConfirmOrderJob
expect(job).to have_received(:send_confirm_email).once
expect(ActionMailer::Base.deliveries.count).to be 1
end

View File

@@ -48,7 +48,7 @@ describe StandingOrderPlacementJob do
end
it "marks placeable proxy_orders as processed by setting placed_at" do
expect{job.perform}.to change{proxy_order.reload.placed_at}
expect{ job.perform }.to change{ proxy_order.reload.placed_at }
expect(proxy_order.placed_at).to be_within(5.seconds).of Time.now
end
@@ -134,7 +134,7 @@ describe StandingOrderPlacementJob do
it "ignores it" do
ActionMailer::Base.deliveries.clear
expect{job.send(:process, order)}.to_not change{order.reload.state}
expect{ job.send(:process, order) }.to_not change{ order.reload.state }
expect(order.payments.first.state).to eq "checkout"
expect(ActionMailer::Base.deliveries.count).to be 0
end
@@ -147,7 +147,7 @@ describe StandingOrderPlacementJob do
end
it "does not place the order, sends an empty_order email" do
expect{job.send(:process, order)}.to_not change{order.reload.completed_at}.from(nil)
expect{ job.send(:process, order) }.to_not change{ order.reload.completed_at }.from(nil)
expect(job).to_not have_received(:send_placement_email)
expect(job).to have_received(:send_empty_email)
end
@@ -157,13 +157,13 @@ describe StandingOrderPlacementJob do
it "processes the order to completion, but does not process the payment" do
# If this spec starts complaining about no shipping methods being available
# on CI, there is probably another spec resetting the currency though Rails.cache.clear
expect{job.send(:process, order)}.to change{order.reload.completed_at}.from(nil)
expect{ job.send(:process, order) }.to change{ order.reload.completed_at }.from(nil)
expect(order.completed_at).to be_within(5.seconds).of Time.now
expect(order.payments.first.state).to eq "checkout"
end
it "does not enqueue confirmation emails" do
expect{job.send(:process, order)}.to_not enqueue_job ConfirmOrderJob
expect{ job.send(:process, order) }.to_not enqueue_job ConfirmOrderJob
expect(job).to have_received(:send_placement_email).with(order, anything).once
end

View File

@@ -210,14 +210,14 @@ module OpenFoodNetwork
before{ allow(finder).to receive(:customer) { customer } }
context "when the customer email matches the raw email" do
before{ allow(customer).to receive(:email) {"email@email.com"} }
before{ allow(customer).to receive(:email) { "email@email.com" } }
it "returns true" do
expect(finder.send(:allow_search_by_email?)).to be true
end
end
context "when the customer email does not match the raw email" do
before{ allow(customer).to receive(:email) {"nah@email.com"} }
before{ allow(customer).to receive(:email) { "nah@email.com" } }
it "returns false" do
expect(finder.send(:allow_search_by_email?)).to be false
end
@@ -229,14 +229,14 @@ module OpenFoodNetwork
before{ allow(finder).to receive(:user) { user } }
context "when the user email matches the raw email" do
before{ allow(user).to receive(:email) {"email@email.com"} }
before{ allow(user).to receive(:email) { "email@email.com" } }
it "returns true" do
expect(finder.send(:allow_search_by_email?)).to be true
end
end
context "when the user email does not match the raw email" do
before{ allow(user).to receive(:email) {"nah@email.com"} }
before{ allow(user).to receive(:email) { "nah@email.com" } }
it "returns false" do
expect(finder.send(:allow_search_by_email?)).to be false
end

View File

@@ -51,7 +51,7 @@ module OpenFoodNetwork
21,
"",
"sku"
]]
]]
end
it "fetches variants for some params" do

View File

@@ -6,9 +6,9 @@ module OpenFoodNetwork
let!(:standing_order) { create(:standing_order) }
it "raises an error when initialized with an object that is not a StandingOrder or an ActiveRecord::Relation" do
expect{ProxyOrderSyncer.new(standing_order)}.to_not raise_error
expect{ProxyOrderSyncer.new(StandingOrder.where(id: standing_order.id))}.to_not raise_error
expect{ProxyOrderSyncer.new("something")}.to raise_error RuntimeError
expect{ ProxyOrderSyncer.new(standing_order) }.to_not raise_error
expect{ ProxyOrderSyncer.new(StandingOrder.where(id: standing_order.id)) }.to_not raise_error
expect{ ProxyOrderSyncer.new("something") }.to raise_error RuntimeError
end
end
@@ -47,8 +47,8 @@ module OpenFoodNetwork
let(:new_standing_order) { build(:standing_order, schedule: schedule, begins_at: now + 1.minute, ends_at: now + 2.minutes) }
it "builds proxy orders for in-range order cycles that are not already closed" do
allow(syncer).to receive(:standing_order) { new_standing_order }
expect{syncer.send(:initialise_proxy_orders!)}.to_not change(ProxyOrder, :count).from(0)
expect{new_standing_order.save!}.to change(ProxyOrder, :count).from(0).to(2)
expect{ syncer.send(:initialise_proxy_orders!) }.to_not change(ProxyOrder, :count).from(0)
expect{ new_standing_order.save! }.to change(ProxyOrder, :count).from(0).to(2)
expect(new_standing_order.proxy_orders.map(&:order_cycle_id)).to include oc3.id, oc4.id
end
end
@@ -56,7 +56,7 @@ module OpenFoodNetwork
describe "#create_proxy_orders!" do
it "creates proxy orders for in-range order cycles that are not already closed" do
allow(syncer).to receive(:standing_order) { standing_order }
expect{syncer.send(:create_proxy_orders!)}.to change(ProxyOrder, :count).from(0).to(2)
expect{ syncer.send(:create_proxy_orders!) }.to change(ProxyOrder, :count).from(0).to(2)
expect(standing_order.proxy_orders.map(&:order_cycle)).to include oc3, oc4
end
end
@@ -70,7 +70,7 @@ module OpenFoodNetwork
it "destroys proxy orders that are closed or out of range" do
allow(syncer).to receive(:standing_order) { standing_order }
expect{syncer.send(:remove_obsolete_proxy_orders!)}.to change(ProxyOrder, :count).from(5).to(2)
expect{ syncer.send(:remove_obsolete_proxy_orders!) }.to change(ProxyOrder, :count).from(5).to(2)
expect(standing_order.proxy_orders.map(&:order_cycle)).to include oc3, oc4
end
end

View File

@@ -57,7 +57,7 @@ module OpenFoodNetwork
end
it "creates a new payment on the order" do
expect{updater.update!}.to change(Spree::Payment, :count).by(1)
expect{ updater.update! }.to change(Spree::Payment, :count).by(1)
expect(order.payments.first.amount).to eq 5
end
end
@@ -75,7 +75,7 @@ module OpenFoodNetwork
context "when the payment total doesn't match the outstanding balance on the order" do
before { allow(order).to receive(:outstanding_balance) { 5 } }
it "updates the payment total to reflect the outstanding balance" do
expect{updater.update!}.to change(payment, :amount).from(10).to(5)
expect{ updater.update! }.to change(payment, :amount).from(10).to(5)
end
end
@@ -83,7 +83,7 @@ module OpenFoodNetwork
before { allow(order).to receive(:outstanding_balance) { 10 } }
it "does nothing" do
expect{updater.update!}.to_not change(payment, :amount).from(10)
expect{ updater.update! }.to_not change(payment, :amount).from(10)
end
end
end
@@ -111,7 +111,7 @@ module OpenFoodNetwork
context "when the payment total doesn't match the outstanding balance on the order" do
before { allow(order).to receive(:outstanding_balance) { 5 } }
it "updates the payment total to reflect the outstanding balance" do
expect{updater.update!}.to change(payment, :amount).from(10).to(5)
expect{ updater.update! }.to change(payment, :amount).from(10).to(5)
end
end
@@ -119,7 +119,7 @@ module OpenFoodNetwork
before { allow(order).to receive(:outstanding_balance) { 10 } }
it "does nothing" do
expect{updater.update!}.to_not change(payment, :amount).from(10)
expect{ updater.update! }.to_not change(payment, :amount).from(10)
end
end
end
@@ -131,7 +131,7 @@ module OpenFoodNetwork
context "when the payment total doesn't match the outstanding balance on the order" do
before { allow(order).to receive(:outstanding_balance) { 5 } }
it "updates the payment total to reflect the outstanding balance" do
expect{updater.update!}.to change(payment, :amount).from(10).to(5)
expect{ updater.update! }.to change(payment, :amount).from(10).to(5)
end
end
@@ -139,7 +139,7 @@ module OpenFoodNetwork
before { allow(order).to receive(:outstanding_balance) { 10 } }
it "does nothing" do
expect{updater.update!}.to_not change(payment, :amount).from(10)
expect{ updater.update! }.to_not change(payment, :amount).from(10)
end
end
end

View File

@@ -17,7 +17,7 @@ describe StandingOrderMailer do
changes[order.line_items.first.id] = 2
expect do
StandingOrderMailer.placement_email(order, changes).deliver
end.to change{StandingOrderMailer.deliveries.count}.by(1)
end.to change{ StandingOrderMailer.deliveries.count }.by(1)
end
it "sends the email, which notifies the customer of changes made" do
@@ -32,7 +32,7 @@ describe StandingOrderMailer do
before do
expect do
StandingOrderMailer.placement_email(order, {}).deliver
end.to change{StandingOrderMailer.deliveries.count}.by(1)
end.to change{ StandingOrderMailer.deliveries.count }.by(1)
end
it "sends the email" do
@@ -52,7 +52,7 @@ describe StandingOrderMailer do
before do
expect do
StandingOrderMailer.confirmation_email(order).deliver
end.to change{StandingOrderMailer.deliveries.count}.by(1)
end.to change{ StandingOrderMailer.deliveries.count }.by(1)
end
it "sends the email" do
@@ -70,7 +70,7 @@ describe StandingOrderMailer do
before do
expect do
StandingOrderMailer.empty_email(order, {}).deliver
end.to change{StandingOrderMailer.deliveries.count}.by(1)
end.to change{ StandingOrderMailer.deliveries.count }.by(1)
end
it "sends the email" do
@@ -90,7 +90,7 @@ describe StandingOrderMailer do
expect do
StandingOrderMailer.failed_payment_email(order).deliver
end.to change{StandingOrderMailer.deliveries.count}.by(1)
end.to change{ StandingOrderMailer.deliveries.count }.by(1)
end
it "sends the email" do

View File

@@ -74,7 +74,7 @@ describe ProxyOrder, type: :model do
let!(:payment_method) { create(:payment_method) }
let(:order) { create(:order_with_totals, shipping_method: create(:shipping_method)) }
let(:proxy_order) { create(:proxy_order, order: order, canceled_at: Time.zone.now) }
let(:order_cycle) { proxy_order.order_cycle}
let(:order_cycle) { proxy_order.order_cycle }
context "when the order cycle is not yet closed" do
before { order_cycle.update_attributes(orders_open_at: 1.day.ago, orders_close_at: 3.days.from_now) }
@@ -163,7 +163,7 @@ describe ProxyOrder, type: :model do
let!(:proxy_order) { create(:proxy_order, standing_order: standing_order) }
it "builds a new order based the standing order" do
expect{ proxy_order.initialise_order! }.to change{Spree::Order.count}.by(1)
expect{ proxy_order.initialise_order! }.to change{ Spree::Order.count }.by(1)
expect(proxy_order.reload.order).to be_a Spree::Order
order = proxy_order.order
expect(order.line_items.count).to eq standing_order.standing_line_items.count
@@ -189,7 +189,7 @@ describe ProxyOrder, type: :model do
end
it "initialises the order with the requested quantity regardless" do
expect{ proxy_order.initialise_order! }.to change{Spree::Order.count}.by(1)
expect{ proxy_order.initialise_order! }.to change{ Spree::Order.count }.by(1)
expect(proxy_order.reload.order).to be_a Spree::Order
order = proxy_order.order
expect(order.line_items.find_by_variant_id(variant.id).quantity).to eq 5
@@ -202,7 +202,7 @@ describe ProxyOrder, type: :model do
end
it "initialises the order without a user_id" do
expect{ proxy_order.initialise_order! }.to change{Spree::Order.count}.by(1)
expect{ proxy_order.initialise_order! }.to change{ Spree::Order.count }.by(1)
expect(proxy_order.reload.order).to be_a Spree::Order
order = proxy_order.order
expect(order.user).to be nil
@@ -217,7 +217,7 @@ describe ProxyOrder, type: :model do
it "returns the existing order" do
expect do
expect(proxy_order.initialise_order!).to eq existing_order
end.to_not change{Spree::Order.count}
end.to_not change{ Spree::Order.count }
end
end
end

View File

@@ -43,7 +43,7 @@ describe StandingOrder, type: :model do
it "aborts the transaction" do
# ie. canceled_at remains as nil, #cancel not called on second standing order order
expect{standing_order.cancel}.to raise_error "Some error"
expect{ standing_order.cancel }.to raise_error "Some error"
expect(standing_order.reload.canceled_at).to be nil
expect(proxy_order1).to have_received(:cancel)
expect(proxy_order2).to_not have_received(:cancel)

View File

@@ -6,13 +6,13 @@ module OpenFoodNetwork
let!(:schedule) { create(:schedule, order_cycles: order_cycles) }
let!(:order_cycles) do
10.times.map do |i|
create(:simple_order_cycle, orders_open_at: start + i.days, orders_close_at: start + (i+1).days )
Array.new(10) do |i|
create(:simple_order_cycle, orders_open_at: start + i.days, orders_close_at: start + (i + 1).days )
end
end
let!(:standing_orders) do
150.times.map do |i|
Array.new(150) do |_i|
create(:standing_order, schedule: schedule, begins_at: start, ends_at: start + 10.days)
end
StandingOrder.where(schedule_id: schedule)
@@ -28,13 +28,13 @@ module OpenFoodNetwork
t1 = Time.now
syncer.sync!
t2 = Time.now
times << t2-t1
puts (t2-t1).round(2)
times << t2 - t1
puts (t2 - t1).round(2)
expect(ProxyOrder.count).to be 1500
ProxyOrder.destroy_all
end
puts "AVG: #{(times.sum/times.count).round(2)}"
puts "AVG: #{(times.sum / times.count).round(2)}"
end
end
@@ -51,13 +51,13 @@ module OpenFoodNetwork
t1 = Time.now
syncer.sync!
t2 = Time.now
times << t2-t1
puts (t2-t1).round(2)
times << t2 - t1
puts (t2 - t1).round(2)
expect(ProxyOrder.count).to be 300
standing_orders.update_all(begins_at: start)
end
puts "AVG: #{(times.sum/times.count).round(2)}"
puts "AVG: #{(times.sum / times.count).round(2)}"
end
end
end

View File

@@ -33,7 +33,7 @@ describe "checking out an order with a paypal express payment method", type: :re
set_order order
stub_request(:post, "https://api-3t.sandbox.paypal.com/2.0/")
.to_return(:status => 200, :body => mocked_xml_response )
.to_return(:status => 200, :body => mocked_xml_response )
end
context "with a flat percent calculator" do