diff --git a/app/assets/javascripts/user/app/controllers/application_controller.js.coffee b/app/assets/javascripts/user/app/controllers/application_controller.js.coffee index 82b1c400..b59686e6 100644 --- a/app/assets/javascripts/user/app/controllers/application_controller.js.coffee +++ b/app/assets/javascripts/user/app/controllers/application_controller.js.coffee @@ -68,6 +68,12 @@ App.ApplicationController = Ember.Controller.extend @set 'list.supplier.orders_in_process_count', data.count orders_placed_count: (data)-> @set 'list.supplier.orders_placed_count', data.count + new_order: (data)-> + return if @store.all('order').findProperty('id', data.order.id) + @store.pushPayload data + @store.findById('order', data.order.id).then (order)-> + list = order.get('list') + list.get('orders').addObject(order) setCurrentList: (callback)-> diff --git a/app/controllers/users/lists_controller.rb b/app/controllers/users/lists_controller.rb index e4e378fe..eabf4356 100644 --- a/app/controllers/users/lists_controller.rb +++ b/app/controllers/users/lists_controller.rb @@ -6,6 +6,7 @@ module Users lists = List.for_user(current_user, page: params[:page], per_page: params[:per_page].presence || 25) #lists.include_relation(:supplier) lists.reject!{|l| l.id == params[:exclude_list]} if params[:exclude_list].present? + lists.reject!{|l| l.id == current_user.active_list_id } if current_user && current_user.active_list_id.present? # see spec Loading lists and switching to the order products view works, lists loading may unlink active list orders lists.include_relation(:users, :orders, :supplier) render json: lists, each_serializer: UserListSerializer, meta: {total_pages: lists.total_pages, page: lists.current_page} #, root: :lists end diff --git a/app/models/list.rb b/app/models/list.rb index 0855c756..ae0f72d3 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -273,7 +273,8 @@ class List save - broadcast_users 'new_order', order: order.with_products_as_json, total_amount: price + # broadcast_users 'new_order', order: order.with_products_as_json, total_amount: price + broadcast_users 'new_order', OrderSerializer.new(order).as_json broadcast_users 'orders_placed_count', count: orders_placed_count broadcast_supplier supplier.id, 'list_update', SupplierListSerializer.new(self).as_json diff --git a/spec/acceptance/users/active_list.feature b/spec/acceptance/users/active_list.feature index cfe96e83..0e38edff 100644 --- a/spec/acceptance/users/active_list.feature +++ b/spec/acceptance/users/active_list.feature @@ -32,3 +32,12 @@ Feature: Active list view And I wait 1 second Then the user should not see the order in the active list view And the supplier orders in process counter for the user should be 0 + + @javascript + Scenario: Two users on the same list when one place an order + Given There is an open supplier with a menu + And there is a signed in user with an active order + And the user is on the active list page + And there is another signed in user on the same list + When the other user orders a product 5 times + Then the original user should see the newly placed order diff --git a/spec/acceptance/users/order_a_product.feature b/spec/acceptance/users/order_a_product.feature index f094eeff..f7e78a19 100644 --- a/spec/acceptance/users/order_a_product.feature +++ b/spec/acceptance/users/order_a_product.feature @@ -36,3 +36,15 @@ Feature: Ordering a product as a user And the user clicks on the user order button Then an order with 2 products 'Heineken beer' should have been created And no order for the product 'Apple pie' should have been created + + @javascript + Scenario: Loading lists and switching to the order products view works, lists loading may unlink active list orders + Given There is an open supplier with a menu + And there is a signed in user with an active order + And I wait 1 second + And the user is on the order products page + When the user opens the side menu + And the user clicks on the lists link in the side menu + And the user opens the side menu again + And the user clicks on the order products link in the side menu + Then the user should see the products listed for the active list diff --git a/spec/acceptance_steps/users/active_list_steps.rb b/spec/acceptance_steps/users/active_list_steps.rb index 4eab4223..fbb7d0ee 100644 --- a/spec/acceptance_steps/users/active_list_steps.rb +++ b/spec/acceptance_steps/users/active_list_steps.rb @@ -13,3 +13,8 @@ end step "the supplier counters in the user active list view should be updated" do binding.pry end + +step "the original user should see the newly placed order" do + Capybara.session_name = :default + page.should have_content '5 x' +end diff --git a/spec/acceptance_steps/users/order_products_steps.rb b/spec/acceptance_steps/users/order_products_steps.rb index 056f8455..99f0a336 100644 --- a/spec/acceptance_steps/users/order_products_steps.rb +++ b/spec/acceptance_steps/users/order_products_steps.rb @@ -37,6 +37,22 @@ step "there is a signed in user with a placed order" do step "the user has a placed order" end +step "there is another signed in user on the same list" do + step 'there is another signed in user user' + step 'the other user is part of the list' +end + +step 'the other user orders a product :count times' do |count| + @list.place_order products: {@product.id => count.to_i}, user: @other_user +end + +step 'the other user is part of the list' do + @other_user.active_list_id = @list.id + @list.user_ids = @list.user_ids | [@other_user.id] + @other_user.save + @list.save +end + step "the user clicks on the more info button for the product with name :product_name" do |product_name| product = @product && @product.name == product_name ? @product : Product.find_by_name(product_name) find(".order-product-#{product.id} .show-product-description").click @@ -80,3 +96,12 @@ step "the user should see an empty active order panel" do no_orders_message = page.evaluate_script(%|t('product_orders.no_orders')|) page.find('.product-orders').text.should == no_orders_message end + +step 'the user is on the order products page' do + visit "/user#/tables/#{@table.id}" +end + +step 'the user should see the products listed for the active list' do + page.should have_content @heineken_beer.name + page.should have_content @apple_pie.name +end diff --git a/spec/acceptance_steps/users/side_menu_steps.rb b/spec/acceptance_steps/users/side_menu_steps.rb index 79752f2f..24feb25f 100644 --- a/spec/acceptance_steps/users/side_menu_steps.rb +++ b/spec/acceptance_steps/users/side_menu_steps.rb @@ -13,3 +13,7 @@ end step "the user clicks on the active list link in the side menu" do page.execute_script %|$('.side-menu-active-list').click()| end + +step "the user clicks on the order products link in the side menu" do + page.execute_script %|$('.side-menu-list-products').click()| +end diff --git a/wip.md b/wip.md index 0843003e..63e2514a 100644 --- a/wip.md +++ b/wip.md @@ -44,6 +44,7 @@ General ------- - search for class btn and replace with font awesome correct styling if needed, remove otherwize +- Implement faye write security Supplier -------- @@ -63,3 +64,4 @@ User ---- - Cleanup user controller +- Subscribe to general faye channels [':version', 'mozo']