Skip to content

Commit

Permalink
Merge pull request #119 from castle/user-traits-change
Browse files Browse the repository at this point in the history
rename traits to user_traits
  • Loading branch information
nijikon authored Apr 17, 2018
2 parents 22f72b9 + 48e7d83 commit 32c7380
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master

**BREAKING CHANGES:**

- [#119](github.com/castle/castle-ruby/pull/119) usage of `traits` key is deprecated, use `user_traits` instead

## 3.4.2 (2018-02-26)

**Features:**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ track_options = ::Castle::Client.to_options({
properties: {
key: 'value'
},
traits: {
user_traits: {
key: 'value'
}
})
Expand Down
1 change: 1 addition & 0 deletions lib/castle/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def to_context(request, options = {})

def to_options(options = {})
options[:timestamp] ||= Castle::Utils::Timestamp.call
warn '[DEPRECATION] use user_traits instead of traits key' if options.key?(:traits)
options
end

Expand Down
16 changes: 8 additions & 8 deletions spec/lib/castle/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
end

describe 'to_options' do
let(:options) { { user_id: '1234', traits: { name: 'Jo' } } }
let(:result) { { user_id: '1234', traits: { name: 'Jo' }, timestamp: time_auto } }
let(:options) { { user_id: '1234', user_traits: { name: 'Jo' } } }
let(:result) { { user_id: '1234', user_traits: { name: 'Jo' }, timestamp: time_auto } }

it do
expect(described_class.to_options(options)).to eql(result)
Expand Down Expand Up @@ -95,13 +95,13 @@
describe 'identify' do
let(:request_body) do
{ user_id: '1234', timestamp: time_auto,
sent_at: time_auto, context: context, traits: { name: 'Jo' } }
sent_at: time_auto, context: context, user_traits: { name: 'Jo' } }
end

before { client.identify(options) }

context 'when used with symbol keys' do
let(:options) { { user_id: '1234', traits: { name: 'Jo' } } }
let(:options) { { user_id: '1234', user_traits: { name: 'Jo' } } }

it do
assert_requested :post, 'https://api.castle.io/v1/identify', times: 1 do |req|
Expand All @@ -111,9 +111,9 @@

context 'when passed timestamp in options and no defined timestamp' do
let(:client) { client_with_no_timestamp }
let(:options) { { user_id: '1234', traits: { name: 'Jo' }, timestamp: time_user } }
let(:options) { { user_id: '1234', user_traits: { name: 'Jo' }, timestamp: time_user } }
let(:request_body) do
{ user_id: '1234', traits: { name: 'Jo' }, context: context,
{ user_id: '1234', user_traits: { name: 'Jo' }, context: context,
timestamp: time_user, sent_at: time_auto }
end

Expand All @@ -128,7 +128,7 @@
let(:client) { client_with_user_timestamp }
let(:request_body) do
{ user_id: '1234', timestamp: time_user, sent_at: time_auto,
context: context, traits: { name: 'Jo' } }
context: context, user_traits: { name: 'Jo' } }
end

it do
Expand All @@ -140,7 +140,7 @@
end

context 'when used with string keys' do
let(:options) { { 'user_id' => '1234', 'traits' => { 'name' => 'Jo' } } }
let(:options) { { 'user_id' => '1234', 'user_traits' => { 'name' => 'Jo' } } }

it do
assert_requested :post, 'https://api.castle.io/v1/identify', times: 1 do |req|
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/castle/commands/authenticate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
it { expect(command.data).to be_eql(command_data) }
end

context 'with traits' do
let(:payload) { default_payload.merge(traits: { test: '1' }) }
context 'with user_traits' do
let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
let(:command_data) do
default_payload.merge(traits: { test: '1' }, context: context)
default_payload.merge(user_traits: { test: '1' }, context: context)
end

it { expect(command.method).to be_eql(:post) }
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/castle/commands/identify_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
it { expect(command.data).to be_eql(command_data) }
end

context 'with traits' do
let(:payload) { default_payload.merge(traits: { test: '1' }) }
context 'with user_traits' do
let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
let(:command_data) do
default_payload.merge(traits: { test: '1' }, context: context)
default_payload.merge(user_traits: { test: '1' }, context: context)
end

it { expect(command.method).to be_eql(:post) }
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/castle/commands/track_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
it { expect(command.data).to be_eql(command_data) }
end

context 'with traits' do
let(:payload) { default_payload.merge(traits: { test: '1' }) }
context 'with user_traits' do
let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
let(:command_data) do
default_payload.merge(traits: { test: '1' }, context: context)
default_payload.merge(user_traits: { test: '1' }, context: context)
end

it { expect(command.method).to be_eql(:post) }
Expand Down

0 comments on commit 32c7380

Please sign in to comment.