intercom-rails 0.2.21 → 0.2.22

Sign up to get free protection for your applications and to get access to all the features.
data/README.mdown CHANGED
@@ -104,10 +104,10 @@ If you want to customize the style of the link that opens the inbox:
104
104
  config.inbox.style = :custom
105
105
  ```
106
106
 
107
- This option attaches the inbox open event to the click event of an element with an id of `#Intercom`. So the simplest option here would be to add something like the following to your layout:
107
+ This option attaches the inbox open event to the click event of an element with an id of `Intercom`. So the simplest option here would be to add something like the following to your layout:
108
108
 
109
109
  ```html
110
- <a id="#Intercom">Support</a>
110
+ <a id="Intercom">Support</a>
111
111
  ```
112
112
 
113
113
  You can read more about configuring the Inbox within Intercom (Config menu -> Inbox Link).
@@ -29,6 +29,7 @@ module IntercomRails
29
29
  end
30
30
 
31
31
  def include_javascript?
32
+ enabled_for_environment? &&
32
33
  !intercom_script_tag_called_manually? &&
33
34
  html_content_type? &&
34
35
  response_has_closing_body_tag? &&
@@ -56,6 +57,10 @@ module IntercomRails
56
57
  @script_tag ||= ScriptTag.new(:find_current_user_details => true, :find_current_company_details => true, :controller => controller)
57
58
  end
58
59
 
60
+ def enabled_for_environment?
61
+ IntercomRails.config.enabled_environments.include?(Rails.env)
62
+ end
63
+
59
64
  end
60
65
 
61
66
  end
@@ -60,6 +60,10 @@ module IntercomRails
60
60
  end
61
61
  end
62
62
 
63
+ ARRAY_VALIDATOR = Proc.new do |data, field_name|
64
+ raise ArgumentError, "#{field_name} data should be an Array" unless data.kind_of?(Array)
65
+ end
66
+
63
67
  IS_PROC_VALIDATOR = Proc.new do |value, field_name|
64
68
  raise ArgumentError, "#{field_name} is not a proc" unless value.kind_of?(Proc)
65
69
  end
@@ -79,6 +83,7 @@ module IntercomRails
79
83
  config_accessor :api_secret
80
84
  config_accessor :api_key
81
85
  config_accessor :library_url
86
+ config_accessor :enabled_environments, &ARRAY_VALIDATOR
82
87
 
83
88
  config_group :user do
84
89
  config_accessor :current, &IS_PROC_VALIDATOR
@@ -1,3 +1,3 @@
1
1
  module IntercomRails
2
- VERSION = "0.2.21"
2
+ VERSION = "0.2.22"
3
3
  end
@@ -23,6 +23,11 @@ IntercomRails.config do |config|
23
23
  # config.api_key = "..."
24
24
  <%- end -%>
25
25
 
26
+ # == Enabled Environments
27
+ # Which enviornments is auto inclusion of the Javascript enabled for
28
+ #
29
+ config.enabled_environments = ["development", "production"]
30
+
26
31
  # == Curent user name
27
32
  # The method/variable that contains the logged in user in your controllers.
28
33
  # If it is `current_user` or `@user`, then you can ignore this
@@ -59,10 +59,12 @@ class AutoIncludeFilterTest < ActionController::TestCase
59
59
  def setup
60
60
  super
61
61
  IntercomRails.config.app_id = 'my_app_id'
62
+ IntercomRails.config.enabled_environments = ["production"]
62
63
  end
63
64
 
64
65
  def teardown
65
66
  IntercomRails.config.app_id = nil
67
+ Rails.stub(:env) { ActiveSupport::StringInquirer.new("production") }
66
68
  end
67
69
 
68
70
  def test_no_user_present
@@ -164,4 +166,23 @@ class AutoIncludeFilterTest < ActionController::TestCase
164
166
  assert_equal @response.body, "<body>Hello world</body>"
165
167
  end
166
168
 
169
+ def test_running_in_development_but_only_enabled_for_production
170
+ Rails.stub(:env) { ActiveSupport::StringInquirer.new("development") }
171
+ IntercomRails.config.enabled_environments = ["production"]
172
+ get :with_user_instance_variable, :body => "<body>Hello world</body>"
173
+
174
+ assert_equal @response.body, "<body>Hello world</body>"
175
+ end
176
+
177
+ def test_only_enabled_for_production
178
+ # default Rails.env is to run in production
179
+ IntercomRails.config.enabled_environments = ["production"]
180
+ get :with_user_instance_variable, :body => "<body>Hello world</body>"
181
+
182
+ assert_includes @response.body, "<script>"
183
+ assert_includes @response.body, IntercomRails.config.app_id
184
+ assert_includes @response.body, "ben@intercom.io"
185
+ assert_includes @response.body, "Ben McRedmond"
186
+
187
+ end
167
188
  end
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.2.21
4
+ version: 0.2.22
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: 2013-05-28 00:00:00.000000000 Z
14
+ date: 2013-06-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -195,12 +195,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
195
195
  - - ! '>='
196
196
  - !ruby/object:Gem::Version
197
197
  version: '0'
198
+ segments:
199
+ - 0
200
+ hash: 4050575702279904448
198
201
  required_rubygems_version: !ruby/object:Gem::Requirement
199
202
  none: false
200
203
  requirements:
201
204
  - - ! '>='
202
205
  - !ruby/object:Gem::Version
203
206
  version: '0'
207
+ segments:
208
+ - 0
209
+ hash: 4050575702279904448
204
210
  requirements: []
205
211
  rubyforge_project: intercom-rails
206
212
  rubygems_version: 1.8.23
@@ -219,4 +225,3 @@ test_files:
219
225
  - test/intercom-rails/script_tag_helper_test.rb
220
226
  - test/intercom-rails/script_tag_test.rb
221
227
  - test/test_setup.rb
222
- has_rdoc: