Skip to content

Commit

Permalink
Test public instead of private method
Browse files Browse the repository at this point in the history
Refactoring and styling the whole thing, possibly causing conflicts with
other pull requests.
  • Loading branch information
mkllnk committed May 18, 2018
1 parent 57dd984 commit d218a51
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 43 deletions.
7 changes: 0 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Layout/AlignArray:
- 'lib/open_food_network/orders_and_fulfillments_report.rb'
- 'lib/open_food_network/packing_report.rb'
- 'spec/controllers/spree/orders_controller_spec.rb'
- 'spec/lib/open_food_network/order_and_distributor_report_spec.rb'
- 'spec/lib/open_food_network/order_grouper_spec.rb'

# Offense count: 127
Expand Down Expand Up @@ -234,7 +233,6 @@ Layout/EmptyLines:
- 'spec/jobs/heartbeat_job_spec.rb'
- 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb'
- 'spec/lib/open_food_network/option_value_namer_spec.rb'
- 'spec/lib/open_food_network/order_and_distributor_report_spec.rb'
- 'spec/lib/open_food_network/order_cycle_form_applicator_spec.rb'
- 'spec/lib/open_food_network/order_cycle_management_report_spec.rb'
- 'spec/lib/open_food_network/order_cycle_permissions_spec.rb'
Expand Down Expand Up @@ -308,7 +306,6 @@ Layout/EmptyLinesAroundBlockBody:
- 'spec/jobs/update_billable_periods_spec.rb'
- 'spec/lib/open_food_network/group_buy_report_spec.rb'
- 'spec/lib/open_food_network/lettuce_share_report_spec.rb'
- 'spec/lib/open_food_network/order_and_distributor_report_spec.rb'
- 'spec/lib/open_food_network/order_grouper_spec.rb'
- 'spec/lib/open_food_network/referer_parser_spec.rb'
- 'spec/lib/open_food_network/user_balance_calculator_spec.rb'
Expand Down Expand Up @@ -499,7 +496,6 @@ Layout/LeadingCommentSpace:
- 'spec/features/admin/products_spec.rb'
- 'spec/features/admin/reports_spec.rb'
- 'spec/jobs/finalize_account_invoices_spec.rb'
- 'spec/lib/open_food_network/order_and_distributor_report_spec.rb'
- 'spec/lib/open_food_network/order_grouper_spec.rb'
- 'spec/lib/open_food_network/user_balance_calculator_spec.rb'
- 'spec/models/enterprise_spec.rb'
Expand Down Expand Up @@ -618,7 +614,6 @@ Layout/SpaceAfterComma:
- 'spec/features/admin/variant_overrides_spec.rb'
- 'spec/jobs/update_account_invoices_spec.rb'
- 'spec/lib/open_food_network/group_buy_report_spec.rb'
- 'spec/lib/open_food_network/order_and_distributor_report_spec.rb'
- 'spec/lib/open_food_network/subscription_summary_spec.rb'
- 'spec/models/content_configuration_spec.rb'
- 'spec/models/spree/line_item_spec.rb'
Expand Down Expand Up @@ -761,7 +756,6 @@ Layout/SpaceInsideArrayLiteralBrackets:
- 'spec/controllers/cart_controller_spec.rb'
- 'spec/features/admin/reports_spec.rb'
- 'spec/jobs/update_billable_periods_spec.rb'
- 'spec/lib/open_food_network/order_and_distributor_report_spec.rb'
- 'spec/lib/open_food_network/order_grouper_spec.rb'
- 'spec/lib/open_food_network/users_and_enterprises_report_spec.rb'

Expand Down Expand Up @@ -2125,7 +2119,6 @@ Style/HashSyntax:
- 'spec/jobs/subscription_placement_job_spec.rb'
- 'spec/lib/open_food_network/group_buy_report_spec.rb'
- 'spec/lib/open_food_network/lettuce_share_report_spec.rb'
- 'spec/lib/open_food_network/order_and_distributor_report_spec.rb'
- 'spec/lib/open_food_network/order_cycle_form_applicator_spec.rb'
- 'spec/lib/open_food_network/order_grouper_spec.rb'
- 'spec/lib/open_food_network/tag_rule_applicator_spec.rb'
Expand Down
85 changes: 49 additions & 36 deletions spec/lib/open_food_network/order_and_distributor_report_spec.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,61 @@
require 'spec_helper'


module OpenFoodNetwork
describe OrderAndDistributorReport do

describe "orders and distributors report" do

before(:each) do
#normal completed order
@bill_address = create(:address)
@distributor_address = create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234")
@distributor = create(:distributor_enterprise, :address => @distributor_address)
product = create(:product)
product_distribution = create(:product_distribution, :product => product, :distributor => @distributor)
@shipping_instructions = "pick up on thursday please!"
@order = create(:order, :distributor => @distributor, :bill_address => @bill_address, :special_instructions => @shipping_instructions)
@payment_method = create(:payment_method, :distributors => [@distributor])
payment = create(:payment, :payment_method => @payment_method, :order => @order )
@order.payments << payment
@line_item = create(:line_item, :product => product, :order => @order)
@order.line_items << @line_item
end

it "should return a header row describing the report" do
describe 'orders and distributors report' do
it 'should return a header row describing the report' do
subject = OrderAndDistributorReport.new nil

header = subject.header
expect(header).to eq(["Order date", "Order Id",
"Customer Name","Customer Email", "Customer Phone", "Customer City",
"SKU", "Item name", "Variant", "Quantity", "Max Quantity", "Cost", "Shipping Cost",
"Payment Method",
"Distributor", "Distributor address", "Distributor city", "Distributor postcode", "Shipping instructions"])
expect(header).to eq(['Order date', 'Order Id',
'Customer Name', 'Customer Email', 'Customer Phone', 'Customer City',
'SKU', 'Item name', 'Variant', 'Quantity', 'Max Quantity', 'Cost', 'Shipping Cost',
'Payment Method',
'Distributor', 'Distributor address', 'Distributor city', 'Distributor postcode', 'Shipping instructions'])
end

it "should denormalise order and distributor details for display as csv" do
subject = OrderAndDistributorReport.new create(:admin_user), {}, true

table = subject.send(:line_item_details, [@order])

expect(table[0]).to eq([@order.created_at, @order.id,
@bill_address.full_name, @order.email, @bill_address.phone, @bill_address.city,
@line_item.product.sku, @line_item.product.name, @line_item.options_text, @line_item.quantity, @line_item.max_quantity, @line_item.price * @line_item.quantity, @line_item.distribution_fee,
@payment_method.name,
@distributor.name, @distributor.address.address1, @distributor.address.city, @distributor.address.zipcode, @shipping_instructions ])
context 'with completed order' do
let(:bill_address) { create(:address) }
let(:distributor) { create(:distributor_enterprise) }
let(:product) { create(:product) }
let(:shipping_instructions) { 'pick up on thursday please!' }
let(:order) { create(:order, state: 'complete', completed_at: Time.zone.now, distributor: distributor, bill_address: bill_address, special_instructions: shipping_instructions) }
let(:payment_method) { create(:payment_method, distributors: [distributor]) }
let(:payment) { create(:payment, payment_method: payment_method, order: order) }
let(:line_item) { create(:line_item, product: product, order: order) }

before do
order.payments << payment
order.line_items << line_item
end

it 'should denormalise order and distributor details for display as csv' do
subject = OrderAndDistributorReport.new create(:admin_user), {}, true

table = subject.table

expect(table[0]).to eq([
order.reload.created_at,
order.id,
bill_address.full_name,
order.email,
bill_address.phone,
bill_address.city,
line_item.product.sku,
line_item.product.name,
line_item.options_text,
line_item.quantity,
line_item.max_quantity,
line_item.price * line_item.quantity,
line_item.distribution_fee,
payment_method.name,
distributor.name,
distributor.address.address1,
distributor.address.city,
distributor.address.zipcode,
shipping_instructions
])
end
end
end
end
Expand Down

0 comments on commit d218a51

Please sign in to comment.