castle-rb 7.2.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/lib/castle/api/authenticate.rb +3 -12
  3. data/lib/castle/api/end_impersonation.rb +1 -3
  4. data/lib/castle/api/filter.rb +2 -10
  5. data/lib/castle/api/list_items/archive.rb +23 -0
  6. data/lib/castle/api/list_items/count.rb +22 -0
  7. data/lib/castle/api/list_items/create.rb +22 -0
  8. data/lib/castle/api/list_items/get.rb +22 -0
  9. data/lib/castle/api/list_items/query.rb +22 -0
  10. data/lib/castle/api/list_items/unarchive.rb +22 -0
  11. data/lib/castle/api/list_items/update.rb +22 -0
  12. data/lib/castle/api/lists/create.rb +23 -0
  13. data/lib/castle/api/lists/delete.rb +22 -0
  14. data/lib/castle/api/lists/get.rb +22 -0
  15. data/lib/castle/api/lists/get_all.rb +22 -0
  16. data/lib/castle/api/lists/query.rb +22 -0
  17. data/lib/castle/api/lists/update.rb +22 -0
  18. data/lib/castle/api/log.rb +2 -10
  19. data/lib/castle/api/risk.rb +2 -10
  20. data/lib/castle/api/start_impersonation.rb +1 -3
  21. data/lib/castle/api/track.rb +1 -3
  22. data/lib/castle/client.rb +4 -5
  23. data/lib/castle/client_actions/list_items.rb +44 -0
  24. data/lib/castle/client_actions/lists.rb +39 -0
  25. data/lib/castle/commands/list_items/archive.rb +24 -0
  26. data/lib/castle/commands/list_items/count.rb +23 -0
  27. data/lib/castle/commands/list_items/create.rb +22 -0
  28. data/lib/castle/commands/list_items/get.rb +23 -0
  29. data/lib/castle/commands/list_items/query.rb +24 -0
  30. data/lib/castle/commands/list_items/unarchive.rb +23 -0
  31. data/lib/castle/commands/list_items/update.rb +22 -0
  32. data/lib/castle/commands/lists/create.rb +21 -0
  33. data/lib/castle/commands/lists/delete.rb +20 -0
  34. data/lib/castle/commands/lists/get.rb +20 -0
  35. data/lib/castle/commands/lists/get_all.rb +17 -0
  36. data/lib/castle/commands/lists/query.rb +21 -0
  37. data/lib/castle/commands/lists/update.rb +22 -0
  38. data/lib/castle/commands/log.rb +1 -5
  39. data/lib/castle/commands/risk.rb +1 -5
  40. data/lib/castle/configuration.rb +2 -5
  41. data/lib/castle/core/process_response.rb +4 -3
  42. data/lib/castle/core/send_request.rb +1 -3
  43. data/lib/castle/errors.rb +4 -0
  44. data/lib/castle/headers/extract.rb +1 -3
  45. data/lib/castle/headers/filter.rb +2 -3
  46. data/lib/castle/payload/prepare.rb +1 -2
  47. data/lib/castle/session.rb +1 -1
  48. data/lib/castle/version.rb +1 -1
  49. data/lib/castle.rb +29 -3
  50. data/spec/integration/rails/rails_spec.rb +9 -3
  51. data/spec/integration/rails/support/application.rb +2 -2
  52. data/spec/integration/rails/support/home_controller.rb +4 -30
  53. data/spec/lib/castle/api/approve_device_spec.rb +3 -7
  54. data/spec/lib/castle/api/authenticate_spec.rb +23 -26
  55. data/spec/lib/castle/api/end_impersonation_spec.rb +9 -15
  56. data/spec/lib/castle/api/filter_spec.rb +1 -1
  57. data/spec/lib/castle/api/get_device_spec.rb +2 -4
  58. data/spec/lib/castle/api/get_devices_for_user_spec.rb +2 -4
  59. data/spec/lib/castle/api/list_items/archive_spec.rb +18 -0
  60. data/spec/lib/castle/api/list_items/count_spec.rb +21 -0
  61. data/spec/lib/castle/api/list_items/create_spec.rb +22 -0
  62. data/spec/lib/castle/api/list_items/get_spec.rb +18 -0
  63. data/spec/lib/castle/api/list_items/query_spec.rb +21 -0
  64. data/spec/lib/castle/api/list_items/unarchive_spec.rb +18 -0
  65. data/spec/lib/castle/api/list_items/update_spec.rb +22 -0
  66. data/spec/lib/castle/api/lists/create_spec.rb +21 -0
  67. data/spec/lib/castle/api/lists/delete_spec.rb +17 -0
  68. data/spec/lib/castle/api/lists/get_all_spec.rb +17 -0
  69. data/spec/lib/castle/api/lists/get_spec.rb +17 -0
  70. data/spec/lib/castle/api/lists/query_spec.rb +21 -0
  71. data/spec/lib/castle/api/lists/update_spec.rb +21 -0
  72. data/spec/lib/castle/api/log_spec.rb +1 -1
  73. data/spec/lib/castle/api/report_device_spec.rb +3 -7
  74. data/spec/lib/castle/api/risk_spec.rb +1 -1
  75. data/spec/lib/castle/api/start_impersonation_spec.rb +9 -15
  76. data/spec/lib/castle/api/track_spec.rb +10 -17
  77. data/spec/lib/castle/api_spec.rb +1 -1
  78. data/spec/lib/castle/client_id/extract_spec.rb +3 -10
  79. data/spec/lib/castle/client_spec.rb +38 -79
  80. data/spec/lib/castle/command_spec.rb +4 -4
  81. data/spec/lib/castle/commands/approve_device_spec.rb +3 -3
  82. data/spec/lib/castle/commands/authenticate_spec.rb +18 -25
  83. data/spec/lib/castle/commands/end_impersonation_spec.rb +15 -22
  84. data/spec/lib/castle/commands/filter_spec.rb +16 -16
  85. data/spec/lib/castle/commands/get_device_spec.rb +3 -3
  86. data/spec/lib/castle/commands/get_devices_for_user_spec.rb +3 -3
  87. data/spec/lib/castle/commands/list_items/archive_spec.rb +21 -0
  88. data/spec/lib/castle/commands/list_items/count_spec.rb +21 -0
  89. data/spec/lib/castle/commands/list_items/create_spec.rb +22 -0
  90. data/spec/lib/castle/commands/list_items/get_spec.rb +21 -0
  91. data/spec/lib/castle/commands/list_items/query_spec.rb +27 -0
  92. data/spec/lib/castle/commands/list_items/unarchive_spec.rb +21 -0
  93. data/spec/lib/castle/commands/list_items/update_spec.rb +21 -0
  94. data/spec/lib/castle/commands/lists/create_spec.rb +33 -0
  95. data/spec/lib/castle/commands/lists/delete_spec.rb +21 -0
  96. data/spec/lib/castle/commands/lists/get_all_spec.rb +11 -0
  97. data/spec/lib/castle/commands/lists/get_spec.rb +21 -0
  98. data/spec/lib/castle/commands/lists/query_spec.rb +27 -0
  99. data/spec/lib/castle/commands/lists/update_spec.rb +29 -0
  100. data/spec/lib/castle/commands/log_spec.rb +16 -16
  101. data/spec/lib/castle/commands/report_device_spec.rb +3 -3
  102. data/spec/lib/castle/commands/risk_spec.rb +16 -16
  103. data/spec/lib/castle/commands/start_impersonation_spec.rb +15 -22
  104. data/spec/lib/castle/commands/track_spec.rb +20 -25
  105. data/spec/lib/castle/configuration_spec.rb +2 -2
  106. data/spec/lib/castle/context/get_default_spec.rb +10 -9
  107. data/spec/lib/castle/context/merge_spec.rb +1 -1
  108. data/spec/lib/castle/context/prepare_spec.rb +4 -5
  109. data/spec/lib/castle/context/sanitize_spec.rb +1 -1
  110. data/spec/lib/castle/core/get_connection_spec.rb +1 -1
  111. data/spec/lib/castle/core/process_response_spec.rb +4 -7
  112. data/spec/lib/castle/core/process_webhook_spec.rb +13 -7
  113. data/spec/lib/castle/core/send_request_spec.rb +8 -12
  114. data/spec/lib/castle/failover/strategy_spec.rb +6 -6
  115. data/spec/lib/castle/headers/extract_spec.rb +2 -2
  116. data/spec/lib/castle/headers/filter_spec.rb +7 -4
  117. data/spec/lib/castle/headers/format_spec.rb +6 -6
  118. data/spec/lib/castle/ips/extract_spec.rb +3 -7
  119. data/spec/lib/castle/logger_spec.rb +3 -2
  120. data/spec/lib/castle/payload/prepare_spec.rb +5 -8
  121. data/spec/lib/castle/secure_mode_spec.rb +2 -4
  122. data/spec/lib/castle/session_spec.rb +2 -6
  123. data/spec/lib/castle/singleton_configuration_spec.rb +2 -2
  124. data/spec/lib/castle/utils/clean_invalid_chars_spec.rb +1 -1
  125. data/spec/lib/castle/utils/clone_spec.rb +2 -2
  126. data/spec/lib/castle/utils/deep_symbolize_keys_spec.rb +1 -1
  127. data/spec/lib/castle/utils/get_timestamp_spec.rb +1 -1
  128. data/spec/lib/castle/utils/merge_spec.rb +3 -5
  129. data/spec/lib/castle/validators/not_supported_spec.rb +2 -7
  130. data/spec/lib/castle/validators/present_spec.rb +3 -10
  131. data/spec/lib/castle/verdict_spec.rb +4 -4
  132. data/spec/lib/castle/version_spec.rb +1 -1
  133. data/spec/lib/castle/webhooks/verify_spec.rb +13 -7
  134. data/spec/lib/castle_spec.rb +6 -8
  135. data/spec/spec_helper.rb +2 -0
  136. data/spec/support/shared_examples/action_request.rb +16 -34
  137. data/spec/support/shared_examples/configuration.rb +14 -16
  138. data/spec/support/shared_examples/list_items.rb +52 -0
  139. data/spec/support/shared_examples/lists.rb +45 -0
  140. metadata +132 -48
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::Commands::ListItems::Unarchive do
4
+ describe '.build' do
5
+ subject(:command) { described_class.build(options) }
6
+
7
+ context 'with valid options' do
8
+ let(:options) { { list_id: 'list_id', list_item_id: 'list_item_id'} }
9
+
10
+ it { expect(command.method).to be(:put) }
11
+ it { expect(command.path).to eql('lists/list_id/items/list_item_id/unarchive') }
12
+ it { expect(command.data).to be_nil }
13
+ end
14
+
15
+ context 'with invalid options' do
16
+ let(:options) { { list_id: 'list_id' } }
17
+
18
+ it { expect { command }.to raise_error(Castle::InvalidParametersError) }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::Commands::ListItems::Update do
4
+ describe '.build' do
5
+ subject(:command) { described_class.build(options) }
6
+
7
+ context 'with valid options' do
8
+ let(:options) { { list_id: 'list_id', list_item_id: 'list_item_id', comment: 'updating item' } }
9
+
10
+ it { expect(command.method).to be(:put) }
11
+ it { expect(command.path).to eql('lists/list_id/items/list_item_id') }
12
+ it { expect(command.data).to eql(options.except(:list_id, :list_item_id)) }
13
+ end
14
+
15
+ context 'with invalid options' do
16
+ let(:options) { { list_id: 'list_id', list_item_id: 'list_item_id' } }
17
+
18
+ it { expect { command }.to raise_error(Castle::InvalidParametersError) }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::Commands::Lists::Create do
4
+ describe '.build' do
5
+ subject(:command) { described_class.build(options) }
6
+
7
+ let(:options) { { name: 'list_name', color: '$green', primary_field: 'user.email' } }
8
+
9
+ context 'with valid options' do
10
+ it { expect(command.method).to be(:post) }
11
+ it { expect(command.path).to eql('lists') }
12
+ it { expect(command.data).to eql(options) }
13
+ end
14
+
15
+ context 'without name' do
16
+ let(:options) { { color: '$green', primary_field: 'user.email' } }
17
+
18
+ it { expect { command }.to raise_error(Castle::InvalidParametersError) }
19
+ end
20
+
21
+ context 'without color' do
22
+ let(:options) { { name: 'list_name', primary_field: 'user.email' } }
23
+
24
+ it { expect { command }.to raise_error(Castle::InvalidParametersError) }
25
+ end
26
+
27
+ context 'without primary_field' do
28
+ let(:options) { { name: 'list_name', color: '$green' } }
29
+
30
+ it { expect { command }.to raise_error(Castle::InvalidParametersError) }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::Commands::Lists::Delete do
4
+ describe '.build' do
5
+ subject(:command) { described_class.build(options) }
6
+
7
+ let(:options) { { list_id: 'list_id' } }
8
+
9
+ context 'with valid options' do
10
+ it { expect(command.method).to be(:delete) }
11
+ it { expect(command.path).to eql('lists/list_id') }
12
+ it { expect(command.data).to be_nil }
13
+ end
14
+
15
+ context 'without list_id' do
16
+ let(:options) { {} }
17
+
18
+ it { expect { command }.to raise_error(Castle::InvalidParametersError) }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::Commands::Lists::GetAll do
4
+ describe '.build' do
5
+ subject(:command) { described_class.build }
6
+
7
+ it { expect(command.method).to be(:get) }
8
+ it { expect(command.path).to eql('lists') }
9
+ it { expect(command.data).to be_nil }
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::Commands::Lists::Get do
4
+ describe '.build' do
5
+ subject(:command) { described_class.build(options) }
6
+
7
+ let(:options) { { list_id: 'list_id' } }
8
+
9
+ context 'with valid options' do
10
+ it { expect(command.method).to be(:get) }
11
+ it { expect(command.path).to eql('lists/list_id') }
12
+ it { expect(command.data).to be_nil }
13
+ end
14
+
15
+ context 'without list_id' do
16
+ let(:options) { {} }
17
+
18
+ it { expect { command }.to raise_error(Castle::InvalidParametersError) }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::Commands::Lists::Query do
4
+ describe '.build' do
5
+ subject(:command) { described_class.build(options) }
6
+
7
+ context 'with valid options' do
8
+ let(:options) { { filters: [{ field: 'primary_field', op: '$eq', value: 'test' }]} }
9
+
10
+ it { expect(command.method).to be(:post) }
11
+ it { expect(command.path).to eql('lists/query') }
12
+ it { expect(command.data).to eq(options.except(:list_id)) }
13
+ end
14
+
15
+ context 'with invalid filters' do
16
+ let(:options) { { filters: [{ field: 'primary_field', op: '$eq' }]} }
17
+
18
+ it { expect { command }.to raise_error(Castle::InvalidParametersError) }
19
+ end
20
+
21
+ context 'with invalid sort' do
22
+ let(:options) { { sort: { field: 'primary_field' } } }
23
+
24
+ it { expect { command }.to raise_error(Castle::InvalidParametersError) }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Castle::Commands::Lists::Update do
4
+ describe '.build' do
5
+ subject(:command) { described_class.build(options) }
6
+
7
+ context 'with valid options' do
8
+ let(:options) do
9
+ {
10
+ list_id: 'list_id',
11
+ name: 'name',
12
+ description: 'description',
13
+ color: '$yellow',
14
+ default_item_archivation_time: 6000
15
+ }
16
+ end
17
+
18
+ it { expect(command.method).to be(:put) }
19
+ it { expect(command.path).to eql('lists/list_id') }
20
+ it { expect(command.data).to eql(options.except(:list_id)) }
21
+ end
22
+
23
+ context 'without list_id' do
24
+ let(:options) { { name: 'name' } }
25
+
26
+ it { expect { command }.to raise_error(Castle::InvalidParametersError) }
27
+ end
28
+ end
29
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Commands::Log do
3
+ RSpec.describe Castle::Commands::Log do
4
4
  subject(:instance) { described_class }
5
5
 
6
6
  let(:context) { { test: { test1: '1' } } }
@@ -29,45 +29,45 @@ describe Castle::Commands::Log do
29
29
  let(:payload) { default_payload.merge(properties: { test: '1' }) }
30
30
  let(:command_data) { default_payload.merge(properties: { test: '1' }, context: context) }
31
31
 
32
- it { expect(command.method).to be_eql(:post) }
33
- it { expect(command.path).to be_eql('log') }
34
- it { expect(command.data).to be_eql(command_data) }
32
+ it { expect(command.method).to be(:post) }
33
+ it { expect(command.path).to eql('log') }
34
+ it { expect(command.data).to eql(command_data) }
35
35
  end
36
36
 
37
37
  context 'with user_traits' do
38
38
  let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
39
39
  let(:command_data) { default_payload.merge(user_traits: { test: '1' }, context: context) }
40
40
 
41
- it { expect(command.method).to be_eql(:post) }
42
- it { expect(command.path).to be_eql('log') }
43
- it { expect(command.data).to be_eql(command_data) }
41
+ it { expect(command.method).to be(:post) }
42
+ it { expect(command.path).to eql('log') }
43
+ it { expect(command.data).to eql(command_data) }
44
44
  end
45
45
 
46
46
  context 'when active true' do
47
47
  let(:payload) { default_payload.merge(context: context.merge(active: true)) }
48
48
  let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
49
49
 
50
- it { expect(command.method).to be_eql(:post) }
51
- it { expect(command.path).to be_eql('log') }
52
- it { expect(command.data).to be_eql(command_data) }
50
+ it { expect(command.method).to be(:post) }
51
+ it { expect(command.path).to eql('log') }
52
+ it { expect(command.data).to eql(command_data) }
53
53
  end
54
54
 
55
55
  context 'when active false' do
56
56
  let(:payload) { default_payload.merge(context: context.merge(active: false)) }
57
57
  let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
58
58
 
59
- it { expect(command.method).to be_eql(:post) }
60
- it { expect(command.path).to be_eql('log') }
61
- it { expect(command.data).to be_eql(command_data) }
59
+ it { expect(command.method).to be(:post) }
60
+ it { expect(command.path).to eql('log') }
61
+ it { expect(command.data).to eql(command_data) }
62
62
  end
63
63
 
64
64
  context 'when active string' do
65
65
  let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
66
66
  let(:command_data) { default_payload.merge(context: context) }
67
67
 
68
- it { expect(command.method).to be_eql(:post) }
69
- it { expect(command.path).to be_eql('log') }
70
- it { expect(command.data).to be_eql(command_data) }
68
+ it { expect(command.method).to be(:post) }
69
+ it { expect(command.path).to eql('log') }
70
+ it { expect(command.data).to eql(command_data) }
71
71
  end
72
72
  end
73
73
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Commands::ReportDevice do
3
+ RSpec.describe Castle::Commands::ReportDevice do
4
4
  subject(:instance) { described_class }
5
5
 
6
6
  let(:context) { {} }
@@ -16,8 +16,8 @@ describe Castle::Commands::ReportDevice do
16
16
  end
17
17
 
18
18
  context 'with device_token' do
19
- it { expect(command.method).to be_eql(:put) }
20
- it { expect(command.path).to be_eql("devices/#{device_token}/report") }
19
+ it { expect(command.method).to be(:put) }
20
+ it { expect(command.path).to eql("devices/#{device_token}/report") }
21
21
  it { expect(command.data).to be_nil }
22
22
  end
23
23
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Commands::Risk do
3
+ RSpec.describe Castle::Commands::Risk do
4
4
  subject(:instance) { described_class }
5
5
 
6
6
  let(:context) { { test: { test1: '1' } } }
@@ -29,45 +29,45 @@ describe Castle::Commands::Risk do
29
29
  let(:payload) { default_payload.merge(properties: { test: '1' }) }
30
30
  let(:command_data) { default_payload.merge(properties: { test: '1' }, context: context) }
31
31
 
32
- it { expect(command.method).to be_eql(:post) }
33
- it { expect(command.path).to be_eql('risk') }
34
- it { expect(command.data).to be_eql(command_data) }
32
+ it { expect(command.method).to be(:post) }
33
+ it { expect(command.path).to eql('risk') }
34
+ it { expect(command.data).to eql(command_data) }
35
35
  end
36
36
 
37
37
  context 'with user_traits' do
38
38
  let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
39
39
  let(:command_data) { default_payload.merge(user_traits: { test: '1' }, context: context) }
40
40
 
41
- it { expect(command.method).to be_eql(:post) }
42
- it { expect(command.path).to be_eql('risk') }
43
- it { expect(command.data).to be_eql(command_data) }
41
+ it { expect(command.method).to be(:post) }
42
+ it { expect(command.path).to eql('risk') }
43
+ it { expect(command.data).to eql(command_data) }
44
44
  end
45
45
 
46
46
  context 'when active true' do
47
47
  let(:payload) { default_payload.merge(context: context.merge(active: true)) }
48
48
  let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
49
49
 
50
- it { expect(command.method).to be_eql(:post) }
51
- it { expect(command.path).to be_eql('risk') }
52
- it { expect(command.data).to be_eql(command_data) }
50
+ it { expect(command.method).to be(:post) }
51
+ it { expect(command.path).to eql('risk') }
52
+ it { expect(command.data).to eql(command_data) }
53
53
  end
54
54
 
55
55
  context 'when active false' do
56
56
  let(:payload) { default_payload.merge(context: context.merge(active: false)) }
57
57
  let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
58
58
 
59
- it { expect(command.method).to be_eql(:post) }
60
- it { expect(command.path).to be_eql('risk') }
61
- it { expect(command.data).to be_eql(command_data) }
59
+ it { expect(command.method).to be(:post) }
60
+ it { expect(command.path).to eql('risk') }
61
+ it { expect(command.data).to eql(command_data) }
62
62
  end
63
63
 
64
64
  context 'when active string' do
65
65
  let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
66
66
  let(:command_data) { default_payload.merge(context: context) }
67
67
 
68
- it { expect(command.method).to be_eql(:post) }
69
- it { expect(command.path).to be_eql('risk') }
70
- it { expect(command.data).to be_eql(command_data) }
68
+ it { expect(command.method).to be(:post) }
69
+ it { expect(command.path).to eql('risk') }
70
+ it { expect(command.data).to eql(command_data) }
71
71
  end
72
72
  end
73
73
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Commands::StartImpersonation do
3
+ RSpec.describe Castle::Commands::StartImpersonation do
4
4
  subject(:instance) { described_class }
5
5
 
6
6
  let(:context) { { user_agent: 'test', ip: '127.0.0.1', client_id: 'test' } }
@@ -19,40 +19,38 @@ describe Castle::Commands::StartImpersonation do
19
19
 
20
20
  context 'with impersonator' do
21
21
  let(:payload) { default_payload.merge(properties: { impersonator: impersonator }) }
22
- let(:command_data) do
23
- default_payload.merge(properties: { impersonator: impersonator }, context: context)
24
- end
22
+ let(:command_data) { default_payload.merge(properties: { impersonator: impersonator }, context: context) }
25
23
 
26
- it { expect(command.method).to be_eql(:post) }
27
- it { expect(command.path).to be_eql('impersonate') }
28
- it { expect(command.data).to be_eql(command_data) }
24
+ it { expect(command.method).to be(:post) }
25
+ it { expect(command.path).to eql('impersonate') }
26
+ it { expect(command.data).to eql(command_data) }
29
27
  end
30
28
 
31
29
  context 'when active true' do
32
30
  let(:payload) { default_payload.merge(context: context.merge(active: true)) }
33
31
  let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
34
32
 
35
- it { expect(command.method).to be_eql(:post) }
36
- it { expect(command.path).to be_eql('impersonate') }
37
- it { expect(command.data).to be_eql(command_data) }
33
+ it { expect(command.method).to be(:post) }
34
+ it { expect(command.path).to eql('impersonate') }
35
+ it { expect(command.data).to eql(command_data) }
38
36
  end
39
37
 
40
38
  context 'when active false' do
41
39
  let(:payload) { default_payload.merge(context: context.merge(active: false)) }
42
40
  let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
43
41
 
44
- it { expect(command.method).to be_eql(:post) }
45
- it { expect(command.path).to be_eql('impersonate') }
46
- it { expect(command.data).to be_eql(command_data) }
42
+ it { expect(command.method).to be(:post) }
43
+ it { expect(command.path).to eql('impersonate') }
44
+ it { expect(command.data).to eql(command_data) }
47
45
  end
48
46
 
49
47
  context 'when active string' do
50
48
  let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
51
49
  let(:command_data) { default_payload.merge(context: context) }
52
50
 
53
- it { expect(command.method).to be_eql(:post) }
54
- it { expect(command.path).to be_eql('impersonate') }
55
- it { expect(command.data).to be_eql(command_data) }
51
+ it { expect(command.method).to be(:post) }
52
+ it { expect(command.path).to eql('impersonate') }
53
+ it { expect(command.data).to eql(command_data) }
56
54
  end
57
55
  end
58
56
 
@@ -62,12 +60,7 @@ describe Castle::Commands::StartImpersonation do
62
60
  context 'when user_id not present' do
63
61
  let(:payload) { {} }
64
62
 
65
- it do
66
- expect { validate! }.to raise_error(
67
- Castle::InvalidParametersError,
68
- 'user_id is missing or empty'
69
- )
70
- end
63
+ it { expect { validate! }.to raise_error(Castle::InvalidParametersError, 'user_id is missing or empty') }
71
64
  end
72
65
 
73
66
  context 'when user_id present' do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Commands::Track do
3
+ RSpec.describe Castle::Commands::Track do
4
4
  subject(:instance) { described_class }
5
5
 
6
6
  let(:context) { { test: { test1: '1' } } }
@@ -20,54 +20,54 @@ describe Castle::Commands::Track do
20
20
  let(:payload) { default_payload.merge(user_id: '1234') }
21
21
  let(:command_data) { default_payload.merge(user_id: '1234', context: context) }
22
22
 
23
- it { expect(command.method).to be_eql(:post) }
24
- it { expect(command.path).to be_eql('track') }
25
- it { expect(command.data).to be_eql(command_data) }
23
+ it { expect(command.method).to be(:post) }
24
+ it { expect(command.path).to eql('track') }
25
+ it { expect(command.data).to eql(command_data) }
26
26
  end
27
27
 
28
28
  context 'with properties' do
29
29
  let(:payload) { default_payload.merge(properties: { test: '1' }) }
30
30
  let(:command_data) { default_payload.merge(properties: { test: '1' }, context: context) }
31
31
 
32
- it { expect(command.method).to be_eql(:post) }
33
- it { expect(command.path).to be_eql('track') }
34
- it { expect(command.data).to be_eql(command_data) }
32
+ it { expect(command.method).to be(:post) }
33
+ it { expect(command.path).to eql('track') }
34
+ it { expect(command.data).to eql(command_data) }
35
35
  end
36
36
 
37
37
  context 'with user_traits' do
38
38
  let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
39
39
  let(:command_data) { default_payload.merge(user_traits: { test: '1' }, context: context) }
40
40
 
41
- it { expect(command.method).to be_eql(:post) }
42
- it { expect(command.path).to be_eql('track') }
43
- it { expect(command.data).to be_eql(command_data) }
41
+ it { expect(command.method).to be(:post) }
42
+ it { expect(command.path).to eql('track') }
43
+ it { expect(command.data).to eql(command_data) }
44
44
  end
45
45
 
46
46
  context 'when active true' do
47
47
  let(:payload) { default_payload.merge(context: context.merge(active: true)) }
48
48
  let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
49
49
 
50
- it { expect(command.method).to be_eql(:post) }
51
- it { expect(command.path).to be_eql('track') }
52
- it { expect(command.data).to be_eql(command_data) }
50
+ it { expect(command.method).to be(:post) }
51
+ it { expect(command.path).to eql('track') }
52
+ it { expect(command.data).to eql(command_data) }
53
53
  end
54
54
 
55
55
  context 'when active false' do
56
56
  let(:payload) { default_payload.merge(context: context.merge(active: false)) }
57
57
  let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
58
58
 
59
- it { expect(command.method).to be_eql(:post) }
60
- it { expect(command.path).to be_eql('track') }
61
- it { expect(command.data).to be_eql(command_data) }
59
+ it { expect(command.method).to be(:post) }
60
+ it { expect(command.path).to eql('track') }
61
+ it { expect(command.data).to eql(command_data) }
62
62
  end
63
63
 
64
64
  context 'when active string' do
65
65
  let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
66
66
  let(:command_data) { default_payload.merge(context: context) }
67
67
 
68
- it { expect(command.method).to be_eql(:post) }
69
- it { expect(command.path).to be_eql('track') }
70
- it { expect(command.data).to be_eql(command_data) }
68
+ it { expect(command.method).to be(:post) }
69
+ it { expect(command.path).to eql('track') }
70
+ it { expect(command.data).to eql(command_data) }
71
71
  end
72
72
  end
73
73
 
@@ -77,12 +77,7 @@ describe Castle::Commands::Track do
77
77
  context 'when event not present' do
78
78
  let(:payload) { {} }
79
79
 
80
- it do
81
- expect { validate! }.to raise_error(
82
- Castle::InvalidParametersError,
83
- 'event is missing or empty'
84
- )
85
- end
80
+ it { expect { validate! }.to raise_error(Castle::InvalidParametersError, 'event is missing or empty') }
86
81
  end
87
82
 
88
83
  context 'when event present' do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Configuration do
3
+ RSpec.describe Castle::Configuration do
4
4
  subject(:config) { described_class.new }
5
5
 
6
6
  it_behaves_like 'configuration_host'
@@ -10,5 +10,5 @@ describe Castle::Configuration do
10
10
  it_behaves_like 'configuration_failover_strategy'
11
11
  it_behaves_like 'configuration_api_secret'
12
12
 
13
- it { expect(config.api_secret).to be_eql('') }
13
+ it { expect(config.api_secret).to eql('') }
14
14
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Context::GetDefault do
3
+ RSpec.describe Castle::Context::GetDefault do
4
4
  subject { described_class.new(request, nil) }
5
5
 
6
6
  let(:ip) { '1.2.3.4' }
@@ -12,7 +12,8 @@ describe Castle::Context::GetDefault do
12
12
  'HTTP_X_FORWARDED_FOR' => ip,
13
13
  'HTTP_ACCEPT_LANGUAGE' => 'en',
14
14
  'HTTP_USER_AGENT' => 'test',
15
- 'HTTP_COOKIE' => "__cid=#{client_id};other=efgh"
15
+ 'HTTP_COOKIE' => "__cid=#{client_id};other=efgh",
16
+ 'HTTP_CONTENT_LENGTH' => '0'
16
17
  )
17
18
  end
18
19
  let(:request) { Rack::Request.new(env) }
@@ -30,11 +31,11 @@ describe Castle::Context::GetDefault do
30
31
 
31
32
  before { stub_const('Castle::VERSION', version) }
32
33
 
33
- it { expect(default_context[:active]).to be_eql(true) }
34
- it { expect(default_context[:headers]).to be_eql(result_headers) }
35
- it { expect(default_context[:ip]).to be_eql(ip) }
36
- it { expect(default_context[:client_id]).to be_eql(client_id) }
37
- it { expect(default_context[:library][:name]).to be_eql('castle-rb') }
38
- it { expect(default_context[:library][:version]).to be_eql(version) }
39
- it { expect(default_context[:user_agent]).to be_eql('test') }
34
+ it { expect(default_context[:active]).to be(true) }
35
+ it { expect(default_context[:headers]).to eql(result_headers) }
36
+ it { expect(default_context[:ip]).to eql(ip) }
37
+ it { expect(default_context[:client_id]).to eql(client_id) }
38
+ it { expect(default_context[:library][:name]).to eql('castle-rb') }
39
+ it { expect(default_context[:library][:version]).to eql(version) }
40
+ it { expect(default_context[:user_agent]).to eql('test') }
40
41
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Context::Merge do
3
+ RSpec.describe Castle::Context::Merge do
4
4
  let(:first) { { test: { test1: { c: '4' } } } }
5
5
 
6
6
  describe '#call' do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Context::Prepare do
3
+ RSpec.describe Castle::Context::Prepare do
4
4
  let(:ip) { '1.2.3.4' }
5
5
  let(:cookie_id) { 'abcd' }
6
6
  let(:ua) { 'Chrome' }
@@ -9,7 +9,8 @@ describe Castle::Context::Prepare do
9
9
  '/',
10
10
  'HTTP_USER_AGENT' => ua,
11
11
  'HTTP_X_FORWARDED_FOR' => ip,
12
- 'HTTP_COOKIE' => "__cid=#{cookie_id};other=efgh"
12
+ 'HTTP_COOKIE' => "__cid=#{cookie_id};other=efgh",
13
+ 'HTTP_CONTENT_LENGTH' => '0'
13
14
  )
14
15
  end
15
16
  let(:request) { Rack::Request.new(env) }
@@ -27,9 +28,7 @@ describe Castle::Context::Prepare do
27
28
  }
28
29
  end
29
30
 
30
- let(:headers) do
31
- { 'Content-Length': '0', 'User-Agent': ua, 'X-Forwarded-For': ip.to_s, 'Cookie': true }
32
- end
31
+ let(:headers) { { 'Content-Length': '0', 'User-Agent': ua, 'X-Forwarded-For': ip.to_s, Cookie: true } }
33
32
 
34
33
  before { stub_const('Castle::VERSION', '6.0.0') }
35
34
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Context::Sanitize do
3
+ RSpec.describe Castle::Context::Sanitize do
4
4
  let(:paylod) { { test: 'test' } }
5
5
 
6
6
  describe '#call' do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Core::GetConnection do
3
+ RSpec.describe Castle::Core::GetConnection do
4
4
  describe '.call' do
5
5
  subject(:class_call) { described_class.call }
6
6