Spec employees

This commit is contained in:
2015-02-24 13:43:44 +01:00
parent 755690131c
commit 16418dde30
18 changed files with 104 additions and 97 deletions
@@ -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
View File
@@ -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
+7
View File
@@ -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
+21
View File
@@ -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