# 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