Sha256: 9b3ddc7f56753af34cb5abef5b5acbb57c5c6897c48636911ad2e52ce84ca0e5

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

require "active_support/core_ext/string/output_safety"
require 'intercom-rails/script_tag_helper'
require 'minitest/autorun'

class IntercomRailsTest < MiniTest::Unit::TestCase
  include IntercomRails::ScriptTagHelper
  def test_output_is_html_safe?
    assert_equal true, intercom_script_tag({}).html_safe?
  end

  def test_converts_times_to_unix_timestamps
    now = Time.now
    assert_match(/.created_at.\s*:\s*#{now.to_i}/, intercom_script_tag({:created_at => now}))
    assert_match(/.something.\s*:\s*#{now.to_i}/, intercom_script_tag({:custom_data => {"something" => now}}))
  end

  def test_strips_out_nil_entries_for_standard_attributes
    %w(name email user_id).each do |standard_attribute|
      assert_match(/.#{standard_attribute}.\s*:\s*"value"/, intercom_script_tag({standard_attribute => 'value'}))
      assert(!intercom_script_tag({standard_attribute.to_sym => nil}).include?("\"#{standard_attribute}\":"), "should strip #{standard_attribute} when nil")
      assert(!intercom_script_tag({standard_attribute => nil}).include?("\"#{standard_attribute}\":"), "should strip #{standard_attribute} when nil")
    end
  end

  def test_secure_mode
    assert_match(/.user_hash.\s*:\s*"#{Digest::SHA1.hexdigest('abcdefgh' + 'ciaran@intercom.io')}"/, intercom_script_tag({:email => "ciaran@intercom.io"}, {:secret => 'abcdefgh'}))
    assert_match(/.user_hash.\s*:\s*"#{Digest::SHA1.hexdigest('abcdefgh' + '1234')}"/, intercom_script_tag({:user_id => 1234}, {:secret => 'abcdefgh'}))
    assert_match(/.user_hash.\s*:\s*"#{Digest::SHA1.hexdigest('abcdefgh' + '1234')}"/, intercom_script_tag({:user_id => 1234, :email => "ciaran@intercom.io"}, {:secret => 'abcdefgh'}))
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
intercom-rails-0.0.6 test/intercom-rails/script_tag_helper_test.rb