unidom-shopping 1.7.6 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +21 -0
- data/app/controllers/unidom/shopping/application_controller.rb +8 -2
- data/app/helpers/unidom/shopping/application_helper.rb +7 -1
- data/app/jobs/unidom/shopping/application_job.rb +7 -1
- data/app/mailers/unidom/shopping/application_mailer.rb +9 -3
- data/app/models/unidom/shopping/application_record.rb +8 -2
- data/app/models/unidom/shopping/concerns/as_cart_shopper.rb +29 -16
- data/app/models/unidom/shopping/concerns/as_item_shopper.rb +36 -24
- data/app/models/unidom/shopping/concerns/as_shop.rb +21 -13
- data/app/models/unidom/shopping/concerns/as_shopped.rb +40 -32
- data/app/models/unidom/shopping/shopping_cart.rb +30 -21
- data/app/models/unidom/shopping/shopping_item.rb +18 -12
- data/app/views/layouts/unidom/shopping/application.html.erb +1 -1
- data/db/migrate/20020501000000_create_unidom_shopping_carts.rb +4 -4
- data/db/migrate/20020502000000_create_unidom_shopping_items.rb +5 -5
- data/lib/rspec/models/unidom/shopping/concerns/as_cart_shopper_shared_examples.rb +19 -0
- data/lib/rspec/models/unidom/shopping/concerns/as_item_shopper_shared_examples.rb +29 -0
- data/lib/rspec/models/unidom/shopping/shopping_item_spec.rb +2 -2
- data/lib/unidom/shopping/rspec_shared_examples.rb +2 -0
- data/lib/unidom/shopping/version.rb +1 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: edaaa6056e98d80899e568f4e560c3ddb5b523ee9199485a9ae8a6205aad0cab
|
4
|
+
data.tar.gz: 55661d4d5ffb161836913e4ca20e32a109194f951262231c8b815d137f7a4f3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1450d0f6f35b1ddee35d628dfe87e41bf93f42e6e7602f8f065543f398f1b2d80d8086e2eb5e224b49ed9e7ec17cc6680d70d91ba718439cf188a97efdfe1108
|
7
|
+
data.tar.gz: 919daf5e47c28c18f599dc7f20e173aef698f9771c6c87786b06573ada9e1889fd2f892b9597780dbda9f7593b647669db5443912b2ec741d88f86994343ad09
|
data/README.md
CHANGED
@@ -134,6 +134,11 @@ require 'unidom/shopping/validators_rspec'
|
|
134
134
|
# lib/unidom.rb
|
135
135
|
def initialize_unidom
|
136
136
|
|
137
|
+
Unidom::Party::Person.class_eval do
|
138
|
+
include Unidom::Shopping::Concerns::AsCartShopper
|
139
|
+
include Unidom::Shopping::Concerns::AsItemShopper
|
140
|
+
end
|
141
|
+
|
137
142
|
Unidom::Party::Shop.class_eval do
|
138
143
|
include Unidom::Shopping::Concerns::AsShop
|
139
144
|
end
|
@@ -151,6 +156,22 @@ initialize_unidom
|
|
151
156
|
# spec/support/unidom_rspec_shared_examples.rb
|
152
157
|
require 'unidom/shopping/rspec_shared_examples'
|
153
158
|
|
159
|
+
# spec/models/unidom/party/person_spec.rb
|
160
|
+
describe Unidom::Party::Person, type: :model do
|
161
|
+
|
162
|
+
context do
|
163
|
+
|
164
|
+
model_attribtues = {
|
165
|
+
name: 'Tim'
|
166
|
+
}
|
167
|
+
|
168
|
+
it_behaves_like 'Unidom::Shopping::Concerns::AsCartShopper', model_attribtues
|
169
|
+
it_behaves_like 'Unidom::Shopping::Concerns::AsItemShopper', model_attribtues
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
154
175
|
# spec/models/unidom/party/shop_spec.rb
|
155
176
|
describe Unidom::Party::Shop, type: :model do
|
156
177
|
|
@@ -1,6 +1,12 @@
|
|
1
1
|
##
|
2
2
|
# Application controller 是模块内所有控制器的基类。
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
6
|
+
|
7
|
+
class ApplicationController < ActionController::Base
|
8
|
+
protect_from_forgery with: :exception
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
6
12
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
##
|
2
2
|
# Application mailer 是模块内所有电子邮件发送类的基类。
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
6
|
+
|
7
|
+
class ApplicationMailer < ActionMailer::Base
|
8
|
+
default from: 'from@example.com'
|
9
|
+
layout 'mailer'
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
7
13
|
end
|
@@ -1,6 +1,12 @@
|
|
1
1
|
##
|
2
2
|
# Application record 是模块内所有模型的抽象基类。
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
6
|
+
|
7
|
+
class ApplicationRecord < ActiveRecord::Base
|
8
|
+
self.abstract_class = true
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
6
12
|
end
|
@@ -1,28 +1,41 @@
|
|
1
1
|
##
|
2
2
|
# As Cart Shopper 是购物车所有者的领域逻辑关注点。
|
3
3
|
|
4
|
-
module Unidom
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
6
|
+
module Concerns
|
5
7
|
|
6
|
-
|
8
|
+
module AsCartShopper
|
7
9
|
|
8
|
-
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
include Unidom::Common::Concerns::ArgumentValidation
|
9
12
|
|
10
|
-
|
13
|
+
included do |includer|
|
11
14
|
|
12
|
-
|
13
|
-
# 以购物者的身份,从指定的商店 from 获取购物车。时间为 at ,缺省为当前时间。如:
|
14
|
-
# current_person.get_cart! from: shop
|
15
|
-
def get_cart!(from: nil, at: Time.now)
|
16
|
-
shopping_carts.shop_is(from).valid_at(now: at).alive.first_or_create! opened_at: at
|
17
|
-
end
|
15
|
+
has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shopper
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
##
|
18
|
+
# 以购物者的身份,从指定的商店 from 获取购物车。时间为 at ,缺省为当前时间。如:
|
19
|
+
# current_person.get_cart! from: shop
|
20
|
+
def get_cart!(from: nil, at: Time.now)
|
22
21
|
|
23
|
-
|
22
|
+
assert_present! :from, from
|
24
23
|
|
25
|
-
|
26
|
-
|
24
|
+
shopping_carts.shop_is(from).valid_at(now: at).alive.first_or_create! opened_at: at
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_cart?(from: nil, at: Time.now)
|
29
|
+
shopping_carts.shop_is(from).valid_at(now: at).alive.exists?
|
30
|
+
end
|
27
31
|
|
32
|
+
end
|
33
|
+
|
34
|
+
module ClassMethods
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
28
41
|
end
|
@@ -1,36 +1,48 @@
|
|
1
1
|
##
|
2
2
|
# As Item Shopper 是购物项所有者的领域逻辑关注点。
|
3
3
|
|
4
|
-
module Unidom
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
6
|
+
module Concerns
|
5
7
|
|
6
|
-
|
8
|
+
module AsItemShopper
|
7
9
|
|
8
|
-
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
include Unidom::Common::Concerns::ArgumentValidation
|
9
12
|
|
10
|
-
|
13
|
+
included do |includer|
|
11
14
|
|
12
|
-
|
13
|
-
# 以购物者的身份,将商品 it ,放入购物车 into 。购物时间是 at ,缺省为当前时间。单价是 unit_price ,缺省为 0 。数量是 quantity ,缺省为 1 。如:
|
14
|
-
# current_person.add! coca_cola, into: shopping_cart, unit_price: 3.50, quantity: 3
|
15
|
-
def add!(it, into: nil, at: Time.now, unit_price: 0, quantity: 1)
|
16
|
-
query = shopping_items.shopping_cart_is(into).shopped_is(it).valid_at(now: at).alive
|
17
|
-
item = query.first
|
18
|
-
if item.present?
|
19
|
-
item.unit_price = unit_price
|
20
|
-
item.increment! :quantity, quantity
|
21
|
-
else
|
22
|
-
item = shopping_items.create! shopping_cart: into, shopped: it, unit_price: unit_price, quantity: quantity, opened_at: at
|
23
|
-
end
|
24
|
-
item
|
25
|
-
end
|
15
|
+
has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopper
|
26
16
|
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
##
|
18
|
+
# 以购物者的身份,将商品 it ,放入购物车 into 。购物时间是 at ,缺省为当前时间。单价是 unit_price ,缺省为 0 。数量是 quantity ,缺省为 1 。如:
|
19
|
+
# current_person.add! coca_cola, into: shopping_cart, unit_price: 3.50, quantity: 3
|
20
|
+
def add!(it, into: nil, at: Time.now, unit_price: 0, quantity: 1)
|
30
21
|
|
31
|
-
|
22
|
+
assert_present! :it, it
|
32
23
|
|
33
|
-
|
34
|
-
|
24
|
+
query = shopping_items.shopping_cart_is(into).shopped_is(it).valid_at(now: at).alive
|
25
|
+
item = query.first
|
26
|
+
if item.present?
|
27
|
+
item.unit_price = unit_price
|
28
|
+
item.increment! :quantity, quantity
|
29
|
+
else
|
30
|
+
item = shopping_items.create! shopping_cart: into, shopped: it, unit_price: unit_price, quantity: quantity, opened_at: at
|
31
|
+
end
|
32
|
+
item
|
33
|
+
end
|
34
|
+
|
35
|
+
def add?(it, into: nil, at: Time.now)
|
36
|
+
shopping_items.shopping_cart_is(into).shopped_is(it).valid_at(now: at).alive.exists?
|
37
|
+
end
|
35
38
|
|
39
|
+
end
|
40
|
+
|
41
|
+
module ClassMethods
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
36
48
|
end
|
@@ -1,24 +1,32 @@
|
|
1
1
|
##
|
2
2
|
# As Shop 是购物场所的领域逻辑关注点。
|
3
3
|
|
4
|
-
module Unidom
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
6
|
+
module Concerns
|
5
7
|
|
6
|
-
|
8
|
+
module AsShop
|
7
9
|
|
8
|
-
|
10
|
+
extend ActiveSupport::Concern
|
9
11
|
|
10
|
-
|
12
|
+
included do |includer|
|
11
13
|
|
12
|
-
|
13
|
-
# 从当前商店中,获取购物车。购物者为 by 。获取时间为 at ,缺省为当前时间。如:
|
14
|
-
# shop.get_cart! by: current_person
|
15
|
-
def get_cart!(by: nil, at: Time.now)
|
16
|
-
shopping_carts.shopped_by(by).valid_at(now: at).alive.first_or_create! opened_at: at
|
17
|
-
end
|
14
|
+
has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shop
|
18
15
|
|
19
|
-
|
16
|
+
##
|
17
|
+
# 从当前商店中,获取购物车。购物者为 by 。获取时间为 at ,缺省为当前时间。如:
|
18
|
+
# shop.get_cart! by: current_person
|
19
|
+
def get_cart!(by: nil, at: Time.now)
|
20
|
+
shopping_carts.shopped_by(by).valid_at(now: at).alive.first_or_create! opened_at: at
|
21
|
+
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
+
end
|
24
|
+
|
25
|
+
module ClassMethods
|
26
|
+
end
|
23
27
|
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
24
32
|
end
|
@@ -1,40 +1,48 @@
|
|
1
1
|
##
|
2
2
|
# As Shopped 是被购买的商品的领域逻辑关注点。
|
3
3
|
|
4
|
-
module Unidom
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
6
|
+
module Concerns
|
7
|
+
|
8
|
+
module AsShopped
|
9
|
+
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
|
12
|
+
included do |includer|
|
13
|
+
|
14
|
+
has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopped
|
15
|
+
|
16
|
+
##
|
17
|
+
# 将当前商品放入购物车 into ,购物者是 by 。购物时间是 at ,缺省为当前时间。单价是 unit_price ,缺省为 0 。数量是 quantity ,缺省为 1 。如:
|
18
|
+
# coca_cola.is_added! into: shopping_cart, by: current_person, unit_price: 3.50, quantity: 2
|
19
|
+
def is_added!(into: nil, by: nil, at: Time.now, unit_price: 0, quantity: 1)
|
20
|
+
query = shopping_items.shopping_cart_is(into).valid_at(now: at).alive
|
21
|
+
item = query.first
|
22
|
+
if item.present?
|
23
|
+
item.unit_price = unit_price
|
24
|
+
item.shopper = by
|
25
|
+
item.increment! :quantity, quantity
|
26
|
+
else
|
27
|
+
item = shopping_items.create! shopping_cart: into, shopper: by, unit_price: unit_price, quantity: quantity, opened_at: at
|
28
|
+
end
|
29
|
+
item
|
30
|
+
end
|
31
|
+
|
32
|
+
def is_added?(into: nil, by: nil, at: Time.now)
|
33
|
+
query = shopping_items.shopping_cart_is(into)
|
34
|
+
query = query.shopped_by(by) if by.present?
|
35
|
+
query = query.valid_at(now: at).alive
|
36
|
+
query.exists?
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
module ClassMethods
|
42
|
+
end
|
43
|
+
|
24
44
|
end
|
25
|
-
item
|
26
|
-
end
|
27
45
|
|
28
|
-
def is_added?(into: nil, by: nil, at: Time.now)
|
29
|
-
query = shopping_items.shopping_cart_is(into)
|
30
|
-
query = query.shopped_by(by) if by.present?
|
31
|
-
query = query.valid_at(now: at).alive
|
32
|
-
query.exists?
|
33
46
|
end
|
34
|
-
|
35
47
|
end
|
36
|
-
|
37
|
-
module ClassMethods
|
38
|
-
end
|
39
|
-
|
40
48
|
end
|
@@ -1,31 +1,40 @@
|
|
1
1
|
##
|
2
2
|
# Shopping Cart 是购物车。
|
3
3
|
|
4
|
-
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
5
6
|
|
6
|
-
|
7
|
+
class ShoppingCart < ApplicationRecord
|
7
8
|
|
8
|
-
|
9
|
+
self.table_name = 'unidom_shopping_carts'
|
9
10
|
|
10
|
-
|
11
|
-
belongs_to :shop, polymorphic: true
|
11
|
+
include Unidom::Common::Concerns::ModelExtension
|
12
12
|
|
13
|
-
|
13
|
+
belongs_to :shopper, polymorphic: true
|
14
|
+
belongs_to :shop, polymorphic: true
|
14
15
|
|
15
|
-
|
16
|
-
scope :shop_is, ->(shop) { where shop: shop }
|
16
|
+
has_many :items, class_name: 'Unidom::Shopping::ShoppingItem'
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
items.create! shopped: shopped, shopper: by||shopper, unit_price: unit_price, quantity: quantity, opened_at: at
|
28
|
-
end
|
29
|
-
end
|
18
|
+
scope :shopped_by, ->(shopper) { where shopper: shopper }
|
19
|
+
scope :shop_is, ->(shop) { where shop: shop }
|
20
|
+
|
21
|
+
##
|
22
|
+
# 将商品 shopped 放入购物车。购物者为 by 。单价为 unit_price ,缺省值为 0 。数量为 quantity ,缺省值是 1 。时间为 at ,缺省为当前时间。如:
|
23
|
+
# shopping_cart.add! coca_cola, by: current_person, unit_price: 3.50, quantity: 2
|
24
|
+
def add!(shopped, by: nil, unit_price: 0, quantity: 1, at: Time.now)
|
25
|
+
|
26
|
+
assert_present! :shopped, shopped
|
30
27
|
|
31
|
-
|
28
|
+
item = items.shopped_is(shopped).valid_at.alive.first
|
29
|
+
if item.present?
|
30
|
+
item.attributes = { shopper: by||shopper, unit_price: unit_price, quantity: quantity+item.quantity }
|
31
|
+
item.save!
|
32
|
+
else
|
33
|
+
items.create! shopped: shopped, shopper: by||shopper, unit_price: unit_price, quantity: quantity, opened_at: at
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Shopping::ShoppingCart'
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -1,21 +1,27 @@
|
|
1
1
|
##
|
2
2
|
# Shopping Item 是购物项。
|
3
3
|
|
4
|
-
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
5
6
|
|
6
|
-
|
7
|
+
class ShoppingItem < ApplicationRecord
|
7
8
|
|
8
|
-
|
9
|
+
self.table_name = 'unidom_shopping_items'
|
9
10
|
|
10
|
-
|
11
|
-
validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1_000_000_000 }
|
11
|
+
include Unidom::Common::Concerns::ModelExtension
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
belongs_to :shopped, polymorphic: true
|
13
|
+
validates :unit_price, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Unidom::Common::MAXIMUM_AMOUNT }
|
14
|
+
validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Unidom::Common::MAXIMUM_AMOUNT }
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
belongs_to :shopping_cart, class_name: 'Unidom::Shopping::ShoppingCart'
|
17
|
+
belongs_to :shopper, polymorphic: true
|
18
|
+
belongs_to :shopped, polymorphic: true
|
20
19
|
|
21
|
-
|
20
|
+
scope :shopping_cart_is, ->(shopping_cart) { where shopping_cart: shopping_cart }
|
21
|
+
scope :shopped_by, ->(shopper) { where shopper: shopper }
|
22
|
+
scope :shopped_is, ->(shopped) { where shopped: shopped }
|
23
|
+
|
24
|
+
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Shopping::ShoppingItem'
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateUnidomShoppingCarts < ActiveRecord::Migration
|
1
|
+
class CreateUnidomShoppingCarts < ActiveRecord::Migration[6.0]
|
2
2
|
|
3
3
|
def change
|
4
4
|
|
@@ -9,9 +9,9 @@ class CreateUnidomShoppingCarts < ActiveRecord::Migration
|
|
9
9
|
t.references :shop, type: :uuid, null: false,
|
10
10
|
polymorphic: { null: false, default: '', limit: 200 }
|
11
11
|
|
12
|
-
t.column :state, 'char(1)', null: false, default:
|
13
|
-
t.datetime :opened_at, null: false, default: ::
|
14
|
-
t.datetime :closed_at, null: false, default: ::
|
12
|
+
t.column :state, 'char(1)', null: false, default: Unidom::Common::STATE
|
13
|
+
t.datetime :opened_at, null: false, default: Unidom::Common::OPENED_AT
|
14
|
+
t.datetime :closed_at, null: false, default: Unidom::Common::CLOSED_AT
|
15
15
|
t.boolean :defunct, null: false, default: false
|
16
16
|
t.jsonb :notation, null: false, default: {}
|
17
17
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateUnidomShoppingItems < ActiveRecord::Migration
|
1
|
+
class CreateUnidomShoppingItems < ActiveRecord::Migration[6.0]
|
2
2
|
|
3
3
|
def change
|
4
4
|
|
@@ -13,9 +13,9 @@ class CreateUnidomShoppingItems < ActiveRecord::Migration
|
|
13
13
|
t.decimal :unit_price, null: false, default: 0.0, precision: 12, scale: 2
|
14
14
|
t.decimal :quantity, null: false, default: 0.0, precision: 12, scale: 2
|
15
15
|
|
16
|
-
t.column :state, 'char(1)', null: false, default:
|
17
|
-
t.datetime :opened_at, null: false, default: ::
|
18
|
-
t.datetime :closed_at, null: false, default: ::
|
16
|
+
t.column :state, 'char(1)', null: false, default: Unidom::Common::STATE
|
17
|
+
t.datetime :opened_at, null: false, default: Unidom::Common::OPENED_AT
|
18
|
+
t.datetime :closed_at, null: false, default: Unidom::Common::CLOSED_AT
|
19
19
|
t.boolean :defunct, null: false, default: false
|
20
20
|
t.jsonb :notation, null: false, default: {}
|
21
21
|
|
@@ -23,7 +23,7 @@ class CreateUnidomShoppingItems < ActiveRecord::Migration
|
|
23
23
|
|
24
24
|
end
|
25
25
|
|
26
|
-
add_index :unidom_shopping_items, :shopping_cart_id
|
26
|
+
#add_index :unidom_shopping_items, :shopping_cart_id
|
27
27
|
add_index :unidom_shopping_items, :shopper_id
|
28
28
|
add_index :unidom_shopping_items, :shopped_id
|
29
29
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
shared_examples 'Unidom::Shopping::Concerns::AsCartShopper' do |model_attributes|
|
2
|
+
|
3
|
+
context do
|
4
|
+
|
5
|
+
shopping_cart_1_attributes = {
|
6
|
+
shop_id: SecureRandom.uuid,
|
7
|
+
shop_type: 'Unidom::Shopping::Shop::Mock'
|
8
|
+
}
|
9
|
+
|
10
|
+
shopping_cart_2_attributes = {
|
11
|
+
shop_id: SecureRandom.uuid,
|
12
|
+
shop_type: 'Unidom::Shopping::Shop::Mock'
|
13
|
+
}
|
14
|
+
|
15
|
+
it_behaves_like 'has_many', model_attributes, :shopping_carts, Unidom::Shopping::ShoppingCart, [ shopping_cart_1_attributes, shopping_cart_2_attributes ]
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -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
|
@@ -21,9 +21,9 @@ describe Unidom::Shopping::ShoppingItem, type: :model do
|
|
21
21
|
it_behaves_like 'Unidom::Common::Concerns::ModelExtension', model_attributes
|
22
22
|
|
23
23
|
it_behaves_like 'validates numericality', model_attributes, :unit_price,
|
24
|
-
range: 0..
|
24
|
+
range: 0..Unidom::Common::MAXIMUM_AMOUNT, minimum_inclusive: true, maximum_inclusive: true
|
25
25
|
it_behaves_like 'validates numericality', model_attributes, :quantity,
|
26
|
-
range: 0..
|
26
|
+
range: 0..Unidom::Common::MAXIMUM_AMOUNT, minimum_inclusive: true, maximum_inclusive: true
|
27
27
|
|
28
28
|
shopping_cart_attributes = {
|
29
29
|
shopper_id: SecureRandom.uuid,
|
@@ -1,2 +1,4 @@
|
|
1
|
+
require 'rspec/models/unidom/shopping/concerns/as_cart_shopper_shared_examples'
|
2
|
+
require 'rspec/models/unidom/shopping/concerns/as_item_shopper_shared_examples'
|
1
3
|
require 'rspec/models/unidom/shopping/concerns/as_shop_shared_examples'
|
2
4
|
require 'rspec/models/unidom/shopping/concerns/as_shopped_shared_examples'
|
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:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
description: Unidom (UNIfied Domain Object Model) is a series of domain model engines.
|
28
28
|
The Shopping domain model engine includes Shopping Cart and Shopping Item models.
|
29
29
|
Unidom (统一领域对象模型)是一系列的领域模型引擎。购物领域模型引擎包括购物车和购物项的模型。
|
@@ -54,6 +54,8 @@ files:
|
|
54
54
|
- config/routes.rb
|
55
55
|
- db/migrate/20020501000000_create_unidom_shopping_carts.rb
|
56
56
|
- db/migrate/20020502000000_create_unidom_shopping_items.rb
|
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
|
57
59
|
- lib/rspec/models/unidom/shopping/concerns/as_shop_shared_examples.rb
|
58
60
|
- lib/rspec/models/unidom/shopping/concerns/as_shopped_shared_examples.rb
|
59
61
|
- lib/rspec/models/unidom/shopping/shopping_cart_spec.rb
|
@@ -66,11 +68,11 @@ files:
|
|
66
68
|
- lib/unidom/shopping/types_rspec.rb
|
67
69
|
- lib/unidom/shopping/validators_rspec.rb
|
68
70
|
- lib/unidom/shopping/version.rb
|
69
|
-
homepage: https://
|
71
|
+
homepage: https://gitee.com/Unidom/unidom-shopping
|
70
72
|
licenses:
|
71
73
|
- MIT
|
72
74
|
metadata: {}
|
73
|
-
post_install_message:
|
75
|
+
post_install_message:
|
74
76
|
rdoc_options: []
|
75
77
|
require_paths:
|
76
78
|
- lib
|
@@ -85,9 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
87
|
- !ruby/object:Gem::Version
|
86
88
|
version: '0'
|
87
89
|
requirements: []
|
88
|
-
|
89
|
-
|
90
|
-
signing_key:
|
90
|
+
rubygems_version: 3.2.3
|
91
|
+
signing_key:
|
91
92
|
specification_version: 4
|
92
93
|
summary: Unidom Shopping Domain Model Engine 购物领域模型引擎
|
93
94
|
test_files: []
|