zillion 0.0.7 → 0.0.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe94dcc79501b639c14f6102eee9bdc93f7bdf42
4
- data.tar.gz: c72ee7eff41512f0f4414808b5fcf52f6deedae5
3
+ metadata.gz: 6ce05db824e474efb57c076724e898b942e9d1e7
4
+ data.tar.gz: 4b9cd7809dfe54aebde95a44e20c367d5fecdd1e
5
5
  SHA512:
6
- metadata.gz: 0bd984ac1c8abb7f114975ff7781d20c974c5259628d0fa22821cfc14a8f54a5a00a504e11714e1289656abb672992e7f9e656469b393e74212e2a436ab151ee
7
- data.tar.gz: 3850bd41d6b6d5c80018396de7403c7921fff39d7009e0171ceadb340e2f00da7f5b615d8db2d7920f6eaea5be842cc52e927978d998b5ff31b17005313029ef
6
+ metadata.gz: 5474bb4ab5fbec4aa0dfdb1d8d6739086760b76737534e934b8b8149e45a046acc3b9ae48d2262fdb9a90e1522f91da0fb016b48baa7f35c49765f9d23360df6
7
+ data.tar.gz: 8034f57e84d372f1209fc6f074c39661ee21a810860cf2c250d6f968c280ffd5a69ec5d5bf9d3c4944c8b1f3b5c5792fec183591475a321ca5f22aa58c1c5a91
data/lib/zillion/plan.rb CHANGED
@@ -91,7 +91,7 @@ class Plan
91
91
 
92
92
  def ensure_available!(counts)
93
93
  unless available_for?(counts)
94
- raise OverLimitsError.new("This plan has lower limits than: #{counts}")
94
+ raise OverLimitsError.new("The #{name} plan has lower limits than: #{counts}")
95
95
  end
96
96
  end
97
97
 
@@ -158,9 +158,9 @@ class TieredPlan < Plan
158
158
  arr = tiers.select { |t| t[0].include?(units) }
159
159
 
160
160
  if arr.empty?
161
- raise TierNotFoundError.new("No matching tiers found for #{units} units.")
161
+ raise TierNotFoundError.new("No matching tiers found for #{units} units (#{name} plan)")
162
162
  elsif arr.count > 1
163
- raise MultipleTiersFoundError.new("Unit count is in more than one tier!")
163
+ raise MultipleTiersFoundError.new("Unit count is in more than one tier! (#{name} plan)")
164
164
  end
165
165
 
166
166
  arr.first # + [tiers.index(arr.first)]
@@ -200,7 +200,6 @@ class MeteredPlan < TieredPlan
200
200
  units = units_for(tier.last, counts)
201
201
  obj[tier.last.to_sym] = units * tier[1]
202
202
  end
203
-
204
203
  obj
205
204
  end
206
205
 
@@ -267,7 +266,7 @@ class FixedMeteredPlan < MeteredPlan
267
266
  def get_matching_tiers(counts)
268
267
  tier_groups.map do |key, tiers|
269
268
  units = counts[key] or raise "Unit count required for #{key}"
270
- next if limits[key] and limits[key] > units.to_i
269
+ next if limits[key] and limits[key] >= units.to_i
271
270
 
272
271
  find_tier_for(tiers, units.to_i) + [key]
273
272
  end.compact
data/spec/plans_spec.rb CHANGED
@@ -68,7 +68,7 @@ describe 'FreePlan' do
68
68
  expect(plan.available_for?({ bananas: 100 }) ).to eql(true)
69
69
  end
70
70
 
71
- it 'raises not all units for limits are fed' do
71
+ it 'raises if not all units for limits are fed' do
72
72
  other = FreePlan.new(limits: { bananas: 10 })
73
73
  expect { other.available_for?({ apples: 10 }) }.to raise_error
74
74
  end
@@ -275,7 +275,7 @@ describe 'TieredPlan', 'Multiple tiers' do
275
275
  expect { plan.available_for?({ bananas: 5, products: -5 }) }.to raise_error
276
276
  end
277
277
 
278
- it 'returns monthly fee for tier if within its limit' do
278
+ it 'returns true if within tier limits' do
279
279
  expect(plan.available_for?({ bananas: 5, orders: 5, products: 25 })).to eql(true)
280
280
  end
281
281
 
@@ -338,7 +338,7 @@ describe 'MeteredPlan', 'Single tier' do
338
338
  expect { plan.available_for?({ bananas: 5, products: -5 }) }.to raise_error
339
339
  end
340
340
 
341
- it 'returns monthly fee for tier if within its limit' do
341
+ it 'returns true if within its limit' do
342
342
  expect(plan.available_for?({ bananas: 5, products: 25 })).to eql(true)
343
343
  end
344
344
 
@@ -406,7 +406,7 @@ describe 'MeteredPlan', 'Multiple tiers' do
406
406
  expect { plan.available_for?({ bananas: 5, products: -5 }) }.to raise_error
407
407
  end
408
408
 
409
- it 'returns monthly fee for tier if within its limit' do
409
+ it 'returns true if within its limit' do
410
410
  expect(plan.available_for?({ bananas: 5, orders: 5, products: 25 })).to eql(true)
411
411
  end
412
412
 
@@ -422,7 +422,7 @@ describe 'FixedMeteredPlan' do
422
422
  limits: { bananas: 10, orders: 10, products: 10 },
423
423
  tiers: {
424
424
  orders: [
425
- { from: 10, to: 15, monthly_unit_cost: 3 },
425
+ { from: 11, to: 15, monthly_unit_cost: 3 },
426
426
  { from: 16, to: 20, monthly_unit_cost: 1 }
427
427
  ],
428
428
  products: [
@@ -461,6 +461,10 @@ describe 'FixedMeteredPlan' do
461
461
  expect(plan.monthly_fee_for({ bananas: 5, orders: 5, products: 5 })).to eql(10.0)
462
462
  end
463
463
 
464
+ it 'returns monthly fee for if just within limit limits' do
465
+ expect(plan.monthly_fee_for({ bananas: 10, orders: 10, products: 10 })).to eql(10.0)
466
+ end
467
+
464
468
  it 'returns monthly fee for tier if within its limit' do
465
469
  expect(plan.monthly_fee_for({ bananas: 5, orders: 5, products: 25 })).to eql(40.0)
466
470
  end
@@ -499,11 +503,11 @@ describe 'FixedMeteredPlan' do
499
503
  expect(plan.available_for?({ bananas: 5, orders: 5, products: 15 })).to eql(false)
500
504
  end
501
505
 
502
- it 'returns true if within its limit' do
506
+ it 'returns true if above fixed limit but within tier limit' do
503
507
  expect(plan.available_for?({ bananas: 5, orders: 5, products: 15 })).to eql(true)
504
508
  end
505
509
 
506
- it 'returns true if within its limit' do
510
+ it 'returns true e if above fixed limit but within tier limit' do
507
511
  expect(plan.available_for?({ bananas: 5, orders: 15, products: 25 })).to eql(true)
508
512
  end
509
513
 
data/zillion.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "zillion"
6
- s.version = '0.0.7'
6
+ s.version = '0.0.8'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Tomás Pollak']
9
9
  s.email = ['tomas@forkhq.com']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zillion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-25 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler