Forum: RSpec Testing Signin for Admin_Employee

Posted by Tom Tom (fuzzy)
on 2012-02-23 17:32
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) }
       end
     end
  end

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?

Thanks.

***Update***
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.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.