acts_as_span 1.2.1 → 1.2.2
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/CHANGELOG.md +22 -0
- data/PULL_REQUEST_TEMPLATE.md +5 -0
- data/lib/acts_as_span/end_date_propagator.rb +26 -3
- data/lib/acts_as_span/version.rb +1 -1
- data/spec/lib/end_date_propagator_spec.rb +27 -2
- data/spec/spec_models.rb +9 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dce2b4057e3f17e47bc079858edd883ae157fab1ac07255e352471fc0d4a734e
|
4
|
+
data.tar.gz: 004a557469880ade02c121b63446f3014ce4bcea43ab6febfdc88e7e852fec30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eef25c86ddff4ce610a0cfe4e2a9b3fbf983768821566c0b056cdbb117d82f9ab0573c2309cb839ac61077f00fb7a5a6f1302f8bd64371ce43a5fa1d6068bfaa
|
7
|
+
data.tar.gz: 7815bd5e31b5eca225a88278dad84af946a98ad0adef280b5dcdd24f358ae3a4c2005da40dfc035344525c9f157cf98e96aea52b526c5a69c729179849c6e135
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
Types of changes:
|
9
|
+
- **Added** for new features.
|
10
|
+
- **Changed** for changes in existing functionality.
|
11
|
+
- **Deprecated** for soon-to-be removed features.
|
12
|
+
- **Removed** for now removed features.
|
13
|
+
- **Fixed** for any bug fixes.
|
14
|
+
- **Security** in case of vulnerabilities.
|
15
|
+
|
16
|
+
Please include the Github issue or pull request number when applicable
|
17
|
+
|
18
|
+
## [Unreleased]
|
19
|
+
### Added
|
20
|
+
- A change log #31
|
21
|
+
### Fixed
|
22
|
+
- Syntax error in EndDatePropagator#propagate #30
|
@@ -88,14 +88,37 @@ module ActsAsSpan
|
|
88
88
|
def call
|
89
89
|
result = propagate
|
90
90
|
# only add new errors to the object
|
91
|
-
|
92
|
-
|
91
|
+
|
92
|
+
# NOTE: Rails 5 support
|
93
|
+
if ActiveRecord::VERSION::MAJOR > 5
|
94
|
+
add_errors(result.errors)
|
95
|
+
else
|
96
|
+
add_rails_5_errors(result.errors)
|
93
97
|
end
|
98
|
+
|
94
99
|
object
|
95
100
|
end
|
96
101
|
|
97
102
|
private
|
98
103
|
|
104
|
+
def add_errors(errors)
|
105
|
+
errors.each do |error|
|
106
|
+
if object.errors[error.attribute].exclude? error.message
|
107
|
+
object.errors.add(error.attribute, error.message)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Treat errors like a Hash
|
113
|
+
# NOTE: Rails 5 support
|
114
|
+
def add_rails_5_errors(errors)
|
115
|
+
errors.each do |attribute, message|
|
116
|
+
if object.errors[attribute].exclude? message
|
117
|
+
object.errors.add(attribute, message)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
99
122
|
def propagate
|
100
123
|
# return if there is nothing to propagate
|
101
124
|
return object unless should_propagate_from? object
|
@@ -110,7 +133,7 @@ module ActsAsSpan
|
|
110
133
|
|
111
134
|
if errors_cache.present?
|
112
135
|
errors_cache.each do |message|
|
113
|
-
|
136
|
+
next if object.errors.added?(:base, message)
|
114
137
|
|
115
138
|
object.errors.add(:base, message)
|
116
139
|
end
|
data/lib/acts_as_span/version.rb
CHANGED
@@ -3,8 +3,9 @@ require 'spec_helper'
|
|
3
3
|
RSpec.describe ActsAsSpan::EndDatePropagator do
|
4
4
|
let(:end_date_propagator) do
|
5
5
|
ActsAsSpan::EndDatePropagator.new(
|
6
|
-
base_instance,
|
7
|
-
|
6
|
+
base_instance,
|
7
|
+
skipped_classes: skipped_classes,
|
8
|
+
include_errors: include_errors,
|
8
9
|
)
|
9
10
|
end
|
10
11
|
|
@@ -300,6 +301,30 @@ RSpec.describe ActsAsSpan::EndDatePropagator do
|
|
300
301
|
end
|
301
302
|
end
|
302
303
|
|
304
|
+
context 'when the record already has a validation that would be added' do
|
305
|
+
let(:end_date) { Date.current }
|
306
|
+
|
307
|
+
before do
|
308
|
+
base_instance.save!
|
309
|
+
base_instance.end_date = end_date
|
310
|
+
base_instance.errors.add(:base, 'Child is bad')
|
311
|
+
|
312
|
+
child_instance.manual_invalidation = true
|
313
|
+
child_instance.save(validate: false)
|
314
|
+
|
315
|
+
# add the error that would be added by the child's propagation
|
316
|
+
base_instance.errors.add(
|
317
|
+
:base,
|
318
|
+
"Base could not propagate Emancipation date to Child:\nChild is bad",
|
319
|
+
)
|
320
|
+
end
|
321
|
+
|
322
|
+
it 'does not add the duplicate error' do
|
323
|
+
expect { end_date_propagator.call }
|
324
|
+
.not_to(change(base_instance, :errors))
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
303
328
|
context 'when a class is skipped' do
|
304
329
|
let(:end_date) { Date.current }
|
305
330
|
let(:skipped_classes) { [Tale] }
|
data/spec/spec_models.rb
CHANGED
@@ -170,9 +170,11 @@ Temping.create :child do
|
|
170
170
|
validates_with ActsAsSpan::WithinParentDateSpanValidator,
|
171
171
|
parents: [:base]
|
172
172
|
|
173
|
+
validate :not_manually_invalidated
|
174
|
+
|
173
175
|
acts_as_span(
|
174
176
|
start_field: :date_of_birth,
|
175
|
-
end_field: :emancipation_date
|
177
|
+
end_field: :emancipation_date,
|
176
178
|
)
|
177
179
|
|
178
180
|
with_columns do |t|
|
@@ -181,6 +183,12 @@ Temping.create :child do
|
|
181
183
|
t.string :manual_invalidation
|
182
184
|
t.belongs_to :base
|
183
185
|
end
|
186
|
+
|
187
|
+
def not_manually_invalidated
|
188
|
+
return if manual_invalidation.blank? || manual_invalidation == false
|
189
|
+
|
190
|
+
errors.add(:base, 'Child is bad')
|
191
|
+
end
|
184
192
|
end
|
185
193
|
|
186
194
|
Temping.create :dog do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_span
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Sullivan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -147,8 +147,10 @@ files:
|
|
147
147
|
- ".rspec"
|
148
148
|
- ".tool-versions"
|
149
149
|
- ".travis.yml"
|
150
|
+
- CHANGELOG.md
|
150
151
|
- Gemfile
|
151
152
|
- LICENSE
|
153
|
+
- PULL_REQUEST_TEMPLATE.md
|
152
154
|
- README.rdoc
|
153
155
|
- Rakefile
|
154
156
|
- acts_as_span.gemspec
|
@@ -200,7 +202,7 @@ requirements: []
|
|
200
202
|
rubygems_version: 3.0.3
|
201
203
|
signing_key:
|
202
204
|
specification_version: 4
|
203
|
-
summary: acts_as_span 1.2.
|
205
|
+
summary: acts_as_span 1.2.2
|
204
206
|
test_files:
|
205
207
|
- spec/lib/acts_as_span_spec.rb
|
206
208
|
- spec/lib/delegation_spec.rb
|