Skip to content
This repository was archived by the owner on Jul 24, 2020. It is now read-only.

Controller Testing

Simon Podhajsky edited this page Jun 17, 2014 · 4 revisions

In order to test controllers with any measure of success, you need to preface your tests with

before(:all) do
  @app_config = FactoryGirl.create(:app_config)
end
before(:each) do
  @controller.stub(:first_time_user).and_return(FactoryGirl.create(:user))
  @controller.stub(:current_user).and_return(FactoryGirl.create(:admin)) # Or whatever other role
end

This is because unless Reservations detects a valid AppConfig and a user with proper authorization, it will redirect to a set-up page (or bad-authentication page). That is, however, not immediately clear from the tests failing.

It is worth noting, too, that FactoryGirl cleans up after itself; consequently, it is not necessary to add an after(:all) { @app_config.destroy } hook. In fact, it breaks the database state (for some reason), so don't do it.