Speccing and fixing user list loading and adding orders to other users

This commit is contained in:
2014-08-28 18:07:30 +02:00
parent af4510cdc6
commit 14791df379
9 changed files with 66 additions and 1 deletions
@@ -68,6 +68,12 @@ App.ApplicationController = Ember.Controller.extend
@set 'list.supplier.orders_in_process_count', data.count @set 'list.supplier.orders_in_process_count', data.count
orders_placed_count: (data)-> orders_placed_count: (data)->
@set 'list.supplier.orders_placed_count', data.count @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)-> setCurrentList: (callback)->
@@ -6,6 +6,7 @@ module Users
lists = List.for_user(current_user, page: params[:page], per_page: params[:per_page].presence || 25) lists = List.for_user(current_user, page: params[:page], per_page: params[:per_page].presence || 25)
#lists.include_relation(:supplier) #lists.include_relation(:supplier)
lists.reject!{|l| l.id == params[:exclude_list]} if params[:exclude_list].present? 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) lists.include_relation(:users, :orders, :supplier)
render json: lists, each_serializer: UserListSerializer, meta: {total_pages: lists.total_pages, page: lists.current_page} #, root: :lists render json: lists, each_serializer: UserListSerializer, meta: {total_pages: lists.total_pages, page: lists.current_page} #, root: :lists
end end
+2 -1
View File
@@ -273,7 +273,8 @@ class List
save 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_users 'orders_placed_count', count: orders_placed_count
broadcast_supplier supplier.id, 'list_update', SupplierListSerializer.new(self).as_json broadcast_supplier supplier.id, 'list_update', SupplierListSerializer.new(self).as_json
@@ -32,3 +32,12 @@ Feature: Active list view
And I wait 1 second And I wait 1 second
Then the user should not see the order in the active list view 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 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
@@ -36,3 +36,15 @@ Feature: Ordering a product as a user
And the user clicks on the user order button And the user clicks on the user order button
Then an order with 2 products 'Heineken beer' should have been created Then an order with 2 products 'Heineken beer' should have been created
And no order for the product 'Apple pie' 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
@@ -13,3 +13,8 @@ end
step "the supplier counters in the user active list view should be updated" do step "the supplier counters in the user active list view should be updated" do
binding.pry binding.pry
end end
step "the original user should see the newly placed order" do
Capybara.session_name = :default
page.should have_content '5 x'
end
@@ -37,6 +37,22 @@ step "there is a signed in user with a placed order" do
step "the user has a placed order" step "the user has a placed order"
end 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| 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) product = @product && @product.name == product_name ? @product : Product.find_by_name(product_name)
find(".order-product-#{product.id} .show-product-description").click 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')|) no_orders_message = page.evaluate_script(%|t('product_orders.no_orders')|)
page.find('.product-orders').text.should == no_orders_message page.find('.product-orders').text.should == no_orders_message
end 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
@@ -13,3 +13,7 @@ end
step "the user clicks on the active list link in the side menu" do step "the user clicks on the active list link in the side menu" do
page.execute_script %|$('.side-menu-active-list').click()| page.execute_script %|$('.side-menu-active-list').click()|
end end
step "the user clicks on the order products link in the side menu" do
page.execute_script %|$('.side-menu-list-products').click()|
end
+2
View File
@@ -44,6 +44,7 @@ General
------- -------
- search for class btn and replace with font awesome correct styling if needed, remove otherwize - search for class btn and replace with font awesome correct styling if needed, remove otherwize
- Implement faye write security
Supplier Supplier
-------- --------
@@ -63,3 +64,4 @@ User
---- ----
- Cleanup user controller - Cleanup user controller
- Subscribe to general faye channels [':version', 'mozo']