enju_biblio 0.3.9 → 0.3.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/content_types_controller.rb +1 -1
  3. data/app/controllers/item_custom_properties_controller.rb +69 -0
  4. data/app/controllers/items_controller.rb +3 -0
  5. data/app/controllers/manifestation_custom_properties_controller.rb +69 -0
  6. data/app/controllers/manifestations_controller.rb +9 -6
  7. data/app/controllers/resource_import_results_controller.rb +6 -2
  8. data/app/models/agent_type.rb +0 -1
  9. data/app/models/carrier_type.rb +0 -1
  10. data/app/models/content_type.rb +0 -1
  11. data/app/models/form_of_work.rb +1 -2
  12. data/app/models/frequency.rb +0 -1
  13. data/app/models/identifier_type.rb +0 -1
  14. data/app/models/item.rb +17 -6
  15. data/app/models/item_custom_property.rb +18 -0
  16. data/app/models/item_custom_value.rb +17 -0
  17. data/app/models/license.rb +0 -1
  18. data/app/models/manifestation.rb +55 -11
  19. data/app/models/manifestation_custom_property.rb +18 -0
  20. data/app/models/manifestation_custom_value.rb +17 -0
  21. data/app/models/medium_of_performance.rb +1 -2
  22. data/app/models/picture_file.rb +0 -2
  23. data/app/models/resource_export_file.rb +4 -2
  24. data/app/models/resource_import_file.rb +151 -61
  25. data/app/policies/item_custom_property_policy.rb +21 -0
  26. data/app/policies/manifestation_custom_property_policy.rb +21 -0
  27. data/app/views/item_custom_properties/_form.html.erb +32 -0
  28. data/app/views/item_custom_properties/edit.html.erb +13 -0
  29. data/app/views/item_custom_properties/index.html.erb +43 -0
  30. data/app/views/item_custom_properties/new.html.erb +12 -0
  31. data/app/views/item_custom_properties/show.html.erb +28 -0
  32. data/app/views/items/_form.html.erb +13 -0
  33. data/app/views/items/show.html.erb +6 -0
  34. data/app/views/manifestation_custom_properties/_form.html.erb +32 -0
  35. data/app/views/manifestation_custom_properties/edit.html.erb +13 -0
  36. data/app/views/manifestation_custom_properties/index.html.erb +43 -0
  37. data/app/views/manifestation_custom_properties/new.html.erb +12 -0
  38. data/app/views/manifestation_custom_properties/show.html.erb +28 -0
  39. data/app/views/manifestations/_export_detail.html.erb +1 -0
  40. data/app/views/manifestations/_export_list.html.erb +1 -0
  41. data/app/views/manifestations/_form.html.erb +18 -0
  42. data/app/views/manifestations/_show_detail_librarian.html.erb +14 -0
  43. data/app/views/manifestations/_show_detail_user.html.erb +8 -0
  44. data/app/views/manifestations/show.json.jbuilder +2 -0
  45. data/app/views/picture_files/edit.html.erb +4 -0
  46. data/config/locales/translation_en.yml +22 -8
  47. data/config/locales/translation_ja.yml +22 -8
  48. data/config/routes.rb +2 -0
  49. data/db/migrate/20081027150907_create_picture_files.rb +0 -2
  50. data/db/migrate/20200425072340_create_manifestation_custom_properties.rb +12 -0
  51. data/db/migrate/20200425072349_create_item_custom_properties.rb +12 -0
  52. data/db/migrate/20200425074758_create_manifestation_custom_values.rb +12 -0
  53. data/db/migrate/20200425074822_create_item_custom_values.rb +12 -0
  54. data/lib/enju_biblio/openurl.rb +5 -1
  55. data/lib/enju_biblio/sru.rb +2 -0
  56. data/lib/enju_biblio/version.rb +1 -1
  57. data/spec/cassette_library/ResourceImportFile/when_its_mode_is_create_/when_it_is_written_in_utf-8/should_import_custom_values.yml +121 -0
  58. data/spec/cassette_library/resource_import_results/index_txt_ruby/renders_a_list_of_resource_import_results.yml +121 -0
  59. data/spec/controllers/content_types_controller_spec.rb +1 -1
  60. data/spec/controllers/item_custom_properties_controller_spec.rb +449 -0
  61. data/spec/controllers/items_controller_spec.rb +22 -0
  62. data/spec/controllers/manifestation_custom_properties_controller_spec.rb +449 -0
  63. data/spec/controllers/manifestations_controller_spec.rb +22 -0
  64. data/spec/dummy/db/schema.rb +43 -23
  65. data/spec/factories/item_custom_property.rb +6 -0
  66. data/spec/factories/item_custom_value.rb +6 -0
  67. data/spec/factories/manifestation_custom_property.rb +6 -0
  68. data/spec/factories/manifestation_custom_value.rb +6 -0
  69. data/spec/fixtures/creates.yml +2 -0
  70. data/spec/fixtures/item_custom_properties.yml +24 -0
  71. data/spec/fixtures/library_groups.yml +0 -2
  72. data/spec/fixtures/manifestation_custom_properties.yml +24 -0
  73. data/spec/fixtures/picture_files.yml +0 -2
  74. data/spec/fixtures/produces.yml +2 -0
  75. data/spec/fixtures/realizes.yml +2 -0
  76. data/spec/models/item_custom_property_spec.rb +18 -0
  77. data/spec/models/item_custom_value_spec.rb +17 -0
  78. data/spec/models/manifestation_custom_property_spec.rb +18 -0
  79. data/spec/models/manifestation_custom_value_spec.rb +17 -0
  80. data/spec/models/manifestation_spec.rb +16 -1
  81. data/spec/models/picture_file_spec.rb +0 -2
  82. data/spec/models/resource_export_file_spec.rb +61 -8
  83. data/spec/models/resource_import_file_spec.rb +43 -13
  84. data/spec/requests/item_custom_properties_spec.rb +129 -0
  85. data/spec/requests/manifestation_custom_properties_spec.rb +129 -0
  86. data/spec/routing/item_custom_properties_routing_spec.rb +38 -0
  87. data/spec/routing/manifestation_custom_properties_routing_spec.rb +38 -0
  88. data/spec/system/items_spec.rb +12 -0
  89. data/spec/system/manifestations_spec.rb +12 -0
  90. data/spec/views/item_custom_properties/edit.html.erb_spec.rb +21 -0
  91. data/spec/views/item_custom_properties/index.html.erb_spec.rb +25 -0
  92. data/spec/views/item_custom_properties/new.html.erb_spec.rb +21 -0
  93. data/spec/views/item_custom_properties/show.html.erb_spec.rb +16 -0
  94. data/spec/views/manifestation_custom_properties/edit.html.erb_spec.rb +21 -0
  95. data/spec/views/manifestation_custom_properties/index.html.erb_spec.rb +25 -0
  96. data/spec/views/manifestation_custom_properties/new.html.erb_spec.rb +21 -0
  97. data/spec/views/manifestation_custom_properties/show.html.erb_spec.rb +16 -0
  98. data/spec/views/manifestations/show.json.jbuilder_spec.rb +16 -0
  99. data/spec/views/resource_import_results/index.txt.ruby_spec.rb +4 -4
  100. metadata +560 -481
  101. data/db/migrate/20200322053443_add_default_custom_label_to_library_group.rb +0 -6
  102. data/db/migrate/20200322083313_create_custom_labels.rb +0 -10
  103. data/db/migrate/20200322083458_create_custom_properties.rb +0 -12
@@ -575,6 +575,12 @@ describe ManifestationsController do
575
575
  post :create, params: { manifestation: @attrs.merge(attachment: fixture_file_upload('/../../examples/resource_import_file_sample1.tsv', 'text/csv')) }
576
576
  expect(assigns(:manifestation)).to be_valid
577
577
  end
578
+
579
+ it 'accepts custom values' do
580
+ post :create, params: { manifestation: @attrs.merge(manifestation_custom_values_attributes: Array.new(3){FactoryBot.attributes_for(:manifestation_custom_value, manifestation_custom_property_id: FactoryBot.create(:manifestation_custom_property).id)}) }
581
+ expect(assigns(:manifestation)).to be_valid
582
+ expect(assigns(:manifestation).manifestation_custom_values.count).to eq 3
583
+ end
578
584
  end
579
585
 
580
586
  describe 'with invalid params' do
@@ -716,6 +722,22 @@ describe ManifestationsController do
716
722
  }
717
723
  expect(assigns(:manifestation)).to eq @manifestation
718
724
  end
725
+
726
+ it 'accepts custom values' do
727
+ @manifestation.manifestation_custom_values << FactoryBot.build(:manifestation_custom_value)
728
+ put :update, params: { id: @manifestation.id, manifestation: @attrs.merge(manifestation_custom_values_attributes: [{id: @manifestation.manifestation_custom_values.first.id, value: 'test'}]) }
729
+ expect(assigns(:manifestation)).to be_valid
730
+ expect(assigns(:manifestation).manifestation_custom_values.count).to eq 1
731
+ expect(assigns(:manifestation).manifestation_custom_values.first.value).to eq 'test'
732
+ end
733
+
734
+ it 'accepts custom values when the value is empty' do
735
+ @manifestation.manifestation_custom_values << FactoryBot.build(:manifestation_custom_value)
736
+ put :update, params: { id: @manifestation.id, manifestation: @attrs.merge(manifestation_custom_values_attributes: [{id: @manifestation.manifestation_custom_values.first.id, value: ''}]) }
737
+ expect(assigns(:manifestation)).to be_valid
738
+ expect(assigns(:manifestation).manifestation_custom_values.count).to eq 1
739
+ expect(assigns(:manifestation).manifestation_custom_values.first.value).to eq ''
740
+ end
719
741
  end
720
742
 
721
743
  describe 'with invalid params' do
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 2020_03_22_083458) do
13
+ ActiveRecord::Schema.define(version: 2020_04_25_074822) do
14
14
 
15
15
  create_table "accepts", force: :cascade do |t|
16
16
  t.integer "basket_id"
@@ -433,24 +433,6 @@ ActiveRecord::Schema.define(version: 2020_03_22_083458) do
433
433
  t.index ["work_id"], name: "index_creates_on_work_id"
434
434
  end
435
435
 
436
- create_table "custom_labels", force: :cascade do |t|
437
- t.integer "library_group_id", null: false
438
- t.string "label"
439
- t.datetime "created_at", null: false
440
- t.datetime "updated_at", null: false
441
- t.index ["library_group_id"], name: "index_custom_labels_on_library_group_id"
442
- end
443
-
444
- create_table "custom_properties", force: :cascade do |t|
445
- t.integer "resource_id", null: false
446
- t.string "resource_type", null: false
447
- t.integer "custom_label_id", null: false
448
- t.text "value"
449
- t.datetime "created_at", null: false
450
- t.datetime "updated_at", null: false
451
- t.index ["custom_label_id"], name: "index_custom_properties_on_custom_label_id"
452
- end
453
-
454
436
  create_table "demands", force: :cascade do |t|
455
437
  t.integer "user_id"
456
438
  t.integer "item_id"
@@ -662,6 +644,27 @@ ActiveRecord::Schema.define(version: 2020_03_22_083458) do
662
644
  t.index ["user_id"], name: "index_inventory_files_on_user_id"
663
645
  end
664
646
 
647
+ create_table "item_custom_properties", force: :cascade do |t|
648
+ t.string "name", null: false
649
+ t.text "display_name", null: false
650
+ t.text "note"
651
+ t.integer "position", default: 1, null: false
652
+ t.datetime "created_at", null: false
653
+ t.datetime "updated_at", null: false
654
+ t.index ["name"], name: "index_item_custom_properties_on_name", unique: true
655
+ end
656
+
657
+ create_table "item_custom_values", force: :cascade do |t|
658
+ t.integer "item_custom_property_id", null: false
659
+ t.integer "item_id", null: false
660
+ t.text "value"
661
+ t.datetime "created_at", null: false
662
+ t.datetime "updated_at", null: false
663
+ t.index ["item_custom_property_id", "item_id"], name: "index_item_custom_values_on_custom_item_property_and_item_id", unique: true
664
+ t.index ["item_custom_property_id"], name: "index_item_custom_values_on_custom_property_id"
665
+ t.index ["item_id"], name: "index_item_custom_values_on_item_id"
666
+ end
667
+
665
668
  create_table "item_has_use_restrictions", force: :cascade do |t|
666
669
  t.integer "item_id", null: false
667
670
  t.integer "use_restriction_id", null: false
@@ -802,8 +805,6 @@ ActiveRecord::Schema.define(version: 2020_03_22_083458) do
802
805
  t.integer "header_logo_file_size"
803
806
  t.datetime "header_logo_updated_at"
804
807
  t.text "header_logo_meta"
805
- t.text "default_custom_manifestation_label"
806
- t.text "default_custom_item_label"
807
808
  t.index ["short_name"], name: "index_library_groups_on_short_name"
808
809
  t.index ["user_id"], name: "index_library_groups_on_user_id"
809
810
  end
@@ -842,6 +843,27 @@ ActiveRecord::Schema.define(version: 2020_03_22_083458) do
842
843
  t.index ["user_id"], name: "index_manifestation_checkout_stats_on_user_id"
843
844
  end
844
845
 
846
+ create_table "manifestation_custom_properties", force: :cascade do |t|
847
+ t.string "name", null: false
848
+ t.text "display_name", null: false
849
+ t.text "note"
850
+ t.integer "position", default: 1, null: false
851
+ t.datetime "created_at", null: false
852
+ t.datetime "updated_at", null: false
853
+ t.index ["name"], name: "index_manifestation_custom_properties_on_name", unique: true
854
+ end
855
+
856
+ create_table "manifestation_custom_values", force: :cascade do |t|
857
+ t.integer "manifestation_custom_property_id", null: false
858
+ t.integer "manifestation_id", null: false
859
+ t.text "value"
860
+ t.datetime "created_at", null: false
861
+ t.datetime "updated_at", null: false
862
+ t.index ["manifestation_custom_property_id", "manifestation_id"], name: "index_manifestation_custom_values_on_property_manifestation", unique: true
863
+ t.index ["manifestation_custom_property_id"], name: "index_manifestation_custom_values_on_custom_property_id"
864
+ t.index ["manifestation_id"], name: "index_manifestation_custom_values_on_manifestation_id"
865
+ end
866
+
845
867
  create_table "manifestation_relationship_types", force: :cascade do |t|
846
868
  t.string "name", null: false
847
869
  t.text "display_name"
@@ -1050,9 +1072,7 @@ ActiveRecord::Schema.define(version: 2020_03_22_083458) do
1050
1072
  create_table "picture_files", force: :cascade do |t|
1051
1073
  t.integer "picture_attachable_id"
1052
1074
  t.string "picture_attachable_type"
1053
- t.string "content_type"
1054
1075
  t.text "title"
1055
- t.string "thumbnail"
1056
1076
  t.integer "position"
1057
1077
  t.datetime "created_at"
1058
1078
  t.datetime "updated_at"
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :item_custom_property do
3
+ sequence(:name){|n| "property_name_#{n}"}
4
+ sequence(:display_name){|n| "プロパティ名_#{n}"}
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :item_custom_value do
3
+ association :item_custom_property
4
+ sequence(:value){|n| "value_#{n}"}
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :manifestation_custom_property do
3
+ sequence(:name){|n| "property_name_#{n}"}
4
+ sequence(:display_name){|n| "プロパティ名_#{n}"}
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :manifestation_custom_value do
3
+ association :manifestation_custom_property
4
+ sequence(:value){|n| "value_#{n}"}
5
+ end
6
+ end
@@ -2,6 +2,7 @@
2
2
  create_00001:
3
3
  updated_at: 2007-12-13 19:56:07.002082 +09:00
4
4
  agent_id: 1
5
+ create_type_id: 1
5
6
  id: 1
6
7
  work_id: 1
7
8
  position: 1
@@ -9,6 +10,7 @@ create_00001:
9
10
  create_00002:
10
11
  updated_at: 2007-12-13 19:56:48.538796 +09:00
11
12
  agent_id: 1
13
+ create_type_id: 1
12
14
  id: 2
13
15
  work_id: 2
14
16
  position: 1
@@ -0,0 +1,24 @@
1
+ one:
2
+ id: 1
3
+ name: custom_1
4
+ display_name: "カスタム項目1"
5
+ position: 1
6
+
7
+ two:
8
+ id: 2
9
+ name: custom_2
10
+ display_name: "カスタム項目1"
11
+ position: 2
12
+
13
+ # == Schema Information
14
+ #
15
+ # Table name: item_custom_properties
16
+ #
17
+ # id :integer not null, primary key
18
+ # name :string not null
19
+ # display_name :text not null
20
+ # note :text
21
+ # position :integer default(1), not null
22
+ # created_at :datetime not null
23
+ # updated_at :datetime not null
24
+ #
@@ -14,8 +14,6 @@ one:
14
14
  ::/0"
15
15
  user_id: 1
16
16
  pub_year_facet_range_interval: 10
17
- default_custom_manifestation_label: "custom1\r\ncustom2\r\ncustom3"
18
- default_custom_item_label: "custom1\r\ncustom2\r\ncustom3"
19
17
 
20
18
  # == Schema Information
21
19
  #
@@ -0,0 +1,24 @@
1
+ one:
2
+ id: 1
3
+ name: custom_1
4
+ display_name: "カスタム項目1"
5
+ position: 1
6
+
7
+ two:
8
+ id: 2
9
+ name: custom_2
10
+ display_name: "カスタム項目1"
11
+ position: 2
12
+
13
+ # == Schema Information
14
+ #
15
+ # Table name: manifestation_custom_properties
16
+ #
17
+ # id :integer not null, primary key
18
+ # name :string not null
19
+ # display_name :text not null
20
+ # note :text
21
+ # position :integer default(1), not null
22
+ # created_at :datetime not null
23
+ # updated_at :datetime not null
24
+ #
@@ -47,9 +47,7 @@ picture_file_00004:
47
47
  # id :integer not null, primary key
48
48
  # picture_attachable_id :integer
49
49
  # picture_attachable_type :string
50
- # content_type :string
51
50
  # title :text
52
- # thumbnail :string
53
51
  # position :integer
54
52
  # created_at :datetime
55
53
  # updated_at :datetime
@@ -3,6 +3,7 @@ produce_00001:
3
3
  updated_at: 2008-01-11 23:28:19.277110 +09:00
4
4
  manifestation_id: 1
5
5
  agent_id: 1
6
+ produce_type_id: 1
6
7
  id: 1
7
8
  position: 1
8
9
  created_at: 2008-01-11 23:28:19.277110 +09:00
@@ -10,6 +11,7 @@ produce_00002:
10
11
  updated_at: 2008-01-11 23:28:57.068191 +09:00
11
12
  manifestation_id: 2
12
13
  agent_id: 2
14
+ produce_type_id: 1
13
15
  id: 2
14
16
  position: 1
15
17
  created_at: 2008-01-11 23:28:57.068191 +09:00
@@ -3,6 +3,7 @@ realize_00001:
3
3
  updated_at: 2008-01-11 23:28:19.277110 +09:00
4
4
  expression_id: 1
5
5
  agent_id: 1
6
+ realize_type_id: 1
6
7
  id: 1
7
8
  position: 1
8
9
  created_at: 2008-01-11 23:28:19.277110 +09:00
@@ -10,6 +11,7 @@ realize_00002:
10
11
  updated_at: 2008-01-11 23:28:57.068191 +09:00
11
12
  expression_id: 2
12
13
  agent_id: 2
14
+ realize_type_id: 1
13
15
  id: 2
14
16
  position: 2
15
17
  created_at: 2008-01-11 23:28:57.068191 +09:00
@@ -0,0 +1,18 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe ItemCustomProperty, type: :model do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
6
+
7
+ # == Schema Information
8
+ #
9
+ # Table name: item_custom_properties
10
+ #
11
+ # id :integer not null, primary key
12
+ # name :string not null
13
+ # display_name :text not null
14
+ # note :text
15
+ # position :integer default(1), not null
16
+ # created_at :datetime not null
17
+ # updated_at :datetime not null
18
+ #
@@ -0,0 +1,17 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe ItemCustomValue, type: :model do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
6
+
7
+ # == Schema Information
8
+ #
9
+ # Table name: item_custom_values
10
+ #
11
+ # id :integer not null, primary key
12
+ # item_custom_property_id :integer not null
13
+ # item_id :integer not null
14
+ # value :text
15
+ # created_at :datetime not null
16
+ # updated_at :datetime not null
17
+ #
@@ -0,0 +1,18 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe ManifestationCustomProperty, type: :model do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
6
+
7
+ # == Schema Information
8
+ #
9
+ # Table name: manifestation_custom_properties
10
+ #
11
+ # id :integer not null, primary key
12
+ # name :string not null
13
+ # display_name :text not null
14
+ # note :text
15
+ # position :integer default(1), not null
16
+ # created_at :datetime not null
17
+ # updated_at :datetime not null
18
+ #
@@ -0,0 +1,17 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe ManifestationCustomValue, type: :model do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
6
+
7
+ # == Schema Information
8
+ #
9
+ # Table name: manifestation_custom_values
10
+ #
11
+ # id :integer not null, primary key
12
+ # manifestation_custom_property_id :integer not null
13
+ # manifestation_id :integer not null
14
+ # value :text
15
+ # created_at :datetime not null
16
+ # updated_at :datetime not null
17
+ #
@@ -261,7 +261,7 @@ describe Manifestation, solr: true do
261
261
  lines = Manifestation.export()
262
262
  csv = CSV.parse(lines, headers: true, col_sep: "\t")
263
263
  m = csv.find{|row| row["manifestation_id"].to_i == manifestation.id }
264
- expect(m["isbn"]).to eq "9784043898039//9784840239219"
264
+ expect(m["identifier:isbn"]).to eq "9784043898039//9784840239219"
265
265
  end
266
266
 
267
267
  it "should respect the role of the user" do
@@ -292,6 +292,21 @@ describe Manifestation, solr: true do
292
292
  expect(m["note"]).to eq "test\ntest"
293
293
  expect(m["item_note"]).to eq "test\ntest"
294
294
  end
295
+
296
+ it 'should export custom properties"' do
297
+ item = FactoryBot.create(:item)
298
+ item.item_custom_values << FactoryBot.build(:item_custom_value)
299
+ item.manifestation.manifestation_custom_values << FactoryBot.build(:manifestation_custom_value)
300
+ lines = Manifestation.export(role: 'Librarian')
301
+ csv = CSV.parse(lines, headers: true, col_sep: "\t")
302
+ m = csv.find{|row| row["manifestation_id"].to_i == item.manifestation.id }
303
+ item.item_custom_values.each do |custom_value|
304
+ expect(m["item:#{custom_value.item_custom_property.name}"]).to eq custom_value.value
305
+ end
306
+ item.manifestation.manifestation_custom_values.each do |custom_value|
307
+ expect(m["manifestation:#{custom_value.manifestation_custom_property.name}"]).to eq custom_value.value
308
+ end
309
+ end
295
310
  end
296
311
  end
297
312
 
@@ -12,9 +12,7 @@ end
12
12
  # id :integer not null, primary key
13
13
  # picture_attachable_id :integer
14
14
  # picture_attachable_type :string
15
- # content_type :string
16
15
  # title :text
17
- # thumbnail :string
18
16
  # position :integer
19
17
  # created_at :datetime
20
18
  # updated_at :datetime
@@ -26,10 +26,10 @@ describe ResourceExportFile do
26
26
  expect(columns).to include "item_price"
27
27
  end
28
28
 
29
- it "should export NCID value" do
29
+ it "should export custom identifier's value" do
30
30
  manifestation = FactoryBot.create(:manifestation)
31
- ncid = IdentifierType.find_by(name: "ncid")
32
- identifier = FactoryBot.create(:identifier, identifier_type: ncid, body: "BA91833159")
31
+ custom = IdentifierType.find_by(name: "custom")
32
+ identifier = FactoryBot.create(:identifier, identifier_type: custom, body: "a11223344")
33
33
  export_file = ResourceExportFile.new
34
34
  export_file.user = users(:admin)
35
35
  export_file.save!
@@ -37,8 +37,8 @@ describe ResourceExportFile do
37
37
  file = export_file.resource_export
38
38
  expect(file).to be_truthy
39
39
  lines = File.open(file.path).readlines.map(&:chomp)
40
- expect(lines.first.split(/\t/)).to include "ncid"
41
- expect(lines.last.split(/\t/)).to include "BA91833159"
40
+ expect(lines.first.split(/\t/)).to include "identifier:custom"
41
+ expect(lines.last.split(/\t/)).to include "a11223344"
42
42
  end
43
43
 
44
44
  it "should export carrier_type" do
@@ -50,9 +50,7 @@ describe ResourceExportFile do
50
50
  export_file.save!
51
51
  export_file.export!
52
52
  file = export_file.resource_export
53
- expect(file).to be_truthy
54
- csv = CSV.open(file.path, {headers: true, col_sep: "\t"})
55
- csv.each do |row|
53
+ CSV.open(file.path, {headers: true, col_sep: "\t"}).each do |row|
56
54
  expect(row).to have_key "carrier_type"
57
55
  case row["manifestation_id"].to_i
58
56
  when 1
@@ -62,6 +60,61 @@ describe ResourceExportFile do
62
60
  end
63
61
  end
64
62
  end
63
+
64
+ it "should export create_type, realize_type and produce_type" do
65
+ export_file = ResourceExportFile.new
66
+ export_file.user = users(:admin)
67
+ export_file.save!
68
+ export_file.export!
69
+ file = export_file.resource_export
70
+ CSV.open(file.path, {headers: true, col_sep: "\t"}).each do |row|
71
+ manifestation = Manifestation.find(row['manifestation_id'])
72
+ manifestation.creates.each do |create|
73
+ if create.create_type
74
+ expect(row['creator']).to match "#{create.agent.full_name}||#{create.create_type.name}"
75
+ end
76
+ end
77
+
78
+ manifestation.realizes.each do |realize|
79
+ if realize.realize_type
80
+ expect(row['contributor']).to match "#{realize.agent.full_name}||#{realize.realize_type.name}"
81
+ end
82
+ end
83
+
84
+ manifestation.produces.each do |produce|
85
+ if produce.produce_type
86
+ expect(row['publisher']).to match "#{produce.agent.full_name}||#{produce.produce_type.name}"
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ it "should export custom properties" do
93
+ item = FactoryBot.create(:item)
94
+ 3.times do
95
+ item.manifestation.manifestation_custom_values << FactoryBot.build(:manifestation_custom_value)
96
+ end
97
+ 3.times do
98
+ item.item_custom_values << FactoryBot.build(:item_custom_value)
99
+ end
100
+ export_file = ResourceExportFile.new
101
+ export_file.user = users(:admin)
102
+ export_file.save!
103
+ export_file.export!
104
+ file = export_file.resource_export
105
+ CSV.open(file.path, {headers: true, col_sep: "\t"}).each do |row|
106
+ if row['manifestation_id'] == item.manifestation.id
107
+ item.manifestation_custom_values.each do |value|
108
+ expect(row).to have_key "manifestation:#{value.manifestation_custom_property.name}"
109
+ expect(row["manifestation:#{value.manifestation_custom_property.name}"]).to eq value
110
+ end
111
+ item.item_custom_values.each do |value|
112
+ expect(row).to have_key "item:#{value.item_custom_property.name}"
113
+ expect(row["item:#{value.item_custom_property.name}"]).to eq value
114
+ end
115
+ end
116
+ end
117
+ end
65
118
  end
66
119
 
67
120
  # == Schema Information