From 046058b5d23f6cf43a0dae2d232673ff34bfc8ce Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Fri, 27 Feb 2015 15:12:08 +0100 Subject: [PATCH] Poltergeist in the green, and resourceful refactor --- app/abilities/employees/ability.rb | 6 ++ .../suppliers}/ability.rb | 14 +--- .../translation.js.coffee | 3 + .../controllers/settings_controller.js.coffee | 4 + .../supplier/app/models/list.js.coffee | 2 +- .../supplier/app/models/supplier.js.coffee | 4 +- .../app/routes/settings_route.js.coffee | 3 + .../supplier/app/templates/settings.emblem | 6 ++ .../supplier/foundation1/application.js.erb | 1 - .../javascripts/translations.js.coffee.erb | 1 - app/assets/javascripts/user/app/app.js.coffee | 1 + app/controllers/application_controller.rb | 2 + .../controller_after_authentication_hooks.rb | 21 +++++ .../employees/application_controller.rb | 17 +++++ .../employees/suppliers_controller.rb | 8 ++ app/controllers/supplier_controller.rb | 76 +------------------ .../suppliers/application_controller.rb | 13 +--- .../suppliers/products_controller.rb | 14 ++-- .../suppliers/suppliers_controller.rb | 67 ++++++++++++++++ .../employees/supplier_serializer.rb | 6 ++ app/views/layouts/user/foundation.html.slim | 1 + .../suppliers/application/_top_menu.html.slim | 7 -- config/deploy.rb | 2 +- .../initializers/active_model_serializer.rb | 4 + config/locales/supplier.en.yml | 1 + config/locales/supplier.nl.yml | 1 + config/routes.rb | 34 ++++++--- spec/acceptance_steps/global_steps.rb | 16 +++- spec/controllers/supplier/edit_spec.rb | 15 ---- .../suppliers/products_controller_spec.rb | 4 +- spec/routing/supplier_routing_spec.rb | 21 ----- 31 files changed, 210 insertions(+), 165 deletions(-) create mode 100644 app/abilities/employees/ability.rb rename app/{services => abilities/suppliers}/ability.rb (60%) create mode 100644 app/controllers/concerns/controller_after_authentication_hooks.rb create mode 100644 app/controllers/employees/application_controller.rb create mode 100644 app/controllers/employees/suppliers_controller.rb create mode 100644 app/controllers/suppliers/suppliers_controller.rb create mode 100644 app/serializers/employees/supplier_serializer.rb create mode 100644 config/initializers/active_model_serializer.rb delete mode 100644 spec/controllers/supplier/edit_spec.rb diff --git a/app/abilities/employees/ability.rb b/app/abilities/employees/ability.rb new file mode 100644 index 00000000..d7b7a1e2 --- /dev/null +++ b/app/abilities/employees/ability.rb @@ -0,0 +1,6 @@ +class Employees::Ability + include CanCan::Ability + def initialize(employee) + can :read, Supplier + end +end diff --git a/app/services/ability.rb b/app/abilities/suppliers/ability.rb similarity index 60% rename from app/services/ability.rb rename to app/abilities/suppliers/ability.rb index bf1b284b..157c0b38 100644 --- a/app/services/ability.rb +++ b/app/abilities/suppliers/ability.rb @@ -1,15 +1,7 @@ -class Ability - attr_reader :resource +class Suppliers::Ability include CanCan::Ability - def initialize(resource) - @resource = resource - case resource - when Employee then supplier_authorization - end - end - - def supplier_authorization - if resource.settings.manager? + def initialize(employee) + if employee.manager? can :manage, :all #cam :mark_as_open, Supplier else diff --git a/app/assets/javascripts/shared-ember-helpers/translation.js.coffee b/app/assets/javascripts/shared-ember-helpers/translation.js.coffee index e2bbd057..9045c6c9 100644 --- a/app/assets/javascripts/shared-ember-helpers/translation.js.coffee +++ b/app/assets/javascripts/shared-ember-helpers/translation.js.coffee @@ -1,4 +1,7 @@ Ember.Handlebars.helper 't', (path, params..., options)-> + toptions = options.hash + if params.length and typeof(params[0].serialize) is 'function' + $.extend toptions, params[0].serialize() text = t(path, options.hash) tag = if options.hash.bare then text else "#{text}" tag.htmlSafe() diff --git a/app/assets/javascripts/supplier/app/controllers/settings_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/settings_controller.js.coffee index be8d757a..07affb3a 100644 --- a/app/assets/javascripts/supplier/app/controllers/settings_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/settings_controller.js.coffee @@ -5,6 +5,8 @@ App.SettingsController = Ember.ObjectController.extend countries: (-> window.countries ).property() saving: false editIensProfile: (-> @get('model.country') is 'Netherlands' ).property('model.country') + suppliers: (-> @store.all 'supplier').property() + other_suppliers: ( -> @get('suppliers').rejectBy 'id', @get('controllers.application.supplier.id')).property('suppliers.@each') actions: saveSettings: -> @set 'saving', true @@ -12,3 +14,5 @@ App.SettingsController = Ember.ObjectController.extend @set 'saving', false $('.top-menu .supplier-name').text @get('model.name') @transitionToRoute 'index' + switchToSupplier: (supplier)-> + window.location = Routes.switch_to_suppliers_supplier_path(supplier.get('id')) diff --git a/app/assets/javascripts/supplier/app/models/list.js.coffee b/app/assets/javascripts/supplier/app/models/list.js.coffee index 91952710..507dbd51 100644 --- a/app/assets/javascripts/supplier/app/models/list.js.coffee +++ b/app/assets/javascripts/supplier/app/models/list.js.coffee @@ -52,5 +52,5 @@ App.List = DS.Model.extend $.post Routes.mark_helped_suppliers_list_path(@id) remove_needs_payment: -> @set 'needs_payment', false - $.post Routes.supplier_remove_list_needs_payment_path(), list_id: @id + $.post Routes.remove_needs_payment_suppliers_list_path(@id) sorted_orders: (-> @get('relevant_orders').sortBy('created_at').reverseObjects()).property('relevant_orders.@each.isLoaded') diff --git a/app/assets/javascripts/supplier/app/models/supplier.js.coffee b/app/assets/javascripts/supplier/app/models/supplier.js.coffee index 6d66890b..267c71b4 100644 --- a/app/assets/javascripts/supplier/app/models/supplier.js.coffee +++ b/app/assets/javascripts/supplier/app/models/supplier.js.coffee @@ -20,9 +20,9 @@ App.Supplier = DS.Model.extend orders_placed_count: attr('number') close: -> - $.post Routes.supplier_mark_as_closed_path(), => + $.post Routes.mark_as_closed_suppliers_supplier_path(@id), => @set 'open', false open_the_place: -> - $.post Routes.supplier_mark_as_open_path(), => + $.post Routes.mark_as_open_suppliers_supplier_path(@id), => @set 'open', true diff --git a/app/assets/javascripts/supplier/app/routes/settings_route.js.coffee b/app/assets/javascripts/supplier/app/routes/settings_route.js.coffee index d07bc4fe..28e97e3a 100644 --- a/app/assets/javascripts/supplier/app/routes/settings_route.js.coffee +++ b/app/assets/javascripts/supplier/app/routes/settings_route.js.coffee @@ -1,4 +1,7 @@ App.SettingsRoute = Ember.Route.extend + beforeModel: -> + $.getJSON(Routes.employees_suppliers_path()).then (result) => + @store.pushPayload result model: -> @container.lookup('route:application').supplier # setupController: (controller, model)-> # #controller.set 'model', controller.get('controllers.application.supplier') diff --git a/app/assets/javascripts/supplier/app/templates/settings.emblem b/app/assets/javascripts/supplier/app/templates/settings.emblem index 81383513..eeeb28f6 100644 --- a/app/assets/javascripts/supplier/app/templates/settings.emblem +++ b/app/assets/javascripts/supplier/app/templates/settings.emblem @@ -44,3 +44,9 @@ if editIensProfile span.fa.fa-lg.fa-spinner.fa-spin else button.button.submit-supplier-settings{action 'saveSettings'}=t 'settings.save' + + +if other_suppliers + .row: .small-12.columns: ul.button-group.stack-for-small.round + each supplier in other_suppliers + li: a.warning.button{action "switchToSupplier" supplier}= t 'settings.switch_to_supplier' supplier diff --git a/app/assets/javascripts/supplier/foundation1/application.js.erb b/app/assets/javascripts/supplier/foundation1/application.js.erb index b3121e8b..ae08e194 100644 --- a/app/assets/javascripts/supplier/foundation1/application.js.erb +++ b/app/assets/javascripts/supplier/foundation1/application.js.erb @@ -25,7 +25,6 @@ String.prototype.capitalize = function() { return this.charAt(0).toUpperCase() + window.time_zones = <%= ActiveSupport::TimeZone.all.map{|tz| {name: tz.name, formatted: "GMT#{tz.formatted_offset} #{tz.name}"}}.to_json.html_safe %>; window.countries = <%= IsoCountryCodes.all.map{|cc| {name: cc.name}}.to_json.html_safe %>; - var path_mapping = { user_root: '/user', join_occupied_table: '/user/join_occupied_table', diff --git a/app/assets/javascripts/translations.js.coffee.erb b/app/assets/javascripts/translations.js.coffee.erb index 2fd85514..ac476344 100644 --- a/app/assets/javascripts/translations.js.coffee.erb +++ b/app/assets/javascripts/translations.js.coffee.erb @@ -21,7 +21,6 @@ @ttry = (path, vars={})-> @t(path, $.extend(vars, emptyWhenNotFound: true)) - # return translation in the form # Tafel @tspan = (path, vars={}) -> "#{t(path, vars)}" diff --git a/app/assets/javascripts/user/app/app.js.coffee b/app/assets/javascripts/user/app/app.js.coffee index b529f1ef..6866786d 100644 --- a/app/assets/javascripts/user/app/app.js.coffee +++ b/app/assets/javascripts/user/app/app.js.coffee @@ -19,6 +19,7 @@ Ember.Application.initializer @App = Ember.Application.create LOG_TRANSITIONS: true rootElement: '#ember-app-container' + ready: -> window.ember_ready = true App.deferReadiness() diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6f504392..38ed4a63 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,5 @@ class ApplicationController < ActionController::Base + include ControllerAfterAuthenticationHooks before_action :set_locale if Rails.env.development? before_action :force_reloads @@ -14,6 +15,7 @@ class ApplicationController < ActionController::Base private + def allow_all_origins headers['Access-Control-Allow-Origin'] = '*' headers['Access-Control-Request-Method'] = '*' diff --git a/app/controllers/concerns/controller_after_authentication_hooks.rb b/app/controllers/concerns/controller_after_authentication_hooks.rb new file mode 100644 index 00000000..438eb727 --- /dev/null +++ b/app/controllers/concerns/controller_after_authentication_hooks.rb @@ -0,0 +1,21 @@ +module ControllerAfterAuthenticationHooks + extend ActiveSupport::Concern + + included do + class_attribute :after_authentication_hooks + end + + def run_after_authentication_hooks! + Array.wrap(after_authentication_hooks).each do |hook| + next if hook[:options][:only].present? && !Array.wrap(hook[:options][:only]).include?(action_name.to_sym) + instance_eval &hook[:block] + end + end + + module ClassMethods + def after_authentication(options, &blk) + self.after_authentication_hooks ||= [] + after_authentication_hooks << {options: options, block: blk} + end + end +end diff --git a/app/controllers/employees/application_controller.rb b/app/controllers/employees/application_controller.rb new file mode 100644 index 00000000..3d9fd842 --- /dev/null +++ b/app/controllers/employees/application_controller.rb @@ -0,0 +1,17 @@ +module Employees + class ApplicationController < ::ApplicationController + before_action :setup_employee! + load_and_authorize_resource + def setup_employee! + authenticate_employee! + @current_ability = Employees::Ability.new( current_employee ) + run_after_authentication_hooks! + end + 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 } + end + end + end +end diff --git a/app/controllers/employees/suppliers_controller.rb b/app/controllers/employees/suppliers_controller.rb new file mode 100644 index 00000000..7ad02b91 --- /dev/null +++ b/app/controllers/employees/suppliers_controller.rb @@ -0,0 +1,8 @@ +module Employees + class SuppliersController < Employees::ApplicationController + def index + @suppliers = current_employee.suppliers + render json: @suppliers, each_serializer: Employees::SupplierSerializer + end + end +end diff --git a/app/controllers/supplier_controller.rb b/app/controllers/supplier_controller.rb index 26f066e9..e2f9cf3b 100644 --- a/app/controllers/supplier_controller.rb +++ b/app/controllers/supplier_controller.rb @@ -1,46 +1,7 @@ class SupplierController < Suppliers::ApplicationController def home end - - def menu - end - - # GET /supplier/settings - def edit - @supplier = current_supplier - end - - def current - [current_supplier].include_relations(sections: :tables, product_categories: :products) - render json: Suppliers::SupplierSerializer.new(current_supplier).as_json - end - - # POST /supplier/settings - def update - @supplier = current_supplier - respond_to do |format| - format.html do - if current_supplier.update_attributes(supplier_params) - redirect_to supplier_root_path - else - render action: :edit - end - end - format.json do - current_supplier.update_attributes(supplier_params) - render json: Suppliers::SupplierSerializer.new(current_supplier).as_json - end - end - end - - def mark_as_open - current_supplier.mark_as_open! - head :ok - end - def mark_as_closed - current_supplier.mark_as_closed! - head :ok - end +=begin # GET /suppliers/1/active_orders # GET /suppliers/1/active_orders.json def active_orders @@ -95,38 +56,5 @@ class SupplierController < Suppliers::ApplicationController end #POST /supplier/remove_list_needs_payment - def remove_list_needs_payment - @list = List.find_by_supplier_id_and_id(current_supplier.id, params[:list_id]) - @list.remove_needs_payment! - 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, - :address, - :house_number, - :house_number_addition, - :postal_code, - :city, - :country, - :facebook_promotion_url, - :created_at, - :updated_at - ) - end +=end end diff --git a/app/controllers/suppliers/application_controller.rb b/app/controllers/suppliers/application_controller.rb index d6672891..8748ab24 100644 --- a/app/controllers/suppliers/application_controller.rb +++ b/app/controllers/suppliers/application_controller.rb @@ -5,7 +5,6 @@ module Suppliers attr_reader :current_supplier helper_method :current_supplier layout 'supplier/app' - class_attribute :after_authentication_hooks rescue_from 'RestClient::Conflict' do |e| #binding.pry @@ -17,22 +16,14 @@ module Suppliers end end - def self.after_authentication(options, &blk) - self.after_authentication_hooks ||= [] - after_authentication_hooks << {options: options, block: blk} - end - def setup_employee_and_supplier! authenticate_employee! find_current_supplier! return unless current_supplier.present? current_employee.enrich_with_settings current_supplier.settings_for(current_employee) raise CanCan::AccessDenied unless current_employee.active? - @current_ability = ::Ability.new( current_employee ) - Array.wrap(after_authentication_hooks).each do |hook| - next if hook[:options][:only].present? && !Array.wrap(hook[:options][:only]).include?(action_name.to_sym) - instance_eval &hook[:block] - end + @current_ability = Suppliers::Ability.new( current_employee ) + run_after_authentication_hooks! end diff --git a/app/controllers/suppliers/products_controller.rb b/app/controllers/suppliers/products_controller.rb index 2d464f6e..5b589e1b 100644 --- a/app/controllers/suppliers/products_controller.rb +++ b/app/controllers/suppliers/products_controller.rb @@ -1,6 +1,9 @@ module Suppliers class ProductsController < Suppliers::ApplicationController layout 'tablet' + after_authentication only: [:show, :edit, :update, :destroy] do + @product = Product.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) + end # GET /products # GET /products.json @@ -16,7 +19,6 @@ module Suppliers # GET /products/1 # GET /products/1.json def show - @product = Product.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) respond_to do |format| format.html # show.html.erb @@ -38,13 +40,13 @@ module Suppliers # GET /products/1/edit def edit - @product = Product.find(params[:id]) + #@product = Product.find(params[:id]) end # POST /products # POST /products.json def create - @product = Product.new(product_params) + #@product = Product.new(product_params) @product.supplier = current_supplier respond_to do |format| @@ -61,7 +63,7 @@ module Suppliers # PUT /products/1 # PUT /products/1.json def update - @product = Product.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) + #@product = Product.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) respond_to do |format| if @product.update_attributes(product_params) @@ -77,12 +79,12 @@ module Suppliers # DELETE /products/1 # DELETE /products/1.json def destroy - @product = Product.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) + #@product = Product.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) @product.destroy respond_to do |format| format.html { redirect_to suppliers_products_url, notice: t('action.destroy.successfull', model: Product.model_name.human) } - format.json { head :no_content } + format.json { head :ok } end end diff --git a/app/controllers/suppliers/suppliers_controller.rb b/app/controllers/suppliers/suppliers_controller.rb new file mode 100644 index 00000000..663b71c6 --- /dev/null +++ b/app/controllers/suppliers/suppliers_controller.rb @@ -0,0 +1,67 @@ +module Suppliers + class SuppliersController < Suppliers::ApplicationController + def index + + end + + def show + [current_supplier].include_relations(sections: :tables, product_categories: :products) + render json: Suppliers::SupplierSerializer.new(current_supplier).as_json + end + + def update + @supplier = current_supplier + current_supplier.update_attributes(supplier_params) + render json: Suppliers::SupplierSerializer.new(current_supplier).as_json + end + + def switch_to + @switch_supplier = Supplier.find(params[:id]) + session[:supplier_id] = params[:id] if @switch_supplier.employee_ids.include? current_employee.id + redirect_to supplier_root_path(anchor: '/settings') + end + + def mark_as_open + current_supplier.mark_as_open! + head :ok + end + + def mark_as_closed + current_supplier.mark_as_closed! + head :ok + end + def remove_needs_payment + @list = List.find_by_supplier_id_and_id(current_supplier.id, params[:id]) + @list.remove_needs_payment! + head :ok + 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, + :address, + :house_number, + :house_number_addition, + :postal_code, + :city, + :country, + :facebook_promotion_url + ) + end + end +end diff --git a/app/serializers/employees/supplier_serializer.rb b/app/serializers/employees/supplier_serializer.rb new file mode 100644 index 00000000..65da1f93 --- /dev/null +++ b/app/serializers/employees/supplier_serializer.rb @@ -0,0 +1,6 @@ +class Employees::SupplierSerializer < Qwaiter::Serializer + self.root = :supplier + embed :ids, include: true + attributes :open, :name, :lat, :lng, :time_zone, :address, :house_number, :house_number_addition, :postal_code, :city, :country, + :facebook_promotion_url, :iens_profile, :week_starts_on_monday, :orders_in_process_count, :orders_placed_count +end diff --git a/app/views/layouts/user/foundation.html.slim b/app/views/layouts/user/foundation.html.slim index aff6e416..53c80c05 100644 --- a/app/views/layouts/user/foundation.html.slim +++ b/app/views/layouts/user/foundation.html.slim @@ -54,6 +54,7 @@ html lang="en" = javascript_include_tag "user/flat/application" - unless Rails.env.user_app? javascript: + window.ember_ready = false App.advanceReadiness() body #ember-app-container diff --git a/app/views/suppliers/application/_top_menu.html.slim b/app/views/suppliers/application/_top_menu.html.slim index a7b9a3c0..ad0d38fd 100644 --- a/app/views/suppliers/application/_top_menu.html.slim +++ b/app/views/suppliers/application/_top_menu.html.slim @@ -24,13 +24,6 @@ header.top-menu aside.side-menu ul li.title: h3 Menu - - if current_supplier.open? - li - = form_tag supplier_mark_as_closed_path do - a.supplier-close-shop href="javascript:void(0)" onclick="$(this).parents('form').submit()" - span data-t="supplier.close_for_orders" - li= link_to content_tag(:span, '', data: {t: 'supplier.settings'}), supplier_settings_path, class: 'supplier-settings-link' - li= link_to content_tag(:span, '', data: {t: 'supplier.sign_out'}), destroy_employee_session_path, method: :delete, class: 'supplier-sign-out-link' /.navbar.navbar-fixed-top.navbar-inverse .navbar-inner .container diff --git a/config/deploy.rb b/config/deploy.rb index 9b54df0c..192dedf7 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -73,7 +73,7 @@ namespace :deploy do end after :publishing, :restart do - update_remote_cache + deploy.update_remote_cache end after :restart, :clear_cache do diff --git a/config/initializers/active_model_serializer.rb b/config/initializers/active_model_serializer.rb new file mode 100644 index 00000000..b7d9c1ca --- /dev/null +++ b/config/initializers/active_model_serializer.rb @@ -0,0 +1,4 @@ +ActiveModel::Serializer.setup do |config| + config.embed = :ids + config.embed_in_root = true +end diff --git a/config/locales/supplier.en.yml b/config/locales/supplier.en.yml index 96218beb..bb518b1e 100644 --- a/config/locales/supplier.en.yml +++ b/config/locales/supplier.en.yml @@ -125,6 +125,7 @@ en: reviews: title: Reviews explanation: Fill in your Iens id. You can find this id in the web location of your page + switch_to_supplier: Switch to %{name} product_category: # week days depricated week_days: diff --git a/config/locales/supplier.nl.yml b/config/locales/supplier.nl.yml index 6ea19349..cc01dced 100644 --- a/config/locales/supplier.nl.yml +++ b/config/locales/supplier.nl.yml @@ -124,6 +124,7 @@ nl: reviews: title: Reviews explanation: Vul hier je iens id in. Deze kan je halen uit de url van je iens pagina + switch_to_supplier: Switch to %{name} product_category: week_days: abbreviation: diff --git a/config/routes.rb b/config/routes.rb index f52e8ebe..61ba61fc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -86,9 +86,9 @@ Qwaiter::Application.routes.draw do end - get '/supplier/suppliers/current' => 'supplier#current' #ember - get '/supplier/suppliers/:id' => 'supplier#current' #ember - put '/supplier/suppliers/:id' => 'supplier#update' #ember + #get '/supplier/suppliers/current' => 'supplier#current' #ember + #get '/supplier/suppliers/:id' => 'supplier#current' #ember + #put '/supplier/suppliers/:id' => 'supplier#update' #ember #match '/show_products' => 'dashboard#show_products', as: :user_products # GENERAL @@ -106,18 +106,25 @@ Qwaiter::Application.routes.draw do # SUPPLIER get '/supplier' => 'supplier#home', as: :supplier_root - get '/supplier/active_orders' => 'supplier#active_orders', as: :supplier_active_orders - get '/supplier/active_lists' => 'supplier#active_lists', as: :supplier_active_lists - get '/supplier/menu' => 'supplier#menu', as: :suppliers_menu - post '/supplier/remove_list_needs_payment' => 'supplier#remove_list_needs_payment', as: :supplier_remove_list_needs_payment + #get '/supplier/active_orders' => 'supplier#active_orders', as: :supplier_active_orders + #get '/supplier/active_lists' => 'supplier#active_lists', as: :supplier_active_lists + #get '/supplier/menu' => 'supplier#menu', as: :suppliers_menu + #post '/supplier/remove_list_needs_payment' => 'supplier#remove_list_needs_payment', as: :supplier_remove_list_needs_payment - post '/supplier/mark_as_open' => 'supplier#mark_as_open', as: :supplier_mark_as_open - post '/supplier/mark_as_closed' => 'supplier#mark_as_closed', as: :supplier_mark_as_closed + #post '/supplier/mark_as_open' => 'supplier#mark_as_open', as: :supplier_mark_as_open + #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, :patch] + #get '/supplier/settings' => 'supplier#edit', as: :supplier_settings + #match '/supplier/settings' => 'supplier#update', as: :supplier_update_settings, via: [:put, :post, :patch] namespace :suppliers, path: '/supplier' do + resources :suppliers do + member do + get :switch_to + post :mark_as_open + post :mark_as_closed + end + end resources :sections do member do get :manage_tables @@ -150,6 +157,7 @@ Qwaiter::Application.routes.draw do get :extra_info post :mark_helped post :close + post :remove_needs_payment end end resources :product_categories do @@ -169,6 +177,10 @@ Qwaiter::Application.routes.draw do root to: 'sections#index' end + namespace :employees, path: '/employee' do + resources :suppliers + end + #DEMO & DEVELOPMENT get '/select_qrcode' => 'dashboard#select_qrcode' get '/table_qr_image' => 'dashboard#table_qr_image', as: :table_qr_image diff --git a/spec/acceptance_steps/global_steps.rb b/spec/acceptance_steps/global_steps.rb index c23244ea..811a0033 100644 --- a/spec/acceptance_steps/global_steps.rb +++ b/spec/acceptance_steps/global_steps.rb @@ -33,5 +33,19 @@ step "I open the debugger" do end step 'I reload the page' do - page.driver.browser.navigate.refresh() + case Capybara.current_driver + when :selenium then page.driver.browser.navigate.refresh() + when :poltergeist + visit page.current_url + sleep 1 + #steps = 0 + #r = page.evaluate_script 'window.ember_ready' + #while !r and steps < 20 + #sleep 0.1 + #r = page.evaluate_script 'window.ember_ready' + #steps += 1 + #end + else + visit page.current_url + end end diff --git a/spec/controllers/supplier/edit_spec.rb b/spec/controllers/supplier/edit_spec.rb deleted file mode 100644 index a2c23b48..00000000 --- a/spec/controllers/supplier/edit_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -# encoding: UTF-8 -require 'spec_helper' - -describe SupplierController, type: :controller do - before :each do - setup_supplier_for_controller - end - - describe "GET settings" do - it 'displays the settings page' do - get :edit - end - end - -end diff --git a/spec/controllers/suppliers/products_controller_spec.rb b/spec/controllers/suppliers/products_controller_spec.rb index b9b3dfab..d03d499d 100644 --- a/spec/controllers/suppliers/products_controller_spec.rb +++ b/spec/controllers/suppliers/products_controller_spec.rb @@ -116,7 +116,7 @@ describe Suppliers::ProductsController, type: :controller do it "deletes the product" do expect{ - delete :destroy, id: @product + delete :destroy, id: @product }.to change(Product, :count).by(-1) end @@ -128,7 +128,7 @@ describe Suppliers::ProductsController, type: :controller do it "should not be possible to delete a product of another supplier" do product = create :product expect{ - delete :destroy, id: product + delete :destroy, id: product.id }.to_not change(Product, :count) end end diff --git a/spec/routing/supplier_routing_spec.rb b/spec/routing/supplier_routing_spec.rb index d3649133..517406e0 100644 --- a/spec/routing/supplier_routing_spec.rb +++ b/spec/routing/supplier_routing_spec.rb @@ -6,26 +6,5 @@ describe SupplierController, type: :routing do it "routes root to #home" do get("/supplier").should route_to("supplier#home") end - it "routes to #active_orders" do - get("/supplier/active_orders").should route_to("supplier#active_orders") - end - it "routes to #active_lists" do - get("/supplier/active_lists").should route_to("supplier#active_lists") - end - it "routes to #mark_as_open" do - post("/supplier/mark_as_open").should route_to("supplier#mark_as_open") - end - it "routes to #mark_as_closed" do - post("/supplier/mark_as_closed").should route_to("supplier#mark_as_closed") - end - it "routes to #settings" do - get("/supplier/settings").should route_to("supplier#edit") - end - it "routes to #update via put" do - put("/supplier/settings").should route_to("supplier#update") - end - it "routes to #update via post" do - post("/supplier/settings").should route_to("supplier#update") - end end end