Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tallty_import_export
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
tallty_import_export
Commits
e9a29a01
Commit
e9a29a01
authored
Nov 19, 2020
by
Ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
导入测试增加上下文
parent
b14c28b8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
7 deletions
+11
-7
import.rb
lib/tallty_import_export/import.rb
+0
-1
importable_spec.rb
spec/importable_spec.rb
+11
-6
test1.xlsx
spec/test1.xlsx
+0
-0
No files found.
lib/tallty_import_export/import.rb
View file @
e9a29a01
...
@@ -80,7 +80,6 @@ module TalltyImportExport
...
@@ -80,7 +80,6 @@ module TalltyImportExport
else
else
associations
.
create!
(
line_info
)
associations
.
create!
(
line_info
)
end
end
end
end
end
end
end
end
spec/importable_spec.rb
View file @
e9a29a01
...
@@ -8,9 +8,10 @@ RSpec.describe TalltyImportExport::Importable do
...
@@ -8,9 +8,10 @@ RSpec.describe TalltyImportExport::Importable do
[
[
{
key:
'name'
,
name:
'名称'
},
{
key:
'name'
,
name:
'名称'
},
{
key:
'code'
,
name:
'学号'
,
convert: :handle_code
},
{
key:
'code'
,
name:
'学号'
,
convert: :handle_code
},
{
key:
'sub_code'
,
name:
'副学号'
,
convert: :skip
},
{
key:
'sub_code'
,
name:
'副学号'
,
convert: :skip
},
{
key:
'meta1'
,
name:
'meta字段1'
,
json: :meta
},
{
key:
'meta1'
,
name:
'meta字段1'
,
json: :meta
},
{
key:
'meta2'
,
name:
'meta字段2'
,
json: :meta
},
{
key:
'meta2'
,
name:
'meta字段2'
,
json: :meta
},
{
key:
'sum'
,
name:
'累加值'
,
convert: :handle_sum
},
]
]
end
end
end
end
...
@@ -23,6 +24,10 @@ RSpec.describe TalltyImportExport::Importable do
...
@@ -23,6 +24,10 @@ RSpec.describe TalltyImportExport::Importable do
def
handle_code
code
,
processing_line_info
,
raw_line_info
def
handle_code
code
,
processing_line_info
,
raw_line_info
"
#{
code
}
_
#{
raw_line_info
[
'sub_code'
]
}
"
"
#{
code
}
_
#{
raw_line_info
[
'sub_code'
]
}
"
end
end
def
handle_sum
num
,
processing_line_info
,
raw_line_info
context
.
last_line_info
?
context
.
last_line_info
[
'sum'
]
+
num
:
num
end
end
end
end
end
end
end
...
@@ -38,11 +43,11 @@ RSpec.describe TalltyImportExport::Importable do
...
@@ -38,11 +43,11 @@ RSpec.describe TalltyImportExport::Importable do
Test
.
import_xlsx
(
'./spec/test1.xlsx'
,
@result
)
Test
.
import_xlsx
(
'./spec/test1.xlsx'
,
@result
)
expect
(
@result
).
to
eq
([
expect
(
@result
).
to
eq
([
{
"name"
=>
1
,
"code"
=>
"20070101_1"
,
"sub_code"
=>
nil
,
"meta"
=>
{
"meta1"
=>
"meta1"
,
"meta2"
=>
"metaA"
}
},
{
"name"
=>
1
,
"code"
=>
"20070101_1"
,
"sub_code"
=>
nil
,
"meta"
=>
{
"meta1"
=>
"meta1"
,
"meta2"
=>
"metaA"
},
"sum"
=>
1
},
{
"name"
=>
2
,
"code"
=>
"20070102_2"
,
"sub_code"
=>
nil
,
"meta"
=>
{
"meta1"
=>
"meta2"
,
"meta2"
=>
"metaB"
}
},
{
"name"
=>
2
,
"code"
=>
"20070102_2"
,
"sub_code"
=>
nil
,
"meta"
=>
{
"meta1"
=>
"meta2"
,
"meta2"
=>
"metaB"
},
"sum"
=>
3
},
{
"name"
=>
3
,
"code"
=>
"20070103_3"
,
"sub_code"
=>
nil
,
"meta"
=>
{
"meta1"
=>
"meta3"
,
"meta2"
=>
"metaC"
}
},
{
"name"
=>
3
,
"code"
=>
"20070103_3"
,
"sub_code"
=>
nil
,
"meta"
=>
{
"meta1"
=>
"meta3"
,
"meta2"
=>
"metaC"
},
"sum"
=>
6
},
{
"name"
=>
4
,
"code"
=>
"20070104_4"
,
"sub_code"
=>
nil
,
"meta"
=>
{
"meta1"
=>
"meta4"
,
"meta2"
=>
"metaD"
}
},
{
"name"
=>
4
,
"code"
=>
"20070104_4"
,
"sub_code"
=>
nil
,
"meta"
=>
{
"meta1"
=>
"meta4"
,
"meta2"
=>
"metaD"
},
"sum"
=>
10
},
{
"name"
=>
5
,
"code"
=>
"20070105_5"
,
"sub_code"
=>
nil
,
"meta"
=>
{
"meta1"
=>
"meta5"
,
"meta2"
=>
"metaE"
}
},
{
"name"
=>
5
,
"code"
=>
"20070105_5"
,
"sub_code"
=>
nil
,
"meta"
=>
{
"meta1"
=>
"meta5"
,
"meta2"
=>
"metaE"
},
"sum"
=>
15
},
])
])
end
end
end
end
spec/test1.xlsx
View file @
e9a29a01
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment