From 4e78fa19a3e48764131d8a89de64e203fd54e45e Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 10 Jan 2013 15:29:13 +1100 Subject: [PATCH] Add spec for updating order cycle, minor fixes --- .../admin/order_cycles_controller.rb | 2 +- app/views/admin/order_cycles/_form.html.haml | 2 +- spec/requests/admin/order_cycles_spec.rb | 38 ++++++++++++++++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index 6eef8e5a09..651785e999 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -42,7 +42,7 @@ module Admin if @order_cycle.update_attributes(params[:order_cycle]) OpenFoodWeb::OrderCycleFormApplicator.new(@order_cycle).go! - flash[:notice] = 'Your order cycle has been saved.' + flash[:notice] = 'Your order cycle has been updated.' format.html { redirect_to admin_order_cycles_path } format.json { render :json => {:success => true} } else diff --git a/app/views/admin/order_cycles/_form.html.haml b/app/views/admin/order_cycles/_form.html.haml index 0bbe19529d..dc4a84a9eb 100644 --- a/app/views/admin/order_cycles/_form.html.haml +++ b/app/views/admin/order_cycles/_form.html.haml @@ -31,7 +31,7 @@ %img{'ng-src' => '{{ product.image_url }}'} {{ product.name }} .exchange-product-variant{'ng-repeat' => 'variant in product.variants'} - = check_box_tag 'order_cycle_exchange_{{ $parent.$index }}_exchange_variants_{{ variant.id }}', 1, 1, 'ng-model' => 'exchange.variants[variant.id]', 'id' => 'order_cycle_exchange_{{ $parent.$index }}_exchange_variants_{{ variant.id }}' + = check_box_tag 'order_cycle_exchange_{{ $parent.$parent.$index }}_exchange_variants_{{ variant.id }}', 1, 1, 'ng-model' => 'exchange.variants[variant.id]', 'id' => 'order_cycle_exchange_{{ $parent.$parent.$index }}_exchange_variants_{{ variant.id }}' {{ variant.label }} = select_tag :new_supplier_id, options_from_collection_for_select(Enterprise.is_primary_producer, :id, :name), {'ng-model' => 'new_supplier_id'} diff --git a/spec/requests/admin/order_cycles_spec.rb b/spec/requests/admin/order_cycles_spec.rb index 2ce79f1842..cdccb7c7c0 100644 --- a/spec/requests/admin/order_cycles_spec.rb +++ b/spec/requests/admin/order_cycles_spec.rb @@ -110,15 +110,49 @@ feature %q{ # Given an order cycle with all the settings oc = create(:order_cycle) + # And a coordinating enterprise and a supplying enterprise with some products with variants + create(:enterprise, name: 'My coordinator') + supplier = create(:supplier_enterprise, name: 'My supplier') + product = create(:product, supplier: supplier) + v1 = create(:variant, product: product) + v2 = create(:variant, product: product) + # When I go to its edit page login_to_admin_section click_link 'Order Cycles' click_link oc.name # And I update it - pending + fill_in 'order_cycle_name', with: 'Plums & Avos' + fill_in 'order_cycle_orders_open_at', with: '2012-11-06 06:00:00' + fill_in 'order_cycle_orders_close_at', with: '2012-11-13 17:00:00' + select 'My coordinator', from: 'order_cycle_coordinator_id' - # Then my updates should have been applied + # And I add a supplier and some products + select 'My supplier', from: 'new_supplier_id' + click_button 'Add supplier' + page.all("table.exchanges tr.supplier td.products input").each { |e| e.click } + + uncheck "order_cycle_exchange_1_exchange_variants_2" + check "order_cycle_exchange_2_exchange_variants_#{v1.id}" + check "order_cycle_exchange_2_exchange_variants_#{v2.id}" + + # And I click Update + 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='2012-11-06 06:00:00 UTC']" + page.should have_selector "input[value='2012-11-13 17:00:00 UTC']" + page.should have_content 'My coordinator' + + page.should have_selector 'td.suppliers', text: 'My supplier' + + # And it should have some variants selected + OrderCycle.last.variants.map { |v| v.id }.sort.should == [1, v1.id, v2.id].sort end