Error: I'm getting a response 302 (please sign in error) where I should get 200.
require 'spec_helper' describe "NewsPosts" do describe "GET /news_posts when signed off" do it "tells noobs they need to be logged in!" do get news_posts_path response.status.should be(302) end end describe "GET /news_posts when signed on as admin" do before :each do user = Factory(:user) user.admin = true user.roles << Role.where(:name => "communications") user.save post '/signin', :email => user.email, :password => user.password #sign_on_as_admin #stub_admin_user #controller.stub(:check_authorization).and_return(true) end it "Works for admins!" do get news_posts_path response.status.should be(200) end end end (spec_helper.rb) [code] . . . def integration_sign_in(user) visit signin_path fill_in :email, :with => user.email fill_in :password, :with => user.password click_button end def sign_on_as_admin @user = Factory(:user) @user.admin = true @user.roles << Role.where(:name => "communications") @user.save integration_sign_in(@user) end def stub_admin_user @user = Factory(:user) @user.roles << Role.where(:name => "communications") @user.admin = true controller.stub(:current_user).and_return(@user) end . . .
class NewsPostsController < ApplicationController before_filter :check_authorization . . . end
The key here is the method 'check_authorization'.
class ApplicationController < ActionController::Base before_filter :authenticate protect_from_forgery include SessionsHelper private def check_authorization unless current_user.can?(action_name, controller_name) flash[:error] = "You are not authorized to view the page you requested" redirect_to '/' end end end
Nothing I do seems to fix the problem. Any input would be appreciated.
Edit: Oh, and so, I'm completly in the dark as to how to figure out why things aren't working. It would be nice to be able to puts breadcrums to the console window to help me figure out what's happening.
This post has been edited by NotarySojac: 03 October 2012 - 08:20 PM