Hi, I recently inherited a project in which a former developer was not familiar with rails, and decided to put a lot of important logic into view helpers.
class ApplicationController < ActionController::Base protect_from_forgery include SessionsHelper include BannersHelper include UsersHelper include EventsHelper end
In particular, session management. This works fine with the application, but I am having trouble writing tests for this.
Specific example. Some of the actions are done before_filter to see if current_user administrator. This current_user usually set using the sessions_helper method, which is used in all our controllers. Therefore, in order to test our controllers correctly, I need to be able to use this current_user method
I tried this:
require 'test_helper' require File.expand_path('../../../app/helpers/sessions_helper.rb', __FILE__) class AppsControllerTest < ActionController::TestCase setup do @app = apps(:one) current_user = users(:one) end test "should create app" do assert_difference('App.count') do post :create, :app => @app.attributes end end
The require statement finds session_helper.rb in order, but without Rails magic it is not available in the same way as in AppsControllerTest
How can I trick this crazy setup for testing?
source share