Sha256: 98fb2ece411e31fb81a4b21e3e323aa256b2014ca3e867ed5e041aa5d7ebb057

Contents?: true

Size: 1.19 KB

Versions: 10

Compression:

Stored size: 1.19 KB

Contents

require File.dirname(__FILE__) + '/helper'
require 'hoptoad_notifier/rails/javascript_notifier'
require 'ostruct'

class JavascriptNotifierTest < Test::Unit::TestCase
  module FakeRenderer
    def javascript_tag(text)
      "<script>#{text}</script>"
    end
    def escape_javascript(text)
      "ESC#{text}ESC"
    end
  end

  class FakeController
    def self.helper_method(*args)
    end

    include HoptoadNotifier::Rails::JavascriptNotifier

    def action_name
      "action"
    end

    def controller_name
      "controller"
    end

    def request
      @request ||= OpenStruct.new
    end

    def render_to_string(options)
      context = OpenStruct.new(options[:locals])
      context.extend(FakeRenderer)
      context.instance_eval do
        erb = ERB.new(IO.read(options[:file]))
        erb.result(binding)
      end
    end
  end

  should "make sure escape_javacript is called on the request.url" do
    HoptoadNotifier.configure do
    end
    controller = FakeController.new
    controller.request.url = "bad_javascript"
    assert controller.send(:hoptoad_javascript_notifier)['"ESCbad_javascriptESC"']
    assert ! controller.send(:hoptoad_javascript_notifier)['"bad_javascript"']
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
square-hoptoad_notifier-2.4.9 test/javascript_notifier_test.rb
hoptoad_notifier-2.4.11 test/javascript_notifier_test.rb
hoptoad_notifier-2.4.10 test/javascript_notifier_test.rb
hoptoad_notifier-2.4.9 test/javascript_notifier_test.rb
square-hoptoad_notifier-2.4.8 test/javascript_notifier_test.rb
hoptoad_notifier-2.4.8 test/javascript_notifier_test.rb
hoptoad_notifier-2.4.7 test/javascript_notifier_test.rb
hoptoad_notifier-2.4.6 test/javascript_notifier_test.rb
hoptoad_notifier-2.4.5 test/javascript_notifier_test.rb
hoptoad_notifier-2.4.4 test/javascript_notifier_test.rb