From eb368a31cacc69598a03266fee40c03cf2684828 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Thu, 2 Jun 2016 14:40:30 +0200 Subject: [PATCH] upgrade refactor --- app/assets/javascripts/supplier/app/models/order.js.coffee | 4 ++-- app/assets/javascripts/supplier/app/models/table.js.coffee | 1 + app/assets/javascripts/supplier/app/router.js.coffee | 2 +- .../supplier/app/routes/application.js.coffee.erb | 2 +- .../templates/components/button/change-list-table.emblem | 2 +- .../supplier/app/templates/dashboard/active-list.emblem | 2 +- .../supplier/app/templates/dashboard/active-order.emblem | 2 +- .../javascripts/supplier/app/templates/list/_content.emblem | 2 +- .../javascripts/supplier/app/templates/lists/index.emblem | 4 ++-- .../supplier/app/templates/modals/change-list-table.emblem | 4 ++-- .../supplier/app/templates/modals/table_edit.emblem | 2 +- .../javascripts/supplier/app/templates/section/table.emblem | 4 ++-- app/assets/javascripts/supplier/app/templates/table.emblem | 4 ++-- .../supplier/app/templates/table_number_with_info.emblem | 2 +- .../javascripts/supplier/app/templates/tables/index.emblem | 4 ++-- app/controllers/new_suppliers_controller.rb | 2 +- app/controllers/suppliers/application_controller.rb | 2 +- app/controllers/suppliers/pages_controller.rb | 2 +- app/models/new_supplier.rb | 3 ++- config/initializers/queue.rb | 1 + config/locales/models.en.yml | 2 +- config/locales/models.nl.yml | 2 +- spec/acceptance/suppliers/signup.feature | 6 ++++-- spec/models/new_supplier_spec.rb | 3 ++- spec/spec_helper.rb | 2 +- 25 files changed, 36 insertions(+), 30 deletions(-) diff --git a/app/assets/javascripts/supplier/app/models/order.js.coffee b/app/assets/javascripts/supplier/app/models/order.js.coffee index 80ce79b0..4a5c4e27 100644 --- a/app/assets/javascripts/supplier/app/models/order.js.coffee +++ b/app/assets/javascripts/supplier/app/models/order.js.coffee @@ -40,8 +40,8 @@ App.Order = DS.Model.extend display_with_table: (-> table = t('models.table').toLowerCase() - "#{@get('display')} #{table} #{@get('list.table.number')}".htmlSafe() - ).property('display', 'list.table.number') + "#{@get('display')} #{table} #{@get('list.table.table_number')}".htmlSafe() + ).property('display', 'list.table.table_number') display_tag: (-> "#{@get('display')}".htmlSafe() diff --git a/app/assets/javascripts/supplier/app/models/table.js.coffee b/app/assets/javascripts/supplier/app/models/table.js.coffee index a7e2bc45..e13dcd60 100644 --- a/app/assets/javascripts/supplier/app/models/table.js.coffee +++ b/app/assets/javascripts/supplier/app/models/table.js.coffee @@ -18,3 +18,4 @@ App.Table = DS.Model.extend # Casted number to use in sortBy because a numberField will # set property number to string value (TablesIndexController) casted_number: (-> parseInt(@get('number'))).property('number') + table_number: Ember.computed.alias('number') diff --git a/app/assets/javascripts/supplier/app/router.js.coffee b/app/assets/javascripts/supplier/app/router.js.coffee index 018ba6ac..b6d08366 100644 --- a/app/assets/javascripts/supplier/app/router.js.coffee +++ b/app/assets/javascripts/supplier/app/router.js.coffee @@ -14,7 +14,7 @@ App.Router.map -> @resource 'list', path: ':list_id' @route 'employees' @route 'employee', path: '/employees/:employee_id' - @route 'page', path: 'pages/:page_id' + @resource 'page', path: 'pages/:page_id' @route 'orders-display' # chromecast etc @route 'menu' @route 'settings' diff --git a/app/assets/javascripts/supplier/app/routes/application.js.coffee.erb b/app/assets/javascripts/supplier/app/routes/application.js.coffee.erb index c1199d6f..f9acf842 100644 --- a/app/assets/javascripts/supplier/app/routes/application.js.coffee.erb +++ b/app/assets/javascripts/supplier/app/routes/application.js.coffee.erb @@ -121,7 +121,7 @@ App.ApplicationRoute = Ember.Route.extend if list = @store.peekRecord('list', data.id) list.isNeedingHelp() return if @get('globals.active_section.id') and list.get('section.id') isnt @get('globals.active_section.id') - @set 'globals.flash_message', t('table.needs_help.flash_message', number: list.get('table.number') || -1) + @set 'globals.flash_message', t('table.needs_help.flash_message', number: list.get('table.table_number') || -1) try ion.sound.play 'bell_ring' list_needs_payment: (data) -> if list = @store.peekRecord('list', data.id) diff --git a/app/assets/javascripts/supplier/app/templates/components/button/change-list-table.emblem b/app/assets/javascripts/supplier/app/templates/components/button/change-list-table.emblem index ad8d9592..f8133bdb 100644 --- a/app/assets/javascripts/supplier/app/templates/components/button/change-list-table.emblem +++ b/app/assets/javascripts/supplier/app/templates/components/button/change-list-table.emblem @@ -1 +1 @@ -= table-number list.table.number += table-number list.table.table_number diff --git a/app/assets/javascripts/supplier/app/templates/dashboard/active-list.emblem b/app/assets/javascripts/supplier/app/templates/dashboard/active-list.emblem index d131acda..9e4ffce2 100644 --- a/app/assets/javascripts/supplier/app/templates/dashboard/active-list.emblem +++ b/app/assets/javascripts/supplier/app/templates/dashboard/active-list.emblem @@ -5,7 +5,7 @@ span.icon.needs-help if list.needs_payment span.icon.needs-payment - span.table-number= table-number list.table.number + span.table-number= table-number list.table.table_number = link-to 'section' list.table.section class="link-to-section" span=list.table.section.title span.currency=currency list.total diff --git a/app/assets/javascripts/supplier/app/templates/dashboard/active-order.emblem b/app/assets/javascripts/supplier/app/templates/dashboard/active-order.emblem index 1540b7c0..bc528ac7 100644 --- a/app/assets/javascripts/supplier/app/templates/dashboard/active-order.emblem +++ b/app/assets/javascripts/supplier/app/templates/dashboard/active-order.emblem @@ -4,7 +4,7 @@ if order.active span.active-order span.order-display= order.display - span.table-number= table-number order.list.table.number + span.table-number= table-number order.list.table.table_number = link-to 'section' order.list.table.section class="link-to-section" span=order.list.table.section.title span.currency=currency order.total diff --git a/app/assets/javascripts/supplier/app/templates/list/_content.emblem b/app/assets/javascripts/supplier/app/templates/list/_content.emblem index b0ba1bdd..c9e59815 100644 --- a/app/assets/javascripts/supplier/app/templates/list/_content.emblem +++ b/app/assets/javascripts/supplier/app/templates/list/_content.emblem @@ -11,7 +11,7 @@ if list.closed_at if list.active .display-row .display-label=t 'models.section' - .display-field= list.table.section.title + .display-field= link-to "section" list.table.section: list.table.section.title .display-row .display-label=t 'models.table' .display-field diff --git a/app/assets/javascripts/supplier/app/templates/lists/index.emblem b/app/assets/javascripts/supplier/app/templates/lists/index.emblem index 9f72f31c..69b8ba59 100644 --- a/app/assets/javascripts/supplier/app/templates/lists/index.emblem +++ b/app/assets/javascripts/supplier/app/templates/lists/index.emblem @@ -13,7 +13,7 @@ else span.boolean.needs-payment=boolean list.needs_payment span.timestamp.created_at= time list.created_at span.state= state 'list' list.state - span.table-number= table-number list.table.number + span.table-number= table-number list.table.table_number span.currency= currency list.price .row.list-row-total: .small-12.columns span.total-sentence= t 'lists.index.total_sentence' @@ -47,7 +47,7 @@ else td.boolean.needs_help=boolean list.needs_help td.boolean.needs_payment=boolean list.needs_payment td.timestamp=time list.closed_at - td.table_number= list.table.number + td.table_number= list.table.table_number td.currency=currency list.price td.timestamp=time list.created_at tfoot diff --git a/app/assets/javascripts/supplier/app/templates/modals/change-list-table.emblem b/app/assets/javascripts/supplier/app/templates/modals/change-list-table.emblem index b742a397..945267fc 100644 --- a/app/assets/javascripts/supplier/app/templates/modals/change-list-table.emblem +++ b/app/assets/javascripts/supplier/app/templates/modals/change-list-table.emblem @@ -1,10 +1,10 @@ -h4=t 'modal.change_list_table.subtitle' current_table_number=model.table.number +h4=t 'modal.change_list_table.subtitle' current_table_number=model.table.table_number = users-buttons users=model.users each sections as |section| h3= section.title ul.change-list-table-section-tables each section.sorted_tables as |table| unless table.active_list - li: a{action "moveToTable" table}= table-number table.number + li: a{action "moveToTable" table}= table-number table.table_number hr button.modal-close{action "close"}=t 'modal.change_list_table.close_button' diff --git a/app/assets/javascripts/supplier/app/templates/modals/table_edit.emblem b/app/assets/javascripts/supplier/app/templates/modals/table_edit.emblem index cbda0ee1..f0a9cec0 100644 --- a/app/assets/javascripts/supplier/app/templates/modals/table_edit.emblem +++ b/app/assets/javascripts/supplier/app/templates/modals/table_edit.emblem @@ -1,6 +1,6 @@ p=t 'table.modal.body_header' .form-row.number - .form-label=t 'attributes.table.number' + .form-label=t 'attributes.table.table_number' .form-field= number-field numericValue=model.number .form-row.section .form-label=t 'models.section' diff --git a/app/assets/javascripts/supplier/app/templates/section/table.emblem b/app/assets/javascripts/supplier/app/templates/section/table.emblem index 322349b0..0d85e650 100644 --- a/app/assets/javascripts/supplier/app/templates/section/table.emblem +++ b/app/assets/javascripts/supplier/app/templates/section/table.emblem @@ -1,4 +1,4 @@ -.table-number= table.number +.table-number= table.table_number unless section.editmode .status-icons span.needs_payment @@ -6,7 +6,7 @@ unless section.editmode span.active_order if table.active_list div.table-actions - .title= table.number + .title= table.table_number if table.active_list .table-action-row /= view "mark-list-helped-button" tableBinding="table.active_list" diff --git a/app/assets/javascripts/supplier/app/templates/table.emblem b/app/assets/javascripts/supplier/app/templates/table.emblem index c3319700..e6aa027f 100644 --- a/app/assets/javascripts/supplier/app/templates/table.emblem +++ b/app/assets/javascripts/supplier/app/templates/table.emblem @@ -1,9 +1,9 @@ .row: .small-12.columns h2.main-section-header=t 'models.table' .display-row - .display-label= t 'attributes.table.number' + .display-label= t 'attributes.table.table_number' .display-field - span= table.number + span= table.table_number if table.section .display-row .display-label=t 'models.section' diff --git a/app/assets/javascripts/supplier/app/templates/table_number_with_info.emblem b/app/assets/javascripts/supplier/app/templates/table_number_with_info.emblem index 30c09686..f4e6ebe8 100644 --- a/app/assets/javascripts/supplier/app/templates/table_number_with_info.emblem +++ b/app/assets/javascripts/supplier/app/templates/table_number_with_info.emblem @@ -1,3 +1,3 @@ -.number= list.table.number +.number= list.table.table_number .extra-list-info span.loading.medium diff --git a/app/assets/javascripts/supplier/app/templates/tables/index.emblem b/app/assets/javascripts/supplier/app/templates/tables/index.emblem index 79196729..6ffe0ffc 100644 --- a/app/assets/javascripts/supplier/app/templates/tables/index.emblem +++ b/app/assets/javascripts/supplier/app/templates/tables/index.emblem @@ -4,14 +4,14 @@ table.table thead tr - th=t 'attributes.table.number' + th=t 'attributes.table.table_number' th.link=t 'models.section' /th.timestamp= t 'attributes.table.created_at' th.actions=t 'helpers.actions.title' tbody each tables as |table| tr - td= link-to 'table' table: span= table.number + td= link-to 'table' table: span= table.table_number td.link if table.section = link-to 'section' table.section diff --git a/app/controllers/new_suppliers_controller.rb b/app/controllers/new_suppliers_controller.rb index 7a45d1e9..09d46203 100644 --- a/app/controllers/new_suppliers_controller.rb +++ b/app/controllers/new_suppliers_controller.rb @@ -22,6 +22,7 @@ class NewSuppliersController < ApplicationController sign_in @new_supplier.employee if @new_supplier.employee.suppliers.size < 2 session[:supplier_id] = @new_supplier.employee.suppliers.first.try(:id) + redirect_to supplier_root_path else render "choose_supplier" end @@ -29,7 +30,6 @@ class NewSuppliersController < ApplicationController else save_new_supplier end - end def choose_supplier diff --git a/app/controllers/suppliers/application_controller.rb b/app/controllers/suppliers/application_controller.rb index 8748ab24..363030cb 100644 --- a/app/controllers/suppliers/application_controller.rb +++ b/app/controllers/suppliers/application_controller.rb @@ -12,7 +12,7 @@ module Suppliers rescue_from CanCan::AccessDenied do |exception| respond_to do |format| format.html { redirect_to root_path, alert: 'Action forbidden'} - format.json { render json: {}, status: :forbidden } + format.json { render json: {errors: "403 Forbidden"}, status: :forbidden } end end diff --git a/app/controllers/suppliers/pages_controller.rb b/app/controllers/suppliers/pages_controller.rb index cf313669..d333f0f7 100644 --- a/app/controllers/suppliers/pages_controller.rb +++ b/app/controllers/suppliers/pages_controller.rb @@ -1,6 +1,6 @@ module Suppliers class PagesController < Suppliers::ApplicationController - prepend_before_action :find_page, only: [:show] + before_action :find_page, only: [:show] def index @pages = Page.all_for_suppliers(locale: params[:locale]) render json: @pages diff --git a/app/models/new_supplier.rb b/app/models/new_supplier.rb index 06caf584..0da4ff1d 100644 --- a/app/models/new_supplier.rb +++ b/app/models/new_supplier.rb @@ -34,7 +34,7 @@ class NewSupplier return true if current_employee.present? return false unless email.present? and password.present? existing_employee = Employee.find_by_email email - if existing_employee.valid_password?(password) + if existing_employee.try(:valid_password?, password) @employee = existing_employee return true end @@ -60,6 +60,7 @@ class NewSupplier return if @employee = current_employee if Employee.count_by_email(email) > 0 employee = Employee.find_by_email(email) + # Login employee when valid password is given for signup if employee.valid_password? password @employee = employee else diff --git a/config/initializers/queue.rb b/config/initializers/queue.rb index 7e98127b..953d5d23 100644 --- a/config/initializers/queue.rb +++ b/config/initializers/queue.rb @@ -1,3 +1,4 @@ +require 'sucker_punch/async_syntax' # remove for rails >= 5 Rails.application.configure do config.active_job.queue_adapter = :sucker_punch end diff --git a/config/locales/models.en.yml b/config/locales/models.en.yml index 600cd170..2a324bd7 100644 --- a/config/locales/models.en.yml +++ b/config/locales/models.en.yml @@ -87,7 +87,7 @@ en: password: Password password_confirmation: Password confirmation table: - number: Number + table_number: Number from_number: From number to_number: To number created_at: Created diff --git a/config/locales/models.nl.yml b/config/locales/models.nl.yml index cbf30920..d8750990 100644 --- a/config/locales/models.nl.yml +++ b/config/locales/models.nl.yml @@ -85,7 +85,7 @@ nl: password: Wachtwoord password_confirmation: Nogmaals wachtwoord table: - number: Nummer + table_number: Nummer from_number: Vanaf nummer to_number: Tot nummer created_at: Aangemaakt diff --git a/spec/acceptance/suppliers/signup.feature b/spec/acceptance/suppliers/signup.feature index b20155ab..faa25cac 100644 --- a/spec/acceptance/suppliers/signup.feature +++ b/spec/acceptance/suppliers/signup.feature @@ -37,7 +37,8 @@ Feature: A supplier can sign up When I visit the supplier signup path And fill in the supplier signup form with an existing supplier name And click on the supplier signup submit button - Then the new supplier signup for should have an error on 'supplier_name' + #Then the new supplier signup for should have an error on 'supplier_name' # no new supplier + Then the supplier should be redirected to the root path @javascript Scenario: Existing non signed in employee creates existing supplier name @@ -46,7 +47,8 @@ Feature: A supplier can sign up And fill in the supplier signup form with existing employee credentials And fill in the supplier signup form with an existing supplier name And click on the supplier signup submit button - Then the new supplier signup for should have an error on 'supplier_name' + #Then the new supplier signup for should have an error on 'supplier_name' + Then the supplier should be redirected to the root path #Scenarios #- non existing non signed in employee #- existing non signed in employee diff --git a/spec/models/new_supplier_spec.rb b/spec/models/new_supplier_spec.rb index 693de705..4f331beb 100644 --- a/spec/models/new_supplier_spec.rb +++ b/spec/models/new_supplier_spec.rb @@ -16,7 +16,8 @@ describe NewSupplier do subject.errors[:password_confirmation].should be_present end - it "does not create a supplier when the name is already taken" do + # This is tested with acceptance tests since part of this logic is inside the controller + xit "does not create a supplier when the name is already taken" do create :supplier, name: 'New suppy' expect{ subject.save }.not_to change{ Supplier.count } subject.errors[:supplier_name].should be_present diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f2d398d5..d91435e5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -23,7 +23,7 @@ Devise.stretches = 1 #Capybara.javascript_driver = :webkit #Capybara.javascript_driver = :poltergeist Capybara.javascript_driver = :selenium -Capybara.default_wait_time = 5 # ember needs more time than the default of 2 +Capybara.default_max_wait_time = 5 # ember needs more time than the default of 2 Capybara.server_port = 62625 Capybara::Screenshot.webkit_options = { width: 1024, height: 768 } WebMock.disable_net_connect!(allow_localhost: true)