unidom-category 1.6.6 → 1.6.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 +34 -0
- data/app/models/unidom/category/categorizing.rb +6 -0
- data/app/models/unidom/category/category_rollup.rb +6 -0
- data/lib/rspec/models/unidom/category/categorizing_shared_examples.rb +15 -0
- data/lib/rspec/models/unidom/category/category_rollup_spec.rb +5 -0
- data/lib/unidom/category/rspec_shared_examples.rb +1 -0
- data/lib/unidom/category/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 327e3c1b6b31f400085d42a6db6d423413fecc89
|
4
|
+
data.tar.gz: ea3c26216914f7c62a47d7f3e30f6e8308d1275d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebf5931767abe6a2618e5aac9fc11cb0c624d35e08008cdd63ec784a2d8923f95d0ffa5613f77c9648dca47e51e293b5c7abf269edd349b984a3d5491ae53311
|
7
|
+
data.tar.gz: e4ba296d1499cf920d84c7267b0f1e13de71124b843f52395d63644166d283eda7385ff5be1c126eb7a2f53cd40d4617a86693ba5e91ea8df926a8d72b5c91b3
|
data/README.md
CHANGED
@@ -109,6 +109,8 @@ end
|
|
109
109
|
|
110
110
|
## RSpec examples
|
111
111
|
|
112
|
+
### RSpec example manifest (run automatically)
|
113
|
+
|
112
114
|
```ruby
|
113
115
|
# spec/models/unidom_spec.rb
|
114
116
|
require 'unidom/category/models_rspec'
|
@@ -119,3 +121,35 @@ require 'unidom/category/types_rspec'
|
|
119
121
|
# spec/validators/unidom_spec.rb
|
120
122
|
require 'unidom/category/validators_rspec'
|
121
123
|
```
|
124
|
+
|
125
|
+
### RSpec shared examples (to be integrated)
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
# spec/support/unidom_rspec_shared_examples.rb
|
129
|
+
require 'unidom/category/rspec_shared_examples'
|
130
|
+
|
131
|
+
# spec/models/unidom/category/categorizing_spec.rb
|
132
|
+
describe Unidom::Category::Categorizing, type: :model do
|
133
|
+
|
134
|
+
before :each do
|
135
|
+
end
|
136
|
+
|
137
|
+
after :each do
|
138
|
+
end
|
139
|
+
|
140
|
+
context do
|
141
|
+
|
142
|
+
model_attributes = {}
|
143
|
+
|
144
|
+
categorized = Unidom::Product::Product.create! name: 'Model X', abbreviation: 'MX', packing_norm: 'car', measurement_unit: 'car', opened_at: Time.now
|
145
|
+
|
146
|
+
tesla = Unidom::Party::Company.create! name: 'Tesla'
|
147
|
+
scheme = Unidom::Category::CategoryScheme.create! owner: tesla, name: 'eCar'
|
148
|
+
category = Unidom::Category::Category.create! scheme: scheme, name: 'Battery-powered vehicles'
|
149
|
+
|
150
|
+
it_behaves_like 'Unidom::Category::Categorizing', model_attributes, categorized, category
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
```
|
@@ -14,7 +14,13 @@ class Unidom::Category::Categorizing < Unidom::Category::ApplicationRecord
|
|
14
14
|
scope :categorized_is, ->(categorized) { where categorized: categorized }
|
15
15
|
|
16
16
|
def self.categorize!(categorized, into: nil, at: Time.now)
|
17
|
+
|
18
|
+
assert_present! :categorized, categorized
|
19
|
+
assert_present! :into, into
|
20
|
+
assert_present! :at, at
|
21
|
+
|
17
22
|
categorized_is(categorized).category_is(into).valid_at.alive.first_or_create! elemental: true, opened_at: at
|
23
|
+
|
18
24
|
end
|
19
25
|
|
20
26
|
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Category::Categorizing'
|
@@ -33,7 +33,13 @@ class Unidom::Category::CategoryRollup < Unidom::Category::ApplicationRecord
|
|
33
33
|
# 将 it 归为 into 的下级分类,时间是 at ,缺省为当前时间。如:
|
34
34
|
# Unidom::Category::CategoryRollup.roll_up! moto, into: vehicle
|
35
35
|
def self.roll_up!(it, into: nil, at: Time.now)
|
36
|
+
|
37
|
+
#assert_present! :it, it
|
38
|
+
#assert_present! :into, into
|
39
|
+
#assert_present! :at, at
|
40
|
+
|
36
41
|
self.descendant_category_is(it).ancestor_category_is(into).valid_at(now: at).alive.first_or_create! opened_at: at
|
42
|
+
|
37
43
|
end
|
38
44
|
|
39
45
|
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Category::CategoryRollup'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
shared_examples 'Unidom::Category::Categorizing' do |model_attributes, categorized, category|
|
2
|
+
|
3
|
+
before :each do
|
4
|
+
end
|
5
|
+
|
6
|
+
after :each do
|
7
|
+
end
|
8
|
+
|
9
|
+
context do
|
10
|
+
|
11
|
+
it_behaves_like 'assert_present!', described_class, :categorize!, [ categorized, { into: category, at: Time.now } ], [ { 0 => :categorized }, :into, :at ]
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -28,6 +28,11 @@ describe Unidom::Category::CategoryRollup, type: :model do
|
|
28
28
|
it_behaves_like 'monomorphic scope', model_attributes, :ancestor_category_is, :ancestor_category
|
29
29
|
it_behaves_like 'monomorphic scope', model_attributes, :descendant_category_is, :descendant_category
|
30
30
|
|
31
|
+
#it = Unidom::Category::Category.create! category_attributes.merge(code: 'ZC', name: 'Sub Category', abbreviation: 'SubCat')
|
32
|
+
#into = Unidom::Category::Category.create! category_attributes.merge(code: 'YC')
|
33
|
+
|
34
|
+
#it_behaves_like 'assert_present!', described_class, :roll_up!, [ it, { into: into, at: Time.now } ], [ { 0 => :it }, :into, :at ]
|
35
|
+
|
31
36
|
end
|
32
37
|
|
33
38
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rspec/models/unidom/category/categorizing_shared_examples'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unidom-category
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.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-
|
11
|
+
date: 2017-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- db/migrate/20000302000000_create_unidom_categories.rb
|
59
59
|
- db/migrate/20000303000000_create_unidom_category_rollups.rb
|
60
60
|
- db/migrate/20000304000000_create_unidom_categorizings.rb
|
61
|
+
- lib/rspec/models/unidom/category/categorizing_shared_examples.rb
|
61
62
|
- lib/rspec/models/unidom/category/categorizing_spec.rb
|
62
63
|
- lib/rspec/models/unidom/category/category_rollup_spec.rb
|
63
64
|
- lib/rspec/models/unidom/category/category_scheme_spec.rb
|
@@ -66,6 +67,7 @@ files:
|
|
66
67
|
- lib/unidom/category.rb
|
67
68
|
- lib/unidom/category/engine.rb
|
68
69
|
- lib/unidom/category/models_rspec.rb
|
70
|
+
- lib/unidom/category/rspec_shared_examples.rb
|
69
71
|
- lib/unidom/category/types_rspec.rb
|
70
72
|
- lib/unidom/category/validators_rspec.rb
|
71
73
|
- lib/unidom/category/version.rb
|