database-exporter 0.0.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 +7 -0
- data/.gitignore +39 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +74 -0
- data/LICENSE +22 -0
- data/README.md +682 -0
- data/Rakefile +7 -0
- data/bin/database-exporter +48 -0
- data/database_exporter.gemspec +34 -0
- data/example_data/contentful_model.json +316 -0
- data/example_data/contentful_structure.json +89 -0
- data/example_data/example_settings.yml +25 -0
- data/example_data/mapping.json +119 -0
- data/lib/cli.rb +13 -0
- data/lib/configuration.rb +69 -0
- data/lib/converters/content_types_structure_creator.rb +58 -0
- data/lib/converters/contentful_model_to_json.rb +78 -0
- data/lib/database/export.rb +74 -0
- data/lib/database/modules/json_export.rb +79 -0
- data/lib/database/modules/relations_export.rb +270 -0
- data/lib/database/modules/utils.rb +20 -0
- data/lib/migrator.rb +29 -0
- data/lib/version.rb +3 -0
- data/spec/fixtures/database/data/assets/image/image_1.json +9 -0
- data/spec/fixtures/database/data/assets/image/image_2.json +9 -0
- data/spec/fixtures/database/data/assets/image/image_3.json +9 -0
- data/spec/fixtures/database/data/assets/image/image_4.json +9 -0
- data/spec/fixtures/database/data/collections/comment.json +18 -0
- data/spec/fixtures/database/data/collections/job_skills.json +13 -0
- data/spec/fixtures/database/data/collections/jobs.json +44 -0
- data/spec/fixtures/database/data/collections/profile.json +19 -0
- data/spec/fixtures/database/data/collections/user.json +36 -0
- data/spec/fixtures/database/data/entries/comment/comment_1.json +9 -0
- data/spec/fixtures/database/data/entries/comment/comment_2.json +9 -0
- data/spec/fixtures/database/data/entries/comment/comment_3.json +9 -0
- data/spec/fixtures/database/data/entries/comment/comment_4.json +9 -0
- data/spec/fixtures/database/data/entries/comment/comment_5.json +9 -0
- data/spec/fixtures/database/data/entries/job_skills/job_skills_1.json +7 -0
- data/spec/fixtures/database/data/entries/job_skills/job_skills_10.json +7 -0
- data/spec/fixtures/database/data/entries/job_skills/job_skills_2.json +7 -0
- data/spec/fixtures/database/data/entries/job_skills/job_skills_3.json +7 -0
- data/spec/fixtures/database/data/entries/job_skills/job_skills_4.json +7 -0
- data/spec/fixtures/database/data/entries/job_skills/job_skills_5.json +7 -0
- data/spec/fixtures/database/data/entries/job_skills/job_skills_6.json +7 -0
- data/spec/fixtures/database/data/entries/job_skills/job_skills_7.json +7 -0
- data/spec/fixtures/database/data/entries/job_skills/job_skills_8.json +7 -0
- data/spec/fixtures/database/data/entries/job_skills/job_skills_9.json +7 -0
- data/spec/fixtures/database/data/entries/jobs/jobs_1.json +56 -0
- data/spec/fixtures/database/data/entries/jobs/jobs_2.json +55 -0
- data/spec/fixtures/database/data/entries/jobs/jobs_4.json +49 -0
- data/spec/fixtures/database/data/entries/profile/profile_1.json +12 -0
- data/spec/fixtures/database/data/entries/profile/profile_2.json +12 -0
- data/spec/fixtures/database/data/entries/user/user_1.json +24 -0
- data/spec/fixtures/database/data/entries/user/user_2.json +20 -0
- data/spec/fixtures/database/data/helpers/job_add_id_comments.json +11 -0
- data/spec/fixtures/database/data/helpers/job_add_id_job_add_skills.json +24 -0
- data/spec/fixtures/database/data/helpers/user_id_job_adds.json +9 -0
- data/spec/fixtures/database/data/helpers/user_id_profiles.json +8 -0
- data/spec/fixtures/database/data/table_names.json +10 -0
- data/spec/fixtures/database/table_names.json +4 -0
- data/spec/fixtures/development.sqlite3 +0 -0
- data/spec/fixtures/json_responses/transformed_row.json +7 -0
- data/spec/fixtures/json_row/row.json +6 -0
- data/spec/fixtures/settings/contentful_model.json +316 -0
- data/spec/fixtures/settings/contentful_structure.json +89 -0
- data/spec/fixtures/settings/contentful_structure_test.json +82 -0
- data/spec/fixtures/settings/mapping.json +119 -0
- data/spec/fixtures/settings/settings.yml +27 -0
- data/spec/lib/configuration_spec.rb +17 -0
- data/spec/lib/database/export_spec.rb +49 -0
- data/spec/lib/database/json_export_spec.rb +49 -0
- data/spec/lib/database/relations_export_spec.rb +201 -0
- data/spec/lib/migrator_spec.rb +112 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/support/db_rows_json.rb +9 -0
- data/spec/support/shared_configuration.rb +27 -0
- metadata +358 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Comment": {
|
|
3
|
+
"id": "6H6pGAV1PUsuoAW26Iu48W",
|
|
4
|
+
"name": "Comment",
|
|
5
|
+
"description": null,
|
|
6
|
+
"displayField": "subject",
|
|
7
|
+
"fields": {
|
|
8
|
+
"subject": "Text",
|
|
9
|
+
"content": "Text"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"User": {
|
|
13
|
+
"id": "1TVvxCqoRq0qUYAOQuOqys",
|
|
14
|
+
"name": "User",
|
|
15
|
+
"description": null,
|
|
16
|
+
"displayField": "first_name",
|
|
17
|
+
"fields": {
|
|
18
|
+
"first_name": "Text",
|
|
19
|
+
"last_name": "Text",
|
|
20
|
+
"birthday": "Date",
|
|
21
|
+
"Job adds": {
|
|
22
|
+
"id": "job_adds",
|
|
23
|
+
"type": "Array",
|
|
24
|
+
"link_type": "Entry",
|
|
25
|
+
"link": "Link"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"Jobs": {
|
|
30
|
+
"id": "4L1bg4WQ5aWQMiE82ouag",
|
|
31
|
+
"name": "Jobs",
|
|
32
|
+
"description": null,
|
|
33
|
+
"displayField": "title",
|
|
34
|
+
"fields": {
|
|
35
|
+
"title": "Text",
|
|
36
|
+
"description": "Text",
|
|
37
|
+
"Image": {
|
|
38
|
+
"id": "image",
|
|
39
|
+
"type": "Asset",
|
|
40
|
+
"link": "Link"
|
|
41
|
+
},
|
|
42
|
+
"Creator": {
|
|
43
|
+
"id": "creator",
|
|
44
|
+
"type": "Entry",
|
|
45
|
+
"link": "Link"
|
|
46
|
+
},
|
|
47
|
+
"Comments": {
|
|
48
|
+
"id": "comments",
|
|
49
|
+
"type": "Array",
|
|
50
|
+
"link_type": "Entry",
|
|
51
|
+
"link": "Link"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"Profile": {
|
|
56
|
+
"id": "4WFZh4MwC4Mc0EQWAeOY8A",
|
|
57
|
+
"name": "Profile",
|
|
58
|
+
"description": null,
|
|
59
|
+
"displayField": null,
|
|
60
|
+
"fields": {
|
|
61
|
+
"Nickname": {
|
|
62
|
+
"id": "nickname",
|
|
63
|
+
"type": "Entry",
|
|
64
|
+
"link": "Link"
|
|
65
|
+
},
|
|
66
|
+
"User": {
|
|
67
|
+
"id": "user",
|
|
68
|
+
"type": "Entry",
|
|
69
|
+
"link": "Link"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"Job Skills": {
|
|
74
|
+
"id": "2soCP557HGKoOOK0SqmMOm",
|
|
75
|
+
"name": "Job Skills",
|
|
76
|
+
"description": null,
|
|
77
|
+
"displayField": "name",
|
|
78
|
+
"fields": {
|
|
79
|
+
"name": "Text"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
{
|
|
2
|
+
"JobAdds": {
|
|
3
|
+
"content_type": "Jobs",
|
|
4
|
+
"type": "entry",
|
|
5
|
+
"fields": {
|
|
6
|
+
"title": "name",
|
|
7
|
+
"description": "specification"
|
|
8
|
+
},
|
|
9
|
+
"links": {
|
|
10
|
+
"aggregate_belongs": [
|
|
11
|
+
{
|
|
12
|
+
"relation_to": "Users",
|
|
13
|
+
"primary_id": "user_id",
|
|
14
|
+
"field": "first_name"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"aggregate_many": [
|
|
18
|
+
{
|
|
19
|
+
"primary_id": "job_add_id",
|
|
20
|
+
"relation_to": "Comments",
|
|
21
|
+
"field": "subject",
|
|
22
|
+
"save_as": "subjects_comments"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"belongs_to": [
|
|
26
|
+
{
|
|
27
|
+
"relation_to": "Images",
|
|
28
|
+
"foreign_id": "image_id"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"relation_to": "Users",
|
|
32
|
+
"foreign_id": "user_id"
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"many": [
|
|
36
|
+
{
|
|
37
|
+
"relation_to": "Comments",
|
|
38
|
+
"primary_id": "job_add_id"
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"many_through": [
|
|
42
|
+
{
|
|
43
|
+
"relation_to": "Skills",
|
|
44
|
+
"primary_id": "job_add_id",
|
|
45
|
+
"foreign_id": "skill_id",
|
|
46
|
+
"through": "JobAddSkills"
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"Comments": {
|
|
52
|
+
"content_type": "Comment",
|
|
53
|
+
"type": "entry",
|
|
54
|
+
"fields": {
|
|
55
|
+
"title": "subject",
|
|
56
|
+
"body": "content"
|
|
57
|
+
},
|
|
58
|
+
"links": {
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"Skills": {
|
|
62
|
+
"content_type": "Job Skills",
|
|
63
|
+
"type": "entry",
|
|
64
|
+
"fields": {
|
|
65
|
+
},
|
|
66
|
+
"links": {
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"Profiles": {
|
|
70
|
+
"content_type": "Profile",
|
|
71
|
+
"type": "entry",
|
|
72
|
+
"fields": {
|
|
73
|
+
},
|
|
74
|
+
"links": {
|
|
75
|
+
"belongs_to": [
|
|
76
|
+
{
|
|
77
|
+
"relation_to": "Users",
|
|
78
|
+
"foreign_id": "user_id"
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"Users": {
|
|
84
|
+
"content_type": "User",
|
|
85
|
+
"type": "entry",
|
|
86
|
+
"fields": {
|
|
87
|
+
},
|
|
88
|
+
"links": {
|
|
89
|
+
"aggregate_has_one": [
|
|
90
|
+
{
|
|
91
|
+
"relation_to": "Profiles",
|
|
92
|
+
"primary_id": "user_id",
|
|
93
|
+
"field": "nickname",
|
|
94
|
+
"save_as": "custom_nick"
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
"has_one": [
|
|
98
|
+
{
|
|
99
|
+
"relation_to": "Profiles",
|
|
100
|
+
"primary_id": "user_id"
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
"many": [
|
|
104
|
+
{
|
|
105
|
+
"relation_to": "JobAdds",
|
|
106
|
+
"primary_id": "user_id"
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"Images": {
|
|
112
|
+
"content_type": "Image",
|
|
113
|
+
"type": "asset",
|
|
114
|
+
"fields": {
|
|
115
|
+
},
|
|
116
|
+
"links": {
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#PATH to all data
|
|
2
|
+
data_dir: spec/fixtures/database/data
|
|
3
|
+
|
|
4
|
+
#Connecting to a database
|
|
5
|
+
adapter: sqlite
|
|
6
|
+
host: localhost
|
|
7
|
+
database: spec/fixtures/development.sqlite3
|
|
8
|
+
user: username
|
|
9
|
+
password: password
|
|
10
|
+
|
|
11
|
+
# Extract data from models:
|
|
12
|
+
mapped:
|
|
13
|
+
tables:
|
|
14
|
+
- :users
|
|
15
|
+
- :skills
|
|
16
|
+
- :comments
|
|
17
|
+
- :images
|
|
18
|
+
- :job_adds
|
|
19
|
+
- :profiles
|
|
20
|
+
|
|
21
|
+
## MAPPING ##
|
|
22
|
+
mapping_dir: spec/fixtures/settings/mapping.json
|
|
23
|
+
contentful_structure_dir: spec/fixtures/settings//contentful_structure.json
|
|
24
|
+
|
|
25
|
+
## CONVERT
|
|
26
|
+
content_model_json: spec/fixtures/settings/contentful_model.json
|
|
27
|
+
converted_model_dir: spec/fixtures/settings/contentful_structure_test.json
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require './lib/configuration'
|
|
3
|
+
|
|
4
|
+
module Contentful
|
|
5
|
+
describe Configuration do
|
|
6
|
+
|
|
7
|
+
include_context 'shared_configuration'
|
|
8
|
+
|
|
9
|
+
it 'initialize' do
|
|
10
|
+
expect(@config.assets_dir).to eq 'spec/fixtures/database/data/assets'
|
|
11
|
+
expect(@config.collections_dir).to eq 'spec/fixtures/database/data/collections'
|
|
12
|
+
expect(@config.data_dir).to eq 'spec/fixtures/database/data'
|
|
13
|
+
expect(@config.entries_dir).to eq 'spec/fixtures/database/data/entries'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require './lib/database/export'
|
|
3
|
+
|
|
4
|
+
module Contentful
|
|
5
|
+
module Exporter
|
|
6
|
+
module Database
|
|
7
|
+
describe Export do
|
|
8
|
+
|
|
9
|
+
include_context 'shared_configuration'
|
|
10
|
+
|
|
11
|
+
before do
|
|
12
|
+
@exporter = Export.new(@config)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'initialize' do
|
|
16
|
+
expect(@exporter.config).to be_kind_of Contentful::Configuration
|
|
17
|
+
expect(@exporter.mapping).to be_a Hash
|
|
18
|
+
expect(@exporter.tables).to be_a Array
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'tables_name' do
|
|
22
|
+
expect_any_instance_of(Contentful::Configuration).to receive_message_chain("db.tables") { %w(table_name table_name2) }
|
|
23
|
+
@exporter.tables_name
|
|
24
|
+
table_names = JSON.parse(File.read('spec/fixtures/database/table_names.json'))
|
|
25
|
+
expect(table_names).to include('table_name', 'table_name2')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'create_data_relations' do
|
|
29
|
+
expect_any_instance_of(Export).to receive(:relations_from_mapping) { ['table', 'table2'] }
|
|
30
|
+
expect_any_instance_of(Export).to receive(:generate_relations_helper_indexes).exactly(2).times
|
|
31
|
+
expect_any_instance_of(Export).to receive(:map_relations_to_links).exactly(2).times
|
|
32
|
+
@exporter.create_data_relations
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'mapping_structure' do
|
|
36
|
+
mapping = @exporter.mapping_structure
|
|
37
|
+
expect(mapping.count).to eq 6
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'load_tables' do
|
|
41
|
+
tables = @exporter.load_tables
|
|
42
|
+
expect(tables.count).to eq 2
|
|
43
|
+
expect(tables).to include(:example_model_name, :example_model_name_two)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require './lib/database/modules/json_export'
|
|
3
|
+
require './lib/database/export'
|
|
4
|
+
|
|
5
|
+
module Contentful
|
|
6
|
+
module Exporter
|
|
7
|
+
module Database
|
|
8
|
+
describe JsonExport do
|
|
9
|
+
|
|
10
|
+
include_context 'shared_configuration'
|
|
11
|
+
|
|
12
|
+
before do
|
|
13
|
+
@exporter = Export.new(@config)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'asset?' do
|
|
17
|
+
result = @exporter.asset?('Images')
|
|
18
|
+
expect(result).to be true
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'save_object_to_file' do
|
|
22
|
+
expect_any_instance_of(Contentful::Configuration).to receive(:db).exactly(1).times { {table_name: [load_fixture('json_row/row')]} }
|
|
23
|
+
@exporter.save_object_to_file(:table_name, 'Users', 'Users', @config.entries_dir)
|
|
24
|
+
transformed_json = load_fixture('json_responses/transformed_row')
|
|
25
|
+
expect(transformed_json).to include('id' => 'model_name_12', 'name' => 'Test name', 'description' => 'awesome exporter', 'rate' => 100, 'database_id' => 12)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'model id' do
|
|
29
|
+
result = @exporter.model_id('Images', 'image', 444)
|
|
30
|
+
expect(result).to eq 'image_444'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'format_value' do
|
|
34
|
+
result = @exporter.format_value('u---test--string!')
|
|
35
|
+
expect(result).to eq 'u-test-string'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'copy_field_value' do
|
|
39
|
+
copy_result = {}
|
|
40
|
+
expect_any_instance_of(Export).to receive(:mapping) { {'model_name' => {copy: {'field_name' => 'save_as'}}} }
|
|
41
|
+
expect_any_instance_of(Export).to receive(:format_value) { 'field_value_copied' }
|
|
42
|
+
@exporter.copy_field_value('field_name', 'some_value', 'model_name', copy_result)
|
|
43
|
+
expect(copy_result).to include('save_as' => 'field_value_copied')
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require './lib/database/export'
|
|
3
|
+
|
|
4
|
+
module Contentful
|
|
5
|
+
module Exporter
|
|
6
|
+
module Database
|
|
7
|
+
describe JsonExport do
|
|
8
|
+
|
|
9
|
+
include_context 'shared_configuration'
|
|
10
|
+
|
|
11
|
+
before do
|
|
12
|
+
@exporter = Export.new(@config)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'export_collections' do
|
|
16
|
+
expect_any_instance_of(Export).to receive(:save_relation_foreign_keys).exactly(3).times
|
|
17
|
+
result = @exporter.generate_relations_helper_indexes(load_fixture('settings/mapping')['Users']['links'])
|
|
18
|
+
expect(result.count).to eq 3
|
|
19
|
+
expect(result).to be_an Hash
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'save_relation_foreign_keys' do
|
|
23
|
+
expect_any_instance_of(Export).to receive(:save_relation_foreign_keys_for_model).with(load_fixture('settings/mapping')['JobAdds']['links']['many_through'].first, 'many_through').exactly(1).times
|
|
24
|
+
@exporter.save_relation_foreign_keys('many_through', load_fixture('settings/mapping')['JobAdds']['links']['many_through'])
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context 'save_relation_foreign_keys_for_model' do
|
|
28
|
+
it 'with many_through' do
|
|
29
|
+
expect_any_instance_of(Export).to receive(:save_foreign_keys).with('JobAddSkills', 'job_add_id', 'skill_id')
|
|
30
|
+
@exporter.save_relation_foreign_keys_for_model(load_fixture('settings/mapping')['JobAdds']['links']['many_through'].first, 'many_through')
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'save_foreign_keys' do
|
|
35
|
+
expect_any_instance_of(Contentful::Configuration).to receive(:db) { {related_model: [load_fixture('json_row/row')]} }
|
|
36
|
+
expect_any_instance_of(Export).to receive(:add_index_to_helper_hash).with({}, load_fixture('json_row/row'), 'primary_id', 'related_model_id')
|
|
37
|
+
@exporter.save_foreign_keys('related_model', 'primary_id', 'related_model_id')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context 'save_relation_foreign_keys_for_model' do
|
|
41
|
+
it 'when array for key is empty' do
|
|
42
|
+
result = @exporter.add_index_to_helper_hash({}, {model_id: 1, model_asset_id: 5}, 'model_asset_id', 'model_id')
|
|
43
|
+
expect(result).to include(5 => [1])
|
|
44
|
+
end
|
|
45
|
+
it 'when array for key exists' do
|
|
46
|
+
result = @exporter.add_index_to_helper_hash({5 => [2]}, {model_id: 1, model_asset_id: 5}, 'model_asset_id', 'model_id')
|
|
47
|
+
expect(result).to include(5 => [2, 1])
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context 'relationships' do
|
|
52
|
+
it 'belongs_to' do
|
|
53
|
+
expect_any_instance_of(Export).to receive(:map_belongs_to_association).with('model_name', {:linked_model => 'linked_model'}, {:entry => 'test'}, 'path')
|
|
54
|
+
@exporter.relationships({entry: 'test'}, 'path', 'belongs_to', 'model_name', {linked_model: 'linked_model'})
|
|
55
|
+
end
|
|
56
|
+
it 'has_one' do
|
|
57
|
+
expect_any_instance_of(Export).to receive(:map_has_one_association).with('model_name', {:linked_model => 'linked_model'}, {:entry => 'test'}, 'path', :relation_to)
|
|
58
|
+
@exporter.relationships({entry: 'test'}, 'path', 'has_one', 'model_name', {linked_model: 'linked_model'})
|
|
59
|
+
end
|
|
60
|
+
it 'many' do
|
|
61
|
+
expect_any_instance_of(Export).to receive(:map_many_association).with('model_name', {:linked_model => 'linked_model'}, {:entry => 'test'}, 'path', :relation_to)
|
|
62
|
+
@exporter.relationships({entry: 'test'}, 'path', 'many', 'model_name', {linked_model: 'linked_model'})
|
|
63
|
+
end
|
|
64
|
+
it 'many_through' do
|
|
65
|
+
expect_any_instance_of(Export).to receive(:map_many_association).with('model_name', {:linked_model => 'linked_model'}, {:entry => 'test'}, 'path', :through)
|
|
66
|
+
@exporter.relationships({entry: 'test'}, 'path', 'many_through', 'model_name', {linked_model: 'linked_model'})
|
|
67
|
+
end
|
|
68
|
+
it 'aggregate_through' do
|
|
69
|
+
expect_any_instance_of(Export).to receive(:aggregate_data).with('model_name', {:linked_model => 'linked_model'}, {:entry => 'test'}, 'path', :through)
|
|
70
|
+
@exporter.relationships({entry: 'test'}, 'path', 'aggregate_through', 'model_name', {linked_model: 'linked_model'})
|
|
71
|
+
end
|
|
72
|
+
it 'aggregate_many' do
|
|
73
|
+
expect_any_instance_of(Export).to receive(:aggregate_data).with('model_name', {:linked_model => 'linked_model'}, {:entry => 'test'}, 'path', :relation_to)
|
|
74
|
+
@exporter.relationships({entry: 'test'}, 'path', 'aggregate_many', 'model_name', {linked_model: 'linked_model'})
|
|
75
|
+
end
|
|
76
|
+
it 'aggregate_belongs' do
|
|
77
|
+
expect_any_instance_of(Export).to receive(:aggregate_belongs).with({:linked_model => 'linked_model'}, {:entry => 'test'}, 'path', :relation_to)
|
|
78
|
+
@exporter.relationships({entry: 'test'}, 'path', 'aggregate_belongs', 'model_name', {linked_model: 'linked_model'})
|
|
79
|
+
end
|
|
80
|
+
it 'aggregate_has_one' do
|
|
81
|
+
expect_any_instance_of(Export).to receive(:aggregate_has_one).with({:linked_model => 'linked_model'}, {:entry => 'test'}, 'path', :relation_to)
|
|
82
|
+
@exporter.relationships({entry: 'test'}, 'path', 'aggregate_has_one', 'model_name', {linked_model: 'linked_model'})
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
context 'contentful_field_attribute ' do
|
|
87
|
+
it 'type' do
|
|
88
|
+
result = @exporter.contentful_field_attribute('Profiles', 'Users', 'type')
|
|
89
|
+
expect(result).to eq 'Entry'
|
|
90
|
+
end
|
|
91
|
+
it 'id' do
|
|
92
|
+
result = @exporter.contentful_field_attribute('Profiles', 'Users', 'id')
|
|
93
|
+
expect(result).to eq 'user'
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'relations_from_mapping' do
|
|
98
|
+
result = @exporter.relations_from_mapping
|
|
99
|
+
expect(result['JobAdds']).to eq (load_fixture('settings/mapping')['JobAdds']['links'])
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it 'map_entry_relations' do
|
|
103
|
+
expect_any_instance_of(Export).to receive(:map_entry_relation).with('path', :relations, {relation_to: 'related_model', foreign_id: 'foreign_id'}, 'model_name')
|
|
104
|
+
@exporter.map_entry_relations('path', 'model_name', {relations: {relation_to: 'related_model', foreign_id: 'foreign_id'}}, 0)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it 'build_hash_with_associated_objects' do
|
|
108
|
+
object = @exporter.build_hash_with_associated_objects({'1' => [1, 2, 3], '2' => [4, 5]}, {'database_id' => 1}, 'image', 'asset')
|
|
109
|
+
expect(object).to be_a Array
|
|
110
|
+
expect(object.count).to eq 3
|
|
111
|
+
expect(object.first).to include('type' => 'File', 'id' => 'image_1')
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it 'save_has_one_entry' do
|
|
115
|
+
expect_any_instance_of(Export).to receive(:add_associated_object_to_file).with({'entry' => 'value'}, 'profiles', 'content_type_name', 'user_id', 'entry')
|
|
116
|
+
expect_any_instance_of(Export).to receive(:model_content_type) { 'content type name' }
|
|
117
|
+
@exporter.save_has_one_entry({relation_to: 'Profiles', primary_id: 'user_id'},
|
|
118
|
+
'profile', {'entry' => 'value'},
|
|
119
|
+
'entry_path',
|
|
120
|
+
:relation_to,
|
|
121
|
+
'entry')
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it 'save_belongs_to_entries' do
|
|
125
|
+
expect_any_instance_of(Export).to receive(:model_content_type) { 'content type name' }
|
|
126
|
+
expect_any_instance_of(Export).to receive(:write_json_to_file).with('entry_path', {'image_id' => 3, 'image' => {'type' => 'File', 'id' => 'content_type_name_3'}})
|
|
127
|
+
@exporter.save_belongs_to_entries({relation_to: 'Images', foreign_id: 'image_id'},
|
|
128
|
+
'Asset',
|
|
129
|
+
'image',
|
|
130
|
+
{'image_id' => 3},
|
|
131
|
+
'entry_path')
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it 'save_many_entries' do
|
|
135
|
+
expect_any_instance_of(Export).to receive(:model_content_type) { 'content type name' }
|
|
136
|
+
expect_any_instance_of(Export).to receive(:add_associated_object_to_file).with({'image_id' => 3}, 'comments', 'content_type_name', 'job_add_id', 'entry') { [image: 1] }
|
|
137
|
+
expect_any_instance_of(Export).to receive(:write_json_to_file).with('entry_path', {'image_id' => 3, 'comments' => [{:image => 1}]})
|
|
138
|
+
@exporter.save_many_entries({relation_to: 'Comments', primary_id: 'job_add_id'},
|
|
139
|
+
'comments',
|
|
140
|
+
{'image_id' => 3},
|
|
141
|
+
'entry_path',
|
|
142
|
+
:relation_to,
|
|
143
|
+
'entry')
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it 'map_many_association' do
|
|
147
|
+
expect_any_instance_of(Export).to receive(:contentful_field_attribute).with('model_name', 'Comments', :id) { 'ct_field_id' }
|
|
148
|
+
expect_any_instance_of(Export).to receive(:save_many_entries).with({:relation_to => 'Comments',
|
|
149
|
+
:primary_id => 'job_add_id'},
|
|
150
|
+
'ct_field_id',
|
|
151
|
+
{'entry' => 'value'},
|
|
152
|
+
'entry_path',
|
|
153
|
+
'related_to', 'entry')
|
|
154
|
+
@exporter.map_many_association('model_name',
|
|
155
|
+
{relation_to: 'Comments', primary_id: 'job_add_id'},
|
|
156
|
+
{'entry' => 'value'},
|
|
157
|
+
'entry_path',
|
|
158
|
+
'related_to')
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it 'aggregate_data' do
|
|
162
|
+
expect_any_instance_of(Export).to receive(:save_aggregated_entries).with(
|
|
163
|
+
{:relation_to => 'Comments', :primary_id => 'job_add_id'},
|
|
164
|
+
'ct_field_id',
|
|
165
|
+
{'entry' => 'value'},
|
|
166
|
+
'entry_path',
|
|
167
|
+
'related_to')
|
|
168
|
+
expect_any_instance_of(Export).to receive(:contentful_field_attribute).with('model_name', 'Comments', :id) { 'ct_field_id' }
|
|
169
|
+
@exporter.aggregate_data('model_name',
|
|
170
|
+
{:relation_to => 'Comments',
|
|
171
|
+
:primary_id => 'job_add_id'},
|
|
172
|
+
{'entry' => 'value'},
|
|
173
|
+
'entry_path',
|
|
174
|
+
'related_to')
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it 'aggregate_has_one' do
|
|
178
|
+
expect_any_instance_of(Export).to receive(:mapping) { {'Comments' => {content_type: 'related model dir'}} }
|
|
179
|
+
expect_any_instance_of(Export).to receive(:save_aggregated_has_one_data).with('entry_path', {'entry' => 'value'}, 'comments', 'related_model_dir', {:relation_to => 'Comments', :primary_id => 'job_add_id', :field => 'test'}, 'test')
|
|
180
|
+
@exporter.aggregate_has_one({relation_to: 'Comments',
|
|
181
|
+
primary_id: 'job_add_id', field: 'test'},
|
|
182
|
+
{'entry' => 'value'},
|
|
183
|
+
'entry_path',
|
|
184
|
+
:relation_to)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
it 'save_aggregated_entries' do
|
|
188
|
+
expect_any_instance_of(Export).to receive(:model_content_type) { 'comments' }
|
|
189
|
+
expect_any_instance_of(Export).to receive(:save_aggregated_object_to_file).with({'entry' => 'value'}, 'comments', 'comments', {:relation_to => 'Comments', :primary_id => 'job_add_id', :save_as => 'new_name'}) { [object: {type: 'entry'}] }
|
|
190
|
+
expect_any_instance_of(Export).to receive(:write_json_to_file).with('entry_path', {'entry' => 'value', 'ct_field_id' => [{:object => {:type => 'entry'}}]})
|
|
191
|
+
@exporter.save_aggregated_entries({:relation_to => 'Comments', :primary_id => 'job_add_id', save_as: 'new_name'},
|
|
192
|
+
'ct_field_id',
|
|
193
|
+
{'entry' => 'value'},
|
|
194
|
+
'entry_path',
|
|
195
|
+
:relation_to)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|