require 'action_controller_test_setup' class TestController < ActionController::Base skip_after_filter :intercom_rails_auto_include, :only => :with_user_instance_variable_after_filter_skipped def without_user render :text => params[:body], :content_type => 'text/html' end def with_user_instance_variable @user = dummy_user render :text => params[:body], :content_type => 'text/html' end def with_user_instance_variable_after_filter_skipped with_user_instance_variable end def with_user_and_app_instance_variables @user = dummy_user @app = dummy_company render :text => params[:body], :content_type => 'text/html' end def with_user_instance_variable_and_custom_data @user = dummy_user intercom_custom_data.user['testing_stuff'] = true render :text => params[:body], :content_type => 'text/html' end def with_unusable_user_instance_variable @user = Object.new render :text => params[:body], :content_type => 'text/html' end def with_current_user_method render :text => params[:body], :content_type => 'text/html' end def with_admin_instance_variable @admin = dummy_user(:email => 'eoghan@intercom.io', :name => 'Eoghan McCabe') render :text => params[:body], :content_type => 'text/html' end def current_user raise NameError if params[:action] != 'with_current_user_method' dummy_user(:email => 'ciaran@intercom.io', :name => 'Ciaran Lee') end end class AutoIncludeFilterTest < ActionController::TestCase include InterTest tests TestController def setup super IntercomRails.config.app_id = 'my_app_id' IntercomRails.config.enabled_environments = ["production"] end def teardown IntercomRails.config.app_id = nil Rails.stub(:env) { ActiveSupport::StringInquirer.new("production") } end def test_no_user_present get :without_user, :body => "
Hello world" assert_equal @response.body, "Hello world" end def test_user_present_with_no_body_tag get :with_user_instance_variable, :body => "Hello world" assert_equal @response.body, "Hello world" end def test_user_present_but_unusuable get :with_unusable_user_instance_variable, :body => "Hello world" assert_equal @response.body, "Hello world" end def test_user_instance_variable_present_with_body_tag get :with_user_instance_variable, :body => "Hello world" assert_includes @response.body, "