Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ jobs:
strategy:
matrix:
ruby-version:
- '2.0'
- '2.1'
- '2.2'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually the active version is only 3.*.

<2.2 we have some dep issues.

- '2.3'
- '2.5'
- '2.6'
# - '2.7'
# - '3.0'
- '2.7'
- '3.0'
- '3.1'
- '3.2'
- '3.3'
- '3.4'

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- name: Set up Ruby
uses: ruby/setup-ruby@0a29871fe2b0200a17a4497bae54fe5df0d973aa # v1.115.3
uses: ruby/setup-ruby@d697be2f83c6234b20877c3b5eac7a7f342f0d0c # v1.269.0
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
Expand Down
4 changes: 2 additions & 2 deletions lib/mixpanel-ruby/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def track(distinct_id, event, properties={}, ip=nil)
properties = {
'distinct_id' => distinct_id,
'token' => @token,
'time' => Time.now.to_f,
'time' => (Time.now.to_f * 1000).to_i,
'mp_lib' => 'ruby',
'$lib_version' => Mixpanel::VERSION,
}.merge(properties)
Expand Down Expand Up @@ -103,7 +103,7 @@ def import(api_key, distinct_id, event, properties={}, ip=nil)
properties = {
'distinct_id' => distinct_id,
'token' => @token,
'time' => Time.now.to_f,
'time' => (Time.now.to_f * 1000).to_i,
'mp_lib' => 'ruby',
'$lib_version' => Mixpanel::VERSION,
}.merge(properties)
Expand Down
2 changes: 1 addition & 1 deletion lib/mixpanel-ruby/groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def delete_group(group_key, group_id, optional_params={})
def update(message)
data = {
'$token' => @token,
'$time' => Time.now.to_f,
'$time' => (Time.now.to_f * 1000).to_i,
}.merge(message)

message = {'data' => data}
Expand Down
2 changes: 1 addition & 1 deletion lib/mixpanel-ruby/people.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def delete_user(distinct_id, optional_params={})
def update(message)
data = {
'$token' => @token,
'$time' => Time.now.to_f,
'$time' => (Time.now.to_f * 1000).to_i,
}.merge(message)

message = {'data' => data}
Expand Down
2 changes: 1 addition & 1 deletion lib/mixpanel-ruby/tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def generate_tracking_url(distinct_id, event, properties={}, endpoint=nil)
properties = {
'distinct_id' => distinct_id,
'token' => @token,
'time' => Time.now.to_f,
'time' => (Time.now.to_f * 1000).to_i,
'mp_lib' => 'ruby',
'$lib_version' => Mixpanel::VERSION,
}.merge(properties)
Expand Down
6 changes: 4 additions & 2 deletions mixpanel-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ spec = Gem::Specification.new do |spec|
spec.homepage = 'https://mixpanel.com/help/reference/ruby'
spec.license = 'Apache License 2.0'

spec.required_ruby_version = '>= 2.0.0'
spec.required_ruby_version = '>= 2.3.0'
spec.add_runtime_dependency 'mutex_m'
spec.add_runtime_dependency "base64"

spec.add_development_dependency 'activesupport', '~> 4.0'
spec.add_development_dependency 'rake', '~> 0'
spec.add_development_dependency 'rake', '~> 13'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'webmock', '~> 1.18'
end
4 changes: 2 additions & 2 deletions spec/mixpanel-ruby/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'mp_lib' => 'ruby',
'$lib_version' => Mixpanel::VERSION,
'token' => 'TEST TOKEN',
'time' => @time_now.to_i
'time' => @time_now.to_i * 1000
}
}]])
end
Expand All @@ -46,7 +46,7 @@
'mp_lib' => 'ruby',
'$lib_version' => Mixpanel::VERSION,
'token' => 'TEST TOKEN',
'time' => @time_now.to_i
'time' => @time_now.to_i * 1000
}
}
} ]])
Expand Down
20 changes: 10 additions & 10 deletions spec/mixpanel-ruby/groups_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'$token' => 'TEST TOKEN',
'$group_key' => 'TEST GROUP KEY',
'$group_id' => 'TEST GROUP ID',
'$time' => @time_now.to_i * 1000,
'$time' => (@time_now.to_f * 1000).to_i,
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent timestamp format in test expectations. Line 26 expects (@time_now.to_f * 1000).to_i (which preserves millisecond precision), but lines 42 and 57 expect @time_now.to_i * 1000 (which loses millisecond precision). All test expectations should use the same format: (@time_now.to_f * 1000).to_i to be consistent and match the implementation's intended behavior.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

'$set' => {
'$groupname' => 'Mixpanel',
'$grouprevenue' => 200
Expand All @@ -39,7 +39,7 @@
'$token' => 'TEST TOKEN',
'$group_key' => 'TEST GROUP KEY',
'$group_id' => 'TEST GROUP ID',
'$time' => @time_now.to_i * 1000,
'$time' => (@time_now.to_f * 1000).to_i,
'$set' => {
'created_at' => '2013-01-02T03:04:05'
}
Expand All @@ -54,7 +54,7 @@
'$token' => 'TEST TOKEN',
'$group_key' => 'TEST GROUP KEY',
'$group_id' => 'TEST GROUP ID',
'$time' => @time_now.to_i * 1000,
'$time' => (@time_now.to_f * 1000).to_i,
'$set' => {
'created_at' => '2013-01-02T02:04:05'
}
Expand All @@ -70,7 +70,7 @@
'$token' => 'TEST TOKEN',
'$group_key' => 'TEST GROUP KEY',
'$group_id' => 'TEST GROUP ID',
'$time' => @time_now.to_i * 1000,
'$time' => (@time_now.to_f * 1000).to_i,
'$set' => {
'created_at' => '2013-01-02T02:04:05'
}
Expand All @@ -86,7 +86,7 @@
'$token' => 'TEST TOKEN',
'$group_key' => 'TEST GROUP KEY',
'$group_id' => 'TEST GROUP ID',
'$time' => @time_now.to_i * 1000,
'$time' => (@time_now.to_f * 1000).to_i,
'$set_once' => {
'$groupname' => 'Mixpanel',
'$grouprevenue' => 200
Expand All @@ -102,7 +102,7 @@
'$token' => 'TEST TOKEN',
'$group_key' => 'TEST GROUP KEY',
'$group_id' => 'TEST GROUP ID',
'$time' => @time_now.to_i * 1000,
'$time' => (@time_now.to_f * 1000).to_i,
'$remove' => {
'Albums' => 'Diamond Dogs'
}
Expand All @@ -117,7 +117,7 @@
'$token' => 'TEST TOKEN',
'$group_key' => 'TEST GROUP KEY',
'$group_id' => 'TEST GROUP ID',
'$time' => @time_now.to_i * 1000,
'$time' => (@time_now.to_f * 1000).to_i,
'$union' => {
'Albums' => ['Diamond Dogs']
}
Expand All @@ -130,7 +130,7 @@
'$token' => 'TEST TOKEN',
'$group_key' => 'TEST GROUP KEY',
'$group_id' => 'TEST GROUP ID',
'$time' => @time_now.to_i * 1000,
'$time' => (@time_now.to_f * 1000).to_i,
'$unset' => ['Albums']
}]])
end
Expand All @@ -141,7 +141,7 @@
'$token' => 'TEST TOKEN',
'$group_key' => 'TEST GROUP KEY',
'$group_id' => 'TEST GROUP ID',
'$time' => @time_now.to_i * 1000,
'$time' => (@time_now.to_f * 1000).to_i,
'$unset' => ['Albums', 'Vinyls']
}]])
end
Expand All @@ -152,7 +152,7 @@
'$token' => 'TEST TOKEN',
'$group_key' => 'TEST GROUP KEY',
'$group_id' => 'TEST GROUP ID',
'$time' => @time_now.to_i * 1000,
'$time' => (@time_now.to_f * 1000).to_i,
'$delete' => ''
}]])
end
Expand Down
10 changes: 5 additions & 5 deletions spec/mixpanel-ruby/tracker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
'mp_lib' => 'ruby',
'$lib_version' => Mixpanel::VERSION,
'token' => 'TEST TOKEN',
'time' => @time_now.to_i
'time' => @time_now.to_i * 1000
}
expected_data = {'event' => event, 'properties' => properties.merge(default_properties)}

Expand Down Expand Up @@ -61,7 +61,7 @@
with { |req| body = req.body }

message_urlencoded = body[/^data=(.*?)(?:&|$)/, 1]
message_json = Base64.strict_decode64(URI.unescape(message_urlencoded))
message_json = Base64.strict_decode64(CGI.unescape(message_urlencoded))
message = JSON.load(message_json)
expect(message).to eq({
'event' => 'TEST EVENT',
Expand All @@ -71,7 +71,7 @@
'mp_lib' => 'ruby',
'$lib_version' => Mixpanel::VERSION,
'token' => 'TEST TOKEN',
'time' => @time_now.to_i
'time' => @time_now.to_i * 1000
}
})
end
Expand All @@ -94,7 +94,7 @@
'mp_lib' => 'ruby',
'$lib_version' => Mixpanel::VERSION,
'token' => 'TEST TOKEN',
'time' => @time_now.to_i
'time' => @time_now.to_i * 1000
}
}
],
Expand All @@ -106,7 +106,7 @@
'mp_lib' => 'ruby',
'$lib_version' => Mixpanel::VERSION,
'token' => 'TEST TOKEN',
'time' => @time_now.to_i
'time' => @time_now.to_i * 1000
}
},
'api_key' => 'API_KEY',
Expand Down
Loading