Sha256: 85b447b3a7d0016c07ad191549d28ddbd8f400d431674c04bd4360f03b05e063

Contents?: true

Size: 1.6 KB

Versions: 5

Compression:

Stored size: 1.6 KB

Contents

require File.expand_path '../helper', __FILE__

require 'airbrake/rails/controller_methods'

class TestController
  include Airbrake::Rails::ControllerMethods

  def current_user
    nil
  end
end

class NoSessionTestController
  include Airbrake::Rails::ControllerMethods

  def session
    nil
  end
end



class ControllerMethodsTest < Test::Unit::TestCase
  context "#airbrake_current_user" do
    setup do

      NilClass.class_eval do
        @@called = false

        def self.called
          !! @@called
        end

        def id
          @@called = true
        end
      end

      @controller = TestController.new
    end

    should "not call #id on NilClass" do
      @controller.send(:airbrake_current_user)
      assert_equal false, NilClass.called
    end
  end

  context '#airbrake_session_data' do
    setup do
      @controller = NoSessionTestController.new
    end
    should 'not call session if no session' do
      no_session = @controller.send(:airbrake_session_data)
      assert_equal no_session, {:session => 'no session found'}
    end
  end

  context "Rails 3" do
    setup do
      @controller = TestController.new
      ::Rails = Object.new
      ::Rails.stubs(:version).returns("3.2.17")
    end
    should "respond to rails3? with true" do
      assert @controller.send(:rails3?)
    end
    should "call filter_rails3_parameters" do
      hash = {:a => "b"}
      filtered_hash = {:c => "d"}

      @controller.expects(:filter_rails3_parameters).with(hash).
        returns(filtered_hash)
      assert_equal filtered_hash,
        @controller.send(:airbrake_filter_if_filtering, hash)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
airbrake-4.1.0 test/controller_methods_test.rb
airbrake-4.0.0 test/controller_methods_test.rb
airbrake-3.2.1 test/controller_methods_test.rb
airbrake-3.2.0 test/controller_methods_test.rb
airbrake-3.1.17 test/controller_methods_test.rb