changing table user acceptance specs in the green
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
App.SelectQrcodeController = Ember.Controller.extend
|
App.SelectQrcodeController = Ember.Controller.extend
|
||||||
actions:
|
actions:
|
||||||
selectQr: (table)->
|
selectQr: (table)->
|
||||||
Qstorage.setItem 'table_id', table._id
|
|
||||||
@secured ->
|
@secured ->
|
||||||
$.getJSON($data_host + '/user/table_info.json?'+@authentication_string+'&table_id='+table._id).then (res)=>
|
$.getJSON($data_host + '/user/table_info.json?'+@authentication_string+'&table_id='+table._id).then (res)=>
|
||||||
if res.current_table_id
|
if res.current_table_id
|
||||||
@@ -29,6 +28,8 @@ App.SelectQrcodeController = Ember.Controller.extend
|
|||||||
if res2.occupied
|
if res2.occupied
|
||||||
@redirect_to 'user_root', message: 'move_table.cannot_move_to_occupied_tabe'
|
@redirect_to 'user_root', message: 'move_table.cannot_move_to_occupied_tabe'
|
||||||
else
|
else
|
||||||
|
# Now we can move table
|
||||||
|
Qstorage.setItem 'table_id', table._id
|
||||||
@redirect_to 'table', table._id, message: 'move_table.moved_to_another_table'
|
@redirect_to 'table', table._id, message: 'move_table.moved_to_another_table'
|
||||||
cancel: =>
|
cancel: =>
|
||||||
@redirect_to 'table', res.current_table_id
|
@redirect_to 'table', res.current_table_id
|
||||||
|
|||||||
@@ -2,5 +2,5 @@ modal-dialog action="close"
|
|||||||
h3.flush--top= title
|
h3.flush--top= title
|
||||||
p=body
|
p=body
|
||||||
hr
|
hr
|
||||||
button{action "close"}= t 'confirm.cancel'
|
button.confirm-cancel{action "close"}= t 'confirm.cancel'
|
||||||
button.right{action 'confirm'}= t 'confirm.confirm'
|
button.confirm-ok.right{action 'confirm'}= t 'confirm.confirm'
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
each table in tables
|
each table in tables
|
||||||
img{action selectQr table} src="/table_qr_image.svg?table_id=#{unbound table._id}"
|
a{action selectQr table}: img src="/table_qr_image.svg?table_id=#{unbound table._id}"
|
||||||
|
|||||||
@@ -8,7 +8,11 @@ class DashboardController < ApplicationController
|
|||||||
# Testing action
|
# Testing action
|
||||||
def select_qrcode
|
def select_qrcode
|
||||||
#@tables = Table.all.sample(2) | List.active.map(&:table)
|
#@tables = Table.all.sample(2) | List.active.map(&:table)
|
||||||
@tables = (current_supplier || Supplier.first).tables.sample(5) | List.active.map(&:table)
|
if Rails.env.test?
|
||||||
|
@tables = Table.all
|
||||||
|
else
|
||||||
|
@tables = (current_supplier || Supplier.first).tables.sample(5) | List.active.map(&:table)
|
||||||
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render layout: 'phone' }
|
format.html { render layout: 'phone' }
|
||||||
format.json { render json: @tables.to_json }
|
format.json { render json: @tables.to_json }
|
||||||
|
|||||||
@@ -36,23 +36,51 @@ class UserController < Users::ApplicationController
|
|||||||
#end
|
#end
|
||||||
|
|
||||||
# GET /user/table_info.json
|
# GET /user/table_info.json
|
||||||
#def table_info
|
# used for moving table request
|
||||||
#respond_to do |format|
|
# TODO wrap logic of actions
|
||||||
#format.json do
|
# - table_info
|
||||||
#render json: json_alert('messages.table_not_found') and return unless params[:table_id].present?
|
# - move_table
|
||||||
#@table = Table.find(params[:table_id])
|
# into separate class and implement security in a non stupid way as it is now
|
||||||
#res = {}
|
def table_info
|
||||||
#res[:occupied] = @table.occupied?
|
respond_to do |format|
|
||||||
#res[:reserved] = @table.reserved?
|
format.json do
|
||||||
#res[:supplier_closed] = @table.supplier.closed?
|
render json: json_alert('messages.table_not_found') and return unless params[:table_id].present?
|
||||||
#if list.present?
|
@table = Table.find(params[:table_id])
|
||||||
#res[:other_supplier] = true if list.supplier_id != @table.supplier_id
|
res = {}
|
||||||
#res[:current_table_id] = list.table_id
|
res[:occupied] = @table.occupied?
|
||||||
#end
|
res[:reserved] = @table.reserved?
|
||||||
#render json: res
|
res[:supplier_closed] = @table.supplier.closed?
|
||||||
#end
|
if list.present?
|
||||||
#end
|
res[:other_supplier] = true if list.supplier_id != @table.supplier_id
|
||||||
#end
|
res[:current_table_id] = list.table_id
|
||||||
|
end
|
||||||
|
render json: res
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /user/move_table.json
|
||||||
|
# used to move the table
|
||||||
|
# TODO wrap logic of actions
|
||||||
|
# - table_info
|
||||||
|
# - move_table
|
||||||
|
# into separate class and implement security in a non stupid way as it is now
|
||||||
|
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}
|
||||||
|
elsif @table.reserved?
|
||||||
|
render json: {reserved: true}
|
||||||
|
elsif list.supplier_id != @table.supplier_id
|
||||||
|
res[:other_supplier] = true if list.supplier_id != @table.supplier_id
|
||||||
|
res[:current_table_id] = list.table_id
|
||||||
|
else
|
||||||
|
list.move_to_table! @table
|
||||||
|
render json: {occupied: false, reserved: false}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# GET /suppliers/1/product_list
|
# GET /suppliers/1/product_list
|
||||||
# GET /suppliers/1/product_list.json
|
# GET /suppliers/1/product_list.json
|
||||||
@@ -285,15 +313,4 @@ class UserController < Users::ApplicationController
|
|||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|||||||
@@ -14,8 +14,9 @@ step "the uses indicates in the popup that he wants to change the table" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
step "the user should see the supplier menu having the other table as base" do
|
step "the user should see the supplier menu having the other table as base" do
|
||||||
route_should_be 'user#list_products'
|
#route_should_be 'user#list_products'
|
||||||
find('.table-number').text.should == @other_table.number.to_s
|
page.should have_content 'Apple pie'
|
||||||
|
find('.table-number').text.should == "Tafel #{@other_table.number.to_s}"
|
||||||
end
|
end
|
||||||
|
|
||||||
step "the user list should have been moved to the other table" do
|
step "the user list should have been moved to the other table" do
|
||||||
@@ -32,7 +33,12 @@ step "there is another table with an active list of another user" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
step "the user scans a QR code of another not occupied table" do
|
step "the user scans a QR code of another not occupied table" do
|
||||||
page.execute_script "Quser.actions_for_table({table_id: '#{@other_table.id}'})"
|
r = page.evaluate_script %|
|
||||||
|
c = App.__container__.lookup('controller:select_qrcode');
|
||||||
|
c.send('selectQr', {_id: "#{@other_table.id}"});
|
||||||
|
c.toString()
|
||||||
|
|
|
||||||
|
#page.execute_script "Quser.actions_for_table({table_id: '#{@other_table.id}'})"
|
||||||
end
|
end
|
||||||
|
|
||||||
step "the user scans a QR code of another occupied table" do
|
step "the user scans a QR code of another occupied table" do
|
||||||
|
|||||||
@@ -108,6 +108,10 @@ RSpec.configure do |config|
|
|||||||
Qwaiter::Couchbase.load_design_docs!
|
Qwaiter::Couchbase.load_design_docs!
|
||||||
# NOT THREADSAFE!!!!!! but good enough for testing since the real couchbase flush is slowwwwww....
|
# NOT THREADSAFE!!!!!! but good enough for testing since the real couchbase flush is slowwwwww....
|
||||||
Qwaiter::Counter.connection = InMemoryQCounter.new
|
Qwaiter::Counter.connection = InMemoryQCounter.new
|
||||||
|
# Threadsafe would be using the drb counter
|
||||||
|
# require 'drb'
|
||||||
|
# counter = DRbObject.new nil, 'druby://:9000'
|
||||||
|
# Qwaiter::Counter.connection = counter
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before :each do
|
config.before :each do
|
||||||
|
|||||||
@@ -3,27 +3,39 @@
|
|||||||
# a clean start and Hash#clear is soooo much faster than
|
# a clean start and Hash#clear is soooo much faster than
|
||||||
# a couchbase bucket flush
|
# a couchbase bucket flush
|
||||||
class InMemoryQCounter
|
class InMemoryQCounter
|
||||||
STORE = {}
|
attr_reader :store
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@store = {}
|
||||||
|
end
|
||||||
|
|
||||||
def get(key, options = {})
|
def get(key, options = {})
|
||||||
STORE[key]
|
store[key]
|
||||||
end
|
end
|
||||||
|
|
||||||
def set(key, value)
|
def set(key, value)
|
||||||
STORE[key] = value
|
store[key] = value
|
||||||
end
|
end
|
||||||
|
|
||||||
def incr(key, options = {})
|
def incr(key, options = {})
|
||||||
STORE[key] ||= options[:initial].to_i
|
store[key] ||= options[:initial].to_i
|
||||||
STORE[key] += 1
|
store[key] += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def decr(key, options = {})
|
def decr(key, options = {})
|
||||||
STORE[key] ||= options[:initial].to_i
|
store[key] ||= options[:initial].to_i
|
||||||
STORE[key] -= 1
|
store[key] -= 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def flush
|
def flush
|
||||||
STORE.clear
|
store.clear
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
=begin Make drb server
|
||||||
|
require 'drb'
|
||||||
|
DRb.start_service 'druby://:9000', InMemoryQCounter.new
|
||||||
|
puts "Counter server running at #{DRb.uri}"
|
||||||
|
trap("INT") { DRb.stop_service }
|
||||||
|
DRb.thread.join
|
||||||
|
=end
|
||||||
|
|||||||
Reference in New Issue
Block a user