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
+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