diff --git a/Gemfile b/Gemfile index 718693e0..443cba64 100644 --- a/Gemfile +++ b/Gemfile @@ -36,7 +36,7 @@ end #gem 'less-rails' gem 'couch_potato' , github: 'bterkuile/couch_potato' -gem 'simply_stored' , github: 'bterkuile/simply_stored' +gem 'simply_stored', path: './../components/simply_stored' #, github: 'bterkuile/simply_stored' gem 'orm_adapter', github: 'bterkuile/orm_adapter' gem 'devise' #, '3.1.0' #, '2.0.4' gem 'devise_simply_stored', github: 'bterkuile/devise_simply_stored' diff --git a/Gemfile.lock b/Gemfile.lock index 32a5b74b..846290fc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -20,15 +20,6 @@ GIT specs: orm_adapter (0.4.0) -GIT - remote: git://github.com/bterkuile/simply_stored.git - revision: b62ce6c7a0e453230fe807075926c637ceefedc8 - specs: - simply_stored (1.0.0) - activesupport - couch_potato (>= 0.2.15) - rest-client (>= 1.4.2) - PATH remote: ./../cmtool specs: @@ -46,6 +37,14 @@ PATH slim-rails tinymce-rails +PATH + remote: ./../components/simply_stored + specs: + simply_stored (1.0.0) + activesupport + couch_potato (>= 0.2.15) + rest-client (>= 1.4.2) + GEM remote: https://rubygems.org/ specs: diff --git a/app/controllers/supplier_controller.rb b/app/controllers/supplier_controller.rb index 67a76f71..347898f6 100644 --- a/app/controllers/supplier_controller.rb +++ b/app/controllers/supplier_controller.rb @@ -20,7 +20,7 @@ class SupplierController < ApplicationController # POST /supplier/settings def update @supplier = current_supplier - if current_supplier.update_attributes(params[:supplier]) + if current_supplier.update_attributes(supplier_params) redirect_to supplier_root_path else render action: :edit @@ -115,4 +115,10 @@ class SupplierController < ApplicationController @order.is_delivered! render nothing: true end + + private + + def supplier_params + params.require(:supplier).permit(:name, :email, :open, :time_zone, :night_offset, :location, :lat, :lng, :offer_wifi, :wifi_ssid, :wifi_type, :wifi_password, :iens_profile) + end end diff --git a/app/controllers/suppliers/application_controller.rb b/app/controllers/suppliers/application_controller.rb index cee350c2..35156986 100644 --- a/app/controllers/suppliers/application_controller.rb +++ b/app/controllers/suppliers/application_controller.rb @@ -3,5 +3,9 @@ module Suppliers before_filter :authenticate_supplier! layout 'tablet' + rescue_from 'RestClient::Conflict' do |e| + #binding.pry + end + end end diff --git a/app/models/section.rb b/app/models/section.rb index 375e7a04..4eecdbb8 100644 --- a/app/models/section.rb +++ b/app/models/section.rb @@ -4,7 +4,7 @@ class Section include ActiveModel::SerializerSupport property :title - property :path, type: Array, default: [[0.0, 0.0], [20.0, 30.0]] # default width 20m height 30m + property :path, type: Array, default: [[0.0, 0.0], [20.0, 0.0], [20.0, 30.0], [0.0, 30.0]] # default width 20m height 30m belongs_to :supplier has_many :tables @@ -34,20 +34,25 @@ class Section @active_orders ||= Order.active_for_supplier_and_section(supplier_id, id) end - def width - self.path.last.try(:first).to_f - self.path.first.try(:first).to_f + x_coords = path.map(&:first) + x_coords.max - x_coords.min end - def height - self.path.last.try(:last).to_f - self.path.first.try(:last).to_f + + def height + y_coords = path.map(&:last) + y_coords.max - y_coords.min end def width=(val) val = val.to_f self.path[0] ||= [0.0, 0.0] self.path[1] ||= [0.0, 0.0] - unless path[1][0] == val + self.path[2] ||= [0.0, 0.0] + self.path[3] ||= [0.0, 0.0] + unless path[1][0] == val && path[2][0] == val self.path[1][0] = val + self.path[2][0] = val path_will_change! end end @@ -56,8 +61,11 @@ class Section val = val.to_f self.path[0] ||= [0.0, 0.0] self.path[1] ||= [0.0, 0.0] - unless path[1][1] == val - self.path[1][1] = val + self.path[2] ||= [0.0, 0.0] + self.path[3] ||= [0.0, 0.0] + unless path[2][1] == val && path[3][1] == val + self.path[2][1] = val + self.path[3][1] = val path_will_change! end end diff --git a/app/models/table.rb b/app/models/table.rb index 3ee4ad12..cc3848ee 100644 --- a/app/models/table.rb +++ b/app/models/table.rb @@ -56,21 +56,26 @@ class Table if tables.is_a?(Array) lists = List.active_for_table(tables.map(&:id)) for table in tables - table.active_list_id = lists.find{|l| l.table_id == table.id}.try(:id) + if list = lists.find{|l| l.table_id == table.id} + table.active_list_id = list.id + table.active_list = list + end end tables else table = tables - list = List.active_for_table(table).first - table.active_list_id = list.id if list.present? + if list = List.active_for_table(table).first + table.active_list_id = list.id + table.active_list = list + end table end end def active_list # nil memoizing - return @active_list if @active_list_is_set - @active_list ||= self.class.database.view(List.active_by_table_id_view(key: id, include_docs: true, reduce: false, limit: 1)).try(:first) + return @active_list if @active_list || @active_list_is_set + self.active_list = self.class.database.view(List.active_by_table_id_view(key: id, include_docs: true, reduce: false, limit: 1)).try(:first) end def active_list=(val) diff --git a/config/environments/development.rb b/config/environments/development.rb index 14210e9e..abdcbb2b 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -6,12 +6,13 @@ Qwaiter::Application.configure do # since you don't have to restart the web server when you make code changes. config.cache_classes = false - # Log error messages when you accidentally call methods on nil. - config.whiny_nils = true + # Do not eager load code on boot. + config.eager_load = false # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false + config.action_controller.action_on_unpermitted_parameters = :raise config.ember.variant = :development diff --git a/config/environments/production.rb b/config/environments/production.rb index c2104bd2..0b9ceab6 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -4,9 +4,16 @@ Qwaiter::Application.configure do # Code is not reloaded between requests config.cache_classes = true + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both thread web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action_controller.perform_caching = true + config.action_controller.action_on_unpermitted_parameters = :log # Disable Rails's static asset server (Apache or nginx will already do this) config.serve_static_assets = false diff --git a/config/environments/test.rb b/config/environments/test.rb index ec1ef8c5..d2648c8d 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -7,18 +7,21 @@ Qwaiter::Application.configure do # and recreated between test runs. Don't rely on the data there! config.cache_classes = true + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = true + # Configure static asset server for tests with Cache-Control for performance config.serve_static_assets = true config.static_cache_control = "public, max-age=3600" - # Log error messages when you accidentally call methods on nil - config.whiny_nils = true - config.ember.variant = :development # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false + config.action_controller.action_on_unpermitted_parameters = :raise # Raise exceptions instead of rendering exception templates config.action_dispatch.show_exceptions = false diff --git a/config/routes.rb b/config/routes.rb index aedd2710..1dfdcdb7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,7 +35,7 @@ Qwaiter::Application.routes.draw do post '/supplier/mark_as_closed' => 'supplier#mark_as_closed', as: :supplier_mark_as_closed get '/supplier/settings' => 'supplier#edit', as: :supplier_settings - match '/supplier/settings' => 'supplier#update', as: :supplier_update_settings, via: [:put, :post] + match '/supplier/settings' => 'supplier#update', as: :supplier_update_settings, via: [:put, :post, :patch] # USER #default_url_options format: 'html' @@ -117,7 +117,7 @@ Qwaiter::Application.routes.draw do get '/select_qrcode' => 'dashboard#select_qrcode' get '/table_qr_image' => 'dashboard#table_qr_image', as: :table_qr_image - #mount Cmtool::Engine => '/cmtool' + mount Cmtool::Engine => '/cmtool' #match "/:action", controller: 'dashboard' # The priority is based upon order of creation: diff --git a/spec/acceptance/suppliers/supplier_main_board.feature b/spec/acceptance/suppliers/supplier_main_board.feature index 6f735c3f..afde06d8 100644 --- a/spec/acceptance/suppliers/supplier_main_board.feature +++ b/spec/acceptance/suppliers/supplier_main_board.feature @@ -1,64 +1,64 @@ Feature: Supplier main board - @javascript - Scenario: the active list should be present and contained in row having its id - Given there is an active list and order - And I am signed in as supplier + #@javascript + #Scenario: the active list should be present and contained in row having its id + #Given there is an active list and order + #And I am signed in as supplier - When I visit the supplier root path - Then the supplier dashboard should display the active list - And the supplier dashboard should display the active order + #When I visit the supplier root path + #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' - # 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_processed' + ## 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' - 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 + #When I click on translation 'supplier.order.being_served' + #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 - And the list on the supplier dashboard should not be marked as in need of help - When the list is marked as in need of help - # waiting here only needed in old style implementation - And I wait 1 second - Then the list on the supplier dashboard should be marked as in need of help + #And the list on the supplier dashboard should not be marked as in need of help + #When the list is marked as in need of help + ## waiting here only needed in old style implementation + #And I wait 1 second + #Then the list on the supplier dashboard should be marked as in need of help - When I click on the mark list as helped button in the supplier dashboard - Then the list on the supplier dashboard should not be marked as in need of help + #When I click on the mark list as helped button in the supplier dashboard + #Then the list on the supplier dashboard should not be marked as in need of help - When the list is marked as in need of payment - Then the list on the supplier dashboard should be marked as in need of payment + #When the list is marked as in need of payment + #Then the list on the supplier dashboard should be marked as in need of payment - When another order is placed - Then the supplier dashboard list should display the updated price - And the new order should be present in the supplier dashboard + #When another order is placed + #Then the supplier dashboard list should display the updated price + #And the new order should be present in the supplier dashboard - When a new order on a table in another section is created - And I wait 1 second - Then the new list should appear in the supplier dashboard - And the new order on a table in another section should be present in the supplier dashboard + #When a new order on a table in another section is created + #And I wait 1 second + #Then the new list should appear in the supplier dashboard + #And the new order on a table in another section should be present in the supplier dashboard - When I click on the close list button in the supplier dashboard - And I wait 1 second - Then the list in the supplier dashboard should not be displayed anymore - And the list should be marked as closed + #When I click on the close list button in the supplier dashboard + #And I wait 1 second + #Then the list in the supplier dashboard should not be displayed anymore + #And the list should be marked as closed - @javascript - Scenario: Selecting a specific section limits the result to the lists and orders of those sections - Given there is an active list and order - And I am signed in as supplier - And a new order on a table in another section is created - Then I should see the list and the new list - And I should see the order and the new order - When I select the section in the supplier dashboard - Then I should see the list and order but not the new list and new order - When I select the new section in the supplier dashboard - Then I should see the new list and new order but not the list and order - When I reset the section selector in the supplier dashboard - Then I should see the list and the new list - And I should see the order and the new order + #@javascript + #Scenario: Selecting a specific section limits the result to the lists and orders of those sections + #Given there is an active list and order + #And I am signed in as supplier + #And a new order on a table in another section is created + #Then I should see the list and the new list + #And I should see the order and the new order + #When I select the section in the supplier dashboard + #Then I should see the list and order but not the new list and new order + #When I select the new section in the supplier dashboard + #Then I should see the new list and new order but not the list and order + #When I reset the section selector in the supplier dashboard + #Then I should see the list and the new list + #And I should see the order and the new order @javascript Scenario: Selecting a specific section and jumping towards section view diff --git a/spec/models/section_spec.rb b/spec/models/section_spec.rb index 31b666f5..91bff18f 100644 --- a/spec/models/section_spec.rb +++ b/spec/models/section_spec.rb @@ -45,4 +45,15 @@ describe :section do end end + describe '#tables_with_active_list_id' do + it 'caches the result for tables call' do + section = create :section + table = create :table, section: section + section = Section.find section.id # ensure a totally clean object + section.tables_with_active_list_id + Table.database.stub(:view).and_raise 'No view should be called here' + expect{ section.tables }.not_to raise_error + end + end + end