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.actions
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.button-text=t 'order.being_processed'
/button.hide.mark-order-active{ action markOrderActive view.content.id}
span.button-icon
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
i.fa.fa-check.fa-stack-2x
i.fa.fa-check.fa-stack-2x
@@ -1,5 +1,6 @@
HomeSectionOption = Ember.SelectOption.extend
select_label: (-> "- #{@get('content.title')}").property('content.title')
valueBinding: 'content.id'
Qsupplier.App.HomeSectionSelectorView = Ember.Select.extend
classNames: 'section_selector'
optionView: HomeSectionOption
+99 -98
View File
@@ -17,42 +17,42 @@ class UserController < Users::ApplicationController
# POST /user/create_list {table_id: 1234}
#DEPRICATED, see order_selected_products, this one now handles list creation as well
def create_list
render nothing: true and return unless current_user.present?
@table = Table.find(params[:table_id])
if @table.occupied?
respond_to do |format|
format.html { redirect_to user_root_path, alert: t('messages.table_is_occupied') }
format.json { render json: json_alert('messages.table_is_occupied')}
end
else
if @list = List.from_table( @table, current_user )
end
respond_to do |format|
format.html { redirect_to user_list_products_path }
format.json { render json: json_notice('messages.new_list_created')}
end
end
end
#def create_list
#render nothing: true and return unless current_user.present?
#@table = Table.find(params[:table_id])
#if @table.occupied?
#respond_to do |format|
#format.html { redirect_to user_root_path, alert: t('messages.table_is_occupied') }
#format.json { render json: json_alert('messages.table_is_occupied')}
#end
#else
#if @list = List.from_table( @table, current_user )
#end
#respond_to do |format|
#format.html { redirect_to user_list_products_path }
#format.json { render json: json_notice('messages.new_list_created')}
#end
#end
#end
# GET /user/table_info.json
def table_info
respond_to do |format|
format.json do
render json: json_alert('messages.table_not_found') and return unless params[:table_id].present?
@table = Table.find(params[:table_id])
res = {}
res[:occupied] = @table.occupied?
res[:reserved] = @table.reserved?
res[:supplier_closed] = @table.supplier.closed?
if list.present?
res[:other_supplier] = true if list.supplier_id != @table.supplier_id
res[:current_table_id] = list.table_id
end
render json: res
end
end
end
#def table_info
#respond_to do |format|
#format.json do
#render json: json_alert('messages.table_not_found') and return unless params[:table_id].present?
#@table = Table.find(params[:table_id])
#res = {}
#res[:occupied] = @table.occupied?
#res[:reserved] = @table.reserved?
#res[:supplier_closed] = @table.supplier.closed?
#if list.present?
#res[:other_supplier] = true if list.supplier_id != @table.supplier_id
#res[:current_table_id] = list.table_id
#end
#render json: res
#end
#end
#end
# GET /suppliers/1/product_list
# GET /suppliers/1/product_list.json
@@ -206,66 +206,67 @@ class UserController < Users::ApplicationController
##
# Displays the closed lists of the user
# GET /user/list_history
def list_history
respond_to do |format|
format.html {}
format.json do
@lists = List.for_user(current_user, page: params[:page], per_page: params[:per_page].presence || 14)
@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}
end
end
end
#def list_history
#respond_to do |format|
#format.html {}
#format.json do
#@lists = List.for_user(current_user, page: params[:page], per_page: params[:per_page].presence || 14)
#@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}
#end
#end
#end
##
# Displays a closed list of the user
# GET /user/list_history/:list_id
def history_list
respond_to do |format|
format.html do
end
format.json do
@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)
if params[:list_closed].present? && current_user.active_list_id == @list.id
current_user.list_is_closed!
flash.now[:notice] = t('messages.the_list_has_been_closed', list: List.model_name.human)
end
render json: @list.with_orders_as_json.merge(supplier_name: @list.supplier.name)
end
end
end
#def history_list
#respond_to do |format|
#format.html do
#end
#format.json do
#@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)
#if params[:list_closed].present? && current_user.active_list_id == @list.id
#current_user.list_is_closed!
#flash.now[:notice] = t('messages.the_list_has_been_closed', list: List.model_name.human)
#end
#render json: @list.with_orders_as_json.merge(supplier_name: @list.supplier.name)
#end
#end
#end
# POST /user/order_selected_products.json
def order_selected_products
if list.present?
@list = list
else
render json: json_alert('messages.table_not_found') and return unless params[:table_id].present?
@table = Table.find(params[:table_id])
if @table.occupied?
render json: json_alert('messages.table_is_occupied', location: :join_occupied_table, location_params: {table_id: @table.id})
else
if @list = List.from_table( @table, current_user )
else
#TODO handle second list creation for user
end
end
end
respond_to do |format|
format.html do
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
redirect_to user_root_path, notice: t('messages.order_is_placed')
end
format.json do
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
render json: json_notice('messages.order_is_placed', location: :active_list)
end
end
end
#def order_selected_products
#if list.present?
#@list = list
#else
#render json: json_alert('messages.table_not_found') and return unless params[:table_id].present?
#@table = Table.find(params[:table_id])
#if @table.occupied?
#render json: json_alert('messages.table_is_occupied', location: :join_occupied_table, location_params: {table_id: @table.id})
#else
#if @list = List.from_table( @table, current_user )
#else
##TODO handle second list creation for user
#end
#end
#end
#respond_to do |format|
#format.html do
#redirect_to(user_root_path, alert: t('messages.cannot_order_on_non_active_list')) and return unless @list.active?
#@list.place_order products: params[:products], user: current_user
#redirect_to user_root_path, notice: t('messages.order_is_placed')
#end
#format.json do
#render json: json_alert('messages.cannot_order_on_non_active_list') and return unless @list.active?
## Todo, better document and uniform this
#@list.place_order products: (params[:order] || params[:products]), user: current_user
#render json: json_notice('messages.order_is_placed', location: :active_list)
#end
#end
#end
def obtain_token
redirect_to user_omniauth_authorize_path('facebook') and return unless current_user.present?
@@ -284,15 +285,15 @@ class UserController < Users::ApplicationController
end
end
def move_table
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?
@table = Table.find(params[:table_id])
if @table.occupied?
render json: {occupied: true}
else
list.move_to_table! @table
render json: {occupied: false}
end
end
#def move_table
#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?
#@table = Table.find(params[:table_id])
#if @table.occupied?
#render json: {occupied: true}
#else
#list.move_to_table! @table
#render json: {occupied: false}
#end
#end
end
+3 -1
View File
@@ -1,6 +1,8 @@
module Users
class OrdersController < Users::ApplicationController
respond_to :json
# Used by the user Ember app
def create
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] }
@@ -18,7 +20,7 @@ module Users
list = List.from_table( table, current_user )
end
order = list.place_order converted_order
order = list.place_order products: converted_order, user: current_user
render json: order, serializer: OrderSerializer
end
end
+1 -1
View File
@@ -22,7 +22,7 @@ class WaiterController < ApplicationController
def order_products
@table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:table_id])
@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
end
+5 -5
View File
@@ -205,10 +205,10 @@ class List
self.section_id = to_table.section_id
if save
# Update the section of an order
#orders.each do |order|
#order.section_id = self.section_id
#order.save
#end
orders.each do |order|
order.section_id = self.section_id
order.save
end
# 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_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'
end
def place_order(products, user: nil, employee: nil)
def place_order(products: {}, user: nil, employee: nil)
return false unless products.any?
order = Order.create list: self, supplier: supplier, user: user, employee: employee, section_id: section_id, table_id: table_id
return unless order.id
+1
View File
@@ -19,6 +19,7 @@ en:
timeout: "Your session expired. Please sign in again to continue."
unauthenticated: "You need to sign in or sign up 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:
confirmation_instructions:
supplier_subject: "Confirmation instructions2"
+1
View File
@@ -27,6 +27,7 @@ nl:
invalid_token: 'Invalid authentication token.'
timeout: 'Uw sessie is verlopen. U moet opnieuw inloggen om verder te gaan.'
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:
title: Inloggen
button: Inloggen
@@ -9,12 +9,14 @@ Feature: Supplier main board
Then the supplier dashboard should display the active list
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
And I wait 1 second
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
Then the order in the supplier dashboard should not be displayed anymore
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_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_order = @new_list.place_order @user, {@product.id => 3}
@new_order = @new_list.place_order(products: {@product.id => 3}, user: @user)
end
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
end
step "I click on selector :selector" do |selector|
find(selector).click
end
step 'I visit :path' do |path|
visit path
end
+1 -1
View File
@@ -9,7 +9,7 @@ step "the order should be marked as delivered" do
end
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
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
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
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
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
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
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
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
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
describe 'broadcasting' 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{
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)
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)
end
end
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.price.should == 15.54
end