Testing Signin for Admin_Employee

I am following railstutorial 2nd edition and in it we have a Signin test
in our integration tests as follows:

require ‘spec_helper’

describe “Authentication” do

subject { page }

 describe "signin" do
   before { visit signin_path }

   it { should have_selector('h2',     text: 'Sign in') }
   it { should have_selector('title',  text: 'Sign in') }

   describe "with valid information" do
     let(:employee) { FactoryGirl.create(:employee) }
     before { valid_signin(employee) }

     it { should have_selector('title',     text:

employee.emp_full_name) }

     it { should_not have_link('Employees',     href:

employees_path) }
it { should_not have_link(‘Profile’, href:
employee_path(employee)) }
it { should_not have_link(‘Settings’, href:
edit_employee_path(employee)) }
it { should_not have_link(‘New Employee’, href:
newemployee_path) }

     it { should have_link('Sign out',      href: signout_path) }

     it { should_not have_link('Sign in',   href: signin_path) }


This test passes as shown.

I am trying to modify the test for the case when an Employee has admin
privileges. To that end I have modified the
app/views/layouts/_header.html.erb to ensure that only employees with
admin privileges can see the four links that currently read as
‘should_not have_link’.

FactoryGirl has the ability to create an admin employee.
I have admin_employee defined in employee controller which is:

def admin_employee
  redirect_to(root_path) unless current_employee.admin?

Can someone please help me design my test so that the above test will
pass for an employee with admin privileges?


I have a valid_sigin(employee) method in my spec/support/utilities file
so I defined a new method ‘valid_signin(admin)’ so then I replace the
existing method in the before block with the new method and also in the
‘let’ line I replaced :employee with :admin and I had to modify the URI
to read employee_path(admin) and then I created a new file and just
tested this test by itself and it passed … now I have to get the test
to pass in context.