activerecord-import 0.18.0 → 0.18.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1c586e3530cab4dd5f201737dd31c9634079ba1
4
- data.tar.gz: 1eb5d9c977a304bbff53ce32ffd61a0620426cc0
3
+ metadata.gz: 49847bc4a5b9c30133bb9a3ea8223906bcb65927
4
+ data.tar.gz: a4eeffe1ba579ccfe60f0e4e2e8ba7f641594aff
5
5
  SHA512:
6
- metadata.gz: cd502299bf521c3f9c6f98a2e4eb55ba8b88f0715401a7b959eedbfd26c0a455524642e3e76dbb429931fa006b519376a9be307daa12dd5b73e14f1c48ada29c
7
- data.tar.gz: 6a980c019a2db629a2ba1772b6630119ac8a04da23dc06c091cdb378a75ceeaf37ad17e5104d7c51f2982cf0253ec6485a538327655aea2e0d29a480364549ce
6
+ metadata.gz: 4b862bf40ca9dc76c6980bca024e9001db7e5ec89cdcfb98860cf9710280a44db4587e51ef45d5212c0121bc2bd407e45d6bbf6e047bf2ac5f8256c6b7d29ea6
7
+ data.tar.gz: 4409b8fbf9ea44482496a22679029eaf80e5a411cda999624f4587436e68b26eb59be7e263d0f324c39c5156da97be6b49929efde6d6c7bcda7a9c153a17c49a
@@ -1,3 +1,10 @@
1
+ ## Changes in 0.18.1
2
+
3
+ ### Fixes
4
+
5
+ * Fix to enable validation callbacks (before_validation,
6
+ after_validation). Thanks to @sinsoku, @jkowens via \#406.
7
+
1
8
  ## Changes in 0.18.0
2
9
 
3
10
  ### New Features
@@ -37,12 +37,20 @@ module ActiveRecord::Import #:nodoc:
37
37
  model.send(:validation_context=, validation_context)
38
38
  model.errors.clear
39
39
 
40
- @validators.each do |v|
41
- if validation_context == v.options.fetch(:on, validation_context)
42
- v.validate(model) if validate?(v, model)
40
+ validation_proc = lambda do
41
+ @validators.each do |v|
42
+ if validation_context == v.options.fetch(:on, validation_context)
43
+ v.validate(model) if validate?(v, model)
44
+ end
43
45
  end
44
46
  end
45
47
 
48
+ if model.respond_to?(:run_validation_callbacks)
49
+ model.send(:_run_validation_callbacks, &validation_proc)
50
+ else
51
+ model.send(:run_callbacks, :validation, &validation_proc)
52
+ end
53
+
46
54
  model.send(:validation_context=, current_context)
47
55
  model.errors.empty?
48
56
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Import
3
- VERSION = "0.18.0".freeze
3
+ VERSION = "0.18.1".freeze
4
4
  end
5
5
  end
@@ -224,6 +224,12 @@ describe "#import" do
224
224
  end
225
225
  assert_equal 0, Topic.where(title: invalid_values.map(&:first)).count
226
226
  end
227
+
228
+ it "should run callbacks" do
229
+ assert_no_difference "Topic.count" do
230
+ Topic.import columns, [["invalid", "Jerry Carter"]], validate: true
231
+ end
232
+ end
227
233
  end
228
234
  end
229
235
 
@@ -3,6 +3,8 @@ class Topic < ActiveRecord::Base
3
3
  validates :title, numericality: { only_integer: true }, on: :context_test
4
4
  validates :title, uniqueness: true
5
5
 
6
+ before_validation -> { errors.add(:title, :invalid) if title == 'invalid' }
7
+
6
8
  has_many :books, inverse_of: :topic
7
9
  belongs_to :parent, class_name: "Topic"
8
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-import
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Dennis