[rspec-users] Testing Signin for Admin_Employee

Tom Tom lists at ruby-forum.com
Thu Feb 23 16:32:06 UTC 2012

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:
new_employee_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 user.
I have admin_employee defined in employee controller which is:

    def admin_employee
      redirect_to(root_path) unless current_user.admin?

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


Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list