repository-support 0.1.1
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 +7 -0
- data/.gitignore +14 -0
- data/.rbenv-gemsets +1 -0
- data/.rspec +2 -0
- data/.rubocop.yml +24 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +204 -0
- data/Rakefile +20 -0
- data/bin/bundle +105 -0
- data/bin/bundler +16 -0
- data/bin/htmldiff +29 -0
- data/bin/ldiff +29 -0
- data/bin/rake +29 -0
- data/bin/rspec +29 -0
- data/bin/rubocop +29 -0
- data/bin/ruby-parse +29 -0
- data/bin/ruby-rewrite +29 -0
- data/bin/setup +36 -0
- data/lib/repository/support.rb +15 -0
- data/lib/repository/support/error_factory.rb +18 -0
- data/lib/repository/support/result_builder.rb +31 -0
- data/lib/repository/support/store_result.rb +31 -0
- data/lib/repository/support/test_attribute_container.rb +62 -0
- data/lib/repository/support/version.rb +9 -0
- data/repository-support.gemspec +33 -0
- data/spec/repository/support/error_factory_spec.rb +40 -0
- data/spec/repository/support/result_builder_spec.rb +70 -0
- data/spec/repository/support/store_result_spec.rb +70 -0
- data/spec/repository/support/test_attribute_container_spec.rb +36 -0
- data/spec/repository/support_spec.rb +9 -0
- data/spec/spec_helper.rb +13 -0
- metadata +205 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Repository::Support::ResultBuilder do
|
6
|
+
describe 'initialisation' do
|
7
|
+
it 'requires one parameter' do
|
8
|
+
message = /wrong number of arguments \(.+?\)/
|
9
|
+
expect { described_class.new }.to raise_error ArgumentError, message
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'can be initialised with anything' do
|
13
|
+
init_values = ['something', nil, 42.7, self]
|
14
|
+
init_values.each do |value|
|
15
|
+
expect { described_class.new value }.not_to raise_error
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end # describe 'initialisation'
|
19
|
+
|
20
|
+
describe 'has a #build method that' do
|
21
|
+
let(:obj) { described_class.new record }
|
22
|
+
|
23
|
+
context 'when the initialiser parameter is truthy' do
|
24
|
+
let(:record) { true }
|
25
|
+
let(:result) { obj.build }
|
26
|
+
|
27
|
+
describe 'returns a StoreResult instance which' do
|
28
|
+
it 'is successful' do
|
29
|
+
expect(result).to be_success
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns the initialiser parameter as its :entity attribute' do
|
33
|
+
expect(result.entity).to eq record
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns an empty Array as its :errors attribute' do
|
37
|
+
errors = result.errors
|
38
|
+
expect(errors).to respond_to :to_ary
|
39
|
+
expect(errors).to be_empty
|
40
|
+
end
|
41
|
+
end # describe 'returns a StoreResult instance which'
|
42
|
+
end # context 'when the initialiser parameter is truthy'
|
43
|
+
|
44
|
+
context 'when the initialiser parameter is falsy' do
|
45
|
+
let(:record) { false }
|
46
|
+
|
47
|
+
it 'requires a block' do
|
48
|
+
# message = 'no block given (yield)'
|
49
|
+
expect { obj.build }.to raise_error LocalJumpError # , message
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'returns a StoreResult instance which' do
|
53
|
+
let(:errors_value) { 'RETURNED FROM BLOCK' }
|
54
|
+
let(:result) { obj.build { |_r| errors_value } }
|
55
|
+
|
56
|
+
it 'is not successful' do
|
57
|
+
expect(result).not_to be_success
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns an :entity attribute value of nil' do
|
61
|
+
expect(result.entity).to be nil
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns the return value of the block as the :errors attribute' do
|
65
|
+
expect(result.errors).to be errors_value
|
66
|
+
end
|
67
|
+
end # describe 'returns a StoreResult instance which'
|
68
|
+
end # context 'when the initialiser parameter is falsy'
|
69
|
+
end # describe 'has a #build method that'
|
70
|
+
end # describe Repository::Support::ResultBuilder
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Repository::Support::StoreResult do
|
6
|
+
describe 'initialisation' do
|
7
|
+
it 'requires three keyword-named parameters' do
|
8
|
+
# message = 'missing keywords: entity, success, errors'
|
9
|
+
expect { described_class.new }.to raise_error ArgumentError # , message
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'succeeds with specified values that can then be read back correctly' do
|
13
|
+
entity = 'ENTITY'
|
14
|
+
success = 'SUCCESS'
|
15
|
+
errors = 'ERRORS'
|
16
|
+
obj = described_class.new entity: entity, success: success, errors: errors
|
17
|
+
expect(obj.entity).to eq entity
|
18
|
+
expect(obj.success).to eq success
|
19
|
+
expect(obj.errors).to eq errors
|
20
|
+
end
|
21
|
+
end # describe 'initialisation'
|
22
|
+
|
23
|
+
describe 'has a #success? method that' do
|
24
|
+
it 'returns the same object as the #success accessor method' do
|
25
|
+
obj = described_class.new entity: nil, success: 'SUCCESS', errors: nil
|
26
|
+
# Note the difference between 'to be' and 'to eq'.
|
27
|
+
expect(obj.success?).to be obj.success
|
28
|
+
end
|
29
|
+
end # describe 'has a #success? method that'
|
30
|
+
end # describe Repository::Support::StoreResult
|
31
|
+
|
32
|
+
describe Repository::Support::StoreResult::Success do
|
33
|
+
let(:entity) { Object.new }
|
34
|
+
let(:obj) { described_class.new entity }
|
35
|
+
|
36
|
+
describe 'returns' do
|
37
|
+
it 'true from its #success accessor method' do
|
38
|
+
expect(obj.success).to be true
|
39
|
+
expect(obj).to be_success
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'the specified entity from its #entity accessor method' do
|
43
|
+
expect(obj.entity).to be entity
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'an empty array from its #errors accessor method' do
|
47
|
+
expect(obj.errors).to eq []
|
48
|
+
end
|
49
|
+
end # describe 'returns'
|
50
|
+
end # describe Repository::Support::StoreResult::Success
|
51
|
+
|
52
|
+
describe Repository::Support::StoreResult::Failure do
|
53
|
+
let(:errors) { 'ERRORS' }
|
54
|
+
let(:obj) { described_class.new errors }
|
55
|
+
|
56
|
+
describe 'returns' do
|
57
|
+
it 'false from its #success accessor method' do
|
58
|
+
expect(obj.success).not_to be true
|
59
|
+
expect(obj).not_to be_success
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'nil from its #entity accessor method' do
|
63
|
+
expect(obj.entity).to be nil
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'the passed-in :errors parameter from its #errors accessor method' do
|
67
|
+
expect(obj.errors).to be errors
|
68
|
+
end
|
69
|
+
end # describe 'returns'
|
70
|
+
end # describe Repository::Support::StoreResult::Failure
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
# Test-dummy class to exercise `TestAttributeContainer`.
|
6
|
+
class TestClass
|
7
|
+
extend Repository::Support::TestAttributeContainer
|
8
|
+
|
9
|
+
init_empty_attribute_container
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Repository::Support::TestAttributeContainer do
|
13
|
+
let(:obj) { TestClass.new }
|
14
|
+
|
15
|
+
it 'has reader and writer methods for :attributes' do
|
16
|
+
expect(obj).to respond_to :attributes
|
17
|
+
expect(obj).to respond_to :attributes=
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'supports mass initialisation of attributes' do
|
21
|
+
obj.attributes = { thing: true, the_answer: 42 }
|
22
|
+
expect(obj.thing).to be true
|
23
|
+
expect(obj.the_answer).to be 42
|
24
|
+
end
|
25
|
+
|
26
|
+
description = 'has new named-attribute accessors added when the name is' \
|
27
|
+
' added to :attributes'
|
28
|
+
it description do
|
29
|
+
expect { obj.thing }.to raise_error NoMethodError
|
30
|
+
expect { obj.thing = false }.to raise_error NoMethodError
|
31
|
+
obj.attributes[:thing] = 'something'
|
32
|
+
expect { obj.thing }.not_to raise_error
|
33
|
+
expect { obj.thing = 'something else' }.not_to raise_error
|
34
|
+
expect(obj.thing).to eq 'something else'
|
35
|
+
end
|
36
|
+
end # describe TestClass
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start 'rails' do
|
5
|
+
add_filter '/gemset/'
|
6
|
+
end
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
9
|
+
|
10
|
+
require 'awesome_print'
|
11
|
+
# require 'pry'
|
12
|
+
|
13
|
+
require 'repository/support'
|
metadata
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: repository-support
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Dickey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 4.2.10
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 4.2.10
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.16'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.16'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '12.3'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 12.3.0
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '12.3'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 12.3.0
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rspec
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '3.7'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '3.7'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rubocop
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0.52'
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 0.52.1
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0.52'
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 0.52.1
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: simplecov
|
103
|
+
requirement: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - "~>"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0.15'
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.15.1
|
111
|
+
type: :development
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.15'
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 0.15.1
|
121
|
+
- !ruby/object:Gem::Dependency
|
122
|
+
name: awesome_print
|
123
|
+
requirement: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: 1.8.0
|
128
|
+
type: :development
|
129
|
+
prerelease: false
|
130
|
+
version_requirements: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 1.8.0
|
135
|
+
description: Support classes for Repository::Base and subclasses.
|
136
|
+
email:
|
137
|
+
- jdickey@seven-sigma.com
|
138
|
+
executables: []
|
139
|
+
extensions: []
|
140
|
+
extra_rdoc_files: []
|
141
|
+
files:
|
142
|
+
- ".gitignore"
|
143
|
+
- ".rbenv-gemsets"
|
144
|
+
- ".rspec"
|
145
|
+
- ".rubocop.yml"
|
146
|
+
- ".ruby-version"
|
147
|
+
- ".travis.yml"
|
148
|
+
- Gemfile
|
149
|
+
- LICENSE.txt
|
150
|
+
- README.md
|
151
|
+
- Rakefile
|
152
|
+
- bin/bundle
|
153
|
+
- bin/bundler
|
154
|
+
- bin/htmldiff
|
155
|
+
- bin/ldiff
|
156
|
+
- bin/rake
|
157
|
+
- bin/rspec
|
158
|
+
- bin/rubocop
|
159
|
+
- bin/ruby-parse
|
160
|
+
- bin/ruby-rewrite
|
161
|
+
- bin/setup
|
162
|
+
- lib/repository/support.rb
|
163
|
+
- lib/repository/support/error_factory.rb
|
164
|
+
- lib/repository/support/result_builder.rb
|
165
|
+
- lib/repository/support/store_result.rb
|
166
|
+
- lib/repository/support/test_attribute_container.rb
|
167
|
+
- lib/repository/support/version.rb
|
168
|
+
- repository-support.gemspec
|
169
|
+
- spec/repository/support/error_factory_spec.rb
|
170
|
+
- spec/repository/support/result_builder_spec.rb
|
171
|
+
- spec/repository/support/store_result_spec.rb
|
172
|
+
- spec/repository/support/test_attribute_container_spec.rb
|
173
|
+
- spec/repository/support_spec.rb
|
174
|
+
- spec/spec_helper.rb
|
175
|
+
homepage: https://github.com/jdickey/repository-support
|
176
|
+
licenses:
|
177
|
+
- MIT
|
178
|
+
metadata: {}
|
179
|
+
post_install_message:
|
180
|
+
rdoc_options: []
|
181
|
+
require_paths:
|
182
|
+
- lib
|
183
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 2.4.0
|
188
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0'
|
193
|
+
requirements: []
|
194
|
+
rubyforge_project:
|
195
|
+
rubygems_version: 2.7.3
|
196
|
+
signing_key:
|
197
|
+
specification_version: 4
|
198
|
+
summary: Support classes for Repository::Base and subclasses.
|
199
|
+
test_files:
|
200
|
+
- spec/repository/support/error_factory_spec.rb
|
201
|
+
- spec/repository/support/result_builder_spec.rb
|
202
|
+
- spec/repository/support/store_result_spec.rb
|
203
|
+
- spec/repository/support/test_attribute_container_spec.rb
|
204
|
+
- spec/repository/support_spec.rb
|
205
|
+
- spec/spec_helper.rb
|