intercom-rails 0.2.18 → 0.2.19

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  require 'intercom-rails/exceptions'
2
+ require 'intercom-rails/date_helper'
2
3
  require 'intercom-rails/proxy'
3
4
  require 'intercom-rails/proxy/user'
4
5
  require 'intercom-rails/proxy/company'
@@ -0,0 +1,9 @@
1
+ module IntercomRails
2
+ class DateHelper
3
+ def self.convert_dates_to_unix_timestamps(object)
4
+ return Hash[object.map { |k, v| [k, convert_dates_to_unix_timestamps(v)] }] if object.is_a?(Hash)
5
+ return object.to_i if object.is_a?(Time) || object.is_a?(DateTime)
6
+ object
7
+ end
8
+ end
9
+ end
@@ -22,7 +22,8 @@ module IntercomRails
22
22
  end
23
23
 
24
24
  def to_hash
25
- standard_data.merge custom_data
25
+ data = standard_data.merge(custom_data)
26
+ DateHelper.convert_dates_to_unix_timestamps(data)
26
27
  end
27
28
 
28
29
  def standard_data
@@ -51,7 +51,7 @@ module IntercomRails
51
51
 
52
52
  private
53
53
  def user_details=(user_details)
54
- @user_details = convert_dates_to_unix_timestamps(user_details || {})
54
+ @user_details = DateHelper.convert_dates_to_unix_timestamps(user_details || {})
55
55
  @user_details = @user_details.with_indifferent_access.tap do |u|
56
56
  [:email, :name, :user_id].each { |k| u.delete(k) if u[k].nil? }
57
57
 
@@ -68,7 +68,7 @@ module IntercomRails
68
68
  end
69
69
 
70
70
  def company_details=(company_details)
71
- @company_details = convert_dates_to_unix_timestamps(company_details || {})
71
+ @company_details = DateHelper.convert_dates_to_unix_timestamps(company_details || {})
72
72
  @company_details = @company_details.with_indifferent_access.tap do |c|
73
73
  [:id, :name].each { |k| c.delete(k) if c[k].nil? }
74
74
  end
@@ -109,13 +109,6 @@ module IntercomRails
109
109
 
110
110
  config
111
111
  end
112
-
113
- def convert_dates_to_unix_timestamps(object)
114
- return Hash[object.map { |k, v| [k, convert_dates_to_unix_timestamps(v)] }] if object.is_a?(Hash)
115
- return object.to_i if object.is_a?(Time) || object.is_a?(DateTime)
116
- object
117
- end
118
-
119
112
  end
120
113
 
121
114
  end
@@ -1,3 +1,3 @@
1
1
  module IntercomRails
2
- VERSION = "0.2.18"
2
+ VERSION = "0.2.19"
3
3
  end
@@ -82,6 +82,22 @@ class UserTest < MiniTest::Unit::TestCase
82
82
  assert_equal 'pro', @user_proxy.to_hash['plan']
83
83
  end
84
84
 
85
+ def test_converts_dates_to_timestamps
86
+ plan_dummy_user = DUMMY_USER.dup
87
+ plan_dummy_user.instance_eval do
88
+ def some_date
89
+ Time.at(5)
90
+ end
91
+ end
92
+
93
+ IntercomRails.config.user.custom_data = {
94
+ 'some_date' => :some_date
95
+ }
96
+
97
+ @user_proxy = User.new(plan_dummy_user)
98
+ assert_equal 5, @user_proxy.to_hash['some_date']
99
+ end
100
+
85
101
  def test_valid_returns_true_if_user_id_or_email
86
102
  assert_equal true, User.new(DUMMY_USER).valid?
87
103
  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.18
4
+ version: 0.2.19
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-04-22 00:00:00.000000000 Z
14
+ date: 2013-05-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -156,6 +156,7 @@ files:
156
156
  - lib/intercom-rails/auto_include_filter.rb
157
157
  - lib/intercom-rails/config.rb
158
158
  - lib/intercom-rails/custom_data_helper.rb
159
+ - lib/intercom-rails/date_helper.rb
159
160
  - lib/intercom-rails/exceptions.rb
160
161
  - lib/intercom-rails/import.rb
161
162
  - lib/intercom-rails/intercom.rake
@@ -194,18 +195,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
194
195
  - - ! '>='
195
196
  - !ruby/object:Gem::Version
196
197
  version: '0'
197
- segments:
198
- - 0
199
- hash: -3918465583784430054
200
198
  required_rubygems_version: !ruby/object:Gem::Requirement
201
199
  none: false
202
200
  requirements:
203
201
  - - ! '>='
204
202
  - !ruby/object:Gem::Version
205
203
  version: '0'
206
- segments:
207
- - 0
208
- hash: -3918465583784430054
209
204
  requirements: []
210
205
  rubyforge_project: intercom-rails
211
206
  rubygems_version: 1.8.23
@@ -224,3 +219,4 @@ test_files:
224
219
  - test/intercom-rails/script_tag_helper_test.rb
225
220
  - test/intercom-rails/script_tag_test.rb
226
221
  - test/test_setup.rb
222
+ has_rdoc: