unidom-price 1.7.4 → 1.7.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af6155b7fa6b0db7e89984b77185841d4c17cb10
4
- data.tar.gz: 65fa87de86bff3302a12c3053af1c7300e21b166
3
+ metadata.gz: 2a61dafa0005f117a0f8a4399db39e38b378d0dd
4
+ data.tar.gz: 944c6ec8824681f2017b5d695b6d0730ea1225dc
5
5
  SHA512:
6
- metadata.gz: 9f536bfcad78f27a142255a382b131a5fbf6e0546086cd9db70a28c89c07027dc63bbb9bb3321086937a83aa17a150eff95310e7922054e880e3ec80dd0c2b3e
7
- data.tar.gz: 8f2d5fca12f00cba093737f6da900ee59d19872133162f3af77d228d983787927e4b328864a8535a41dbcbf62762d397c00e02b7d81a643e47c42ca197a03af2
6
+ metadata.gz: 151fe246663561bab24cb12ec9b8c7d5930e560a971f64f5842dee93f7c2db964f9cce6762de64be3289d633c7752cf42a92d91668474c779846276969383382
7
+ data.tar.gz: b10a1c96510d2fbf28db596b2d4e4b2012f248727999b6c58533e23250b191cdcb58f654c87a0340419c8136b1136caca705bd5003b0f0a27f085b66e44cb874
data/README.md CHANGED
@@ -203,7 +203,9 @@ describe Unidom::Product::Product do
203
203
  packing_norm: '1 per 1'
204
204
  }
205
205
 
206
- it_behaves_like 'Unidom::Price::Concerns::AsPriced', model_attribtues
206
+ pricer = Unidom::Party::Person.create! name: 'Tim'
207
+
208
+ it_behaves_like 'Unidom::Price::Concerns::AsPriced', model_attribtues, pricer
207
209
 
208
210
  end
209
211
  ```
@@ -3,20 +3,31 @@
3
3
 
4
4
  module Unidom::Price::Concerns::AsPriced
5
5
 
6
- extend ActiveSupport::Concern
6
+ extend ActiveSupport::Concern
7
+ include Unidom::Common::Concerns::ArgumentValidation
7
8
 
8
9
  included do |includer|
9
10
 
10
11
  has_many :prices, class_name: 'Unidom::Price::Price', as: :priced
11
12
 
12
13
  def is_priced!(amount, by: nil, at: Time.now)
14
+
15
+ assert_present! :amount, amount
16
+ assert_present! :by, by
17
+ assert_present! :at, at
18
+
13
19
  pricing = prices.valid_at(now: at).alive.first
14
20
  pricing.soft_destroy if pricing.present?
15
21
  prices.create! pricer: by, amount: amount, opened_at: at
22
+
16
23
  end
17
24
 
18
25
  def is_priced?(at: Time.now)
26
+
27
+ assert_present! :at, at
28
+
19
29
  prices.valid_at(now: at).alive.exists?
30
+
20
31
  end
21
32
 
22
33
  end
@@ -1,17 +1,69 @@
1
- shared_examples 'Unidom::Price::Concerns::AsPriced' do |model_attributes|
1
+ shared_examples 'Unidom::Price::Concerns::AsPriced' do |model_attributes, pricer|
2
2
 
3
- price_1_attribtues = {
4
- pricer_id: SecureRandom.uuid,
5
- pricer_type: 'Unidom::Price::Pricer::Mock',
6
- amount: 10.00
7
- }
3
+ before :each do
4
+ @priced = described_class.create! model_attributes
5
+ @amount = 10.00
6
+ end
8
7
 
9
- price_2_attribtues = {
10
- pricer_id: SecureRandom.uuid,
11
- pricer_type: 'Unidom::Price::Pricer::Mock',
12
- amount: 21.00
13
- }
8
+ after :each do
9
+ end
14
10
 
15
- it_behaves_like 'has_many', model_attributes, :prices, Unidom::Price::Price, [ price_1_attribtues, price_2_attribtues ]
11
+ context '#is_priced!' do
12
+
13
+ it 'should reject the amount argument = nil' do expect { @priced.is_priced! nil, by: pricer, at: Time.now }.to raise_error(ArgumentError, 'The amount argument is required.') end
14
+ it 'should reject the by argument = nil' do expect { @priced.is_priced! @amount, by: nil, at: Time.now }.to raise_error(ArgumentError, 'The by argument is required.') end
15
+ it 'should reject the at argument = nil' do expect { @priced.is_priced! @amount, by: pricer, at: nil }.to raise_error(ArgumentError, 'The at argument is required.') end
16
+
17
+ it "should be able to be priced by #{pricer.inspect}" do
18
+ price = @priced.is_priced! @amount, by: pricer
19
+ expect(price).to be_present
20
+ expect(price).to be_a(Unidom::Price::Price)
21
+ expect(price).not_to be_new_record
22
+ end
23
+
24
+ it "should be able to be priced by #{pricer.inspect}, at #{Time.now.inspect}" do
25
+ price = @priced.is_priced! @amount, by: pricer, at: Time.now
26
+ expect(price).to be_present
27
+ expect(price).to be_a(Unidom::Price::Price)
28
+ expect(price).not_to be_new_record
29
+ end
30
+
31
+ end
32
+
33
+ context '#is_priced?' do
34
+
35
+ it 'should reject the at argument = nil' do expect { @priced.is_priced? at: nil }.to raise_error(ArgumentError, 'The at argument is required.') end
36
+
37
+ it "should be able to be priced by #{pricer.inspect}" do
38
+ expect(@priced.is_priced?).to be_falsey
39
+ @priced.is_priced! @amount, by: pricer
40
+ expect(@priced.is_priced?).to be_truthy
41
+ end
42
+
43
+ it "should be able to be priced by #{pricer.inspect}, at #{Time.now.inspect}" do
44
+ expect(@priced.is_priced? at: Time.now).to be_falsey
45
+ @priced.is_priced! @amount, by: pricer, at: Time.now
46
+ expect(@priced.is_priced? at: Time.now).to be_truthy
47
+ end
48
+
49
+ end
50
+
51
+ context do
52
+
53
+ price_1_attribtues = {
54
+ pricer_id: SecureRandom.uuid,
55
+ pricer_type: 'Unidom::Price::Pricer::Mock',
56
+ amount: 10.00
57
+ }
58
+
59
+ price_2_attribtues = {
60
+ pricer_id: SecureRandom.uuid,
61
+ pricer_type: 'Unidom::Price::Pricer::Mock',
62
+ amount: 21.00
63
+ }
64
+
65
+ it_behaves_like 'has_many', model_attributes, :prices, Unidom::Price::Price, [ price_1_attribtues, price_2_attribtues ]
66
+
67
+ end
16
68
 
17
69
  end
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Price
3
- VERSION = '1.7.4'.freeze
3
+ VERSION = '1.7.5'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-price
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.4
4
+ version: 1.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-18 00:00:00.000000000 Z
11
+ date: 2017-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common