Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
excelsieur
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
excelsieur
Commits
a39c6d52
Verified
Commit
a39c6d52
authored
6 years ago
by
Alexis Reigel
Browse files
Options
Downloads
Patches
Plain Diff
don't run when the initial valid check fails
parent
e8ddf4f1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!9
Result object
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/excelsior/import.rb
+10
-4
10 additions, 4 deletions
lib/excelsior/import.rb
test/excelsior_test.rb
+6
-0
6 additions, 0 deletions
test/excelsior_test.rb
with
16 additions
and
4 deletions
lib/excelsior/import.rb
+
10
−
4
View file @
a39c6d52
...
...
@@ -30,10 +30,12 @@ module Excelsior
@report
=
Report
.
new
valid
?
valid
ate!
end
def
run
(
&
block
)
return
unless
valid?
if
self
.
class
.
use_transaction
model_class
.
transaction
do
insert_rows
(
&
block
)
...
...
@@ -45,7 +47,7 @@ module Excelsior
end
end
def
valid
?
def
valid
ate!
@errors
=
fields
.
to_a
.
each_with_object
({})
do
|
f
,
acc
|
acc
[
:missing_column
]
||=
[]
...
...
@@ -53,6 +55,10 @@ module Excelsior
end
end
def
valid?
@errors
[
:missing_column
].
empty?
end
private
def
model_class
...
...
@@ -60,6 +66,8 @@ module Excelsior
end
def
add_model_errors
(
record
,
index
)
@errors
[
:model
]
||=
[]
if
record
.
errors
.
empty?
report_insert
return
...
...
@@ -67,8 +75,6 @@ module Excelsior
report_failure
@errors
[
:model
]
||=
[]
@errors
[
:model
]
<<
Error
.
new
(
index
+
1
,
record
.
errors
.
full_messages
)
end
...
...
This diff is collapsed.
Click to expand it.
test/excelsior_test.rb
+
6
−
0
View file @
a39c6d52
...
...
@@ -156,6 +156,12 @@ describe Excelsior do
assert
import
.
errors
[
:missing_column
].
any?
end
it
'does not run the import'
do
import
=
UserImport
.
new
(
'test/files/missing-column.xlsx'
)
import
.
run
assert_equal
0
,
import
.
report
.
total
end
it
'returns the model validation errors'
do
import
=
UserImport
.
new
(
'test/files/missing-first-name.xlsx'
).
tap
(
&
:run
)
assert
import
.
errors
[
:model
].
any?
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment