Now that I have CanCan and Devise working nicely I need to add to my tests.
Should I expect to end up with double the number of tests, maybe more? I need to test everything as a "guest" user then test as user and also as admin.
With rspec how would you lay this out?
describe "GET edit" do
login_admin
it "assigns the requested forum_topic as @forum_topic" do
ForumTopic.stub(:find).with("37") { mock_forum_topic }
get :edit, :id => "37"
response.should redirect_to( new_user_session_path )
end
it "assigns the requested forum_topic as @forum_topic" do
ForumTopic.stub(:find).with("37") { mock_forum_topic }
get :edit, :id => "37"
assigns(:forum_topic).should be(mock_forum_topic)
end
end
helper module
def login_admin
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:admin]
sign_in Factory.create(:admin)
end
end
def login_user
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
@user = Factory.create(:user)
sign_in @user
end
end