Files
mozo-backend/spec/controllers/admin/tables_controller_spec.rb
T

141 lines
3.3 KiB
Ruby

# 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