Spec employees
This commit is contained in:
@@ -24,7 +24,7 @@ App.List = DS.Model.extend
|
||||
@set 'table', null
|
||||
@isHelped()
|
||||
@isPaid()
|
||||
iskHelped: ->
|
||||
isHelped: ->
|
||||
@set 'needs_help', false
|
||||
isNeedingHelp: ->
|
||||
@set 'needs_help', true
|
||||
@@ -44,11 +44,11 @@ App.List = DS.Model.extend
|
||||
!!@get('orders').filter( (order) -> order.get('state') is 'active' or order.get('state') is 'placed').length
|
||||
).property('state', 'orders.@each.state')
|
||||
close: ->
|
||||
@markClosed()
|
||||
@isClosed()
|
||||
$.post Routes.close_suppliers_list_path(@id)
|
||||
|
||||
is_helped: ->
|
||||
@markHelped()
|
||||
markHelped: ->
|
||||
@isHelped()
|
||||
$.post Routes.mark_helped_suppliers_list_path(@id)
|
||||
remove_needs_payment: ->
|
||||
@set 'needs_payment', false
|
||||
|
||||
@@ -4,20 +4,20 @@ p=t 'employee.modal.body_header'
|
||||
.form-field
|
||||
= input valueBinding="model.name"
|
||||
= errors model.errors.name
|
||||
.form-row.name
|
||||
.form-row.email
|
||||
.form-label=t 'attributes.employee.email'
|
||||
.form-field.half
|
||||
= input type="email" valueBinding="model.email" action="save"
|
||||
= errors model.errors.email
|
||||
if isNotSelf
|
||||
.form-row.active
|
||||
.form-row.manager
|
||||
.form-label= t 'attributes.employee.manager'
|
||||
.form-field= view "boolean-switch" value=model.manager
|
||||
.form-row.active
|
||||
.form-label= t 'attributes.employee.active'
|
||||
.form-field= view "boolean-switch" value=model.active
|
||||
|
||||
.form-row.active
|
||||
.form-row.color
|
||||
.form-label= t 'attributes.employee.color'
|
||||
.form-field.full
|
||||
span.current-color= colorbox model.color
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
App.MarkListHelpedButtonView = Ember.View.extend
|
||||
templateName: 'mark_list_helped_button'
|
||||
classNames: ['mark_list_as_helped']
|
||||
classNames: ['mark-list-as-helped-button']
|
||||
classNameBindings: ['content.needs_help:show:hide']
|
||||
tagName: 'button'
|
||||
click: (e)->
|
||||
# record could be promise or object
|
||||
@get('content').invoke 'is_helped'
|
||||
#record = @get('content')
|
||||
#if record.then then record.then (l) -> l.is_helped() else record.is_helped()
|
||||
@get('content').invoke 'markHelped'
|
||||
|
||||
@@ -32,8 +32,9 @@ td.colorbox
|
||||
border-bottom: 1px solid #eee
|
||||
&.active
|
||||
background-image: image-url('supplier/order-check.png')
|
||||
&.delivered
|
||||
&.delivered, &.closed
|
||||
background-image: image-url('supplier/order-doublecheck.png')
|
||||
&.closed
|
||||
.created_at
|
||||
float: right
|
||||
padding-right: 20px
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
border-bottom: 1px solid #eee
|
||||
&.active
|
||||
background-image: image-url('user/order-check.png')
|
||||
&.delivered
|
||||
&.delivered, &.closed
|
||||
background-image: image-url('user/order-doublecheck.png')
|
||||
.created_at
|
||||
float: right
|
||||
|
||||
@@ -5,6 +5,7 @@ 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
|
||||
@@ -16,6 +17,11 @@ 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!
|
||||
@@ -23,6 +29,10 @@ module Suppliers
|
||||
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
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
module Suppliers
|
||||
class EmployeesController < Suppliers::ApplicationController
|
||||
|
||||
after_authentication only: [:show, :update, :destroy] do
|
||||
@employee = current_supplier.get_employee params[:id]
|
||||
render json: {}, status: 404 unless @employee.present?
|
||||
end
|
||||
# GET /employees
|
||||
# GET /employees.json
|
||||
def index
|
||||
@@ -11,7 +14,6 @@ module Suppliers
|
||||
# GET /employees/1
|
||||
# GET /employees/1.json
|
||||
def show
|
||||
@employee = Employee.find(params[:id])
|
||||
render json: @employee, serializer: Suppliers::EmployeeSerializer
|
||||
end
|
||||
|
||||
@@ -19,7 +21,6 @@ module Suppliers
|
||||
# POST /employees.json
|
||||
def create
|
||||
@employee = Employee.find_by_email(employee_params[:email]) if employee_params[:email].present?
|
||||
@employee ||= Employee.new(employee_params)
|
||||
|
||||
if @employee.save
|
||||
current_supplier.add_employee @employee unless current_supplier.employee_ids.include? @employee.id # already linked
|
||||
@@ -32,9 +33,7 @@ module Suppliers
|
||||
# PUT /employees/1
|
||||
# PUT /employees/1.json
|
||||
def update
|
||||
@employee = Employee.find(params[:id])
|
||||
render json: {}, status: 404 unless current_supplier.employee_ids.include?(@employee.id)
|
||||
current_supplier.settings_for(@employee).update!(employee_params)
|
||||
#current_supplier.settings_for(@employee).update!(employee_params)
|
||||
respond_to do |format|
|
||||
if @employee.update_attributes(employee_params)
|
||||
format.json { head :no_content }
|
||||
@@ -47,8 +46,6 @@ module Suppliers
|
||||
# DELETE /employees/1
|
||||
# DELETE /employees/1.json
|
||||
def destroy
|
||||
@employee = Employee.find(params[:id])
|
||||
render json: {}, status: :forbidden unless current_supplier.employee_ids.include?(@employee.id)
|
||||
head :forbidden and return if @employee == current_employee # do not remove self at the moment
|
||||
current_supplier.remove_employee @employee
|
||||
|
||||
|
||||
+1
-1
@@ -132,9 +132,9 @@ class Order
|
||||
|
||||
if placed? || active?
|
||||
decrement_counter = placed? ? 'placed' : 'in_process'
|
||||
self.state = 'closed'
|
||||
supplier.public_send "decrement_orders_#{decrement_counter}_count!"
|
||||
end
|
||||
self.state = 'closed'
|
||||
|
||||
if save
|
||||
broadcast_user user.id, 'order_closed', id: id if user
|
||||
|
||||
@@ -119,6 +119,13 @@ class Supplier
|
||||
!open?
|
||||
end
|
||||
|
||||
def get_employee(id)
|
||||
return nil unless employee_ids.include?(id)
|
||||
employee = Employee.find id
|
||||
employee.settings = settings_for(employee)
|
||||
employee
|
||||
end
|
||||
|
||||
def mark_as_open!
|
||||
self.open = true
|
||||
save
|
||||
|
||||
@@ -4,4 +4,25 @@ NullModel = Naught.build do
|
||||
@created_at ||= Time.current
|
||||
end
|
||||
alias_method :updated_at, :created_at
|
||||
def presence
|
||||
nil
|
||||
end
|
||||
def blank?
|
||||
true
|
||||
end
|
||||
|
||||
def present?
|
||||
false
|
||||
end
|
||||
|
||||
def empty?
|
||||
true
|
||||
end
|
||||
def include?
|
||||
false
|
||||
end
|
||||
|
||||
def any?
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -102,15 +102,8 @@ Qwaiter::Application.routes.draw do
|
||||
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
|
||||
#get '/supplier/lists/:list_id' => 'supplier#show_list', as: :supplier_show_list
|
||||
|
||||
#post '/supplier/close_list' => 'supplier#close_list', as: :supplier_close_list
|
||||
#post '/supplier/mark_list_as_helped' => 'supplier#mark_list_as_helped', as: :supplier_mark_list_as_helped
|
||||
post '/supplier/remove_list_needs_payment' => 'supplier#remove_list_needs_payment', as: :supplier_remove_list_needs_payment
|
||||
|
||||
#post '/supplier/mark_order_in_process' => 'supplier#mark_order_in_process', as: :supplier_mark_order_in_process
|
||||
#post '/supplier/order_is_delivered' => 'supplier#order_is_delivered', as: :supplier_order_is_delivered
|
||||
|
||||
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
|
||||
|
||||
@@ -174,59 +167,7 @@ Qwaiter::Application.routes.draw do
|
||||
get '/table_qr_image' => 'dashboard#table_qr_image', as: :table_qr_image
|
||||
|
||||
mount Cmtool::Engine => '/cmtool'
|
||||
#match "/:action", controller: 'dashboard'
|
||||
|
||||
# The priority is based upon order of creation:
|
||||
# first created -> highest priority.
|
||||
|
||||
# Sample of regular route:
|
||||
# match 'products/:id' => 'catalog#view'
|
||||
# Keep in mind you can assign values other than :controller and :action
|
||||
|
||||
# Sample of named route:
|
||||
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
||||
# This route can be invoked with purchase_url(:id => product.id)
|
||||
|
||||
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
||||
# resources :products
|
||||
|
||||
# Sample resource route with options:
|
||||
# resources :products do
|
||||
# member do
|
||||
# get 'short'
|
||||
# post 'toggle'
|
||||
# end
|
||||
#
|
||||
# collection do
|
||||
# get 'sold'
|
||||
# end
|
||||
# end
|
||||
|
||||
# Sample resource route with sub-resources:
|
||||
# resources :products do
|
||||
# resources :comments, :sales
|
||||
# resource :seller
|
||||
# end
|
||||
|
||||
# Sample resource route with more complex sub-resources
|
||||
# resources :products do
|
||||
# resources :comments
|
||||
# resources :sales do
|
||||
# get 'recent', :on => :collection
|
||||
# end
|
||||
# end
|
||||
|
||||
# Sample resource route within a namespace:
|
||||
# namespace :admin do
|
||||
# # Directs /admin/products/* to Admin::ProductsController
|
||||
# # (app/controllers/admin/products_controller.rb)
|
||||
# resources :products
|
||||
# end
|
||||
|
||||
# You can have the root of your site routed with "root"
|
||||
# just remember to delete public/index.html.
|
||||
#
|
||||
#root :to => 'dashboard#home'
|
||||
root :to => 'pages#home', defaults: {locale: 'nl'}
|
||||
get '/:locale' => 'pages#home', constraints: {locale: ALLOWED_LOCALES}
|
||||
devise_scope :supplier do
|
||||
@@ -235,10 +176,4 @@ Qwaiter::Application.routes.draw do
|
||||
scope '(/:locale)', constraints: {locale: ALLOWED_LOCALES}, defaults: { locale: 'nl' } do
|
||||
get "/:name" => "pages#show", constraints: {name: /.*/}, as: :go_to
|
||||
end
|
||||
|
||||
# See how all your routes lay out with "rake routes"
|
||||
|
||||
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
||||
# Note: This route will make all actions in every controller accessible via GET requests.
|
||||
# match ':controller(/:action(/:id))(.:format)'
|
||||
end
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
Feature: Manage employees
|
||||
|
||||
@javascript
|
||||
Scenario: a just signed up manager can manage employees
|
||||
Given there is a confirmed and open supplier
|
||||
And there is an other employee
|
||||
And I am signed in as supplier
|
||||
When the supplier employee visits the 'employees' path
|
||||
And the supplier employee clicks on the other employee table edit button
|
||||
And the supplier emloyee sets the 'name' to 'Edited employee'
|
||||
And the supplier emloyee clicks the active switch to deactivate the employee
|
||||
And the supplier employee clicks the confirm modal button
|
||||
Then the other employee should no longer be active for the current supplier
|
||||
@@ -0,0 +1,23 @@
|
||||
step "there is an other employee" do
|
||||
@other_employee = create :employee, :confirmed, name: 'Other employee'
|
||||
@supplier.add_employee @other_employee
|
||||
end
|
||||
|
||||
step "the supplier employee clicks on the other employee table edit button" do
|
||||
find 'table.table'
|
||||
all('tr').last.find('.table-edit').click
|
||||
end
|
||||
|
||||
step "the supplier emloyee sets the :attribute to :value" do |attribute, value|
|
||||
js_set_field ".form-row.#{attribute} input", value
|
||||
end
|
||||
|
||||
step "the supplier emloyee clicks the active switch to deactivate the employee" do
|
||||
js_click '.form-row.active .switch'
|
||||
end
|
||||
|
||||
step "the other employee should no longer be active for the current supplier" do
|
||||
sleep 1
|
||||
@supplier.reload
|
||||
@supplier.settings_for(@other_employee).active?.should be false
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
step "the supplier employee clicks on :selector" do |selector|
|
||||
js_click selector
|
||||
end
|
||||
|
||||
step "the supplier employee clicks the confirm modal button" do
|
||||
js_click '.modal-confirm'
|
||||
end
|
||||
@@ -32,3 +32,7 @@ end
|
||||
step "the supplier should be redirected to the root path" do
|
||||
ember_route_should_be '/'
|
||||
end
|
||||
|
||||
step "the supplier employee visits the :path_spec path" do |path_spec|
|
||||
visit "/supplier#/#{path_spec}"
|
||||
end
|
||||
|
||||
@@ -14,15 +14,6 @@ describe Suppliers::ProductsController, type: :controller do
|
||||
setup_supplier_for_controller
|
||||
end
|
||||
|
||||
describe "GET #index" do
|
||||
it "does not include products from another supplier" do
|
||||
product1 = create :product, supplier: @supplier
|
||||
product2 = create :product
|
||||
get :index
|
||||
assigns(:products).should eq([product1])
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested product to @product" do
|
||||
product = create :product, supplier: @supplier
|
||||
|
||||
@@ -14,7 +14,7 @@ describe Page do
|
||||
|
||||
it 'returns a NullPage when no page found' do
|
||||
page = Page.suppliers_page('non-existent', locale: 'nl')
|
||||
page.should be_a Page::NullPage
|
||||
page.should_not be_present
|
||||
page.title.should == 'Non existent'
|
||||
page.locale.should == 'nl'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user