Fix list unit and supplier main board acceptance specs

This commit is contained in:
2014-05-28 15:16:08 +02:00
parent 4855b2e8e0
commit e9554ea3e7
14 changed files with 133 additions and 121 deletions
@@ -7,13 +7,13 @@ td.section_title {{view.content.section.title}}
td.currency {{currency view.content.total }} td.currency {{currency view.content.total }}
td.actions td.actions
if view.content.placed if view.content.placed
/button.mark_order_active{ action markOrderActive view.content.id} button.mark_order_active{ action markOrderActive view.content.id}
span.fa.fa-check.fa-2x span.fa.fa-check.fa-2x
/span.button-text=t 'order.being_processed' /span.button-text=t 'order.being_processed'
/button.hide.mark-order-active{ action markOrderActive view.content.id} /button.hide.mark-order-active{ action markOrderActive view.content.id}
span.button-icon span.button-icon
span.button-text=t 'order.being_processed' span.button-text=t 'order.being_processed'
/button.mark_order_delivered{ action markOrderDelivered view.content.id} button.mark_order_delivered{ action markOrderDelivered view.content.id}
span.fa-shifted-stack span.fa-shifted-stack
i.fa.fa-check.fa-stack-2x i.fa.fa-check.fa-stack-2x
i.fa.fa-check.fa-stack-2x i.fa.fa-check.fa-stack-2x
@@ -1,5 +1,6 @@
HomeSectionOption = Ember.SelectOption.extend HomeSectionOption = Ember.SelectOption.extend
select_label: (-> "- #{@get('content.title')}").property('content.title') select_label: (-> "- #{@get('content.title')}").property('content.title')
valueBinding: 'content.id'
Qsupplier.App.HomeSectionSelectorView = Ember.Select.extend Qsupplier.App.HomeSectionSelectorView = Ember.Select.extend
classNames: 'section_selector' classNames: 'section_selector'
optionView: HomeSectionOption optionView: HomeSectionOption
+99 -98
View File
@@ -17,42 +17,42 @@ class UserController < Users::ApplicationController
# POST /user/create_list {table_id: 1234} # POST /user/create_list {table_id: 1234}
#DEPRICATED, see order_selected_products, this one now handles list creation as well #DEPRICATED, see order_selected_products, this one now handles list creation as well
def create_list #def create_list
render nothing: true and return unless current_user.present? #render nothing: true and return unless current_user.present?
@table = Table.find(params[:table_id]) #@table = Table.find(params[:table_id])
if @table.occupied? #if @table.occupied?
respond_to do |format| #respond_to do |format|
format.html { redirect_to user_root_path, alert: t('messages.table_is_occupied') } #format.html { redirect_to user_root_path, alert: t('messages.table_is_occupied') }
format.json { render json: json_alert('messages.table_is_occupied')} #format.json { render json: json_alert('messages.table_is_occupied')}
end #end
else #else
if @list = List.from_table( @table, current_user ) #if @list = List.from_table( @table, current_user )
end #end
respond_to do |format| #respond_to do |format|
format.html { redirect_to user_list_products_path } #format.html { redirect_to user_list_products_path }
format.json { render json: json_notice('messages.new_list_created')} #format.json { render json: json_notice('messages.new_list_created')}
end #end
end #end
end #end
# GET /user/table_info.json # GET /user/table_info.json
def table_info #def table_info
respond_to do |format| #respond_to do |format|
format.json do #format.json do
render json: json_alert('messages.table_not_found') and return unless params[:table_id].present? #render json: json_alert('messages.table_not_found') and return unless params[:table_id].present?
@table = Table.find(params[:table_id]) #@table = Table.find(params[:table_id])
res = {} #res = {}
res[:occupied] = @table.occupied? #res[:occupied] = @table.occupied?
res[:reserved] = @table.reserved? #res[:reserved] = @table.reserved?
res[:supplier_closed] = @table.supplier.closed? #res[:supplier_closed] = @table.supplier.closed?
if list.present? #if list.present?
res[:other_supplier] = true if list.supplier_id != @table.supplier_id #res[:other_supplier] = true if list.supplier_id != @table.supplier_id
res[:current_table_id] = list.table_id #res[:current_table_id] = list.table_id
end #end
render json: res #render json: res
end #end
end #end
end #end
# GET /suppliers/1/product_list # GET /suppliers/1/product_list
# GET /suppliers/1/product_list.json # GET /suppliers/1/product_list.json
@@ -206,66 +206,67 @@ class UserController < Users::ApplicationController
## ##
# Displays the closed lists of the user # Displays the closed lists of the user
# GET /user/list_history # GET /user/list_history
def list_history #def list_history
respond_to do |format| #respond_to do |format|
format.html {} #format.html {}
format.json do #format.json do
@lists = List.for_user(current_user, page: params[:page], per_page: params[:per_page].presence || 14) #@lists = List.for_user(current_user, page: params[:page], per_page: params[:per_page].presence || 14)
@lists.include_relation(:supplier) #@lists.include_relation(:supplier)
render json: @lists.inject(lists: [], current_page: @lists.current_page, num_pages: @lists.num_pages, total_count: @lists.total_count){|h, l| h[:lists] << l.as_json.merge(supplier_name: l.supplier.name); h} #render json: @lists.inject(lists: [], current_page: @lists.current_page, num_pages: @lists.num_pages, total_count: @lists.total_count){|h, l| h[:lists] << l.as_json.merge(supplier_name: l.supplier.name); h}
end #end
end #end
end #end
## ##
# Displays a closed list of the user # Displays a closed list of the user
# GET /user/list_history/:list_id # GET /user/list_history/:list_id
def history_list #def history_list
respond_to do |format| #respond_to do |format|
format.html do #format.html do
end #end
format.json do #format.json do
@list = List.find(params[:list_id]) #@list = List.find(params[:list_id])
render json: json_alert('messages.illegal_history_list_attempt') and return unless @list.user_ids.include?(current_user.id) #render json: json_alert('messages.illegal_history_list_attempt') and return unless @list.user_ids.include?(current_user.id)
if params[:list_closed].present? && current_user.active_list_id == @list.id #if params[:list_closed].present? && current_user.active_list_id == @list.id
current_user.list_is_closed! #current_user.list_is_closed!
flash.now[:notice] = t('messages.the_list_has_been_closed', list: List.model_name.human) #flash.now[:notice] = t('messages.the_list_has_been_closed', list: List.model_name.human)
end #end
render json: @list.with_orders_as_json.merge(supplier_name: @list.supplier.name) #render json: @list.with_orders_as_json.merge(supplier_name: @list.supplier.name)
end #end
end #end
end #end
# POST /user/order_selected_products.json # POST /user/order_selected_products.json
def order_selected_products #def order_selected_products
if list.present? #if list.present?
@list = list #@list = list
else #else
render json: json_alert('messages.table_not_found') and return unless params[:table_id].present? #render json: json_alert('messages.table_not_found') and return unless params[:table_id].present?
@table = Table.find(params[:table_id]) #@table = Table.find(params[:table_id])
if @table.occupied? #if @table.occupied?
render json: json_alert('messages.table_is_occupied', location: :join_occupied_table, location_params: {table_id: @table.id}) #render json: json_alert('messages.table_is_occupied', location: :join_occupied_table, location_params: {table_id: @table.id})
else #else
if @list = List.from_table( @table, current_user ) #if @list = List.from_table( @table, current_user )
else #else
#TODO handle second list creation for user ##TODO handle second list creation for user
end #end
end #end
end #end
respond_to do |format| #respond_to do |format|
format.html do #format.html do
redirect_to(user_root_path, alert: t('messages.cannot_order_on_non_active_list')) and return unless @list.active? #redirect_to(user_root_path, alert: t('messages.cannot_order_on_non_active_list')) and return unless @list.active?
@list.place_order params[:products], user: current_user #@list.place_order products: params[:products], user: current_user
redirect_to user_root_path, notice: t('messages.order_is_placed') #redirect_to user_root_path, notice: t('messages.order_is_placed')
end #end
format.json do #format.json do
render json: json_alert('messages.cannot_order_on_non_active_list') and return unless @list.active? #render json: json_alert('messages.cannot_order_on_non_active_list') and return unless @list.active?
@list.place_order params[:order] || params[:products], user: current_user ## Todo, better document and uniform this
render json: json_notice('messages.order_is_placed', location: :active_list) #@list.place_order products: (params[:order] || params[:products]), user: current_user
end #render json: json_notice('messages.order_is_placed', location: :active_list)
end #end
end #end
#end
def obtain_token def obtain_token
redirect_to user_omniauth_authorize_path('facebook') and return unless current_user.present? redirect_to user_omniauth_authorize_path('facebook') and return unless current_user.present?
@@ -284,15 +285,15 @@ class UserController < Users::ApplicationController
end end
end end
def move_table #def move_table
render json: json_alert('messages.no_active_list', list_active: false) and return unless list.present? #render json: json_alert('messages.no_active_list', list_active: false) and return unless list.present?
render json: json_alert('messages.table_not_found') and return unless params[:table_id].present? #render json: json_alert('messages.table_not_found') and return unless params[:table_id].present?
@table = Table.find(params[:table_id]) #@table = Table.find(params[:table_id])
if @table.occupied? #if @table.occupied?
render json: {occupied: true} #render json: {occupied: true}
else #else
list.move_to_table! @table #list.move_to_table! @table
render json: {occupied: false} #render json: {occupied: false}
end #end
end #end
end end
+3 -1
View File
@@ -1,6 +1,8 @@
module Users module Users
class OrdersController < Users::ApplicationController class OrdersController < Users::ApplicationController
respond_to :json respond_to :json
# Used by the user Ember app
def create def create
render json: {}, status: :unprocessable_entity and return unless params[:order].present? && params[:order][:product_orders].present? render json: {}, status: :unprocessable_entity and return unless params[:order].present? && params[:order][:product_orders].present?
converted_order = params[:order][:product_orders].each_with_object({}){|po, o| o[po[:product_id]] = po[:quantity] } converted_order = params[:order][:product_orders].each_with_object({}){|po, o| o[po[:product_id]] = po[:quantity] }
@@ -18,7 +20,7 @@ module Users
list = List.from_table( table, current_user ) list = List.from_table( table, current_user )
end end
order = list.place_order converted_order order = list.place_order products: converted_order, user: current_user
render json: order, serializer: OrderSerializer render json: order, serializer: OrderSerializer
end end
end end
+1 -1
View File
@@ -22,7 +22,7 @@ class WaiterController < ApplicationController
def order_products def order_products
@table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:table_id]) @table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:table_id])
@list = List.from_table_by_employee(@table, current_employee) @list = List.from_table_by_employee(@table, current_employee)
@list.place_order params[:order], employee: current_employee @list.place_order products: params[:order], employee: current_employee
render nothing: true render nothing: true
end end
+5 -5
View File
@@ -205,10 +205,10 @@ class List
self.section_id = to_table.section_id self.section_id = to_table.section_id
if save if save
# Update the section of an order # Update the section of an order
#orders.each do |order| orders.each do |order|
#order.section_id = self.section_id order.section_id = self.section_id
#order.save order.save
#end end
# user performs a client side refresh # user performs a client side refresh
broadcast_users 'list_changed_table', list_id: id #, from_table_id: from_table, to_table_id: to_table.id broadcast_users 'list_changed_table', list_id: id #, from_table_id: from_table, to_table_id: to_table.id
broadcast_supplier supplier_id, 'list_changed_table', list: as_json, section_title: to_table.section.try(:title), from_table_id: from_table broadcast_supplier supplier_id, 'list_changed_table', list: as_json, section_title: to_table.section.try(:title), from_table_id: from_table
@@ -288,7 +288,7 @@ class List
state == 'active' state == 'active'
end end
def place_order(products, user: nil, employee: nil) def place_order(products: {}, user: nil, employee: nil)
return false unless products.any? return false unless products.any?
order = Order.create list: self, supplier: supplier, user: user, employee: employee, section_id: section_id, table_id: table_id order = Order.create list: self, supplier: supplier, user: user, employee: employee, section_id: section_id, table_id: table_id
return unless order.id return unless order.id
+1
View File
@@ -19,6 +19,7 @@ en:
timeout: "Your session expired. Please sign in again to continue." timeout: "Your session expired. Please sign in again to continue."
unauthenticated: "You need to sign in or sign up before continuing." unauthenticated: "You need to sign in or sign up before continuing."
unconfirmed: "You have to confirm your account before continuing." unconfirmed: "You have to confirm your account before continuing."
not_found_in_database: "You are not yet known in our system. Sign up to use Qwaiter!"
mailer: mailer:
confirmation_instructions: confirmation_instructions:
supplier_subject: "Confirmation instructions2" supplier_subject: "Confirmation instructions2"
+1
View File
@@ -27,6 +27,7 @@ nl:
invalid_token: 'Invalid authentication token.' invalid_token: 'Invalid authentication token.'
timeout: 'Uw sessie is verlopen. U moet opnieuw inloggen om verder te gaan.' timeout: 'Uw sessie is verlopen. U moet opnieuw inloggen om verder te gaan.'
inactive: 'Your account was not activated yet.' inactive: 'Your account was not activated yet.'
not_found_in_database: "Je bent nog niet bij ons bekend. Meld je aan om Qwaiter te kunnen gebruiken!"
sessions: sessions:
title: Inloggen title: Inloggen
button: Inloggen button: Inloggen
@@ -9,12 +9,14 @@ Feature: Supplier main board
Then the supplier dashboard should display the active list Then the supplier dashboard should display the active list
And the supplier dashboard should display the active order And the supplier dashboard should display the active order
When I click on translation 'supplier.order.being_processed' #When I click on translation 'supplier.order.being_processed'
When I click on selector '.active-orders-table .mark_order_active'
# waiting here only needed in old style implementation # waiting here only needed in old style implementation
And I wait 1 second And I wait 1 second
Then the supplier order row should be marked as active Then the supplier order row should be marked as active
When I click on translation 'supplier.order.being_served' #When I click on translation 'supplier.order.being_served'
When I click on selector '.active-orders-table .mark_order_delivered'
And I wait 1 second And I wait 1 second
Then the order in the supplier dashboard should not be displayed anymore Then the order in the supplier dashboard should not be displayed anymore
And the order should be marked as delivered And the order should be marked as delivered
+1 -1
View File
@@ -23,7 +23,7 @@ step 'a new order on a table in another section is created' do
@new_section = create :section, title: 'Terrace', supplier: @supplier @new_section = create :section, title: 'Terrace', supplier: @supplier
@new_table = create :table, number: 59, section: @new_section, supplier: @supplier @new_table = create :table, number: 59, section: @new_section, supplier: @supplier
@new_list = create :list, section: @new_section, table: @new_table, supplier: @supplier, user_ids: [@user.id] @new_list = create :list, section: @new_section, table: @new_table, supplier: @supplier, user_ids: [@user.id]
@new_order = @new_list.place_order @user, {@product.id => 3} @new_order = @new_list.place_order(products: {@product.id => 3}, user: @user)
end end
step "I am signed in as a user" do step "I am signed in as a user" do
+4
View File
@@ -9,6 +9,10 @@ step "I click on translation :translation" do |translation_key|
click_on text click_on text
end end
step "I click on selector :selector" do |selector|
find(selector).click
end
step 'I visit :path' do |path| step 'I visit :path' do |path|
visit path visit path
end end
+1 -1
View File
@@ -9,7 +9,7 @@ step "the order should be marked as delivered" do
end end
step "another order is placed" do step "another order is placed" do
@new_order = @list.place_order @user, {@product.id => 5} @new_order = @list.place_order(products: {@product.id => 5}, user: @user)
end end
step "the user order should be created as a new order" do step "the user order should be created as a new order" do
@@ -33,19 +33,19 @@ step "the order in the supplier dashboard should not be displayed anymore" do
end end
step "the list on the supplier dashboard should not be marked as in need of help" do step "the list on the supplier dashboard should not be marked as in need of help" do
page.should_not have_selector(".list-row-#{@list.id} .list-needs-help-indicator") page.should_not have_selector(".list-row-#{@list.id} .icon.needs-help")
end end
step "the list on the supplier dashboard should be marked as in need of help" do step "the list on the supplier dashboard should be marked as in need of help" do
page.should have_selector(".list-row-#{@list.id} .list-needs-help-indicator") page.should have_selector(".list-row-#{@list.id} .icon.needs-help")
end end
step "the list on the supplier dashboard should not be marked as in need of payment" do step "the list on the supplier dashboard should not be marked as in need of payment" do
page.should_not have_selector(".list-row-#{@list.id} .list-needs-payment-indicator") page.should_not have_selector(".list-row-#{@list.id} .icon.needs-payment")
end end
step "the list on the supplier dashboard should be marked as in need of payment" do step "the list on the supplier dashboard should be marked as in need of payment" do
page.should have_selector(".list-row-#{@list.id} .list-needs-payment-indicator") page.should have_selector(".list-row-#{@list.id} .icon.needs-payment")
end end
step "the supplier dashboard list should display the updated price" do step "the supplier dashboard list should display the updated price" do
+6 -6
View File
@@ -125,29 +125,29 @@ describe List do
describe '#place_order' do describe '#place_order' do
it 'returns an order object' do it 'returns an order object' do
list.place_order(product.id => 7, user: user).should be_a Order list.place_order(products: {product.id => 7}, user: user).should be_a Order
end end
it 'creates an order' do it 'creates an order' do
expect{ list.place_order(product.id => 7, user: user) }.to change{ Order.count }.by(1) expect{ list.place_order(products: {product.id => 7}, user: user) }.to change{ Order.count }.by(1)
end end
describe 'broadcasting' do describe 'broadcasting' do
it 'broadcasts to the user and the supplier the active order counter' do it 'broadcasts to the user and the supplier the active order counter' do
list.place_order(product.id => 7, user: user) list.place_order(products: {product.id => 7}, user: user)
expect{ expect{
list.place_order(product.id => 3, user: user) list.place_order(products: {product.id => 3}, user: user)
}.to broadcast_to_user(user.id).message('orders_placed_count').with(count: 2) }.to broadcast_to_user(user.id).message('orders_placed_count').with(count: 2)
expect{ expect{
list.place_order(product.id => 5, user: user) list.place_order(products: {product.id => 5}, user: user)
}.to broadcast_to_supplier(supplier.id).message('orders_placed_count').with(count: 3) }.to broadcast_to_supplier(supplier.id).message('orders_placed_count').with(count: 3)
end end
end end
it 'sets the list price as kind of caching' do it 'sets the list price as kind of caching' do
list.place_order(product.id => 7, user: user) list.place_order(products: {product.id => 7}, user: user)
list.reload list.reload
list.price.should == 15.54 list.price.should == 15.54
end end