mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-27 21:06:49 +00:00
Merge branch 'simple-order-cycles'
Conflicts: app/views/admin/order_cycles/_row.html.haml
This commit is contained in:
@@ -131,16 +131,16 @@ feature %q{
|
||||
page.should have_selector 'td.distributors', text: 'My distributor'
|
||||
|
||||
# And it should have some fees
|
||||
OrderCycle.last.exchanges.incoming.first.enterprise_fees.should == [supplier_fee]
|
||||
OrderCycle.last.coordinator_fees.should == [coordinator_fee]
|
||||
OrderCycle.last.exchanges.outgoing.first.enterprise_fees.should == [distributor_fee]
|
||||
oc = OrderCycle.last
|
||||
oc.exchanges.incoming.first.enterprise_fees.should == [supplier_fee]
|
||||
oc.coordinator_fees.should == [coordinator_fee]
|
||||
oc.exchanges.outgoing.first.enterprise_fees.should == [distributor_fee]
|
||||
|
||||
# And it should have some variants selected
|
||||
OrderCycle.last.exchanges.first.variants.count.should == 2
|
||||
OrderCycle.last.exchanges.last.variants.count.should == 2
|
||||
oc.exchanges.first.variants.count.should == 2
|
||||
oc.exchanges.last.variants.count.should == 2
|
||||
|
||||
# And my pickup time and instructions should have been saved
|
||||
oc = OrderCycle.last
|
||||
exchange = oc.exchanges.where(:sender_id => oc.coordinator_id).first
|
||||
exchange.pickup_time.should == 'pickup time'
|
||||
exchange.pickup_instructions.should == 'pickup instructions'
|
||||
@@ -576,7 +576,165 @@ feature %q{
|
||||
occ = OrderCycle.last
|
||||
occ.name.should == "COPY OF #{oc.name}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "simplified interface for enterprise users selling only their own produce" do
|
||||
let(:user) { create_enterprise_user }
|
||||
let(:enterprise) { create(:enterprise, is_primary_producer: true, sells: 'own') }
|
||||
let!(:p1) { create(:simple_product, supplier: enterprise) }
|
||||
let!(:p2) { create(:simple_product, supplier: enterprise) }
|
||||
let!(:p3) { create(:simple_product, supplier: enterprise) }
|
||||
let!(:v) { create(:variant, product: p3) }
|
||||
let!(:fee) { create(:enterprise_fee, enterprise: enterprise, name: 'Coord fee') }
|
||||
|
||||
use_short_wait
|
||||
|
||||
before do
|
||||
user.enterprise_roles.create! enterprise: enterprise
|
||||
login_to_admin_as user
|
||||
end
|
||||
|
||||
it "shows me an index of order cycles without enterprise columns" do
|
||||
create(:order_cycle, coordinator: enterprise)
|
||||
visit admin_order_cycles_path
|
||||
page.should_not have_selector 'th', text: 'SUPPLIERS'
|
||||
page.should_not have_selector 'th', text: 'COORDINATOR'
|
||||
page.should_not have_selector 'th', text: 'DISTRIBUTORS'
|
||||
end
|
||||
|
||||
it "creates order cycles", js: true do
|
||||
# When I go to the new order cycle page
|
||||
visit admin_order_cycles_path
|
||||
click_link 'New Order Cycle'
|
||||
|
||||
# And I fill in the basic fields
|
||||
fill_in 'order_cycle_name', with: 'Plums & Avos'
|
||||
fill_in 'order_cycle_orders_open_at', with: '2014-10-17 06:00:00'
|
||||
fill_in 'order_cycle_orders_close_at', with: '2014-10-24 17:00:00'
|
||||
fill_in 'order_cycle_outgoing_exchange_0_pickup_time', with: 'pickup time'
|
||||
fill_in 'order_cycle_outgoing_exchange_0_pickup_instructions', with: 'pickup instructions'
|
||||
|
||||
# Then my products / variants should already be selected
|
||||
page.should have_checked_field "order_cycle_incoming_exchange_0_variants_#{p1.master.id}"
|
||||
page.should have_checked_field "order_cycle_incoming_exchange_0_variants_#{p2.master.id}"
|
||||
page.should have_checked_field "order_cycle_incoming_exchange_0_variants_#{v.id}"
|
||||
|
||||
# When I unselect a product
|
||||
uncheck "order_cycle_incoming_exchange_0_variants_#{p2.master.id}"
|
||||
|
||||
# And I add a fee and save
|
||||
click_button 'Add coordinator fee'
|
||||
click_button 'Add coordinator fee'
|
||||
click_link 'order_cycle_coordinator_fee_1_remove'
|
||||
page.should have_select 'order_cycle_coordinator_fee_0_id'
|
||||
page.should_not have_select 'order_cycle_coordinator_fee_1_id'
|
||||
|
||||
select 'Coord fee', from: 'order_cycle_coordinator_fee_0_id'
|
||||
click_button 'Create'
|
||||
|
||||
# Then my order cycle should have been created
|
||||
page.should have_content 'Your order cycle has been created.'
|
||||
page.should have_selector 'a', text: 'Plums & Avos'
|
||||
page.should have_selector "input[value='2014-10-17 06:00:00 +1100']"
|
||||
page.should have_selector "input[value='2014-10-24 17:00:00 +1100']"
|
||||
|
||||
# And it should have some variants selected
|
||||
oc = OrderCycle.last
|
||||
oc.exchanges.incoming.first.variants.count.should == 2
|
||||
oc.exchanges.outgoing.first.variants.count.should == 2
|
||||
|
||||
# And it should have the fee
|
||||
oc.coordinator_fees.should == [fee]
|
||||
|
||||
# And my pickup time and instructions should have been saved
|
||||
ex = oc.exchanges.outgoing.first
|
||||
ex.pickup_time.should == 'pickup time'
|
||||
ex.pickup_instructions.should == 'pickup instructions'
|
||||
end
|
||||
|
||||
scenario "editing an order cycle" do
|
||||
# Given an order cycle with pickup time and instructions
|
||||
fee = create(:enterprise_fee, name: 'my fee', enterprise: enterprise)
|
||||
oc = create(:simple_order_cycle, suppliers: [enterprise], coordinator: enterprise, distributors: [enterprise], variants: [p1.master], coordinator_fees: [fee])
|
||||
ex = oc.exchanges.outgoing.first
|
||||
ex.update_attributes! pickup_time: 'pickup time', pickup_instructions: 'pickup instructions'
|
||||
|
||||
# When I edit it
|
||||
login_to_admin_section
|
||||
click_link 'Order Cycles'
|
||||
click_link oc.name
|
||||
wait_until { page.find('#order_cycle_name').value.present? }
|
||||
|
||||
# Then I should see the basic settings
|
||||
page.should have_field 'order_cycle_name', with: oc.name
|
||||
page.should have_field 'order_cycle_orders_open_at', with: oc.orders_open_at.to_s
|
||||
page.should have_field 'order_cycle_orders_close_at', with: oc.orders_close_at.to_s
|
||||
page.should have_field 'order_cycle_outgoing_exchange_0_pickup_time', with: 'pickup time'
|
||||
page.should have_field 'order_cycle_outgoing_exchange_0_pickup_instructions', with: 'pickup instructions'
|
||||
|
||||
# And I should see the products
|
||||
page.should have_checked_field "order_cycle_incoming_exchange_0_variants_#{p1.master.id}"
|
||||
page.should have_unchecked_field "order_cycle_incoming_exchange_0_variants_#{p2.master.id}"
|
||||
page.should have_unchecked_field "order_cycle_incoming_exchange_0_variants_#{v.id}"
|
||||
|
||||
# And I should see the coordinator fees
|
||||
page.should have_select 'order_cycle_coordinator_fee_0_id', selected: 'my fee'
|
||||
end
|
||||
|
||||
scenario "updating an order cycle" do
|
||||
# Given an order cycle with pickup time and instructions
|
||||
fee1 = create(:enterprise_fee, name: 'my fee', enterprise: enterprise)
|
||||
fee2 = create(:enterprise_fee, name: 'that fee', enterprise: enterprise)
|
||||
oc = create(:simple_order_cycle, suppliers: [enterprise], coordinator: enterprise, distributors: [enterprise], variants: [p1.master], coordinator_fees: [fee1])
|
||||
ex = oc.exchanges.outgoing.first
|
||||
ex.update_attributes! pickup_time: 'pickup time', pickup_instructions: 'pickup instructions'
|
||||
|
||||
# When I edit it
|
||||
login_to_admin_section
|
||||
visit edit_admin_order_cycle_path oc
|
||||
wait_until { page.find('#order_cycle_name').value.present? }
|
||||
|
||||
# And I fill in the basic fields
|
||||
fill_in 'order_cycle_name', with: 'Plums & Avos'
|
||||
fill_in 'order_cycle_orders_open_at', with: '2014-10-17 06:00:00'
|
||||
fill_in 'order_cycle_orders_close_at', with: '2014-10-24 17:00:00'
|
||||
fill_in 'order_cycle_outgoing_exchange_0_pickup_time', with: 'xy'
|
||||
fill_in 'order_cycle_outgoing_exchange_0_pickup_instructions', with: 'zzy'
|
||||
|
||||
# And I make some product selections
|
||||
uncheck "order_cycle_incoming_exchange_0_variants_#{p1.master.id}"
|
||||
check "order_cycle_incoming_exchange_0_variants_#{p2.master.id}"
|
||||
check "order_cycle_incoming_exchange_0_variants_#{v.id}"
|
||||
uncheck "order_cycle_incoming_exchange_0_variants_#{v.id}"
|
||||
|
||||
# And I select some fees and update
|
||||
click_link 'order_cycle_coordinator_fee_0_remove'
|
||||
page.should_not have_select 'order_cycle_coordinator_fee_0_id'
|
||||
click_button 'Add coordinator fee'
|
||||
select 'that fee', from: 'order_cycle_coordinator_fee_0_id'
|
||||
|
||||
click_button 'Update'
|
||||
|
||||
# Then my order cycle should have been updated
|
||||
page.should have_content 'Your order cycle has been updated.'
|
||||
page.should have_selector 'a', text: 'Plums & Avos'
|
||||
page.should have_selector "input[value='2014-10-17 06:00:00 +1100']"
|
||||
page.should have_selector "input[value='2014-10-24 17:00:00 +1100']"
|
||||
|
||||
# And it should have a variant selected
|
||||
oc = OrderCycle.last
|
||||
oc.exchanges.incoming.first.variants.should == [p2.master]
|
||||
oc.exchanges.outgoing.first.variants.should == [p2.master]
|
||||
|
||||
# And it should have the fee
|
||||
oc.coordinator_fees.should == [fee2]
|
||||
|
||||
# And my pickup time and instructions should have been saved
|
||||
ex = oc.exchanges.outgoing.first
|
||||
ex.pickup_time.should == 'xy'
|
||||
ex.pickup_instructions.should == 'zzy'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user