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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b325eefc9a4503a854a5af5f9d62b23820ce5177752ee95b48128d3d63d86e7b
4
- data.tar.gz: 89c73478dc48ca7f8f70d7e74d52a96c4660dfa4458a100b93b0a6216ce5ef5f
3
+ metadata.gz: dce2b4057e3f17e47bc079858edd883ae157fab1ac07255e352471fc0d4a734e
4
+ data.tar.gz: 004a557469880ade02c121b63446f3014ce4bcea43ab6febfdc88e7e852fec30
5
5
  SHA512:
6
- metadata.gz: 5130c797f801bbd7e29bf89311603bf8d29c0659107e9c50e231d9c123f25dadc55793d54ba885ad08b1fe4e77486eab41516e8194133f9ceca693e2a94b398c
7
- data.tar.gz: 7f42fe723d78b4b129b63a07677c9551ac50005d84d7ff6c5f45ccd21088a7e453122ae7fe5734c9e34636cb9ad05dbb877517e8198ef2ea64a24bc3a5ba1513
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
@@ -0,0 +1,5 @@
1
+ ## Checklist
2
+ - [ ] Continuous integration passes, or no functional code was changed
3
+ - [ ] Changelog entry added, or no entry is necessary
4
+
5
+ ## Notes
@@ -88,14 +88,37 @@ module ActsAsSpan
88
88
  def call
89
89
  result = propagate
90
90
  # only add new errors to the object
91
- result.errors.each do |error, message|
92
- object.errors.add(error) if object.errors[error].exclude? message
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
- skip if object.errors.added?(:base, message)
136
+ next if object.errors.added?(:base, message)
114
137
 
115
138
  object.errors.add(:base, message)
116
139
  end
@@ -4,7 +4,7 @@ module ActsAsSpan
4
4
  module VERSION
5
5
  MAJOR = 1
6
6
  MINOR = 2
7
- TINY = 1
7
+ TINY = 2
8
8
  PRE = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
@@ -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, skipped_classes: skipped_classes,
7
- include_errors: include_errors
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.1
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-02-02 00:00:00.000000000 Z
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.1
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