continuing the refactor of the admin section
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user