unidom-shopping 1.7.7 → 1.7.8

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: fad12157f35160f38a4612e987bbbf9d7c359727
4
- data.tar.gz: c1c86f859f2000ed8bdbed9dc7b97d3bdf135b8a
3
+ metadata.gz: 1548647b8b13755ca7d414a601fbe6e94c317b1e
4
+ data.tar.gz: 0a163221d51585cfae5ebfb47a62f1b2bb6c6f7e
5
5
  SHA512:
6
- metadata.gz: a718e6ddca9eda138882f5ee21ca7dc4e552eefb49dd3e83d4797b183f987d65f211e480886295eff8e0d2e2974439a02c06fea132bf121b75e72ecc7080342f
7
- data.tar.gz: ea7f772ab9c5748009a7d93260ca5d6b4367f85b9bee476293562b785a09755909f09d192f226612bbbdff77f023f93a8984525d5ce97558881d3adb9cebe9b1
6
+ metadata.gz: 9ef062e2df7d18a3e388ca5b5a4852ddd673a3ac31f01f98073b6df500cfb6c67f9d9cc7ae24f4d2f0c4f37c71c3f372de3ebf8864811775213bc6573716ef25
7
+ data.tar.gz: 2465a6c0a6bae51c6ef4c8aba313e0e5ac3adc9f1d89965123f3cad9c3bf6565a90477aa3031e3751462d3163525cbeefb2419c1f7108fa6c5328bb3e76a82cc
data/README.md CHANGED
@@ -136,6 +136,7 @@ def initialize_unidom
136
136
 
137
137
  Unidom::Party::Person.class_eval do
138
138
  include Unidom::Shopping::Concerns::AsCartShopper
139
+ include Unidom::Shopping::Concerns::AsItemShopper
139
140
  end
140
141
 
141
142
  Unidom::Party::Shop.class_eval do
@@ -165,6 +166,7 @@ describe Unidom::Party::Person, type: :model do
165
166
  }
166
167
 
167
168
  it_behaves_like 'Unidom::Shopping::Concerns::AsCartShopper', model_attribtues
169
+ it_behaves_like 'Unidom::Shopping::Concerns::AsItemShopper', model_attribtues
168
170
 
169
171
  end
170
172
 
@@ -3,7 +3,8 @@
3
3
 
4
4
  module Unidom::Shopping::Concerns::AsCartShopper
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
 
@@ -13,7 +14,11 @@ module Unidom::Shopping::Concerns::AsCartShopper
13
14
  # 以购物者的身份,从指定的商店 from 获取购物车。时间为 at ,缺省为当前时间。如:
14
15
  # current_person.get_cart! from: shop
15
16
  def get_cart!(from: nil, at: Time.now)
17
+
18
+ assert_present! :from, from
19
+
16
20
  shopping_carts.shop_is(from).valid_at(now: at).alive.first_or_create! opened_at: at
21
+
17
22
  end
18
23
 
19
24
  def get_cart?(from: nil, at: Time.now)
@@ -3,7 +3,8 @@
3
3
 
4
4
  module Unidom::Shopping::Concerns::AsItemShopper
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
 
@@ -13,6 +14,9 @@ module Unidom::Shopping::Concerns::AsItemShopper
13
14
  # 以购物者的身份,将商品 it ,放入购物车 into 。购物时间是 at ,缺省为当前时间。单价是 unit_price ,缺省为 0 。数量是 quantity ,缺省为 1 。如:
14
15
  # current_person.add! coca_cola, into: shopping_cart, unit_price: 3.50, quantity: 3
15
16
  def add!(it, into: nil, at: Time.now, unit_price: 0, quantity: 1)
17
+
18
+ assert_present! :it, it
19
+
16
20
  query = shopping_items.shopping_cart_is(into).shopped_is(it).valid_at(now: at).alive
17
21
  item = query.first
18
22
  if item.present?
@@ -19,6 +19,9 @@ class Unidom::Shopping::ShoppingCart < Unidom::Shopping::ApplicationRecord
19
19
  # 将商品 shopped 放入购物车。购物者为 by 。单价为 unit_price ,缺省值为 0 。数量为 quantity ,缺省值是 1 。时间为 at ,缺省为当前时间。如:
20
20
  # shopping_cart.add! coca_cola, by: current_person, unit_price: 3.50, quantity: 2
21
21
  def add!(shopped, by: nil, unit_price: 0, quantity: 1, at: Time.now)
22
+
23
+ assert_present! :shopped, shopped
24
+
22
25
  item = items.shopped_is(shopped).valid_at.alive.first
23
26
  if item.present?
24
27
  item.attributes = { shopper: by||shopper, unit_price: unit_price, quantity: quantity+item.quantity }
@@ -0,0 +1,29 @@
1
+ shared_examples 'Unidom::Shopping::Concerns::AsItemShopper' do |model_attributes|
2
+
3
+ context do
4
+
5
+ shopping_item_1_attributes = {
6
+ shopping_cart_id: SecureRandom.uuid,
7
+ shopper_id: SecureRandom.uuid,
8
+ shopper_type: 'Unidom::Shopping::Shopper::Mock',
9
+ shopped_id: SecureRandom.uuid,
10
+ shopped_type: 'Unidom::Shopping::Shopped::Mock',
11
+ unit_price: 10.00,
12
+ quantity: 1.00
13
+ }
14
+
15
+ shopping_item_2_attributes = {
16
+ shopping_cart_id: SecureRandom.uuid,
17
+ shopper_id: SecureRandom.uuid,
18
+ shopper_type: 'Unidom::Shopping::Shopper::Mock',
19
+ shopped_id: SecureRandom.uuid,
20
+ shopped_type: 'Unidom::Shopping::Shopped::Mock',
21
+ unit_price: 12.00,
22
+ quantity: 3.00
23
+ }
24
+
25
+ it_behaves_like 'has_many', model_attributes, :shopping_items, Unidom::Shopping::ShoppingItem, [ shopping_item_1_attributes, shopping_item_2_attributes ]
26
+
27
+ end
28
+
29
+ end
@@ -1,3 +1,4 @@
1
1
  require 'rspec/models/unidom/shopping/concerns/as_cart_shopper_shared_examples'
2
+ require 'rspec/models/unidom/shopping/concerns/as_item_shopper_shared_examples'
2
3
  require 'rspec/models/unidom/shopping/concerns/as_shop_shared_examples'
3
4
  require 'rspec/models/unidom/shopping/concerns/as_shopped_shared_examples'
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Shopping
3
- VERSION = '1.7.7'.freeze
3
+ VERSION = '1.7.8'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-shopping
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.7
4
+ version: 1.7.8
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-14 00:00:00.000000000 Z
11
+ date: 2017-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common
@@ -55,6 +55,7 @@ files:
55
55
  - db/migrate/20020501000000_create_unidom_shopping_carts.rb
56
56
  - db/migrate/20020502000000_create_unidom_shopping_items.rb
57
57
  - lib/rspec/models/unidom/shopping/concerns/as_cart_shopper_shared_examples.rb
58
+ - lib/rspec/models/unidom/shopping/concerns/as_item_shopper_shared_examples.rb
58
59
  - lib/rspec/models/unidom/shopping/concerns/as_shop_shared_examples.rb
59
60
  - lib/rspec/models/unidom/shopping/concerns/as_shopped_shared_examples.rb
60
61
  - lib/rspec/models/unidom/shopping/shopping_cart_spec.rb