unidom-price 1.7.6 → 1.7.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -14
- data/app/models/unidom/price/concerns/as_pricer.rb +11 -0
- data/lib/rspec/models/unidom/price/concerns/as_priced_shared_examples.rb +0 -6
- data/lib/rspec/models/unidom/price/concerns/as_pricer_shared_examples.rb +6 -1
- data/lib/unidom/price/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aeab6cd86ed792d5475a58e4469f828fd30ff5fd
|
4
|
+
data.tar.gz: bd240520ac7e134f98a260be212630c42c330c05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a7bbe450c789a001650bb623356f02fcf6be99c4fa9610f35ad958c9f6b86b7dafff9dc80bad93b043d291c6443e67805aa74d9a53cb896fea5f3dd067e6ecf
|
7
|
+
data.tar.gz: de953d928ea9f696389b136ef0845f105a25262886d2d5d6ad3d3a2b337aab55d9a635ff835e85ba1c429aaf0abd0538f0cad2260ae1f154d31cc97b1b0e20d0
|
data/README.md
CHANGED
@@ -183,29 +183,45 @@ initialize_unidom
|
|
183
183
|
require 'unidom/price/rspec_shared_examples'
|
184
184
|
|
185
185
|
# spec/models/unidom/party/person_spec.rb
|
186
|
-
describe Unidom::Party::Person do
|
186
|
+
describe Unidom::Party::Person, type: :model do
|
187
187
|
|
188
|
-
|
189
|
-
|
190
|
-
|
188
|
+
context do
|
189
|
+
|
190
|
+
model_attribtues = {
|
191
|
+
name: 'Tim'
|
192
|
+
}
|
193
|
+
|
194
|
+
priced_attributes = {
|
195
|
+
name: 'Model X',
|
196
|
+
abbreviation: 'MX',
|
197
|
+
measurement_unit: 'set',
|
198
|
+
packing_norm: '1 per 1'
|
199
|
+
}
|
200
|
+
priced = Unidom::Product::Product.create! priced_attributes
|
191
201
|
|
192
|
-
|
202
|
+
it_behaves_like 'Unidom::Price::Concerns::AsPricer', model_attribtues, priced
|
203
|
+
|
204
|
+
end
|
193
205
|
|
194
206
|
end
|
195
207
|
|
196
208
|
# spec/models/unidom/position/post_spec.rb
|
197
|
-
describe Unidom::Product::Product do
|
209
|
+
describe Unidom::Product::Product, type: :model do
|
198
210
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
211
|
+
context do
|
212
|
+
|
213
|
+
model_attribtues = {
|
214
|
+
name: 'Model X',
|
215
|
+
abbreviation: 'MX',
|
216
|
+
measurement_unit: 'set',
|
217
|
+
packing_norm: '1 per 1'
|
218
|
+
}
|
205
219
|
|
206
|
-
|
220
|
+
pricer = Unidom::Party::Person.create! name: 'Tim'
|
207
221
|
|
208
|
-
|
222
|
+
it_behaves_like 'Unidom::Price::Concerns::AsPriced', model_attribtues, pricer
|
223
|
+
|
224
|
+
end
|
209
225
|
|
210
226
|
end
|
211
227
|
```
|
@@ -10,13 +10,24 @@ module Unidom::Price::Concerns::AsPricer
|
|
10
10
|
has_many :pricings, class_name: 'Unidom::Price::Price', as: :pricer
|
11
11
|
|
12
12
|
def price!(it, amount, at: Time.now)
|
13
|
+
|
14
|
+
assert_present! :it, it
|
15
|
+
assert_present! :amount, amount
|
16
|
+
assert_present! :at, at
|
17
|
+
|
13
18
|
pricing = pricings.priced_is(it).valid_at(now: at).alive.first
|
14
19
|
pricing.soft_destroy if pricing.present?
|
15
20
|
pricings.create! priced: it, amount: amount, opened_at: at
|
21
|
+
|
16
22
|
end
|
17
23
|
|
18
24
|
def price?(it, at: Time.now)
|
25
|
+
|
26
|
+
assert_present! :it, it
|
27
|
+
assert_present! :at, at
|
28
|
+
|
19
29
|
pricings.priced_is(it).valid_at(now: at).alive.exists?
|
30
|
+
|
20
31
|
end
|
21
32
|
|
22
33
|
end
|
@@ -10,10 +10,6 @@ shared_examples 'Unidom::Price::Concerns::AsPriced' do |model_attributes, pricer
|
|
10
10
|
|
11
11
|
context '#is_priced!' do
|
12
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
13
|
it "should be able to be priced by #{pricer.inspect}" do
|
18
14
|
price = @priced.is_priced! @amount, by: pricer
|
19
15
|
expect(price).to be_present
|
@@ -32,8 +28,6 @@ shared_examples 'Unidom::Price::Concerns::AsPriced' do |model_attributes, pricer
|
|
32
28
|
|
33
29
|
context '#is_priced?' do
|
34
30
|
|
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
31
|
it "should be able to be priced by #{pricer.inspect}" do
|
38
32
|
expect(@priced.is_priced?).to be_falsey
|
39
33
|
@priced.is_priced! @amount, by: pricer
|
@@ -1,4 +1,4 @@
|
|
1
|
-
shared_examples 'Unidom::Price::Concerns::AsPricer' do |model_attributes|
|
1
|
+
shared_examples 'Unidom::Price::Concerns::AsPricer' do |model_attributes, priced|
|
2
2
|
|
3
3
|
context do
|
4
4
|
|
@@ -16,6 +16,11 @@ shared_examples 'Unidom::Price::Concerns::AsPricer' do |model_attributes|
|
|
16
16
|
|
17
17
|
it_behaves_like 'has_many', model_attributes, :pricings, Unidom::Price::Price, [ price_1_attribtues, price_2_attribtues ]
|
18
18
|
|
19
|
+
model = described_class.create! model_attributes
|
20
|
+
amount = 10.00
|
21
|
+
it_behaves_like 'assert_present!', model, :price!, [ priced, amount, { at: Time.now } ], [ { 0 => :it }, { 1 => :amount }, :at ]
|
22
|
+
it_behaves_like 'assert_present!', model, :price?, [ priced, { at: Time.now } ], [ { 0 => :it }, :at ]
|
23
|
+
|
19
24
|
end
|
20
25
|
|
21
26
|
end
|
data/lib/unidom/price/version.rb
CHANGED
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
|
+
version: 1.7.7
|
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-04-
|
11
|
+
date: 2017-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|