intercom-rails 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,95 @@
1
+ require 'import_test_setup'
2
+
3
+ class ImportUnitTest < MiniTest::Unit::TestCase
4
+
5
+ include ImportTest
6
+
7
+ def test_run_with_wrong_rails_env
8
+ Rails.stub(:env).and_return ActiveSupport::StringInquirer.new("development")
9
+
10
+ exception = assert_raises IntercomRails::ImportError do
11
+ IntercomRails::Import.run
12
+ end
13
+
14
+ assert_equal exception.message, "You can only import your users from your production environment"
15
+ end
16
+
17
+ def test_run_with_no_user_class
18
+ IntercomRails::Import.any_instance.stub(:user_klass).and_return(nil)
19
+
20
+ exception = assert_raises IntercomRails::ImportError do
21
+ IntercomRails::Import.run
22
+ end
23
+
24
+ assert_equal exception.message, "We couldn't find your user class, please set one in config/initializers/intercom_rails.rb"
25
+ end
26
+
27
+ def test_run_with_non_activerecord_user_class
28
+ IntercomRails::Import.any_instance.stub(:user_klass).and_return(Class)
29
+
30
+ exception = assert_raises IntercomRails::ImportError do
31
+ IntercomRails::Import.run
32
+ end
33
+
34
+ assert_equal exception.message, "Only ActiveRecord models are supported"
35
+ end
36
+
37
+ def test_run_with_no_api_key
38
+ IntercomRails.config.stub(:api_key).and_return(nil)
39
+
40
+ exception = assert_raises IntercomRails::ImportError do
41
+ IntercomRails::Import.run
42
+ end
43
+
44
+ assert_equal exception.message, "Please add an Intercom API Key to config/initializers/intercom.rb"
45
+ end
46
+
47
+ def test_user_for_wire_returns_nil_if_no_user_id_or_email
48
+ user = Object.new
49
+ user.instance_eval do
50
+ def name
51
+ "Ben"
52
+ end
53
+ end
54
+
55
+ hsh = IntercomRails::Import.new.send(:user_for_wire, user)
56
+ assert_equal hsh, nil
57
+ end
58
+
59
+ def test_user_for_wire_returns_hash_if_user_id_or_email
60
+ hsh = IntercomRails::Import.new.send(:user_for_wire, User.first)
61
+ assert_equal({:user_id => 1, :email => "ben@intercom.io", :name => "Ben McRedmond"}, hsh)
62
+ end
63
+
64
+ def test_send_users_in_batches_prepares_users_for_wire
65
+ expected_batch = {:users => User.all.map { |u| IntercomRails::Import.new.send(:user_for_wire, u) }}.to_json
66
+ IntercomRails::Import.any_instance.should_receive(:send_users).with(expected_batch).and_return({'failed' => []})
67
+ IntercomRails::Import.run
68
+ end
69
+
70
+ def test_status_output
71
+ @import = IntercomRails::Import.new(:status_enabled => true)
72
+ @import.stub(:send_users).and_return('failed' => [1])
73
+ @import.should_receive(:batches).and_yield(nil, 3)
74
+
75
+ $stdout.flush
76
+ @old_stdout = $stdout.dup
77
+ $stdout = @output = StringIO.new
78
+
79
+ @import.run
80
+ expected_output = <<-output
81
+ * Found user class: User
82
+ * Intercom API key found
83
+ * Sending users in batches of 100:
84
+ ..F
85
+ * Successfully created 2 users
86
+ * Failed to create 1 user, this is likely due to bad data
87
+ output
88
+ $stdout.flush
89
+
90
+ assert_equal expected_output, @output.string
91
+ ensure
92
+ $stdout = @old_stdout
93
+ end
94
+
95
+ end
@@ -1,5 +1,7 @@
1
1
  require 'intercom-rails'
2
2
  require 'minitest/autorun'
3
+ require 'rspec/mocks'
4
+ require 'pry'
3
5
 
4
6
  def fake_action_view_class
5
7
  klass = Class.new(ActionView::Base)
@@ -9,3 +11,18 @@ def fake_action_view_class
9
11
  end
10
12
  klass
11
13
  end
14
+
15
+ class Object
16
+ # any_instance.rspec_reset does not work
17
+ def self.unstub_all_instance_methods
18
+ public_instance_methods.each do |method|
19
+ begin
20
+ self.any_instance.unstub(method)
21
+ rescue RSpec::Mocks::MockExpectationError
22
+ next
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ RSpec::Mocks::setup(Object.new)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intercom-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-11-02 00:00:00.000000000 Z
14
+ date: 2012-11-21 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -61,6 +61,22 @@ dependencies:
61
61
  - - ! '>='
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
+ - !ruby/object:Gem::Dependency
65
+ name: rspec-mocks
66
+ requirement: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
64
80
  - !ruby/object:Gem::Dependency
65
81
  name: pry
66
82
  requirement: !ruby/object:Gem::Requirement
@@ -77,6 +93,38 @@ dependencies:
77
93
  - - ! '>='
78
94
  - !ruby/object:Gem::Version
79
95
  version: '0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: sinatra
98
+ requirement: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 1.3.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: 1.3.1
112
+ - !ruby/object:Gem::Dependency
113
+ name: thin
114
+ requirement: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ~>
118
+ - !ruby/object:Gem::Version
119
+ version: 1.4.1
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ~>
126
+ - !ruby/object:Gem::Version
127
+ version: 1.4.1
80
128
  description: Intercom (https://www.intercom.io) is a customer relationship management
81
129
  and messaging tool for web app owners. This library makes it easier to use the correct
82
130
  javascript tracking code in your rails applications.
@@ -88,8 +136,11 @@ executables: []
88
136
  extensions: []
89
137
  extra_rdoc_files: []
90
138
  files:
139
+ - lib/data/cacert.pem
91
140
  - lib/intercom-rails/auto_include_filter.rb
92
141
  - lib/intercom-rails/config.rb
142
+ - lib/intercom-rails/import.rb
143
+ - lib/intercom-rails/intercom.rake
93
144
  - lib/intercom-rails/railtie.rb
94
145
  - lib/intercom-rails/script_tag_helper.rb
95
146
  - lib/intercom-rails/version.rb
@@ -97,12 +148,14 @@ files:
97
148
  - lib/rails/generators/intercom/config/config_generator.rb
98
149
  - lib/rails/generators/intercom/config/intercom.rb.erb
99
150
  - lib/rails/generators/intercom/install/install_generator.rb
100
- - MIT-LICENSE
101
151
  - Rakefile
102
- - README.rdoc
152
+ - README.mdown
103
153
  - test/action_controller_test_setup.rb
154
+ - test/import_test_setup.rb
104
155
  - test/intercom-rails/auto_include_filter_test.rb
105
156
  - test/intercom-rails/config_test.rb
157
+ - test/intercom-rails/import_network_test.rb
158
+ - test/intercom-rails/import_unit_test.rb
106
159
  - test/intercom-rails/script_tag_helper_test.rb
107
160
  - test/test_setup.rb
108
161
  homepage: http://www.intercom.io
@@ -119,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
172
  version: '0'
120
173
  segments:
121
174
  - 0
122
- hash: -3817663782507976710
175
+ hash: -1387323619916474735
123
176
  required_rubygems_version: !ruby/object:Gem::Requirement
124
177
  none: false
125
178
  requirements:
@@ -128,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
181
  version: '0'
129
182
  segments:
130
183
  - 0
131
- hash: -3817663782507976710
184
+ hash: -1387323619916474735
132
185
  requirements: []
133
186
  rubyforge_project: intercom-rails
134
187
  rubygems_version: 1.8.23
@@ -137,7 +190,10 @@ specification_version: 3
137
190
  summary: Rails helper for emitting javascript script tags for Intercom
138
191
  test_files:
139
192
  - test/action_controller_test_setup.rb
193
+ - test/import_test_setup.rb
140
194
  - test/intercom-rails/auto_include_filter_test.rb
141
195
  - test/intercom-rails/config_test.rb
196
+ - test/intercom-rails/import_network_test.rb
197
+ - test/intercom-rails/import_unit_test.rb
142
198
  - test/intercom-rails/script_tag_helper_test.rb
143
199
  - test/test_setup.rb
@@ -1,21 +0,0 @@
1
- The MIT License
2
-
3
- Copyright (c) 2011- Intercom, Inc. (https://www.intercom.io)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
@@ -1,73 +0,0 @@
1
- = IntercomRails
2
-
3
- Rails helper for creating Intercom (https://www.intercom.io) javascript tags.
4
-
5
- For interacting with the Intercom API, use the intercom gem (https://github.com/intercom/intercom-ruby)
6
-
7
- == Installation
8
- Add this to your Gemfile:
9
-
10
- gem "intercom-rails"
11
-
12
- Then run:
13
-
14
- <code>bundle install</code>
15
-
16
- == Usage
17
-
18
- Take note of your app_id from here: You can find your app id here: https://www.intercom.io/apps/api_keys
19
-
20
- === rails generator
21
-
22
- The <strong>intercom:install</strong> rails generator will add <code>intercom_script_tag</code> to your application layout. It provides a great start that will work well for most people and is easily customised.
23
-
24
- <code>rails g intercom:install YOUR-APP-ID</code>
25
-
26
- === manual install
27
-
28
- In your layout file:
29
-
30
- <% if logged_in? %>
31
- <%= intercom_script_tag({
32
- :app_id => 'your-app-id'
33
- :user_id => current_user.id
34
- :email => current_user.email
35
- :name => current_user.name
36
- :created_at => current_user.created_at
37
- :custom_data => {
38
-
39
- }}) %>
40
- <% end %>
41
-
42
- :custom_data allows you to specify any app/user/situational data to associate with the current_user. It will be visible in Intercom, and you'll be able to search/filter/send messages based on it.
43
-
44
- e.g.
45
- :plan => "Pro",
46
- :dashboard_page => 'http://dashboard.example.com/user-id'
47
-
48
- === secure mode
49
-
50
- Pass in a second argument to intercom_script_tag, a hash containing the secret, like so:
51
-
52
- <% if logged_in? %>
53
- <%= intercom_script_tag({
54
- :app_id => 'your-app-id'
55
- :user_id => current_user.id
56
- :email => current_user.email
57
- :name => current_user.name
58
- :created_at => current_user.created_at
59
- },
60
- {:secret => 'your-apps-secret'}
61
- ) %>
62
- <% end %>
63
-
64
-
65
- See {IntercomRails::ScriptTagHelper} for more details.
66
-
67
- == Contributors
68
-
69
- - Dr Nic Williams (@drnic) - provided a rails generator for adding the Intercom javascript tag into your layout.
70
-
71
- == License
72
-
73
- This project rocks and uses MIT-LICENSE.