Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update timestamp generation to support ActiveSupport::TimeWithZone #34

Merged
merged 1 commit into from Apr 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -60,6 +60,7 @@ GEM
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
tilt (1.3.3)
tzinfo (0.3.37)

PLATFORMS
ruby
Expand All @@ -72,3 +73,4 @@ DEPENDENCIES
rspec-mocks
sinatra (~> 1.3.1)
thin (~> 1.4.1)
tzinfo
1 change: 1 addition & 0 deletions intercom-rails.gemspec
Expand Up @@ -24,4 +24,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'pry'
s.add_development_dependency 'sinatra', '~> 1.3.1'
s.add_development_dependency 'thin', '~> 1.4.1'
s.add_development_dependency 'tzinfo'
end
2 changes: 1 addition & 1 deletion lib/intercom-rails/script_tag.rb
Expand Up @@ -112,7 +112,7 @@ def widget_options_from_config

def convert_dates_to_unix_timestamps(object)
return Hash[object.map { |k, v| [k, convert_dates_to_unix_timestamps(v)] }] if object.is_a?(Hash)
return object.strftime('%s').to_i if object.respond_to?(:strftime)
return object.to_i if object.is_a?(Time) || object.is_a?(DateTime)
object
end

Expand Down
7 changes: 7 additions & 0 deletions test/intercom-rails/script_tag_test.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/string/output_safety'
require 'active_support/time'
require 'test_setup'

class ScriptTagTest < MiniTest::Unit::TestCase
Expand All @@ -23,6 +24,12 @@ def test_converts_times_to_unix_timestamps
now = Time.now
nested_time = ScriptTag.new(:user_details => {:custom_data => {"something" => now}})
assert_equal now.to_i, nested_time.intercom_settings[:custom_data]["something"]

utc_time = Time.utc(2013,04,03)
time_zone = ActiveSupport::TimeZone.new('London')
time_with_zone = ActiveSupport::TimeWithZone.new(utc_time, time_zone)
time_from_time_with_zone = ScriptTag.new(:user_details => {:created_at => time_with_zone})
assert_equal utc_time.to_i, time_from_time_with_zone.intercom_settings[:created_at]
end

def test_strips_out_nil_entries_for_standard_attributes
Expand Down