end of day commit
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
# encoding: UTF-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe SupplierController do
|
||||
before :each do
|
||||
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || Supplier.create(name: 'Supplier', email: 'supplier@qwaiter.com', password: 'secret')
|
||||
sign_in @supplier
|
||||
end
|
||||
|
||||
describe "GET settings" do
|
||||
it 'displays the settings page' do
|
||||
get :edit
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,174 @@
|
||||
# encoding: UTF-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe Suppliers::ListsController do
|
||||
before :each do
|
||||
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || Supplier.create(name: 'Supplier', email: 'supplier@qwaiter.com', password: 'secret')
|
||||
sign_in @supplier
|
||||
end
|
||||
|
||||
describe "GET #index" do
|
||||
it "populates an array of lists" do
|
||||
list = create :list, supplier: @supplier
|
||||
get :index
|
||||
assigns(:lists).should eq([list])
|
||||
end
|
||||
|
||||
it "does not include lists from another supplier" do
|
||||
list1 = create :list, supplier: @supplier
|
||||
list2 = create :list
|
||||
get :index
|
||||
assigns(:lists).should eq([list1])
|
||||
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, supplier: @supplier
|
||||
get :show, id: list
|
||||
assigns(:list).should eq(list)
|
||||
end
|
||||
|
||||
it "should not display a list of another supplier" do
|
||||
list = create :list
|
||||
get :show, id: list
|
||||
response.status.should == 404
|
||||
end
|
||||
|
||||
it "renders the #show view" do
|
||||
list = create :list, supplier: @supplier
|
||||
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, supplier: @supplier)
|
||||
}.to change(List, :count).by(1)
|
||||
end
|
||||
|
||||
it "redirects to the new list" do
|
||||
post :create, list: attributes_for(:list, supplier: @supplier)
|
||||
response.should redirect_to [:suppliers, List.last]
|
||||
end
|
||||
|
||||
it "should not be possible to create a list for another supplier" do
|
||||
supplier2 = create :supplier
|
||||
post :create, list: attributes_for(:list, price: '6.66', supplier: supplier2)
|
||||
List.find_by_price(6.66).supplier_id.should == @supplier.id
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid attributes" do
|
||||
it "does not save the new list" do
|
||||
expect{
|
||||
post :create, list: {table_id: ''}
|
||||
}.to_not change(List, :count)
|
||||
end
|
||||
|
||||
it "re-renders the new method" do
|
||||
post :create, list: {table_id: ''}
|
||||
response.should render_template :new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT update' do
|
||||
before :each do
|
||||
@list = create :list, supplier: @supplier
|
||||
end
|
||||
|
||||
context "valid attributes" do
|
||||
it "located the requested list" do
|
||||
put :update, id: @list, list: attributes_for(:list, supplier: @supplier)
|
||||
@list.reload
|
||||
assigns(:list).should eq(@list)
|
||||
end
|
||||
|
||||
it "changes @list's attributes" do
|
||||
put :update, id: @list, list: attributes_for(:list, price: "7.22", supplier: @supplier)
|
||||
@list.reload
|
||||
@list.price.should eq(7.22)
|
||||
end
|
||||
|
||||
it "redirects to the updated list" do
|
||||
put :update, id: @list, list: attributes_for(:list, supplier: @supplier)
|
||||
response.should redirect_to [:suppliers, @list]
|
||||
end
|
||||
it "should not be possible to update a list to another supplier" do
|
||||
supplier2 = create :supplier
|
||||
put :update, id: @list, list: attributes_for(:list, supplier: supplier2)
|
||||
@list.reload
|
||||
@list.supplier_id.should == @supplier.id
|
||||
end
|
||||
|
||||
it "should not be possible to update a list of another supplier" do
|
||||
list = create :list, price: '7.22'
|
||||
put :update, id: list, list: {price: '6.66'}
|
||||
list.reload
|
||||
list.price.should == 7.22
|
||||
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, supplier: @supplier
|
||||
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 [:suppliers, :lists]
|
||||
end
|
||||
|
||||
it "should not be possible to delete a list of another supplier" do
|
||||
list = create :list
|
||||
expect{
|
||||
delete :destroy, id: list
|
||||
}.to_not change(List, :count)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,173 @@
|
||||
# encoding: UTF-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe Suppliers::ProductsController do
|
||||
before :each do
|
||||
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || Supplier.create(name: 'Supplier', email: 'supplier@qwaiter.com', password: 'secret')
|
||||
sign_in @supplier
|
||||
end
|
||||
|
||||
describe "GET #index" do
|
||||
it "populates an array of products" do
|
||||
product = create :product, supplier: @supplier
|
||||
get :index
|
||||
assigns(:products).should eq([product])
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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 to @product" do
|
||||
product = create :product, supplier: @supplier
|
||||
get :show, id: product
|
||||
assigns(:product).should eq(product)
|
||||
end
|
||||
|
||||
it "should not display a product of another supplier" do
|
||||
product = create :product
|
||||
get :show, id: product
|
||||
response.status.should == 404
|
||||
end
|
||||
|
||||
it "renders the #show view" do
|
||||
product = create :product, supplier: @supplier
|
||||
get :show, id: product
|
||||
response.should render_template :show
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new product to @product" do
|
||||
get :new
|
||||
assigns(:product).should be_a Product
|
||||
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" do
|
||||
expect{
|
||||
post :create, product: attributes_for(:product, supplier: @supplier)
|
||||
}.to change(Product, :count).by(1)
|
||||
end
|
||||
|
||||
it "redirects to the new product" do
|
||||
post :create, product: attributes_for(:product, supplier: @supplier)
|
||||
response.should redirect_to [:suppliers, Product.last]
|
||||
end
|
||||
|
||||
it "should not be possible to create a product for another supplier" do
|
||||
supplier2 = create :supplier
|
||||
post :create, product: attributes_for(:product, name: 'Trying to hack', supplier: supplier2)
|
||||
Product.find_by_name('Trying to hack').supplier_id.should == @supplier.id
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid attributes" do
|
||||
it "does not save the new product" do
|
||||
expect{
|
||||
post :create, product: {name: ''}
|
||||
}.to_not change(Product, :count)
|
||||
end
|
||||
|
||||
it "re-renders the new method" do
|
||||
post :create, product: {name: ''}
|
||||
response.should render_template :new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT update' do
|
||||
before :each do
|
||||
@product = create :product, supplier: @supplier
|
||||
end
|
||||
|
||||
context "valid attributes" do
|
||||
it "located the requested product" do
|
||||
put :update, id: @product, product: attributes_for(:product, supplier: @supplier)
|
||||
@product.reload
|
||||
assigns(:product).should eq(@product)
|
||||
end
|
||||
|
||||
it "changes @product's attributes" do
|
||||
put :update, id: @product, product: attributes_for(:product, name: "ChangedByTest", supplier: @supplier)
|
||||
@product.reload
|
||||
@product.name.should eq("ChangedByTest")
|
||||
end
|
||||
|
||||
it "redirects to the updated product" do
|
||||
put :update, id: @product, product: attributes_for(:product, supplier: @supplier)
|
||||
response.should redirect_to [:suppliers, @product]
|
||||
end
|
||||
it "should not be possible to update a product to another supplier" do
|
||||
supplier2 = create :supplier
|
||||
put :update, id: @product, product: attributes_for(:product, name: "Trying to hack", supplier: supplier2)
|
||||
Product.find_by_name('Trying to hack').supplier_id.should == @supplier.id
|
||||
end
|
||||
|
||||
it "should not be possible to update a product of another supplier" do
|
||||
product = create :product, name: 'Other supplier product'
|
||||
put :update, id: product, product: {name: "Trying to hack"}
|
||||
product.reload
|
||||
product.name.should == 'Other supplier product'
|
||||
end
|
||||
end
|
||||
|
||||
context "invalid attributes" do
|
||||
it "locates the requested product" do
|
||||
put :update, id: @product, product: {name: ''}
|
||||
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, supplier: @supplier
|
||||
end
|
||||
|
||||
it "deletes the product" 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 [:suppliers, :products]
|
||||
end
|
||||
|
||||
it "should not be possible to delete a product of another supplier" do
|
||||
product = create :product
|
||||
expect{
|
||||
delete :destroy, id: product
|
||||
}.to_not change(Product, :count)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,173 @@
|
||||
# encoding: UTF-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe Suppliers::TablesController do
|
||||
before :each do
|
||||
@supplier = Supplier.find_by_email('supplier@qwaiter.com') || Supplier.create(name: 'Supplier', email: 'supplier@qwaiter.com', password: 'secret')
|
||||
sign_in @supplier
|
||||
end
|
||||
|
||||
describe "GET #index" do
|
||||
it "populates an array of tables" do
|
||||
table = create :table, supplier: @supplier
|
||||
get :index
|
||||
assigns(:tables).should eq([table])
|
||||
end
|
||||
|
||||
it "does not include tables from another supplier" do
|
||||
table1 = create :table, supplier: @supplier
|
||||
table2 = create :table
|
||||
get :index
|
||||
assigns(:tables).should eq([table1])
|
||||
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, supplier: @supplier
|
||||
get :show, id: table
|
||||
assigns(:table).should eq(table)
|
||||
end
|
||||
|
||||
it "should not display a table of another supplier" do
|
||||
table = create :table
|
||||
get :show, id: table
|
||||
response.status.should == 404
|
||||
end
|
||||
|
||||
it "renders the #show view" do
|
||||
table = create :table, supplier: @supplier
|
||||
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, supplier: @supplier)
|
||||
}.to change(Table, :count).by(1)
|
||||
end
|
||||
|
||||
it "redirects to the new table" do
|
||||
post :create, table: attributes_for(:table, supplier: @supplier)
|
||||
response.should redirect_to [:suppliers, Table.last]
|
||||
end
|
||||
|
||||
it "should not be possible to create a table for another supplier" do
|
||||
supplier2 = create :supplier
|
||||
post :create, table: attributes_for(:table, number: 6, supplier: supplier2)
|
||||
Table.find_by_number(6).supplier_id.should == @supplier.id
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid attributes" do
|
||||
it "does not save the new table" do
|
||||
expect{
|
||||
post :create, table: {number: '-6'}
|
||||
}.to_not change(Table, :count)
|
||||
end
|
||||
|
||||
it "re-renders the new method" do
|
||||
post :create, table: {number: '-6'}
|
||||
response.should render_template :new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT update' do
|
||||
before :each do
|
||||
@table = create :table, supplier: @supplier
|
||||
end
|
||||
|
||||
context "valid attributes" do
|
||||
it "located the requested table" do
|
||||
put :update, id: @table, table: attributes_for(:table, supplier: @supplier)
|
||||
@table.reload
|
||||
assigns(:table).should eq(@table)
|
||||
end
|
||||
|
||||
it "changes @table's attributes" do
|
||||
put :update, id: @table, table: attributes_for(:table, number: "14", supplier: @supplier)
|
||||
@table.reload
|
||||
@table.number.should eq(14)
|
||||
end
|
||||
|
||||
it "redirects to the updated table" do
|
||||
put :update, id: @table, table: attributes_for(:table, supplier: @supplier)
|
||||
response.should redirect_to [:suppliers, @table]
|
||||
end
|
||||
it "should not be possible to update a table to another supplier" do
|
||||
supplier2 = create :supplier
|
||||
put :update, id: @table, table: attributes_for(:table, number: 6, supplier: supplier2)
|
||||
Table.find_by_number(6).supplier_id.should == @supplier.id
|
||||
end
|
||||
|
||||
it "should not be possible to update a table of another supplier" do
|
||||
table = create :table, number: 11
|
||||
put :update, id: table, table: {number: 6}
|
||||
table.reload
|
||||
table.number.should == 11
|
||||
end
|
||||
end
|
||||
|
||||
context "invalid attributes" do
|
||||
it "locates the requested table" do
|
||||
put :update, id: @table, table: {number: '-6'}
|
||||
assigns(:table).should eq(@table)
|
||||
end
|
||||
|
||||
it "re-renders the edit method" do
|
||||
put :update, id: @table, table: {number: '-6'}
|
||||
response.should render_template :edit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE destroy' do
|
||||
before :each do
|
||||
@table = create :table, supplier: @supplier
|
||||
end
|
||||
|
||||
it "deletes the table" 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 [:suppliers, :tables]
|
||||
end
|
||||
|
||||
it "should not be possible to delete a table of another supplier" do
|
||||
table = create :table
|
||||
expect{
|
||||
delete :destroy, id: table
|
||||
}.to_not change(Table, :count)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user