bidu-house 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/bidu/house/report.rb +13 -1
- data/lib/bidu/house/report/error.rb +1 -1
- data/lib/bidu/house/report/multiple.rb +1 -1
- data/lib/bidu/house/version.rb +1 -1
- data/spec/lib/bidu/house/report/multiple_spec.rb +122 -0
- data/spec/lib/bidu/house/report_spec.rb +44 -0
- 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: 96781d4525f8097700f5d5db4795f493b38fe712
|
|
4
|
+
data.tar.gz: ea2a54d9377214dc1e0edd66aa66d9d33daa7acb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: edcdf77746f852974617b39a3288de005f6a704d2aa2e9670b25c61c44f3bac344cb50fbda438d32442a50e6d35bd2273cd80942721b15abd42357631e001b6f
|
|
7
|
+
data.tar.gz: 384598beefd1f88bfea28e7fd8169b33a3e6b589da309636d44b926b4714ee85044829f63beed65ae34ca1ede71626bbce6a1dc73fc2b1a519e2173ce0fee2f4
|
data/Gemfile.lock
CHANGED
data/lib/bidu/house/report.rb
CHANGED
|
@@ -5,6 +5,7 @@ module Bidu
|
|
|
5
5
|
require 'bidu/house/report/active_record'
|
|
6
6
|
require 'bidu/house/report/error'
|
|
7
7
|
require 'bidu/house/report/range'
|
|
8
|
+
require 'bidu/house/report/multiple'
|
|
8
9
|
ALLOWED_PARAMETERS = []
|
|
9
10
|
DEFAULT_OPTION = {}
|
|
10
11
|
|
|
@@ -13,7 +14,7 @@ module Bidu
|
|
|
13
14
|
json_parse :id, case: :snake
|
|
14
15
|
|
|
15
16
|
def initialize(options = {})
|
|
16
|
-
@json =
|
|
17
|
+
@json = default_option.merge(options)
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
def status
|
|
@@ -27,6 +28,17 @@ module Bidu
|
|
|
27
28
|
def as_json
|
|
28
29
|
{ status: status }
|
|
29
30
|
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def default_option
|
|
35
|
+
self.class.default_options
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.default_options
|
|
39
|
+
return {} if self == Report
|
|
40
|
+
self.superclass.default_options.merge(self::DEFAULT_OPTION)
|
|
41
|
+
end
|
|
30
42
|
end
|
|
31
43
|
end
|
|
32
44
|
end
|
data/lib/bidu/house/version.rb
CHANGED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Bidu::House::Report::Multiple do
|
|
4
|
+
class Bidu::House::Report::DocTypeError < Bidu::House::Report::Error
|
|
5
|
+
ALLOWED_PARAMETERS=[:period, :threshold]
|
|
6
|
+
DEFAULT_OPTION = {
|
|
7
|
+
threshold: 0.25,
|
|
8
|
+
clazz: Document,
|
|
9
|
+
external_key: :external_id
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
json_parse :doc_type, case: :snake
|
|
13
|
+
|
|
14
|
+
def base
|
|
15
|
+
super.where(doc_type: doc_type)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class Bidu::House::Report::Multiple::Dummy < Bidu::House::Report
|
|
20
|
+
include Bidu::House::Report::Multiple
|
|
21
|
+
DEFAULT_OPTION = {
|
|
22
|
+
doc_type: [:a, :b]
|
|
23
|
+
}
|
|
24
|
+
json_parse :doc_type, case: :snake
|
|
25
|
+
|
|
26
|
+
def reports_ids
|
|
27
|
+
[ doc_type ].flatten
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def sub_report_class
|
|
31
|
+
Bidu::House::Report::DocTypeError
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def key
|
|
35
|
+
:doc_type
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
let(:subject) { described_class::Dummy.new }
|
|
40
|
+
let(:a_errors) { 1 }
|
|
41
|
+
let(:a_successes) { 1 }
|
|
42
|
+
let(:b_errors) { 1 }
|
|
43
|
+
let(:b_successes) { 1 }
|
|
44
|
+
let(:setup) do
|
|
45
|
+
{
|
|
46
|
+
success: { a: a_successes, b: b_successes },
|
|
47
|
+
error: { a: a_errors, b: b_errors }
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
before do
|
|
52
|
+
Document.delete_all
|
|
53
|
+
setup.each do |status, map|
|
|
54
|
+
map.each do |doc_type, quantity|
|
|
55
|
+
quantity.times do
|
|
56
|
+
Document.create(status: status, doc_type: doc_type, external_id: Document.count)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe '#error?' do
|
|
63
|
+
context 'when all subreports are with error' do
|
|
64
|
+
it { expect(subject.error?).to be_truthy }
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context 'when one of the reports is not an error' do
|
|
68
|
+
let(:a_successes) { 4 }
|
|
69
|
+
|
|
70
|
+
it { expect(subject.error?).to be_truthy }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
context 'when none of the reports is an error' do
|
|
74
|
+
let(:a_successes) { 4 }
|
|
75
|
+
let(:b_successes) { 4 }
|
|
76
|
+
|
|
77
|
+
it { expect(subject.error?).to be_falsey }
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
describe '#as_json' do
|
|
82
|
+
let(:expected) do
|
|
83
|
+
{
|
|
84
|
+
'a' => { ids: [2], percentage: 0.5, status: :error },
|
|
85
|
+
'b' => { ids: [3], percentage: 0.5, status: :error },
|
|
86
|
+
status: :error
|
|
87
|
+
}
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
context 'when all subreports are with error' do
|
|
91
|
+
it { expect(subject.as_json).to eq(expected) }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
context 'when one of the reports is not an error' do
|
|
95
|
+
let(:a_successes) { 4 }
|
|
96
|
+
let(:expected) do
|
|
97
|
+
{
|
|
98
|
+
'a' => { ids: [5], percentage: 0.2, status: :ok },
|
|
99
|
+
'b' => { ids: [6], percentage: 0.5, status: :error },
|
|
100
|
+
status: :error
|
|
101
|
+
}
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it { expect(subject.as_json).to eq(expected) }
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
context 'when none of the reports is an error' do
|
|
108
|
+
let(:a_successes) { 4 }
|
|
109
|
+
let(:b_successes) { 4 }
|
|
110
|
+
let(:expected) do
|
|
111
|
+
{
|
|
112
|
+
'a' => { ids: [8], percentage: 0.2, status: :ok },
|
|
113
|
+
'b' => { ids: [9], percentage: 0.2, status: :ok },
|
|
114
|
+
status: :ok
|
|
115
|
+
}
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it { expect(subject.as_json).to eq(expected) }
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Bidu::House::Report do
|
|
4
|
+
class Bidu::House::Report::Dummy1 < Bidu::House::Report
|
|
5
|
+
DEFAULT_OPTION = {
|
|
6
|
+
option_value: 1,
|
|
7
|
+
other_option: 10
|
|
8
|
+
}
|
|
9
|
+
json_parse :option_value, :other_option, case: :snake
|
|
10
|
+
end
|
|
11
|
+
class Bidu::House::Report::Dummy2 < Bidu::House::Report::Dummy1; end
|
|
12
|
+
class Bidu::House::Report::Dummy3 < Bidu::House::Report::Dummy1
|
|
13
|
+
DEFAULT_OPTION = { option_value: 5 }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe 'default_options' do
|
|
17
|
+
let(:report_class) { described_class::Dummy1 }
|
|
18
|
+
let(:subject) { report_class.new }
|
|
19
|
+
|
|
20
|
+
it 'setup the attributes using class default options' do
|
|
21
|
+
expect(subject.option_value).to eq(1)
|
|
22
|
+
expect(subject.other_option).to eq(10)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context 'when class inherit options' do
|
|
26
|
+
let(:report_class) { described_class::Dummy2 }
|
|
27
|
+
|
|
28
|
+
it 'setup the attributes using superclass default options' do
|
|
29
|
+
expect(subject.option_value).to eq(1)
|
|
30
|
+
expect(subject.other_option).to eq(10)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context 'when class inherit options but overrides some' do
|
|
35
|
+
let(:report_class) { described_class::Dummy3 }
|
|
36
|
+
|
|
37
|
+
it 'setup the attributes using superclass default options' do
|
|
38
|
+
expect(subject.option_value).to eq(5)
|
|
39
|
+
expect(subject.other_option).to eq(10)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bidu-house
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bidu Dev's Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-10-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -211,9 +211,11 @@ files:
|
|
|
211
211
|
- lib/bidu/period_parser.rb
|
|
212
212
|
- lib/json_parser/type_cast_ext.rb
|
|
213
213
|
- spec/lib/bidu/house/report/error_spec.rb
|
|
214
|
+
- spec/lib/bidu/house/report/multiple_spec.rb
|
|
214
215
|
- spec/lib/bidu/house/report/range_spec.rb
|
|
215
216
|
- spec/lib/bidu/house/report/report_config_spec.rb
|
|
216
217
|
- spec/lib/bidu/house/report_builder_spec.rb
|
|
218
|
+
- spec/lib/bidu/house/report_spec.rb
|
|
217
219
|
- spec/lib/bidu/house/status_builder_spec.rb
|
|
218
220
|
- spec/lib/bidu/house/status_spec.rb
|
|
219
221
|
- spec/lib/bidu/period_parser_spec.rb
|