continuing the refactor of the admin section
This commit is contained in:
@@ -2,5 +2,9 @@ module Admin
|
||||
class ApplicationController < ::ApplicationController
|
||||
before_filter :authenticate_administrator!
|
||||
layout 'administrator'
|
||||
private
|
||||
def set_locale
|
||||
I18n.locale = :en
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -44,6 +44,7 @@ module Admin
|
||||
# POST /lists.json
|
||||
def create
|
||||
@list = List.new(params[:list])
|
||||
@list.supplier_id = params[:list][:supplier_id]
|
||||
|
||||
respond_to do |format|
|
||||
if @list.save
|
||||
|
||||
@@ -44,6 +44,7 @@ module Admin
|
||||
# POST /product_categories.json
|
||||
def create
|
||||
@product_category = ProductCategory.new(params[:product_category])
|
||||
@product_category.supplier_id = params[:product_category][:supplier_id]
|
||||
|
||||
respond_to do |format|
|
||||
if @product_category.save
|
||||
|
||||
@@ -44,6 +44,7 @@ module Admin
|
||||
# POST /products.json
|
||||
def create
|
||||
@product = Product.new(params[:product])
|
||||
@product.supplier_id = params[:product][:supplier_id]
|
||||
|
||||
respond_to do |format|
|
||||
if @product.save
|
||||
|
||||
@@ -44,6 +44,7 @@ module Admin
|
||||
# POST /sections.json
|
||||
def create
|
||||
@section = Section.new(params[:section])
|
||||
@section.supplier_id = params[:section][:supplier_id]
|
||||
|
||||
respond_to do |format|
|
||||
if @section.save
|
||||
|
||||
@@ -44,6 +44,7 @@ module Admin
|
||||
# POST /tables.json
|
||||
def create
|
||||
@table = Table.new(params[:table])
|
||||
@table.supplier_id = params[:table][:supplier_id]
|
||||
|
||||
respond_to do |format|
|
||||
if @table.save
|
||||
|
||||
@@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
protect_from_forgery
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
def broadcast_user(uid, event, data = {})
|
||||
message = {channel: "/user/#{uid}", data: {event: event, data: data}}
|
||||
|
||||
@@ -2,4 +2,6 @@ class Administrator
|
||||
include SimplyStored::Couch
|
||||
include Devise::Orm::SimplyStored
|
||||
devise :database_authenticatable, :rememberable #, :recoverable, :rememberable, :trackable, :registerable
|
||||
|
||||
view :by_email, key: :email
|
||||
end
|
||||
|
||||
@@ -17,6 +17,8 @@ class List
|
||||
belongs_to :section
|
||||
has_and_belongs_to_many :users, storing_keys: true
|
||||
|
||||
attr_protected :supplier_id
|
||||
|
||||
validates :table_id, presence: true
|
||||
validates :supplier_id, presence: true
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@ class Product
|
||||
belongs_to :supplier # direct! category is an aid
|
||||
has_many :product_orders
|
||||
|
||||
attr_protected :supplier_id
|
||||
|
||||
validates :name, presence: true
|
||||
validates :supplier_id, presence: true
|
||||
validates :price, presence: true, numericality: true
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ class ProductCategory
|
||||
|
||||
attr_protected :supplier_id
|
||||
|
||||
validates :name, presence: true
|
||||
validates :position, numericality: true
|
||||
validates :supplier_id, presence: true
|
||||
|
||||
|
||||
@@ -8,5 +8,6 @@ class ProductOrder
|
||||
belongs_to :order
|
||||
|
||||
view :by_product_id, key: :product_id
|
||||
view :by_order_id, key: :order_id
|
||||
|
||||
end
|
||||
|
||||
@@ -2,7 +2,6 @@ class Section
|
||||
include SimplyStored::Couch
|
||||
|
||||
property :title
|
||||
|
||||
property :path, type: Array, default: []
|
||||
|
||||
belongs_to :supplier
|
||||
@@ -12,6 +11,7 @@ class Section
|
||||
|
||||
attr_protected :supplier_id
|
||||
|
||||
validates :title, presence: true
|
||||
validates :supplier_id, presence: true
|
||||
|
||||
# Probably faster to directly retreive the document and return nil
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
= form_for @list, html: {class: 'form-horizontal' } do |f|
|
||||
= form_for [:admin, @list], html: {class: 'form-horizontal' } do |f|
|
||||
= render 'error_messages', target: @list
|
||||
.control-group class=(@list.errors[:state].any? ? 'error' : nil)
|
||||
= f.label :state, class: 'control-label'
|
||||
@@ -27,4 +27,4 @@
|
||||
.form-actions
|
||||
= f.submit nil, class: 'btn btn-primary'
|
||||
'
|
||||
= link_to t("helpers.links.cancel"), lists_path, class: 'btn'
|
||||
= link_to t("helpers.links.cancel"), admin_lists_path, class: 'btn'
|
||||
@@ -15,18 +15,18 @@ div.page-header= title :index, model_class
|
||||
tbody
|
||||
- @lists.each do |list|
|
||||
tr
|
||||
td= link_to list.state, list
|
||||
td= list.needs_help
|
||||
td= list.needs_payment
|
||||
td= link_to list.state, [:admin, list]
|
||||
td= show_boolean list.needs_help
|
||||
td= show_boolean list.needs_payment
|
||||
td= list.closed_at
|
||||
td= link_to_if list.table.present?, list.table.try(:number), list.table
|
||||
td= link_to_if list.supplier.present?, list.supplier.try(:name), list.supplier
|
||||
td= link_to_if list.table.present?, list.table.try(:number), [:admin, list.table]
|
||||
td= link_to list.supplier.name, [:admin, list.supplier]
|
||||
td=l list.created_at, format: :short
|
||||
td
|
||||
= link_to t('helpers.links.edit'), [:edit, list], class: 'btn btn-mini'
|
||||
= link_to t('helpers.links.edit'), [:edit, :admin, list], class: 'btn btn-mini'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), list, method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger'
|
||||
= link_to t("helpers.links.destroy"), [:admin, list], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger'
|
||||
- else
|
||||
= no_content_given model_class
|
||||
= link_to t("helpers.links.new"), new_list_path, class: 'btn btn-primary'
|
||||
= link_to t("helpers.links.new"), new_admin_list_path, class: 'btn btn-primary'
|
||||
|
||||
@@ -12,14 +12,13 @@ dl.dl-horizontal.show-list
|
||||
dd= @list.closed_at
|
||||
- if @list.table.present?
|
||||
dt= Table.model_name.human
|
||||
dd= link_to @list.table.number, @list.table
|
||||
- if @list.supplier.present?
|
||||
dd= link_to @list.table.number, [:admin, @list.table]
|
||||
dt= Supplier.model_name.human
|
||||
dd= link_to @list.supplier.name, @list.supplier
|
||||
dd= link_to @list.supplier.name, [:admin, @list.supplier]
|
||||
|
||||
.form-actions
|
||||
= link_to t("helpers.links.back"), lists_path, class: 'btn'
|
||||
= link_to t("helpers.links.back"), admin_lists_path, class: 'btn'
|
||||
'
|
||||
= link_to t('helpers.links.edit'), [:edit, @list], class: 'btn'
|
||||
= link_to t('helpers.links.edit'), [:edit, :admin, @list], class: 'btn'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), @list, method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger'
|
||||
= link_to t("helpers.links.destroy"), [:admin, @list], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger'
|
||||
@@ -0,0 +1,12 @@
|
||||
= simple_form_for [:admin, @product_category], html: {class: 'form-horizontal' } do |f|
|
||||
= render 'error_messages', target: @product_category
|
||||
= f.input :name
|
||||
= f.input :position
|
||||
.control-group class=(@product_category.errors[:supplier_id].any? ? 'error' : nil)
|
||||
= f.label :supplier_id, Supplier.model_name.human, class: 'control-label'
|
||||
.controls
|
||||
= f.collection_select :supplier_id, @suppliers, :id, :name, include_blank: nil
|
||||
.form-actions
|
||||
= f.submit nil, class: 'btn btn-primary'
|
||||
'
|
||||
= link_to t("helpers.links.cancel"), admin_product_categories_path, class: 'btn'
|
||||
+1
-2
@@ -1,4 +1,3 @@
|
||||
- model_class = ProductCategory
|
||||
.page-header
|
||||
= title :edit, model_class
|
||||
.page-header= title :edit, model_class
|
||||
= render 'form'
|
||||
+5
-5
@@ -12,15 +12,15 @@
|
||||
tbody
|
||||
- @product_categories.each do |product_category|
|
||||
tr
|
||||
td.link= link_to product_category.name, product_category
|
||||
td.link= link_to product_category.name, [:admin, product_category]
|
||||
td= product_category.position
|
||||
td.link= link_to_if product_category.supplier.present?, product_category.supplier.try(:name), product_category.supplier
|
||||
td.link= link_to product_category.supplier.name, [:admin, product_category.supplier]
|
||||
td.timestamp=l product_category.created_at, format: :short
|
||||
td.actions
|
||||
= link_to t('helpers.links.edit'), [:edit, product_category], class: 'btn btn-mini'
|
||||
= link_to t('helpers.links.edit'), [:edit, :admin, product_category], class: 'btn btn-mini'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), product_category, method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger'
|
||||
= link_to t("helpers.links.destroy"), [:admin, product_category], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger'
|
||||
- else
|
||||
= no_content_given model_class
|
||||
= link_to t("helpers.links.new"), new_product_category_path, class: 'btn btn-primary'
|
||||
= link_to t("helpers.links.new"), new_admin_product_category_path, class: 'btn btn-primary'
|
||||
|
||||
+1
-2
@@ -1,4 +1,3 @@
|
||||
- model_class = ProductCategory
|
||||
.page-header
|
||||
= title :new, model_class
|
||||
.page-header= title :new, model_class
|
||||
= render 'form'
|
||||
@@ -0,0 +1,17 @@
|
||||
- model_class = ProductCategory
|
||||
.page-header= title :show, @product_category
|
||||
|
||||
dl.dl-horizontal.show-list
|
||||
dt= model_class.human_attribute_name(:name)
|
||||
dd= @product_category.name
|
||||
dt= model_class.human_attribute_name(:position)
|
||||
dd= @product_category.position
|
||||
dt= Supplier.model_name.human
|
||||
dd= link_to @product_category.supplier.name, [:admin, @product_category.supplier]
|
||||
|
||||
.form-actions
|
||||
= link_to t("helpers.links.back"), admin_product_categories_path, class: 'btn'
|
||||
'
|
||||
= link_to t('helpers.links.edit'), [:edit, :admin, @product_category], class: 'btn'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), [:admin, @product_category], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger'
|
||||
@@ -0,0 +1,11 @@
|
||||
= simple_form_for [:admin, @section], html: {class: 'form-horizontal' } do |f|
|
||||
= render 'error_messages', target: @section
|
||||
= f.input :title
|
||||
.control-group class=(@section.errors[:supplier_id].any? ? 'error' : nil)
|
||||
= f.label :supplier_id, Supplier.model_name.human, class: 'control-label'
|
||||
.controls
|
||||
= f.collection_select :supplier_id, @suppliers, :id, :name, include_blank: nil
|
||||
.form-actions
|
||||
= f.submit nil, class: 'btn btn-primary'
|
||||
'
|
||||
= link_to t("helpers.links.cancel"), admin_sections_path, class: 'btn'
|
||||
@@ -5,22 +5,20 @@
|
||||
thead
|
||||
tr
|
||||
th= model_class.human_attribute_name(:title)
|
||||
th= model_class.human_attribute_name(:path)
|
||||
th= Supplier.model_name.human
|
||||
th= model_class.human_attribute_name(:created_at)
|
||||
th=t 'helpers.actions'
|
||||
tbody
|
||||
- @sections.each do |section|
|
||||
tr
|
||||
td= link_to section.title, section
|
||||
td= section.path
|
||||
td= link_to_if section.supplier.present?, section.supplier.try(:name), section.supplier
|
||||
td= link_to section.title, [:admin, section]
|
||||
td= link_to_if section.supplier.present?, section.supplier.try(:name), [:admin, section.supplier]
|
||||
td=l section.created_at, format: :short
|
||||
td
|
||||
= link_to t('helpers.links.edit'), [:edit, section], class: 'btn btn-mini'
|
||||
= link_to t('helpers.links.edit'), [:edit, :admin, section], class: 'btn btn-mini'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), section, method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger'
|
||||
= link_to t("helpers.links.destroy"), [:admin, section], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger'
|
||||
- else
|
||||
= no_content_given model_class
|
||||
= link_to t("helpers.links.new"), new_section_path, class: 'btn btn-primary'
|
||||
= link_to t("helpers.links.new"), new_admin_section_path, class: 'btn btn-primary'
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
- model_class = Section
|
||||
.page-header= title :new, model_class
|
||||
= render 'form'
|
||||
@@ -0,0 +1,17 @@
|
||||
- model_class = Section
|
||||
.page-header= title :show, @section
|
||||
|
||||
dl.dl-horizontal.show-list
|
||||
dt= model_class.human_attribute_name(:title)
|
||||
dd= @section.title
|
||||
dt= model_class.human_attribute_name(:path)
|
||||
dd= @section.path.to_json
|
||||
dt= Supplier.model_name.human
|
||||
dd= link_to @section.supplier.name, [:admin, @section.supplier]
|
||||
|
||||
.form-actions
|
||||
= link_to t("helpers.links.back"), admin_sections_path, class: 'btn'
|
||||
'
|
||||
= link_to t('helpers.links.edit'), [:edit, :admin, @section], class: 'btn'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), [:admin, @section], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger'
|
||||
@@ -35,6 +35,7 @@ html lang="en"
|
||||
b.caret
|
||||
ul.child-menu.dropdown-menu
|
||||
li= link_to Supplier.model_name.human_plural, admin_suppliers_path
|
||||
li= link_to Section.model_name.human_plural, admin_sections_path
|
||||
li= link_to Table.model_name.human_plural, admin_tables_path
|
||||
li= link_to Product.model_name.human_plural, admin_products_path
|
||||
li= link_to List.model_name.human_plural, admin_lists_path
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
= form_for @product_category, html: {class: 'form-horizontal' } do |f|
|
||||
= render 'error_messages', target: @product_category
|
||||
.control-group class=(@product_category.errors[:name].any? ? 'error' : nil)
|
||||
= f.label :name, class: 'control-label'
|
||||
.controls
|
||||
= f.text_field :name, class: 'text_field'
|
||||
.control-group class=(@product_category.errors[:position].any? ? 'error' : nil)
|
||||
= f.label :position, class: 'control-label'
|
||||
.controls
|
||||
= f.text_field :position, class: 'text_field'
|
||||
.control-group class=(@product_category.errors[:supplier_id].any? ? 'error' : nil)
|
||||
= f.label :supplier_id, Supplier.model_name.human, class: 'control-label'
|
||||
.controls
|
||||
= f.collection_select :supplier_id, @suppliers, :id, :name, include_blank: nil
|
||||
.form-actions
|
||||
= f.submit nil, class: 'btn btn-primary'
|
||||
'
|
||||
= link_to t("helpers.links.cancel"), product_categories_path, class: 'btn'
|
||||
@@ -1,18 +0,0 @@
|
||||
- model_class = ProductCategory
|
||||
.page-header= title :show, @product_category
|
||||
|
||||
dl.dl-horizontal.show-list
|
||||
dt= model_class.human_attribute_name(:name)
|
||||
dd= @product_category.name
|
||||
dt= model_class.human_attribute_name(:position)
|
||||
dd= @product_category.position
|
||||
- if @product_category.supplier.present?
|
||||
dt= Supplier.model_name.human
|
||||
dd= link_to @product_category.supplier.name, @product_category.supplier
|
||||
|
||||
.form-actions
|
||||
= link_to t("helpers.links.back"), product_categories_path, class: 'btn'
|
||||
'
|
||||
= link_to t('helpers.links.edit'), [:edit, @product_category], class: 'btn'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), @product_category, method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger'
|
||||
@@ -1,18 +0,0 @@
|
||||
= form_for @section, html: {class: 'form-horizontal' } do |f|
|
||||
= render 'error_messages', target: @section
|
||||
.control-group class=(@section.errors[:title].any? ? 'error' : nil)
|
||||
= f.label :title, class: 'control-label'
|
||||
.controls
|
||||
= f.text_field :title, class: 'text_field'
|
||||
.control-group class=(@section.errors[:path].any? ? 'error' : nil)
|
||||
= f.label :path, class: 'control-label'
|
||||
.controls
|
||||
= f.text_field :path, class: 'text_field'
|
||||
.control-group class=(@section.errors[:supplier_id].any? ? 'error' : nil)
|
||||
= f.label :supplier_id, Supplier.model_name.human, class: 'control-label'
|
||||
.controls
|
||||
= f.collection_select :supplier_id, @suppliers, :id, :name, include_blank: nil
|
||||
.form-actions
|
||||
= f.submit nil, class: 'btn btn-primary'
|
||||
'
|
||||
= link_to t("helpers.links.cancel"), sections_path, class: 'btn'
|
||||
@@ -1,4 +0,0 @@
|
||||
- model_class = Section
|
||||
.page-header
|
||||
= title :new, model_class
|
||||
= render 'form'
|
||||
@@ -1,18 +0,0 @@
|
||||
- model_class = Section
|
||||
.page-header= title :show, @section
|
||||
|
||||
dl.dl-horizontal.show-list
|
||||
dt= model_class.human_attribute_name(:title)
|
||||
dd= @section.title
|
||||
dt= model_class.human_attribute_name(:path)
|
||||
dd= @section.path
|
||||
- if @section.supplier.present?
|
||||
dt= Supplier.model_name.human
|
||||
dd= link_to @section.supplier.name, @section.supplier
|
||||
|
||||
.form-actions
|
||||
= link_to t("helpers.links.back"), sections_path, class: 'btn'
|
||||
'
|
||||
= link_to t('helpers.links.edit'), [:edit, @section], class: 'btn'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), @section, method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger'
|
||||
@@ -7,6 +7,7 @@ Qwaiter::Application.routes.draw do
|
||||
resources :suppliers
|
||||
resources :tables
|
||||
resources :orders
|
||||
resources :sections
|
||||
|
||||
resources :lists
|
||||
resources :products
|
||||
|
||||
@@ -31,6 +31,11 @@ module BjController
|
||||
def controller_class_name
|
||||
"#{controller_name.classify.pluralize}Controller"
|
||||
end
|
||||
|
||||
def required_attribute_name
|
||||
m = model_name.classify.constantize
|
||||
m.validators.find{|v| v.is_a? ActiveModel::Validations::PresenceValidator }.try(:attributes).try(:first) || m.property_names.find{|k| k !~ /(_id|_at)$/}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -87,16 +87,14 @@ describe <%= controller_class_name %> do
|
||||
context "valid attributes" do
|
||||
it "located the requested <%= model_name %>" do
|
||||
put :update, id: @<%= model_name %>, <%= model_name %>: attributes_for(:<%= model_name %>)
|
||||
@<%= model_name %>.reload
|
||||
assigns(:<%= model_name %>).should eq(@<%= model_name %>)
|
||||
end
|
||||
|
||||
it "changes @<%= model_name %>'s attributes" do
|
||||
attributes = attributes_for(:<%= model_name %>)
|
||||
attribute_to_change = attributes.keys.find{|k| k !~ /_id$/}
|
||||
attributes[attribute_to_change] = "ChangedByTest"
|
||||
put :update, id: @<%= model_name %>, <%= model_name %>: attributes
|
||||
put :update, id: @<%= model_name %>, <%= model_name %>: attributes_for(:<%= model_name %>, <%= required_attribute_name %>: "ChangedByTest")
|
||||
@<%= model_name %>.reload
|
||||
@<%= model_name %>.send(attribute_to_change).should eq("ChangedByTest")
|
||||
@<%= model_name %>.<%= required_attribute_name %>.should eq("ChangedByTest")
|
||||
end
|
||||
|
||||
it "redirects to the updated <%= model_name %>" do
|
||||
@@ -104,5 +102,34 @@ describe <%= controller_class_name %> do
|
||||
response.should redirect_to <%= controller_namespace_path.present? ? "[#{controller_namespace_path.split('/').map{|n| ":#{n}"}.join(', ')}, @#{model_name}]" : "@#{model_name}" %>
|
||||
end
|
||||
end
|
||||
|
||||
context "invalid attributes" do
|
||||
it "locates the requested <%= model_name %>" do
|
||||
put :update, id: @<%= model_name %>, <%= model_name %>: {<%= required_attribute_name %>: ''}
|
||||
assigns(:<%= model_name %>).should eq(@<%= model_name %>)
|
||||
end
|
||||
|
||||
it "re-renders the edit method" do
|
||||
put :update, id: @<%= model_name %>, <%= model_name %>: {<%= required_attribute_name %>: ''}
|
||||
response.should render_template :edit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE destroy' do
|
||||
before :each do
|
||||
@<%= model_name %> = create :<%= model_name %>
|
||||
end
|
||||
|
||||
it "deletes the <%= model_name %>" do
|
||||
expect{
|
||||
delete :destroy, id: @<%= model_name %>
|
||||
}.to change(<%= model_name.classify %>, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to <%= model_plural_name %>#index" do
|
||||
delete :destroy, id: @<%= model_name %>
|
||||
response.should redirect_to <%= controller_namespace_path.present? ? "[#{controller_namespace_path.split('/').map{|n| ":#{n}"}.join(', ')}, :#{model_plural_name}]" : "#{model_plural_name}_path" %>
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,12 +11,14 @@ feature 'Supplier main board spec.rb', %q{
|
||||
create_supplier 'supplier@qwaiter.com'
|
||||
create_user 'user@qwaiter.com'
|
||||
end
|
||||
|
||||
def create_active_list(options = {})
|
||||
@table = create :table, supplier: @supplier
|
||||
@list = create :list, supplier: @supplier, table: @table, user_ids: [@user.id]
|
||||
|
||||
end
|
||||
|
||||
context "using javascript", js: true do
|
||||
|
||||
scenario 'the active list should be present and contained in row having its id' do
|
||||
create_active_list
|
||||
login_supplier_as 'supplier@qwaiter.com'
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
# encoding: UTF-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe Admin::ListsController do
|
||||
before :each do
|
||||
@administrator = Administrator.find_by_email('administrator@qwaiter.com') || Administrator.create(email: 'administrator@qwaiter.com', password: 'secret')
|
||||
sign_in @administrator
|
||||
end
|
||||
|
||||
describe "GET #index" do
|
||||
it "populates an array of lists" do
|
||||
list = create :list
|
||||
get :index
|
||||
assigns(:lists).should eq([list])
|
||||
end
|
||||
|
||||
it "should render without errors when no objects are present" do
|
||||
get :index
|
||||
expect{ render_template :index }.not_to raise_error
|
||||
end
|
||||
|
||||
it "renders the :index view" do
|
||||
get :index
|
||||
response.should render_template :index
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested list to @list" do
|
||||
list = create :list
|
||||
get :show, id: list
|
||||
assigns(:list).should eq(list)
|
||||
end
|
||||
|
||||
it "renders the #show view" do
|
||||
list = create :list
|
||||
get :show, id: list
|
||||
response.should render_template :show
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new list to @list" do
|
||||
get :new
|
||||
assigns(:list).should be_a List
|
||||
end
|
||||
|
||||
it "renders the #show view" do
|
||||
get :new
|
||||
response.should render_template :new
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid attributes" do
|
||||
it "creates a new list" do
|
||||
expect{
|
||||
post :create, list: attributes_for(:list)
|
||||
}.to change(List, :count).by(1)
|
||||
end
|
||||
|
||||
it "redirects to the new list" do
|
||||
post :create, list: attributes_for(:list)
|
||||
response.should redirect_to [:admin, List.last]
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid attributes" do
|
||||
it "does not save the new list" do
|
||||
expect{
|
||||
post :create, list: {}
|
||||
}.to_not change(List, :count)
|
||||
end
|
||||
|
||||
it "re-renders the new method" do
|
||||
post :create, list: {}
|
||||
response.should render_template :new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT update' do
|
||||
before :each do
|
||||
@list = create :list
|
||||
end
|
||||
|
||||
context "valid attributes" do
|
||||
it "located the requested list" do
|
||||
put :update, id: @list, list: attributes_for(:list)
|
||||
@list.reload
|
||||
assigns(:list).should eq(@list)
|
||||
end
|
||||
|
||||
it "changes @list's attributes" do
|
||||
put :update, id: @list, list: attributes_for(:list, price: 2.71)
|
||||
@list.reload
|
||||
@list.price.should eq(2.71)
|
||||
end
|
||||
|
||||
it "redirects to the updated list" do
|
||||
put :update, id: @list, list: attributes_for(:list)
|
||||
response.should redirect_to [:admin, @list]
|
||||
end
|
||||
end
|
||||
|
||||
context "invalid attributes" do
|
||||
it "locates the requested list" do
|
||||
put :update, id: @list, list: {table_id: ''}
|
||||
assigns(:list).should eq(@list)
|
||||
end
|
||||
|
||||
it "re-renders the edit method" do
|
||||
put :update, id: @list, list: {table_id: ''}
|
||||
response.should render_template :edit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE destroy' do
|
||||
before :each do
|
||||
@list = create :list
|
||||
end
|
||||
|
||||
it "deletes the list" do
|
||||
expect{
|
||||
delete :destroy, id: @list
|
||||
}.to change(List, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to lists#index" do
|
||||
delete :destroy, id: @list
|
||||
response.should redirect_to [:admin, :lists]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,140 @@
|
||||
# encoding: UTF-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe Admin::ProductCategoriesController do
|
||||
before :each do
|
||||
@administrator = Administrator.find_by_email('administrator@qwaiter.com') || Administrator.create(email: 'administrator@qwaiter.com', password: 'secret')
|
||||
sign_in @administrator
|
||||
end
|
||||
|
||||
describe "GET #index" do
|
||||
it "populates an array of product_categories" do
|
||||
product_category = create :product_category
|
||||
get :index
|
||||
assigns(:product_categories).should eq([product_category])
|
||||
end
|
||||
|
||||
it "should render without errors when no objects are present" do
|
||||
get :index
|
||||
expect{ render_template :index }.not_to raise_error
|
||||
end
|
||||
|
||||
it "renders the :index view" do
|
||||
get :index
|
||||
response.should render_template :index
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested product_category to @product_category" do
|
||||
product_category = create :product_category
|
||||
get :show, id: product_category
|
||||
assigns(:product_category).should eq(product_category)
|
||||
end
|
||||
|
||||
it "renders the #show view" do
|
||||
product_category = create :product_category
|
||||
get :show, id: product_category
|
||||
response.should render_template :show
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new product_category to @product_category" do
|
||||
get :new
|
||||
assigns(:product_category).should be_a ProductCategory
|
||||
end
|
||||
|
||||
it "renders the #show view" do
|
||||
get :new
|
||||
response.should render_template :new
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid attributes" do
|
||||
it "creates a new product_category" do
|
||||
expect{
|
||||
post :create, product_category: attributes_for(:product_category)
|
||||
}.to change(ProductCategory, :count).by(1)
|
||||
end
|
||||
|
||||
it "redirects to the new product_category" do
|
||||
post :create, product_category: attributes_for(:product_category)
|
||||
response.should redirect_to [:admin, ProductCategory.last]
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid attributes" do
|
||||
it "does not save the new product_category" do
|
||||
expect{
|
||||
post :create, product_category: {}
|
||||
}.to_not change(ProductCategory, :count)
|
||||
end
|
||||
|
||||
it "re-renders the new method" do
|
||||
post :create, product_category: {}
|
||||
response.should render_template :new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT update' do
|
||||
before :each do
|
||||
@product_category = create :product_category
|
||||
end
|
||||
|
||||
context "valid attributes" do
|
||||
|
||||
it "located the requested product_category" do
|
||||
put :update, id: @product_category, product_category: attributes_for(:product_category)
|
||||
@product_category.reload
|
||||
assigns(:product_category).should eq(@product_category)
|
||||
end
|
||||
|
||||
it "changes @product_category's attributes" do
|
||||
put :update, id: @product_category, product_category: attributes_for(:product_category, name: "ChangedByTest")
|
||||
@product_category.reload
|
||||
@product_category.name.should eq("ChangedByTest")
|
||||
end
|
||||
|
||||
it "redirects to the updated product_category" do
|
||||
put :update, id: @product_category, product_category: attributes_for(:product_category)
|
||||
response.should redirect_to [:admin, @product_category]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "invalid attributes" do
|
||||
|
||||
it "locates the requested @product_category" do
|
||||
put :update, id: @product_category, product_category: {}
|
||||
assigns(:product_category).should eq(@product_category)
|
||||
end
|
||||
|
||||
it "re-renders the edit method" do
|
||||
put :update, id: @product_category, product_category: {name: ''}
|
||||
response.should render_template :edit
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE destroy' do
|
||||
before :each do
|
||||
@product_category = create :product_category
|
||||
end
|
||||
|
||||
it "deletes the contact" do
|
||||
expect{
|
||||
delete :destroy, id: @product_category
|
||||
}.to change(ProductCategory, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to product_categories#index" do
|
||||
delete :destroy, id: @product_category
|
||||
response.should redirect_to [:admin, :product_categories]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -85,24 +85,56 @@ describe Admin::ProductsController do
|
||||
end
|
||||
|
||||
context "valid attributes" do
|
||||
|
||||
it "located the requested product" do
|
||||
put :update, id: @product, product: attributes_for(:product)
|
||||
@product.reload
|
||||
assigns(:product).should eq(@product)
|
||||
end
|
||||
|
||||
it "changes @product's attributes" do
|
||||
attributes = attributes_for(:product)
|
||||
attribute_to_change = attributes.keys.find{|k| k !~ /_id$/}
|
||||
attributes[attribute_to_change] = "ChangedByTest"
|
||||
put :update, id: @product, product: attributes
|
||||
put :update, id: @product, product: attributes_for(:product, name: "ChangedByTest")
|
||||
@product.reload
|
||||
@product.send(attribute_to_change).should eq("ChangedByTest")
|
||||
@product.name.should eq("ChangedByTest")
|
||||
end
|
||||
|
||||
it "redirects to the updated product" do
|
||||
put :update, id: @product, product: attributes_for(:product)
|
||||
response.should redirect_to [:admin, @product]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "invalid attributes" do
|
||||
|
||||
it "locates the requested @product" do
|
||||
put :update, id: @product, product: {}
|
||||
assigns(:product).should eq(@product)
|
||||
end
|
||||
|
||||
it "re-renders the edit method" do
|
||||
put :update, id: @product, product: {name: ''}
|
||||
response.should render_template :edit
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE destroy' do
|
||||
before :each do
|
||||
@product = create :product
|
||||
end
|
||||
|
||||
it "deletes the contact" do
|
||||
expect{
|
||||
delete :destroy, id: @product
|
||||
}.to change(Product, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to products#index" do
|
||||
delete :destroy, id: @product
|
||||
response.should redirect_to [:admin, :products]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
# encoding: UTF-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe Admin::SectionsController do
|
||||
before :each do
|
||||
@administrator = Administrator.find_by_email('administrator@qwaiter.com') || Administrator.create(email: 'administrator@qwaiter.com', password: 'secret')
|
||||
sign_in @administrator
|
||||
end
|
||||
|
||||
describe "GET #index" do
|
||||
it "populates an array of sections" do
|
||||
section = create :section
|
||||
get :index
|
||||
assigns(:sections).should =~ [section, Section.find_by_title('Room')]
|
||||
end
|
||||
|
||||
it "should render without errors when no objects are present" do
|
||||
get :index
|
||||
expect{ render_template :index }.not_to raise_error
|
||||
end
|
||||
|
||||
it "renders the :index view" do
|
||||
get :index
|
||||
response.should render_template :index
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested section to @section" do
|
||||
section = create :section
|
||||
get :show, id: section
|
||||
assigns(:section).should eq(section)
|
||||
end
|
||||
|
||||
it "renders the #show view" do
|
||||
section = create :section
|
||||
get :show, id: section
|
||||
response.should render_template :show
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new section to @section" do
|
||||
get :new
|
||||
assigns(:section).should be_a Section
|
||||
end
|
||||
|
||||
it "renders the #show view" do
|
||||
get :new
|
||||
response.should render_template :new
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid attributes" do
|
||||
it "creates a new section" do
|
||||
expect{
|
||||
post :create, section: attributes_for(:section)
|
||||
}.to change(Section, :count).by(2) # attributes_for creates a new standard section, the post action the other
|
||||
end
|
||||
|
||||
it "redirects to the new section" do
|
||||
post :create, section: attributes_for(:section, title: 'Section 1 title')
|
||||
response.should redirect_to [:admin, Section.find_by_title('Section 1 title')]
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid attributes" do
|
||||
it "does not save the new section" do
|
||||
expect{
|
||||
post :create, section: {}
|
||||
}.to_not change(Section, :count)
|
||||
end
|
||||
|
||||
it "re-renders the new method" do
|
||||
post :create, section: {}
|
||||
response.should render_template :new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT update' do
|
||||
before :each do
|
||||
@section = create :section
|
||||
end
|
||||
|
||||
context "valid attributes" do
|
||||
|
||||
it "located the requested section" do
|
||||
put :update, id: @section, section: attributes_for(:section)
|
||||
@section.reload
|
||||
assigns(:section).should eq(@section)
|
||||
end
|
||||
|
||||
it "changes @section's attributes" do
|
||||
put :update, id: @section, section: attributes_for(:section, title: "ChangedByTest")
|
||||
@section.reload
|
||||
@section.title.should eq("ChangedByTest")
|
||||
end
|
||||
|
||||
it "redirects to the updated section" do
|
||||
put :update, id: @section, section: attributes_for(:section)
|
||||
response.should redirect_to [:admin, @section]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "invalid attributes" do
|
||||
|
||||
it "locates the requested section" do
|
||||
put :update, id: @section, section: {title: ''}
|
||||
assigns(:section).should eq(@section)
|
||||
end
|
||||
|
||||
it "re-renders the edit method" do
|
||||
put :update, id: @section, section: {title: ''}
|
||||
response.should render_template :edit
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE destroy' do
|
||||
before :each do
|
||||
@section = create :section
|
||||
end
|
||||
|
||||
it "deletes the contact" do
|
||||
expect{
|
||||
delete :destroy, id: @section
|
||||
}.to change(Section, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to sections#index" do
|
||||
delete :destroy, id: @section
|
||||
response.should redirect_to [:admin, :sections]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,140 @@
|
||||
# encoding: UTF-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe Admin::TablesController do
|
||||
before :each do
|
||||
@administrator = Administrator.find_by_email('administrator@qwaiter.com') || Administrator.create(email: 'administrator@qwaiter.com', password: 'secret')
|
||||
sign_in @administrator
|
||||
end
|
||||
|
||||
describe "GET #index" do
|
||||
it "populates an array of tables" do
|
||||
table = create :table
|
||||
get :index
|
||||
assigns(:tables).should eq([table])
|
||||
end
|
||||
|
||||
it "should render without errors when no objects are present" do
|
||||
get :index
|
||||
expect{ render_template :index }.not_to raise_error
|
||||
end
|
||||
|
||||
it "renders the :index view" do
|
||||
get :index
|
||||
response.should render_template :index
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested table to @table" do
|
||||
table = create :table
|
||||
get :show, id: table
|
||||
assigns(:table).should eq(table)
|
||||
end
|
||||
|
||||
it "renders the #show view" do
|
||||
table = create :table
|
||||
get :show, id: table
|
||||
response.should render_template :show
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new table to @table" do
|
||||
get :new
|
||||
assigns(:table).should be_a Table
|
||||
end
|
||||
|
||||
it "renders the #show view" do
|
||||
get :new
|
||||
response.should render_template :new
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid attributes" do
|
||||
it "creates a new table" do
|
||||
expect{
|
||||
post :create, table: attributes_for(:table)
|
||||
}.to change(Table, :count).by(1)
|
||||
end
|
||||
|
||||
it "redirects to the new table" do
|
||||
post :create, table: attributes_for(:table)
|
||||
response.should redirect_to [:admin, Table.last]
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid attributes" do
|
||||
it "does not save the new table" do
|
||||
expect{
|
||||
post :create, table: {number: 0}
|
||||
}.to_not change(Table, :count)
|
||||
end
|
||||
|
||||
it "re-renders the new method" do
|
||||
post :create, table: {number: 0}
|
||||
response.should render_template :new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT update' do
|
||||
before :each do
|
||||
@table = create :table
|
||||
end
|
||||
|
||||
context "valid attributes" do
|
||||
|
||||
it "located the requested table" do
|
||||
put :update, id: @table, table: attributes_for(:table)
|
||||
@table.reload
|
||||
assigns(:table).should eq(@table)
|
||||
end
|
||||
|
||||
it "changes @table's attributes" do
|
||||
put :update, id: @table, table: attributes_for(:table, number: "44")
|
||||
@table.reload
|
||||
@table.number.should eq(44)
|
||||
end
|
||||
|
||||
it "redirects to the updated table" do
|
||||
put :update, id: @table, table: attributes_for(:table)
|
||||
response.should redirect_to [:admin, @table]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "invalid attributes" do
|
||||
|
||||
it "locates the requested table" do
|
||||
put :update, id: @table, table: {number: '0'}
|
||||
assigns(:table).should eq(@table)
|
||||
end
|
||||
|
||||
it "re-renders the edit method" do
|
||||
put :update, id: @table, table: {number: '0'}
|
||||
response.should render_template :edit
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE destroy' do
|
||||
before :each do
|
||||
@table = create :table
|
||||
end
|
||||
|
||||
it "deletes the contact" do
|
||||
expect{
|
||||
delete :destroy, id: @table
|
||||
}.to change(Table, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to tables#index" do
|
||||
delete :destroy, id: @table
|
||||
response.should redirect_to [:admin, :tables]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
FactoryGirl.define do
|
||||
factory :list do
|
||||
association :table
|
||||
association :supplier
|
||||
association :supplier #TODO warning! this may create a different supplier than the one created by the associated table
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
FactoryGirl.define do
|
||||
factory :product_category do
|
||||
sequence(:name){|i| "ProductCategory#{i}"}
|
||||
sequence(:position){|i| i}
|
||||
association :supplier
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,6 @@
|
||||
FactoryGirl.define do
|
||||
factory :product do
|
||||
sequence(:name){|i| "Product#{i}"}
|
||||
price 34.95
|
||||
association :supplier
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
FactoryGirl.define do
|
||||
factory :section do
|
||||
sequence(:title){|i| "Section #{i} title"}
|
||||
association :supplier
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user