activerecord-import 0.18.0 → 0.18.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/activerecord-import/import.rb +11 -3
- data/lib/activerecord-import/version.rb +1 -1
- data/test/import_test.rb +6 -0
- data/test/models/topic.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49847bc4a5b9c30133bb9a3ea8223906bcb65927
|
4
|
+
data.tar.gz: a4eeffe1ba579ccfe60f0e4e2e8ba7f641594aff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b862bf40ca9dc76c6980bca024e9001db7e5ec89cdcfb98860cf9710280a44db4587e51ef45d5212c0121bc2bd407e45d6bbf6e047bf2ac5f8256c6b7d29ea6
|
7
|
+
data.tar.gz: 4409b8fbf9ea44482496a22679029eaf80e5a411cda999624f4587436e68b26eb59be7e263d0f324c39c5156da97be6b49929efde6d6c7bcda7a9c153a17c49a
|
data/CHANGELOG.md
CHANGED
@@ -37,12 +37,20 @@ module ActiveRecord::Import #:nodoc:
|
|
37
37
|
model.send(:validation_context=, validation_context)
|
38
38
|
model.errors.clear
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
v.
|
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
|
data/test/import_test.rb
CHANGED
@@ -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
|
|
data/test/models/topic.rb
CHANGED
@@ -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
|
|