serializer stuff

This commit is contained in:
2015-09-14 18:53:58 +02:00
parent 36e5b21b13
commit ef894f9e02
37 changed files with 141 additions and 63 deletions
+1
View File
@@ -122,6 +122,7 @@ group :test do
#gem 'capybara-webkit' #, '~>0.14.2' # version 1.1.0 does not yet compile in mavericks #gem 'capybara-webkit' #, '~>0.14.2' # version 1.1.0 does not yet compile in mavericks
#gem 'selenium-webdriver', '~> 2.45.0.dev3' #gem 'selenium-webdriver', '~> 2.45.0.dev3'
gem 'selenium-webdriver' gem 'selenium-webdriver'
gem 'hashie'
#gem 'poltergeist' #gem 'poltergeist'
#gem 'capybara-webkit' #gem 'capybara-webkit'
gem 'capybara-screenshot' gem 'capybara-screenshot'
+1
View File
@@ -497,6 +497,7 @@ DEPENDENCIES
foreman foreman
foundation-rails foundation-rails
fuubar fuubar
hashie
iso_country_codes iso_country_codes
jquery-rails jquery-rails
jquery-ui-rails jquery-ui-rails
@@ -4,3 +4,17 @@
# "Accept": "application/json, text/javascript; q=0.01" # "Accept": "application/json, text/javascript; q=0.01"
App.ApplicationAdapter = DS.JSONAPIAdapter.extend App.ApplicationAdapter = DS.JSONAPIAdapter.extend
namespace: 'supplier' namespace: 'supplier'
pathForType: (type)->
type.underscore().pluralize()
createRecord: (store, type, snapshot)->
data = {}
#var serializer = store.serializerFor(type.modelName);
serializer = Ember.get(snapshot.record, 'store').serializerFor('creation')
url = @buildURL(type.modelName, null, snapshot, 'createRecord')
serializer.serializeIntoHash data, type, snapshot, includeId: true
@ajax url, "POST", data: data
#debugger
#Ember.get(snapshot.record, 'store').serializerFor('creation').serialize(snapshot)
#3
@@ -2,29 +2,23 @@ App.IndexController = Ember.Controller.extend
show_lists: true show_lists: true
show_orders: true show_orders: true
lists: (-> @store.peekAll('list')).property() lists: (-> @store.peekAll('list')).property()
orders: (-> @store.peekAll('order')).property() orders: Ember.computed -> @store.peekAll('order')
sections: (-> @store.peekAll('section')).property() sections: (-> @store.peekAll('section')).property()
active_section: Ember.computed.alias 'globals.active_section' active_section: Ember.computed.alias 'globals.active_section'
active_lists: (-> active_lists: Ember.computed 'lists.@each.state', 'active_section.id', ->
@get('orders') # trigger orders, otherwise observers are not initialized/triggered (active_orders)
if section_id = @get('active_section.id') if section_id = @get('active_section.id')
lists = @get('lists').filter (l)=>( l.get('section.id') == section_id && l.get('state') == 'active' ) lists = @get('lists').filter (l)=>( l.get('section.id') == section_id && l.get('state') == 'active' )
else else
lists = @get('lists').filterBy('state', 'active') lists = @get('lists').filterBy('state', 'active')
lists.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first :-) Customer happyness lists.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first, work your way down :-) Customer happyness
).property('lists.@each.state', 'active_section.id')
active_orders: Ember.computed 'active_lists.[]', 'active_orders.@each.state', -> active_orders: Ember.computed 'active_lists.[]', 'orders.@each.state', ->
orders = Ember.A() orders = Ember.A()
@get('active_lists').forEach (list)-> @get('active_lists').forEach (list)->
list.get('orders').filterBy('needs_supplier_attention').forEach (order)-> list.get('orders').filterBy('needs_supplier_attention').forEach (order)->
orders.push order orders.push order
return orders orders.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first, work your way down :-) Customer happyness
#if @get('active_section.id')
# orders = @get('orders').filter (o)=>( o.get('section.id') == @get('active_section.id') && o.get('needs_supplier_attention') )
#else
# orders = @get('orders').filter (o)->( o.get('needs_supplier_attention') )
#orders.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first :-) Customer happyness
#).property('orders.@each.state', 'active_section.id')
show_lists_table: Ember.computed 'show_lists', 'active_lists.[]', -> show_lists_table: Ember.computed 'show_lists', 'active_lists.[]', ->
@get('show_lists') and @get('active_lists.length') @get('show_lists') and @get('active_lists.length')
@@ -2,8 +2,9 @@ attr = DS.attr
App.EmployeeShift = DS.Model.extend App.EmployeeShift = DS.Model.extend
start_from: attr('moment') start_from: attr('moment')
end_on: attr('moment') end_on: attr('moment')
employee: DS.belongsTo 'employee'
description: attr('string') description: attr('string')
employee: DS.belongsTo 'employee', async: false
supplier: DS.belongsTo 'supplier', async: false
calendar_event: (-> calendar_event: (->
id: @id id: @id
title: @get('title') title: @get('title')
@@ -11,7 +12,6 @@ App.EmployeeShift = DS.Model.extend
end: @get('end_on') end: @get('end_on')
color: @get('employee.color') color: @get('employee.color')
).property('start_from', 'end_on', 'title') ).property('start_from', 'end_on', 'title')
supplier: DS.belongsTo('supplier')
title: Ember.computed 'employee.name', 'description', -> title: Ember.computed 'employee.name', 'description', ->
if @get('description') if @get('description')
@@ -5,18 +5,17 @@ App.List = DS.Model.extend
needs_payment: attr 'boolean' needs_payment: attr 'boolean'
user_requests_closing: attr('boolean') user_requests_closing: attr('boolean')
# users: DS.hasMany('user', async: true) # users: DS.hasMany('user', async: true)
users: DS.hasMany('user')
is_paid: attr 'boolean' is_paid: attr 'boolean'
price: attr 'number'
#has_active_orders: attr 'boolean' #has_active_orders: attr 'boolean'
price: attr 'number'
closed_at: DS.attr('date') closed_at: DS.attr('date')
users: DS.hasMany('user', async: false)
#table_number: attr 'number' #table_number: attr 'number'
table: DS.belongsTo('table', inverse: 'active_list', async: true) table: DS.belongsTo('table', inverse: 'active_list', async: false) # should be async, but synchroneously loading now fails with JSONAPI, this seems to work
#users: DS.hasMany('user', inverse: 'active_list') #users: DS.hasMany('user', inverse: 'active_list')
orders: DS.hasMany('order') orders: DS.hasMany('order', async: false)
section: DS.belongsTo('section') section: DS.belongsTo('section', async: false) # should be async, but synchroneously loading now fails with JSONAPI, this seems to work
section_id: attr('string')
active: ( -> @get('state') is 'active' ).property('state') active: ( -> @get('state') is 'active' ).property('state')
isClosed: -> isClosed: ->
@set('state', 'closed') @set('state', 'closed')
@@ -11,7 +11,7 @@ App.Order = DS.Model.extend
active: (-> @get('state') == 'active').property('state') active: (-> @get('state') == 'active').property('state')
delivered: (-> @get('state') == 'delivered').property('state') delivered: (-> @get('state') == 'delivered').property('state')
placed: (-> @get('state') == 'placed').property('state') placed: (-> @get('state') == 'placed').property('state')
needs_supplier_attention: (-> (@get('state') == 'placed') || (@get('state') == 'active')).property('state') needs_supplier_attention: (-> (@get('state') is 'placed') or (@get('state') is 'active')).property('state')
isClosed: -> isClosed: ->
@set 'state', 'closed' @set 'state', 'closed'
@@ -8,9 +8,9 @@ App.Product = DS.Model.extend Ember.Validations.Mixin,
active: attr('boolean', defaultValue: true) active: attr('boolean', defaultValue: true)
position: attr('number', defaultValue: 0) position: attr('number', defaultValue: 0)
image: attr() image: attr()
product_category: DS.belongsTo('product_category') product_category: DS.belongsTo('product_category', async: false)
product_orders: DS.hasMany('product_order') product_orders: DS.hasMany('product_order', async: false)
product_variants: DS.hasMany('product_variant') product_variants: DS.hasMany('product_variant', async: false)
image_src: (-> image_src: (->
image = @get('image') image = @get('image')
@@ -1,8 +1,6 @@
attr = DS.attr attr = DS.attr
App.ProductCategory = DS.Model.extend Ember.Validations.Mixin, App.ProductCategory = DS.Model.extend Ember.Validations.Mixin,
name: attr('string') name: attr('string')
products: DS.hasMany('product')
supplier: DS.belongsTo 'supplier'
active_on_sunday: attr('boolean', defaultValue: true) active_on_sunday: attr('boolean', defaultValue: true)
active_on_monday: attr('boolean', defaultValue: true) active_on_monday: attr('boolean', defaultValue: true)
active_on_tuesday: attr('boolean', defaultValue: true) active_on_tuesday: attr('boolean', defaultValue: true)
@@ -15,6 +13,9 @@ App.ProductCategory = DS.Model.extend Ember.Validations.Mixin,
end_on: attr('number') end_on: attr('number')
position: attr('number') position: attr('number')
products: DS.hasMany('product', async: false)
supplier: DS.belongsTo 'supplier', async: false
sorted_products: (-> @get('products').sortBy('position') ).property('products.@each.position') sorted_products: (-> @get('products').sortBy('position') ).property('products.@each.position')
availability_text: Ember.computed 'active_on_sunday', 'active_on_monday', 'active_on_tuesday', 'active_on_wednesday', 'active_on_thursday', 'active_on_friday', 'active_on_saturday', 'full_day', 'start_from', 'end_on', -> availability_text: Ember.computed 'active_on_sunday', 'active_on_monday', 'active_on_tuesday', 'active_on_wednesday', 'active_on_thursday', 'active_on_friday', 'active_on_saturday', 'full_day', 'start_from', 'end_on', ->
@@ -5,7 +5,7 @@ App.ProductOrder = DS.Model.extend
product_variant: attr('string') product_variant: attr('string')
product_name: attr('string') product_name: attr('string')
product: DS.belongsTo('product', async: true) product: DS.belongsTo('product', async: true)
order: DS.belongsTo('order') order: DS.belongsTo('order', async: false)
increment: -> increment: ->
@set('quantity', @get('quantity') + 1) @set('quantity', @get('quantity') + 1)
total: (-> @get('quantity') * @get('price')).property('quantity', 'price') total: (-> @get('quantity') * @get('price')).property('quantity', 'price')
@@ -6,6 +6,6 @@ App.SectionArea = DS.Model.extend Ember.Validations.Mixin,
position_x: attr 'number', defaultValue: 0 position_x: attr 'number', defaultValue: 0
position_y: attr 'number', defaultValue: 0 position_y: attr 'number', defaultValue: 0
rounded: attr 'boolean', defaultValue: false rounded: attr 'boolean', defaultValue: false
section: DS.belongsTo('section') section: DS.belongsTo('section', async: false)
validations: validations:
title: {presence: true} title: {presence: true}
@@ -3,4 +3,4 @@ App.SectionElement = DS.Model.extend App.SvgElementMixin, App.Rotation,
position_x: attr 'number', defaultValue: 0 position_x: attr 'number', defaultValue: 0
position_y: attr 'number', defaultValue: 0 position_y: attr 'number', defaultValue: 0
rotation: attr 'number', defaultValue: 0 rotation: attr 'number', defaultValue: 0
section: DS.belongsTo('section') section: DS.belongsTo('section', async: false)
@@ -15,9 +15,10 @@ App.Supplier = DS.Model.extend
lat: attr 'number' lat: attr 'number'
lng: attr 'number' lng: attr 'number'
week_starts_on_monday: attr 'boolean' week_starts_on_monday: attr 'boolean'
product_categories: DS.hasMany 'product_category'
orders_in_process_count: attr('number') orders_in_process_count: attr('number')
orders_placed_count: attr('number') orders_placed_count: attr('number')
product_categories: DS.hasMany 'product_category', async: false
employee_shifts: DS.hasMany('employee-shift') employee_shifts: DS.hasMany('employee-shift')
close: -> close: ->
@@ -131,11 +131,12 @@ App.ApplicationRoute = Ember.Route.extend
@store.pushPayload(data.payload) @store.pushPayload(data.payload)
if order_id = data.payload.data.id if order_id = data.payload.data.id
order = @store.peekRecord('order', order_id) order = @store.peekRecord('order', order_id)
return if @get('globals.active_section.id') and order.get('section.id') isnt @get('globals.active_section.id') return if @get('globals.active_section.id') and order.get('list.section.id') isnt @get('globals.active_section.id')
@set 'globals.flash_message', order.get('display_with_table') @set 'globals.flash_message', order.get('display_with_table')
try ion.sound.play('water_droplet') try ion.sound.play('water_droplet')
new_list: (data)-> new_list: (data)->
debugger if data.payload
@store.pushPayload(data.payload)
try ion.sound.play('water_droplet') try ion.sound.play('water_droplet')
list_changed_table: (data) -> @store.pushPayload('list', lists: [data.list]) list_changed_table: (data) -> @store.pushPayload('list', lists: [data.list])
list_closed: (data) -> list.isClosed() if list = @store.peekRecord('list', data.id) list_closed: (data) -> list.isClosed() if list = @store.peekRecord('list', data.id)
@@ -1,7 +1,4 @@
App.SectionsRoute = Ember.Route.extend App.SectionsRoute = Ember.Route.extend
beforeModel: ->
@store.findAll 'section-element'
@store.findAll 'section-area'
model: -> @store.peekAll 'section' model: -> @store.peekAll 'section'
# setupController: (controller, collection) -> # setupController: (controller, collection) ->
@@ -1,7 +1,8 @@
#App.ApplicationSerializer = DS.ActiveModelSerializer #App.ApplicationSerializer = DS.ActiveModelSerializer
App.ApplicationSerializer = DS.JSONAPISerializer.extend App.ApplicationSerializer = DS.JSONAPISerializer.extend {}
keyForAttribute: (attr, method)-> attr App.CreationSerializer = DS.ActiveModelSerializer.extend {}
# keyForAttribute: (attr, method)-> attr
#App.ApplicationStore = DS.Store #App.ApplicationStore = DS.Store
#adapter: DS.ActiveModelAdapter.extend #adapter: DS.ActiveModelAdapter.extend
#namespace: 'supplier' #namespace: 'supplier'
@@ -7,12 +7,12 @@ module Suppliers
@employee_shifts.select! do |shift| @employee_shifts.select! do |shift|
current_supplier.employee_ids.include?(shift.employee.try(:id)) current_supplier.employee_ids.include?(shift.employee.try(:id))
end end
render json: JSONAPI::Serializer.serialize(@employee_shifts, serializer: Suppliers::EmployeeShiftSerializer, is_collection: true, include: %w[employee supplier]) render json: JSONAPI::Serializer.serialize(@employee_shifts, serializer: Suppliers::EmployeeShiftSerializer, is_collection: true, include: %w[employee])
end end
def create def create
@employee_shift.supplier = current_supplier @employee_shift.supplier = current_supplier
@employee_shift.save @employee_shift.save
render json: JSONAPI::Serializer.serialize(@employee_shift, serializer: Suppliers::EmployeeShiftSerializer, include: %w[employee supplier]) render json: JSONAPI::Serializer.serialize(@employee_shift, serializer: Suppliers::EmployeeShiftSerializer, include: %w[employee])
end end
def update def update
@@ -31,6 +31,5 @@ module Suppliers
def employee_shift_params def employee_shift_params
params.require(:employee_shift).permit(:start_from, :end_on, :employee_id, :description) params.require(:employee_shift).permit(:start_from, :end_on, :employee_id, :description)
end end
end end
end end
@@ -23,13 +23,9 @@ module Suppliers
render json: JSONAPI::Serializer.serialize(@lists, serializer: Suppliers::ListSerializer, is_collection: true, include: %w[ render json: JSONAPI::Serializer.serialize(@lists, serializer: Suppliers::ListSerializer, is_collection: true, include: %w[
orders orders
orders.list
orders.user orders.user
orders.product_orders orders.product_orders
orders.product_orders.product
users users
section
table
]) ])
end end
@@ -6,6 +6,15 @@ module Suppliers
def show def show
current_supplier.sections.include_relations(:tables, :section_areas, :section_elements, product_categories: {products: :product_variants}) current_supplier.sections.include_relations(:tables, :section_areas, :section_elements, product_categories: {products: :product_variants})
#render json: JSONAPI::Serializer.serialize(current_supplier, serializer: Suppliers::SupplierSerializer, include: %w[
#sections
#sections.tables
#sections.section_areas
#sections.section_elements
#product_categories
#product_categories.products
#product_categories.products.product_variants
#]) #.new(current_supplier).as_json
render json: JSONAPI::Serializer.serialize(current_supplier, serializer: Suppliers::SupplierSerializer, include: %w[ render json: JSONAPI::Serializer.serialize(current_supplier, serializer: Suppliers::SupplierSerializer, include: %w[
sections sections
sections.tables sections.tables
@@ -14,7 +23,7 @@ module Suppliers
product_categories product_categories
product_categories.products product_categories.products
product_categories.products.product_variants product_categories.products.product_variants
]) #.new(current_supplier).as_json ])
end end
def update def update
+1 -1
View File
@@ -27,7 +27,7 @@ module Users
def show def show
@list ||= List.find(params[:id]) if params[:id] @list ||= List.find(params[:id]) if params[:id]
render json: {}, status: :not_found and return unless @list.present? && Array.wrap(@list.user_ids).include?(current_user.id) render json: {}, status: :not_found and return unless @list.present? && Array.wrap(@list.user_ids).include?(current_user.id)
render json: JSONAPI::Serializer.serialize(@list, serializer: Users::ListSerializer, include: %w[supplier users join_requests join_requests.list join_requests.user]) render json: JSONAPI::Serializer.serialize(@list, serializer: Users::ListSerializer, include: %w[supplier users join_requests join_requests.user])
end end
# POST /user/list_needs_payment.json # POST /user/list_needs_payment.json
+4
View File
@@ -37,6 +37,10 @@ class Employee
end end
end end
def to_hash
attributes.merge(settings.as_json).merge("id" => id)
end
#validates :email, email: true #validates :email, email: true
has_and_belongs_to_many :suppliers, storing_keys: false has_and_belongs_to_many :suppliers, storing_keys: false
has_many :orders has_many :orders
+2 -1
View File
@@ -320,11 +320,12 @@ class List
table table
]) ])
# broadcast_supplier supplier.id, 'new_order', OrderSerializer.new(order) # broadcast_supplier supplier.id, 'new_order', OrderSerializer.new(order)
broadcast_supplier supplier.id, 'new_list', supplier_orders_placed_count: orders_placed_count, payload: supplier_payload broadcast_supplier supplier.id, 'new_list', supplier_orders_placed_count: orders_placed_count, payload: supplier_payload, list_id: self.id
else else
# broadcast_users 'new_order', order: order.with_products_as_json, total_amount: price # broadcast_users 'new_order', order: order.with_products_as_json, total_amount: price
user_payload = JSONAPI::Serializer.serialize(order, serializer: Users::OrderSerializer, include: %w[list user product_orders product_orders.order]) user_payload = JSONAPI::Serializer.serialize(order, serializer: Users::OrderSerializer, include: %w[list user product_orders product_orders.order])
supplier_payload = JSONAPI::Serializer.serialize(order, serializer: Suppliers::OrderSerializer, include: %w[ supplier_payload = JSONAPI::Serializer.serialize(order, serializer: Suppliers::OrderSerializer, include: %w[
list
user user
product_orders product_orders
]) ])
@@ -1,5 +1,6 @@
class Suppliers::EmployeeShiftSerializer class Suppliers::EmployeeShiftSerializer
include Qwaiter::SupplierBaseSerializer include Qwaiter::SupplierBaseSerializer
attributes :start_from, :end_on, :employee_id, :supplier_id attributes :start_from, :end_on
has_one :supplier, serializer: Suppliers::SupplierSerializer has_one :supplier, serializer: Suppliers::SupplierSerializer
has_one :employee, serializer: Suppliers::EmployeeSerializer
end end
@@ -4,4 +4,5 @@ class Suppliers::ProductCategorySerializer
:active_on_thursday, :active_on_friday, :active_on_saturday, :full_day, :start_from, :end_on, :active_on_thursday, :active_on_friday, :active_on_saturday, :full_day, :start_from, :end_on,
:position :position
has_many :products, serializer: Suppliers::ProductSerializer has_many :products, serializer: Suppliers::ProductSerializer
has_one :supplier, serializer: Suppliers::SupplierSerializer
end end
@@ -10,5 +10,5 @@ class Suppliers::ProductSerializer
end end
has_many :product_variants, serializer: Suppliers::ProductVariantSerializer has_many :product_variants, serializer: Suppliers::ProductVariantSerializer
has_one :product_category, serializer: Suppliers::ProductSerializer has_one :product_category, serializer: Suppliers::ProductCategorySerializer
end end
@@ -1,4 +1,5 @@
class Suppliers::ProductVariantSerializer class Suppliers::ProductVariantSerializer
include Qwaiter::SupplierBaseSerializer include Qwaiter::SupplierBaseSerializer
attributes :name attributes :name
has_one :product, serializer: Suppliers::ProductSerializer
end end
@@ -1,7 +1,8 @@
class Suppliers::SectionSerializer class Suppliers::SectionSerializer
include Qwaiter::SupplierBaseSerializer include Qwaiter::SupplierBaseSerializer
attributes :title, :path, :width, :height attributes :title, :width, :height #, :path
has_many :tables, serializer: Suppliers::TableSerializer has_many :tables, serializer: Suppliers::TableSerializer
has_many :section_areas, serializer: Suppliers::SectionAreaSerializer has_many :section_areas, serializer: Suppliers::SectionAreaSerializer
has_many :section_elements, serializer: Suppliers::SectionElementSerializer has_many :section_elements, serializer: Suppliers::SectionElementSerializer
has_one :supplier, serializer: Suppliers::SupplierSerializer
end end
+4
View File
@@ -5,6 +5,10 @@ class JoinRequest
end end
alias _id id alias _id id
def list_id
list.try(:id)
end
def initialize(user: nil, list: nil, created_at: Time.now, updated_at: Time.now) def initialize(user: nil, list: nil, created_at: Time.now, updated_at: Time.now)
@user, @list, @created_at, @updated_at = [user, list, created_at, updated_at] @user, @list, @created_at, @updated_at = [user, list, created_at, updated_at]
end end
@@ -2,7 +2,7 @@
//var $locale = '<%= I18n.locale %>'; //var $locale = '<%= I18n.locale %>';
//var supplier_id = '<%= current_supplier.id %>'; //var supplier_id = '<%= current_supplier.id %>';
var supplier_object=<%= {id: current_supplier.id}.to_json.html_safe %>; var supplier_object=<%= {id: current_supplier.id}.to_json.html_safe %>;
var employee_object=<%=raw current_employee.attributes.merge(id: current_employee.id).to_json %>; var employee_object=<%=raw current_employee.to_json %>;
var data_host = ''; var data_host = '';
var $asset_path = '/assets/'; var $asset_path = '/assets/';
var event_host = '<%= Qwaiter.event_host %>'; var event_host = '<%= Qwaiter.event_host %>';
+2 -2
View File
@@ -1,4 +1,4 @@
.home-panel /.home-panel
.home-header = image_tag 'logo.png' .home-header = image_tag 'logo.png'
.home-center .home-center
a href="#" onClick="QMobile.scanQr()" = image_tag 'user/scan-logo.png' a href="#" onClick="QMobile.scanQr()" = image_tag 'user/scan-logo.png'
@@ -6,7 +6,7 @@
.home-footer-content .home-footer-content
= link_to content_tag(:span, 'P'), user_list_products_path, class: ['home-link', 'home-menu-link'] = link_to content_tag(:span, 'P'), user_list_products_path, class: ['home-link', 'home-menu-link']
= link_to content_tag(:span, 'L'), user_active_list_path, class: ['home-link', 'home-list-link'] = link_to content_tag(:span, 'L'), user_active_list_path, class: ['home-link', 'home-list-link']
- content_for :footer do /- content_for :footer do
javascript: javascript:
$(function(){ $(function(){
Quser.home_loader(); Quser.home_loader();
+1 -1
View File
@@ -54,7 +54,7 @@ Qwaiter::Application.routes.draw do
# USER # USER
#default_url_options format: 'html' #default_url_options format: 'html'
#get '/user/index' => 'user#index', as: :user_root #get '/user/index' => 'user#index', as: :user_root
#get '/user' => 'user#index' get '/user' => 'user#index'
#get '/user/active_list(.:format)' => 'user#active_list', as: :user_active_list #get '/user/active_list(.:format)' => 'user#active_list', as: :user_active_list
#get '/user/list_info' => 'user#list_info', as: :user_list_info, via: [:get, :options] #get '/user/list_info' => 'user#list_info', as: :user_list_info, via: [:get, :options]
#post '/user/needs_help' => 'user#needs_help', as: :user_needs_help #post '/user/needs_help' => 'user#needs_help', as: :user_needs_help
+4 -5
View File
@@ -12,18 +12,17 @@ module Qwaiter::SupplierBaseSerializer
end end
def format_name(attribute_name) def format_name(attribute_name)
#attribute_name.to_s.dasherize attribute_name.to_s.dasherize
attribute_name.to_s
end end
def unformat_name(attribute_name) def unformat_name(attribute_name)
#attribute_name.to_s.underscore attribute_name.to_s.underscore
attribute_name.to_s
end end
#alias_method :default_relationship_related_link, :relationship_related_link #alias_method :default_relationship_related_link, :relationship_related_link
def relationship_related_link(attribute_name) def relationship_related_link(attribute_name)
super if related_link_for_attributes.include?(attribute_name) #super if related_link_for_attributes.include?(attribute_name)
super
end end
def relationship_self_link(attribute_name) def relationship_self_link(attribute_name)
@@ -0,0 +1,18 @@
require 'spec_helper'
describe "asldfj", type: :request do
let(:supplier){ create :supplier }
let(:employee){ create :employee }
before do
supplier.add_employee(employee)
login_as employee, scope: :employee
end
it "works" do
supplier = create :supplier
get "/supplier/suppliers/#{supplier.id}.json"
api_response.data.relationships.product_categorie
included_section = api_response.included.find{|ih| ih['type'] == 'sections'}
included_section['relationships']['tables']['data'].should eq []
included_section['relationships']['section-areas']['data'].should eq []
end
end
+38 -4
View File
@@ -41,6 +41,25 @@ module FactoryAttributesFor
super(obj, options).merge(build(obj).attributes.select{|k,v| k =~ /_id$/}).symbolize_keys super(obj, options).merge(build(obj).attributes.select{|k,v| k =~ /_id$/}).symbolize_keys
end end
end end
module RequestSpecHelpers
module MethodsForHash
def method_missing(m, *args)
r = self[m.to_s.dasherize]
if r.is_a?(Hash)
r.extend MethodsForHash
end
r
end
end
def api_response
result = JSON.parse(response.body)
result.extend MethodsForHash
#result.extend Hashie::Extensions::DeepFind
result
end
end
module SpecSelectorHelpers module SpecSelectorHelpers
def top_navigation def top_navigation
'.navbar-fixed-top' '.navbar-fixed-top'
@@ -61,6 +80,12 @@ module SpecSelectorHelpers
end end
class Ability
include CanCan::Ability
def initialize(record)
can :manage, :All
end
end
class TestCounter < InMemoryQCounter class TestCounter < InMemoryQCounter
#def incr(*args) #def incr(*args)
#result = super #result = super
@@ -103,6 +128,8 @@ RSpec.configure do |config|
config.include SpecRouteHelpers, type: :feature config.include SpecRouteHelpers, type: :feature
config.include SpecEmberHelpers, type: :feature config.include SpecEmberHelpers, type: :feature
config.include SerializersTestHelpers, type: :serializer config.include SerializersTestHelpers, type: :serializer
config.include Warden::Test::Helpers, type: :request
config.include RequestSpecHelpers, type: :request
#config.use_transactional_fixtures = true #config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = true config.infer_base_class_for_anonymous_controllers = true
config.filter_run_excluding broken: true config.filter_run_excluding broken: true
@@ -165,10 +192,17 @@ RSpec.configure do |config|
Qwaiter::Counter.connection.flush Qwaiter::Counter.connection.flush
end end
config.before :each, type: :feature do config.before :each, type: :feature do
#Supplier.any_instance.stub send_confirmation_instructions: true #Supplier.any_instance.stub send_confirmation_instructions: true
Capybara.session_name = :default Capybara.session_name = :default
end end
config.around :each, type: :request do |example|
Warden.test_mode!
example.run
Warden.test_reset!
end
config.after :suite do config.after :suite do
=begin =begin