141 lines
3.6 KiB
Ruby
141 lines
3.6 KiB
Ruby
# 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
|