intercom-rails 0.2.24 → 0.2.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,30 +0,0 @@
1
- require 'active_support/core_ext/string/output_safety'
2
- require 'test_setup'
3
-
4
- class ScriptTagHelperTest < MiniTest::Unit::TestCase
5
-
6
- include IntercomRails::ScriptTagHelper
7
-
8
- def test_delegates_to_script_tag_generate
9
- delegated = false
10
- IntercomRails::ScriptTag.stub(:generate) {
11
- delegated = true
12
- }
13
-
14
- intercom_script_tag({})
15
- assert(delegated, "should delegate to ScriptTag#generate")
16
- ensure
17
- IntercomRails::ScriptTag.rspec_reset
18
- end
19
-
20
- def test_sets_instance_variable
21
- fake_action_view = fake_action_view_class.new
22
- obj = Object.new
23
-
24
- fake_action_view.instance_variable_set(:@controller, obj)
25
-
26
- fake_action_view.intercom_script_tag({})
27
- assert_equal obj.instance_variable_get(IntercomRails::SCRIPT_TAG_HELPER_CALLED_INSTANCE_VARIABLE), true
28
- end
29
-
30
- end
@@ -1,110 +0,0 @@
1
- require 'active_support/core_ext/string/output_safety'
2
- require 'active_support/time'
3
- require 'test_setup'
4
-
5
- class ScriptTagTest < MiniTest::Unit::TestCase
6
-
7
- include InterTest
8
- include IntercomRails
9
-
10
- def setup
11
- super
12
- IntercomRails.config.app_id = 'script_tag_test'
13
- end
14
-
15
- def test_output_is_html_safe?
16
- assert_equal true, ScriptTag.generate({}).html_safe?
17
- end
18
-
19
- def test_converts_times_to_unix_timestamps
20
- time = Time.new(1993,02,13)
21
- top_level_time = ScriptTag.new(:user_details => {:created_at => time})
22
- assert_equal time.to_i, top_level_time.intercom_settings[:created_at]
23
-
24
- now = Time.now
25
- nested_time = ScriptTag.new(:user_details => {:custom_data => {"something" => now}})
26
- assert_equal now.to_i, nested_time.intercom_settings[:custom_data]["something"]
27
-
28
- utc_time = Time.utc(2013,04,03)
29
- time_zone = ActiveSupport::TimeZone.new('London')
30
- time_with_zone = ActiveSupport::TimeWithZone.new(utc_time, time_zone)
31
- time_from_time_with_zone = ScriptTag.new(:user_details => {:created_at => time_with_zone})
32
- assert_equal utc_time.to_i, time_from_time_with_zone.intercom_settings[:created_at]
33
- end
34
-
35
- def test_strips_out_nil_entries_for_standard_attributes
36
- %w(name email user_id).each do |standard_attribute|
37
- with_value = ScriptTag.new(:user_details => {standard_attribute => 'value'})
38
- assert_equal with_value.intercom_settings[standard_attribute], 'value'
39
-
40
- with_nil_value = ScriptTag.new(:user_details => {standard_attribute.to_sym => 'value'})
41
- assert with_nil_value.intercom_settings.has_key?(standard_attribute.to_sym), "should strip :#{standard_attribute} when nil"
42
-
43
- with_nil_value = ScriptTag.new(:user_details => {standard_attribute => 'value'})
44
- assert with_nil_value.intercom_settings.has_key?(standard_attribute), "should strip #{standard_attribute} when nil"
45
- end
46
- end
47
-
48
- def test_secure_mode_with_email
49
- script_tag = ScriptTag.new(:user_details => {:email => 'ciaran@intercom.io'}, :secret => 'abcdefgh')
50
- assert_equal OpenSSL::HMAC.hexdigest("sha256", 'abcdefgh', 'ciaran@intercom.io'), script_tag.intercom_settings[:user_hash]
51
- end
52
-
53
- def test_secure_mode_with_user_id
54
- script_tag = ScriptTag.new(:user_details => {:user_id => '1234'}, :secret => 'abcdefgh')
55
- assert_equal OpenSSL::HMAC.hexdigest("sha256", 'abcdefgh', '1234'), script_tag.intercom_settings[:user_hash]
56
- end
57
-
58
- def test_secure_mode_with_email_and_user_id
59
- script_tag = ScriptTag.new(:user_details => {:user_id => '1234', :email => 'ciaran@intercom.io'}, :secret => 'abcdefgh')
60
- assert_equal OpenSSL::HMAC.hexdigest("sha256", 'abcdefgh', '1234'), script_tag.intercom_settings[:user_hash]
61
- end
62
-
63
- def test_secure_mode_with_secret_from_config
64
- IntercomRails.config.api_secret = 'abcd'
65
- script_tag = ScriptTag.new(:user_details => {:email => 'ben@intercom.io'})
66
- assert_equal OpenSSL::HMAC.hexdigest("sha256", 'abcd', 'ben@intercom.io'), script_tag.intercom_settings[:user_hash]
67
- end
68
-
69
- def test_secure_mode_chooses_passed_secret_over_config
70
- IntercomRails.config.api_secret = 'abcd'
71
- script_tag = ScriptTag.new(:user_details => {:email => 'ben@intercom.io'}, :secret => '1234')
72
- assert_equal OpenSSL::HMAC.hexdigest("sha256", '1234', 'ben@intercom.io'), script_tag.intercom_settings[:user_hash]
73
- script_tag = ScriptTag.new(:user_details => {:user_id => 5678}, :secret => '1234')
74
- assert_equal OpenSSL::HMAC.hexdigest("sha256", '1234', '5678'), script_tag.intercom_settings[:user_hash]
75
- end
76
-
77
- def test_inbox_default_style
78
- IntercomRails.config.inbox.style = :default
79
- script_tag = ScriptTag.new
80
- expected_widget_settings= {'activator' => '#IntercomDefaultWidget'}
81
- assert_equal expected_widget_settings, script_tag.intercom_settings['widget']
82
- end
83
-
84
- def test_inbox_custom_style
85
- IntercomRails.config.inbox.style = :custom
86
- script_tag = ScriptTag.new
87
- expected_widget_settings = {'activator' => '#Intercom'}
88
- assert_equal expected_widget_settings, script_tag.intercom_settings['widget']
89
- end
90
-
91
- def test_company_discovery_and_inclusion
92
- IntercomRails.config.company.current = Proc.new { @app }
93
- object_with_app_instance_variable = Object.new
94
- object_with_app_instance_variable.instance_eval do
95
- @app = dummy_company
96
- end
97
-
98
- script_tag = ScriptTag.new(:controller => object_with_app_instance_variable,
99
- :find_current_company_details => true)
100
- expected_company = {'id' => '6', 'name' => 'Intercom'}
101
- assert_equal expected_company, script_tag.intercom_settings[:company]
102
- end
103
-
104
- def test_escapes_html_attributes
105
- nasty_email = "</script><script>alert('sup?');</script>"
106
- script_tag = ScriptTag.new(:user_details => {:email => nasty_email})
107
- assert !script_tag.output.include?(nasty_email), "script tag included"
108
- end
109
-
110
- end
data/test/test_setup.rb DELETED
@@ -1,51 +0,0 @@
1
- require 'intercom-rails'
2
- require 'minitest/autorun'
3
- require 'rspec/mocks'
4
- require 'pry'
5
-
6
- def dummy_user(options = {})
7
- user = Struct.new(:email, :name).new
8
- user.email = options[:email] || 'ben@intercom.io'
9
- user.name = options[:name] || 'Ben McRedmond'
10
- user
11
- end
12
-
13
- def dummy_company(options = {})
14
- company = Struct.new(:id, :name).new
15
- company.id = options[:id] || '6'
16
- company.name = options[:name] || 'Intercom'
17
- company
18
- end
19
-
20
- def fake_action_view_class
21
- klass = Class.new(ActionView::Base)
22
- klass.class_eval do
23
- include IntercomRails::ScriptTagHelper
24
- attr_reader :controller
25
- end
26
- klass
27
- end
28
-
29
- class Object
30
- # any_instance.rspec_reset does not work
31
- def self.unstub_all_instance_methods
32
- public_instance_methods.each do |method|
33
- begin
34
- self.any_instance.unstub(method)
35
- rescue RSpec::Mocks::MockExpectationError
36
- next
37
- end
38
- end
39
- end
40
- end
41
-
42
- RSpec::Mocks::setup(Object.new)
43
-
44
- module InterTest
45
-
46
- def setup
47
- IntercomRails::Config.reset!
48
- super
49
- end
50
-
51
- end