promonizr 1.13.2

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.
@@ -0,0 +1,155 @@
1
+ require 'spec_helper'
2
+ require 'promonizr/companies'
3
+
4
+ describe Promonizr::Promotion do
5
+ context '#show?' do
6
+ before(:context) do
7
+ @dummy_stage = 'dummy'
8
+ @dummy_url = '/dummy/url'
9
+ end
10
+
11
+ describe 'on proper values' do
12
+ describe 'returns true' do
13
+ it 'when expected stage is passed' do
14
+ promotion = described_class.new(display_config: { 'stage' => { 'landing' => true } })
15
+ expect(promotion.show?(@dummy_url, 'landing')).to be_truthy
16
+ end
17
+
18
+ it 'when one of multiple possible stages is passed' do
19
+ promotion = described_class.new(
20
+ display_config: { 'stage' => { 'landing' => true, 'results' => true } }
21
+ )
22
+ expect(promotion.show?(@dummy_url, 'landing')).to be_truthy
23
+
24
+ promotion = described_class.new(
25
+ display_config: { 'stage' => { 'landing' => true, 'results' => false } }
26
+ )
27
+ expect(promotion.show?(@dummy_url, 'landing')).to be_truthy
28
+ end
29
+
30
+ it 'when both expected stage and excluded url are passed' do
31
+ promotion = described_class.new(display_config: {
32
+ 'stage' => { 'landing' => true, 'results' => true },
33
+ 'url_exclusions' => ['/sample/url', '/another/url', '/foo/bar']
34
+ })
35
+ expect(promotion.show?(@dummy_url, 'landing')).to be_truthy
36
+ expect(promotion.show?(@dummy_url, 'results')).to be_truthy
37
+ end
38
+ end
39
+
40
+ describe 'returns false' do
41
+ it 'when passed stage is configure to be excluded' do
42
+ promotion = described_class.new(display_config: { 'stage' => { 'landing' => false } })
43
+ expect(promotion.show?(@dummy_url, 'landing')).to be_falsey
44
+ end
45
+
46
+ it 'when unexpected stage is passed' do
47
+ promotion = described_class.new(display_config: { 'stage' => { 'landing' => true } })
48
+ expect(promotion.show?(@dummy_url, @dummy_stage)).to be_falsey
49
+ end
50
+
51
+ it 'when stage check is ok but url is excluded' do
52
+ promotion = described_class.new(
53
+ display_config: { 'stage' => { 'landing' => true }, 'url_exclusions' => ['/sample/url'] }
54
+ )
55
+ expect(promotion.show?('/sample/url', 'landing')).to be_falsey
56
+ end
57
+
58
+ it 'when url check is ok but stage is excluded' do
59
+ promotion = described_class.new(
60
+ display_config: { 'stage' => { 'landing' => false }, 'url_exclusions' => ['/sample/url'] }
61
+ )
62
+ expect(promotion.show?(@dummy_url, 'landing')).to be_falsey
63
+ expect(promotion.show?(@dummy_url, @dummy_stage)).to be_falsey
64
+ end
65
+ end
66
+ end
67
+
68
+ describe 'on null, missing, or empty values' do
69
+ it 'returns true when display_config is nil' do
70
+ promotion = described_class.new(display_config: nil)
71
+ expect(promotion.show?(@dummy_url, @dummy_stage)).to be_truthy
72
+ end
73
+
74
+ it 'returns true when display_config is an empty Hash' do
75
+ promotion = described_class.new(display_config: {})
76
+ expect(promotion.show?(@dummy_url, @dummy_stage)).to be_truthy
77
+ end
78
+
79
+ it 'returns true when url_exclusions key is not present' do
80
+ promotion = described_class.new(display_config: { 'stage' => 'landing' })
81
+ expect(promotion.show?(@dummy_url, 'landing')).to be_truthy
82
+ end
83
+ end
84
+
85
+ describe 'on non valid scenarios' do
86
+ it 'raise an exception when not enough params are passed' do
87
+ promotion = described_class.new
88
+ expect{ promotion.show? }.to raise_error(ArgumentError)
89
+
90
+ promotion = described_class.new
91
+ expect{ promotion.show?(@dummy_url) }.to raise_error(ArgumentError)
92
+ end
93
+ end
94
+ end
95
+
96
+ context '#featured?' do
97
+ describe 'on null, missing, or empty values' do
98
+ it 'returns false when display_config is nil' do
99
+ promotion = described_class.new(display_config: nil)
100
+ expect(promotion.featured?).to be_falsey
101
+ end
102
+
103
+ it 'returns false when display_config is an empty Hash' do
104
+ promotion = described_class.new(display_config: {})
105
+ expect(promotion.featured?).to be_falsey
106
+ end
107
+ end
108
+
109
+ describe 'on proper value' do
110
+ it 'returns true when is set as featured' do
111
+ promotion = described_class.new(display_config: { 'featured' => true } )
112
+ expect(promotion.featured?).to be_truthy
113
+ end
114
+
115
+ it 'returns false when is not set as featured' do
116
+ promotion = described_class.new(display_config: { 'featured' => false } )
117
+ expect(promotion.featured?).to be_falsey
118
+ end
119
+ end
120
+ end
121
+
122
+ context '#companies' do
123
+ it 'returns selected companies if they are filtered' do
124
+ allow(Promonizr::Companies).to receive(:by_url_names) { |names, country_code, product| names }
125
+ promotion = described_class.new(companies: ['some_company', 'some_other_company'])
126
+
127
+ expect(promotion.companies).to eq(['some_company', 'some_other_company'])
128
+ end
129
+
130
+ it 'returns all companies if they are not filtered' do
131
+ allow(Promonizr::Companies).to receive(:all).and_return(:all)
132
+ promotion = described_class.new
133
+
134
+ expect(promotion.companies).to eq(:all)
135
+ end
136
+ end
137
+
138
+ context '#image_url' do
139
+ it 'returns url for cloudfront' do
140
+ promotion = described_class.new(
141
+ image_url: 'https://comparaonline.s3.amazonaws.com/promotions/campaigns/121-promo-generic-27_%281%29.jpg'
142
+ )
143
+ expect(promotion.image_url).to eq('https://webimg.comparaonline.com/121-promo-generic-27_%281%29.jpg')
144
+ end
145
+ end
146
+
147
+ context '#featured_image_url' do
148
+ it 'returns url for cloudfront' do
149
+ promotion = described_class.new(
150
+ featured_image_url: 'https://comparaonline.s3.amazonaws.com/promotions/campaigns/108-promo-generic-12-featured_%281%29.jpg'
151
+ )
152
+ expect(promotion.featured_image_url).to eq('https://webimg.comparaonline.com/108-promo-generic-12-featured_%281%29.jpg')
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Promonizr::Request do
4
+ it 'returns a default answer on timeout' do
5
+ allow(RestClient::Request).to receive(:execute) do |options|
6
+ sleep(Promonizr::Request::TIMEOUT_SECONDS + 0.1)
7
+ end
8
+
9
+ allow(Rails.logger = {}).to receive(:error)
10
+ expect(described_class.execute(:get, Faker::Internet.url))
11
+ .to eq(Promonizr::Request::DEFAULT_ANSWER)
12
+ end
13
+
14
+ it 'returns a default answer on an unhandled exception' do
15
+ allow(RestClient::Request).to receive(:execute) do |options|
16
+ raise StandardError.new
17
+ end
18
+
19
+ allow(Rails.logger = {}).to receive(:error)
20
+ expect(described_class.execute(:get, Faker::Internet.url))
21
+ .to eq(Promonizr::Request::DEFAULT_ANSWER)
22
+ end
23
+ end
@@ -0,0 +1,343 @@
1
+ require 'spec_helper'
2
+
3
+ describe Promonizr::Search do
4
+ before(:example) do
5
+ @country_code = Promonizr::Campaigns::COUNTRY_CODES.sample
6
+ @product = Promonizr::Products::TYPE_CODES.sample
7
+ @company_name = 'some_company'
8
+ end
9
+
10
+ before(:context) do
11
+ @attributes = { age: 20, gender: 'male', company_name: @company_name}
12
+ @config = {}
13
+ end
14
+
15
+ context '#filter' do
16
+ it 'narrows by product and country_code' do
17
+ default_company_param = nil
18
+
19
+ stub_request(:post, Promonizr::Evaluations.api_url('evaluate'))
20
+ .with(
21
+ body: {
22
+ countryCode: @country_code,
23
+ product: @product,
24
+ form: {},
25
+ companyName: default_company_param
26
+ }
27
+ ).to_return(status: 200, body: [
28
+ build(:promotion, { country_code: @country_code, product: @product })
29
+ ].to_json)
30
+
31
+ result = Promonizr::Search.filter(@product, @country_code)
32
+ expect(result).to_not be_nil
33
+ expect(result).to_not be_empty
34
+ end
35
+
36
+ it 'narrows by attributes' do
37
+ stub_request(:post, Promonizr::Evaluations::api_url('evaluate'))
38
+ .with(
39
+ body: {
40
+ countryCode: @country_code,
41
+ product: @product,
42
+ form: @attributes,
43
+ companyName: @companyName
44
+ }
45
+ ).to_return(status: 200, body: [
46
+ build(:promotion, {
47
+ country_code: @country_code,
48
+ product: @product,
49
+ form: @attributes
50
+ })
51
+ ].to_json)
52
+
53
+ result = Promonizr::Search.filter(@product, @country_code, @config, @attributes)
54
+ expect(result).to_not be_nil
55
+ expect(result).to_not be_empty
56
+ end
57
+
58
+ it 'sorts ascendant by rules_size' do
59
+ rules_1 = {
60
+ 'age' => { 'conditions' => [{ 'between' => [18, 65] }] },
61
+ 'gender' => { 'conditions' => [{ 'eq' => 'male' }]},
62
+ 'state' => { 'conditions' => [{ 'in' => ['Foo', 'Bar'] }] }
63
+ }
64
+
65
+ rules_2 = {
66
+ 'age' => { 'conditions' => [{ 'between' => [18, 65] }] },
67
+ 'gender' => { 'conditions' => [{ 'eq' => 'male' }]}
68
+ }
69
+
70
+ rules_3 = {
71
+ 'age' => { 'conditions' => [{ 'between' => [18, 65] }] },
72
+ 'gender' => { 'conditions' => [{ 'eq' => 'male' }]},
73
+ 'state' => { 'conditions' => [{ 'in' => ['Foo', 'Bar'] }] },
74
+ 'country_code' => { 'conditions' => [{ 'eq' => 'cl' }] }
75
+ }
76
+
77
+ promotion = lambda { |rules| build(:promotion, {
78
+ country_code: @country_code,
79
+ product: @product,
80
+ rules: rules
81
+ }) }
82
+
83
+ stub_request(:post, Promonizr::Evaluations.api_url('evaluate'))
84
+ .with(
85
+ body: {
86
+ countryCode: @country_code,
87
+ product: @product,
88
+ form: @attributes,
89
+ companyName: @companyName
90
+ },
91
+ ).to_return(status: 200, body: [
92
+ promotion.call(rules_1),
93
+ promotion.call(rules_2),
94
+ promotion.call(rules_3)
95
+ ].to_json)
96
+
97
+ promotions = Promonizr::Search.filter(@product, @country_code, @config, @attributes)
98
+
99
+ expect(promotions[0].rules.size).to eq(2)
100
+ expect(promotions[1].rules.size).to eq(3)
101
+ expect(promotions[2].rules.size).to eq(4)
102
+ end
103
+
104
+ it 'sorts rules descendant by end_date' do
105
+ rules = {
106
+ 'age' => { 'conditions' => [{ 'between' => [18, 65] }] },
107
+ 'gender' => { 'conditions' => [{ 'eq' => 'male' }]}
108
+ }
109
+
110
+ base_date = Faker::Date.forward
111
+ future_date_1 = base_date + 1.month
112
+ future_date_2 = base_date + 1.day
113
+ future_date_3 = base_date + 2.month
114
+
115
+ promotion = lambda { |date| build(:promotion, {
116
+ country_code: @country_code,
117
+ product: @product,
118
+ end_date: date,
119
+ rules: rules
120
+ }) }
121
+
122
+ stub_request(:post, Promonizr::Evaluations.api_url('evaluate'))
123
+ .with(
124
+ body: {
125
+ countryCode: @country_code,
126
+ product: @product,
127
+ form: @attributes,
128
+ companyName: @companyName
129
+ }
130
+ ).to_return(status: 200, body: [
131
+ promotion.call(future_date_1),
132
+ promotion.call(future_date_2),
133
+ promotion.call(future_date_3)
134
+ ].to_json)
135
+
136
+ promotions = Promonizr::Search.filter(@product, @country_code, @config, @attributes)
137
+
138
+ expect(promotions[0].end_date.to_date).to eq(future_date_2)
139
+ expect(promotions[1].end_date.to_date).to eq(future_date_1)
140
+ expect(promotions[2].end_date.to_date).to eq(future_date_3)
141
+ end
142
+ end
143
+
144
+ context '#for_results' do
145
+ it 'only returns promotions with stage results flag enabled' do
146
+ promotion = lambda { |display_config| build(:promotion, {
147
+ country_code: @country_code,
148
+ product: @product,
149
+ display_config: display_config
150
+ }) }
151
+
152
+ stub_request(:post, Promonizr::Evaluations.api_url('evaluate'))
153
+ .with(
154
+ body: {
155
+ countryCode: @country_code,
156
+ product: @product,
157
+ form: @attributes,
158
+ companyName: @companyName
159
+ }
160
+ ).to_return(status: 200, body: [
161
+ promotion.call('stage' => { 'landing' => true }),
162
+ promotion.call('stage' => { 'landing' => true, 'results' => true }),
163
+ promotion.call('stage' => { 'results' => true })
164
+ ].to_json)
165
+
166
+ expect(Promonizr::Search.for_results(@product, @country_code, @attributes).size).to eq(2)
167
+ end
168
+ end
169
+
170
+ context '#for_results_in_bulk' do
171
+ let(:url) { "#{@product}/#{@country_code}" }
172
+ let(:offer_id) { '1234' }
173
+ let(:unexisting_offer_id) { '4321' }
174
+ let(:without_promo_offer_id) { '2345' }
175
+ let(:company) { 'company' }
176
+ let(:form_data) do
177
+ {
178
+ destination: 31
179
+ }
180
+ end
181
+ let(:offers_data) do
182
+ [
183
+ { id: offer_id, company_name: company },
184
+ { id: without_promo_offer_id, company_name: company }
185
+ ]
186
+ end
187
+ let(:promotion) do
188
+ {
189
+ country_code: @country_code,
190
+ product: @product,
191
+ display_config: {stage: {results: true}}
192
+ }
193
+ end
194
+
195
+ before do
196
+ stub_request(:post, Promonizr::Evaluations.api_url("#{url}/campaigns_for_offers"))
197
+ .with(
198
+ body: {
199
+ form: form_data,
200
+ offers: offers_data
201
+ }
202
+ ).to_return(status: 200, body: {
203
+ offer_id => [promotion],
204
+ without_promo_offer_id => []
205
+ }.to_json)
206
+ end
207
+
208
+ it 'returns promotion for offer' do
209
+ promotions = Promonizr::Search.for_results_in_bulk(url, true, form_data, offers_data)
210
+ expect(promotions[offer_id].show_promotion?).to be_truthy
211
+ end
212
+
213
+ it 'returns non showable promotions if disabled' do
214
+ promotions = Promonizr::Search.for_results_in_bulk(url, false, form_data, offers_data)
215
+ expect(promotions[offer_id].show_promotion?).to be_falsey
216
+ end
217
+
218
+ it 'returns non showable promotions for offers without promotions' do
219
+ promotions = Promonizr::Search.for_results_in_bulk(url, true, form_data, offers_data)
220
+ expect(promotions[without_promo_offer_id].show_promotion?).to be_falsey
221
+ end
222
+
223
+ it 'returns non showable promotions for unexisting offers' do
224
+ promotions = Promonizr::Search.for_results_in_bulk(url, true, form_data, offers_data)
225
+ expect(promotions[unexisting_offer_id].show_promotion?).to be_falsey
226
+ end
227
+ end
228
+
229
+ context '#for_carousel' do
230
+ it 'only returns promotions with stage landing flag enabled' do
231
+ promotion = lambda { |display_config| build(:promotion, {
232
+ country_code: @country_code,
233
+ product: @product,
234
+ display_config: display_config,
235
+ }) }
236
+
237
+ stub_request(:post, Promonizr::Evaluations.api_url('evaluate'))
238
+ .with(
239
+ body: {
240
+ countryCode: @country_code,
241
+ product: @product,
242
+ form: @attributes,
243
+ companyName: @companyName
244
+ }
245
+ ).to_return(status: 200, body: [
246
+ promotion.call('stage' => { 'landing' => true }),
247
+ promotion.call('stage' => { 'landing' => true, 'results' => true }),
248
+ promotion.call('stage' => { 'results' => true })
249
+ ].to_json)
250
+
251
+ expect(Promonizr::Search.for_carousel(@product, @country_code, Faker::Internet.url, @attributes).size).to eq(2)
252
+ end
253
+
254
+ it 'only returns promotions with stage landing flag enabled filtering excluded_urls' do
255
+ promotion = lambda { |display_config| build(:promotion, {
256
+ country_code: @country_code,
257
+ product: @product,
258
+ display_config: display_config,
259
+ }) }
260
+ some_url = Faker::Internet.url('comparaonline.com')
261
+
262
+ stub_request(:post, Promonizr::Evaluations.api_url('evaluate'))
263
+ .with(
264
+ body: {
265
+ countryCode: @country_code,
266
+ product: @product,
267
+ form: @attributes,
268
+ companyName: @companyName
269
+ }
270
+ ).to_return(status: 200, body: [
271
+ promotion.call(
272
+ 'stage' => { 'landing' => true },
273
+ 'url_exclusions' => [Faker::Internet.url('foo.com'), Faker::Internet.url('bar.com')]
274
+ ),
275
+ promotion.call(
276
+ 'stage' => { 'landing' => true, 'results' => true },
277
+ 'url_exclusions' => [some_url, Faker::Internet.url]
278
+ ),
279
+ promotion.call('stage' => { 'results' => true })
280
+ ].to_json)
281
+
282
+ expect(Promonizr::Search.for_carousel(@product, @country_code, some_url, @attributes).size).to eq(1)
283
+ end
284
+ end
285
+
286
+ context '#featured' do
287
+ it 'returns the first promotion with featured flag enabled' do
288
+ promotion = lambda { |display_config| build(:promotion, {
289
+ country_code: @country_code,
290
+ product: @product,
291
+ display_config: display_config
292
+ })}
293
+
294
+ stub_request(:post, Promonizr::Evaluations.api_url('evaluate'))
295
+ .with(
296
+ body: {
297
+ countryCode: @country_code,
298
+ product: @product,
299
+ form: @attributes,
300
+ companyName: @companyName
301
+ }
302
+ ).to_return(status: 200, body: [
303
+ promotion.call({}),
304
+ promotion.call('featured' => true),
305
+ build(:promotion, display_config: { 'featured' => true, stage: 'landing' }, mark: true),
306
+ promotion.call('featured' => true, stage: 'landing'),
307
+ promotion.call('featured' => false),
308
+ ].to_json)
309
+
310
+ result = Promonizr::Search.featured(@product, @country_code, Faker::Internet.url, @attributes)
311
+
312
+ expect(result).to be_kind_of(Promonizr::Promotion)
313
+ expect(result.mark).to be_truthy
314
+ end
315
+
316
+ it 'returns the first promotion with featured flag enabled filtering excluded_urls' do
317
+ some_url = Faker::Internet.url('comparaonline.com')
318
+
319
+ stub_request(:post, Promonizr::Evaluations.api_url('evaluate'))
320
+ .with(
321
+ body: {
322
+ countryCode: @country_code,
323
+ product: @product,
324
+ form: @attributes,
325
+ companyName: @companyName
326
+ }
327
+ ).to_return(status: 200, body: [
328
+ build(:featured_promotion,
329
+ 'url_exclusions' => [Faker::Internet.url('foo.com'), Faker::Internet.url('bar.com')],
330
+ mark: true
331
+ ),
332
+ build(:featured_promotion,
333
+ 'url_exclusions' => [some_url, Faker::Internet.url]
334
+ ),
335
+ build(:featured_promotion)
336
+ ].to_json)
337
+
338
+ result = Promonizr::Search.featured(@product, @country_code, some_url, @attributes)
339
+ expect(result).to be_kind_of(Promonizr::Promotion)
340
+ expect(result.mark).to be_truthy
341
+ end
342
+ end
343
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe Promonizr::Utils do
4
+
5
+ describe '.cast_values' do
6
+ context 'hash with several truthy values' do
7
+ hash = { a: true, b: 'True', c: ' true ', d: 'TRUE', e: 'true'}
8
+ casted_hash = Promonizr::Utils::cast_values(hash)
9
+ hash.keys.each do |k|
10
+ it { expect(casted_hash[k]).to be true }
11
+ end
12
+ end
13
+
14
+ context 'hash with mixed truthy and falsy values' do
15
+ hash = { a: true, b: 'True', c: ' true ', d: 'false', e: 'False', f: false }
16
+ casted_hash = Promonizr::Utils::cast_values(hash)
17
+
18
+ it { expect(casted_hash[:a]).to be true }
19
+ it { expect(casted_hash[:b]).to be true }
20
+ it { expect(casted_hash[:c]).to be true }
21
+ it { expect(casted_hash[:d]).to be false }
22
+ it { expect(casted_hash[:e]).to be false }
23
+ it { expect(casted_hash[:f]).to be false }
24
+ end
25
+
26
+ context 'hash without truthy or falsy values' do
27
+ hash = { a: 1, b: 0, c: 'string', d: {}, e: [], f: nil, g: '' }
28
+ casted_hash = Promonizr::Utils::cast_values(hash)
29
+
30
+ it { expect(casted_hash[:a]).to eq(1) }
31
+ it { expect(casted_hash[:b]).to eq(0) }
32
+ it { expect(casted_hash[:c]).to eq('string') }
33
+ it { expect(casted_hash[:d]).to eq({}) }
34
+ it { expect(casted_hash[:e]).to eq([]) }
35
+ it { expect(casted_hash[:f]).to eq(nil) }
36
+ it { expect(casted_hash[:g]).to eq('') }
37
+ end
38
+
39
+ context 'truthy value inside of an array' do
40
+ hash = { 'multitravel' => { 'conditions'=> [ { 'eq' => 'true' } ] } }
41
+ casted_hash = Promonizr::Utils::cast_values(hash)
42
+
43
+ it do
44
+ expect(casted_hash['multitravel']['conditions'][0]['eq']).to be true
45
+ end
46
+ end
47
+
48
+ context 'hash with numeric values as strings' do
49
+ hash = { a: 1, b: '1', c: ' 1.00 ', d: '1.21', e: ' 0.0 ', f: 2.14, g: '0' }
50
+ casted_hash = Promonizr::Utils::cast_values(hash)
51
+
52
+ it { expect(casted_hash[:a]).to be 1 }
53
+ it { expect(casted_hash[:b]).to be 1 }
54
+ it { expect(casted_hash[:c]).to be 1.00 }
55
+ it { expect(casted_hash[:d]).to be 1.21 }
56
+ it { expect(casted_hash[:e]).to be 0.0 }
57
+ it { expect(casted_hash[:f]).to be 2.14 }
58
+ it { expect(casted_hash[:g]).to be 0 }
59
+ end
60
+ end
61
+
62
+ describe '.transform_values' do
63
+ context 'hash deep == 1' do
64
+ hash = { a: 1, b: 2, c: 3 }
65
+ transformed = Promonizr::Utils::transform_values(hash) { |x| x ** 2 }
66
+ it { expect(transformed[:a]).to eq(1) }
67
+ it { expect(transformed[:b]).to eq(4) }
68
+ it { expect(transformed[:c]).to eq(9) }
69
+ end
70
+
71
+ context 'hash deep == 2' do
72
+ hash = { a: { b: 2, c: 3 } }
73
+ transformed = Promonizr::Utils::transform_values(hash) { |x| x ** 3 }
74
+
75
+ it { expect(transformed[:a]).to eq({ b: 8, c: 27 }) }
76
+ it { expect(transformed[:a][:b]).to eq(8) }
77
+ it { expect(transformed[:a][:c]).to eq(27) }
78
+ end
79
+
80
+ context 'hash deep == 3' do
81
+ hash = { a: { b: { c: 2, d: 3 } } }
82
+ transformed = Promonizr::Utils::transform_values(hash) { |x| x ** 2 }
83
+
84
+ it { expect(transformed[:a]).to eq({ b: { c: 4, d: 9 } })}
85
+ end
86
+
87
+ context 'hash contains an array with a hash' do
88
+ hash = { a: { b: [ { c: 2, d: 3 } ] } }
89
+ transformed = Promonizr::Utils::transform_values(hash) { |x| x ** 2 }
90
+
91
+ it { expect(transformed).to eq({ a: { b: [ { c: 4, d: 9 } ] } })}
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Promonizr do
4
+ it 'has a version number' do
5
+ expect(Promonizr::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ ENV['RAILS_ENV'] = 'test'
4
+
5
+ require 'rails'
6
+ require 'rails/engine'
7
+ require 'rails/railtie'
8
+ require 'rest-client'
9
+
10
+ require 'co_config'
11
+ CoConfig.load("#{__dir__}/../config")
12
+
13
+ require 'promonizr'
14
+
15
+ require 'rspec-rails'
16
+ require 'webmock/rspec'
17
+ require 'support/factory_girl'
18
+ require 'faker'
@@ -0,0 +1,9 @@
1
+ require 'factory_girl'
2
+
3
+ RSpec.configure do |config|
4
+ config.include FactoryGirl::Syntax::Methods
5
+
6
+ config.before(:suite) do
7
+ FactoryGirl.find_definitions
8
+ end
9
+ end