enju_biblio 0.3.10.rc.1 → 0.3.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/item_custom_properties_controller.rb +8 -3
  3. data/app/controllers/items_controller.rb +13 -2
  4. data/app/controllers/manifestation_custom_properties_controller.rb +8 -3
  5. data/app/controllers/manifestations_controller.rb +36 -48
  6. data/app/models/item.rb +9 -5
  7. data/app/models/item_custom_property.rb +7 -7
  8. data/app/models/item_custom_value.rb +3 -3
  9. data/app/models/manifestation.rb +38 -12
  10. data/app/models/manifestation_custom_property.rb +7 -7
  11. data/app/models/manifestation_custom_value.rb +3 -3
  12. data/app/models/picture_file.rb +0 -2
  13. data/app/models/resource_export_file.rb +4 -2
  14. data/app/models/resource_import_file.rb +74 -56
  15. data/app/policies/item_custom_property_policy.rb +3 -3
  16. data/app/policies/manifestation_custom_property_policy.rb +3 -3
  17. data/app/views/item_custom_properties/edit.html.erb +12 -5
  18. data/app/views/item_custom_properties/index.html.erb +14 -7
  19. data/app/views/item_custom_properties/new.html.erb +11 -4
  20. data/app/views/item_custom_properties/show.html.erb +24 -17
  21. data/app/views/items/_item.json.jbuilder +17 -0
  22. data/app/views/items/index.json.jbuilder +5 -0
  23. data/app/views/items/show.json.jbuilder +1 -0
  24. data/app/views/manifestation_custom_properties/edit.html.erb +12 -5
  25. data/app/views/manifestation_custom_properties/index.html.erb +14 -7
  26. data/app/views/manifestation_custom_properties/new.html.erb +11 -4
  27. data/app/views/manifestation_custom_properties/show.html.erb +24 -17
  28. data/app/views/manifestations/_export_detail.html.erb +1 -0
  29. data/app/views/manifestations/_export_list.html.erb +1 -0
  30. data/app/views/manifestations/_form.html.erb +5 -0
  31. data/app/views/manifestations/_show_detail_librarian.html.erb +6 -0
  32. data/app/views/manifestations/_show_detail_user.html.erb +8 -0
  33. data/app/views/manifestations/show.json.jbuilder +2 -0
  34. data/config/locales/translation_en.yml +2 -0
  35. data/config/locales/translation_ja.yml +2 -0
  36. data/db/migrate/20081027150907_create_picture_files.rb +0 -2
  37. data/lib/enju_biblio.rb +0 -2
  38. data/lib/enju_biblio/openurl.rb +5 -1
  39. data/lib/enju_biblio/version.rb +1 -1
  40. data/spec/controllers/item_custom_properties_controller_spec.rb +449 -0
  41. data/spec/controllers/items_controller_spec.rb +36 -0
  42. data/spec/controllers/manifestation_custom_properties_controller_spec.rb +449 -0
  43. data/spec/controllers/manifestations_controller_spec.rb +0 -19
  44. data/spec/dummy/db/schema.rb +0 -2
  45. data/spec/fixtures/creates.yml +2 -0
  46. data/spec/fixtures/item_custom_properties.yml +7 -7
  47. data/spec/fixtures/manifestation_custom_properties.yml +7 -7
  48. data/spec/fixtures/picture_files.yml +0 -2
  49. data/spec/fixtures/produces.yml +2 -0
  50. data/spec/fixtures/realizes.yml +2 -0
  51. data/spec/models/item_custom_property_spec.rb +7 -7
  52. data/spec/models/item_custom_value_spec.rb +3 -3
  53. data/spec/models/manifestation_custom_property_spec.rb +7 -7
  54. data/spec/models/manifestation_custom_value_spec.rb +3 -3
  55. data/spec/models/manifestation_spec.rb +1 -66
  56. data/spec/models/picture_file_spec.rb +0 -2
  57. data/spec/models/resource_export_file_spec.rb +61 -8
  58. data/spec/models/resource_import_file_spec.rb +5 -1
  59. data/spec/views/item_custom_properties/index.html.erb_spec.rb +1 -0
  60. data/spec/views/items/index.json.jbuilder_spec.rb +15 -0
  61. data/spec/views/items/show.json.jbuilder_spec.rb +15 -0
  62. data/spec/views/manifestation_custom_properties/index.html.erb_spec.rb +1 -0
  63. data/spec/views/manifestations/show.json.jbuilder_spec.rb +16 -0
  64. metadata +535 -525
  65. data/app/views/manifestations/explain.sru +0 -9
  66. data/app/views/manifestations/index.sru.builder +0 -101
  67. data/lib/enju_biblio/porta_cql.rb +0 -282
  68. data/lib/enju_biblio/sru.rb +0 -83
@@ -58,25 +58,6 @@ describe ManifestationsController do
58
58
  expect(response).to render_template('manifestations/index')
59
59
  end
60
60
 
61
- it 'assigns all manifestations as @manifestations in sru format without operation' do
62
- get :index, format: 'sru'
63
- assert_response :success
64
- expect(assigns(:manifestations)).to be_nil
65
- expect(response).to render_template('manifestations/explain')
66
- end
67
-
68
- it 'assigns all manifestations as @manifestations in sru format with operation' do
69
- get :index, params: { format: 'sru', operation: 'searchRetrieve', query: 'ruby' }
70
- expect(assigns(:manifestations)).to_not be_nil
71
- expect(response).to render_template('manifestations/index')
72
- end
73
-
74
- it 'assigns all manifestations as @manifestations in sru format with operation and title' do
75
- get :index, params: { format: 'sru', query: 'title=ruby', operation: 'searchRetrieve' }
76
- expect(assigns(:manifestations)).to_not be_nil
77
- expect(response).to render_template('manifestations/index')
78
- end
79
-
80
61
  it 'assigns all manifestations as @manifestations in openurl' do
81
62
  get :index, params: { api: 'openurl', title: 'ruby' }
82
63
  expect(assigns(:manifestations)).to_not be_nil
@@ -1072,9 +1072,7 @@ ActiveRecord::Schema.define(version: 2020_04_25_074822) do
1072
1072
  create_table "picture_files", force: :cascade do |t|
1073
1073
  t.integer "picture_attachable_id"
1074
1074
  t.string "picture_attachable_type"
1075
- t.string "content_type"
1076
1075
  t.text "title"
1077
- t.string "thumbnail"
1078
1076
  t.integer "position"
1079
1077
  t.datetime "created_at"
1080
1078
  t.datetime "updated_at"
@@ -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
@@ -14,11 +14,11 @@ two:
14
14
  #
15
15
  # Table name: item_custom_properties
16
16
  #
17
- # id :bigint not null, primary key
18
- # name :string not null
19
- # display_name :jsonb not null
20
- # note :text
21
- # position :integer default(1), not null
22
- # created_at :datetime not null
23
- # updated_at :datetime not null
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
24
  #
@@ -14,11 +14,11 @@ two:
14
14
  #
15
15
  # Table name: manifestation_custom_properties
16
16
  #
17
- # id :bigint not null, primary key
18
- # name :string not null
19
- # display_name :jsonb not null
20
- # note :text
21
- # position :integer default(1), not null
22
- # created_at :datetime not null
23
- # updated_at :datetime not null
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
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
@@ -8,11 +8,11 @@ end
8
8
  #
9
9
  # Table name: item_custom_properties
10
10
  #
11
- # id :bigint not null, primary key
12
- # name :string not null
13
- # display_name_translations :jsonb not null
14
- # note :text
15
- # position :integer default(1), not null
16
- # created_at :datetime not null
17
- # updated_at :datetime not null
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
18
  #
@@ -8,9 +8,9 @@ end
8
8
  #
9
9
  # Table name: item_custom_values
10
10
  #
11
- # id :bigint not null, primary key
12
- # item_custom_property_id :bigint not null
13
- # item_id :bigint not null
11
+ # id :integer not null, primary key
12
+ # item_custom_property_id :integer not null
13
+ # item_id :integer not null
14
14
  # value :text
15
15
  # created_at :datetime not null
16
16
  # updated_at :datetime not null
@@ -8,11 +8,11 @@ end
8
8
  #
9
9
  # Table name: manifestation_custom_properties
10
10
  #
11
- # id :bigint not null, primary key
12
- # name :string not null
13
- # display_name_translations :jsonb not null
14
- # note :text
15
- # position :integer default(1), not null
16
- # created_at :datetime not null
17
- # updated_at :datetime not null
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
18
  #
@@ -8,9 +8,9 @@ end
8
8
  #
9
9
  # Table name: manifestation_custom_values
10
10
  #
11
- # id :bigint not null, primary key
12
- # manifestation_custom_property_id :bigint not null
13
- # manifestation_id :bigint not null
11
+ # id :integer not null, primary key
12
+ # manifestation_custom_property_id :integer not null
13
+ # manifestation_id :integer not null
14
14
  # value :text
15
15
  # created_at :datetime not null
16
16
  # updated_at :datetime not null
@@ -98,71 +98,6 @@ describe Manifestation, solr: true do
98
98
  lambda{Openurl.new({aufirst: "テスト 名称"})}.should raise_error(OpenurlQuerySyntaxError)
99
99
  end
100
100
 
101
- it "should search in sru" do
102
- sru = Sru.new({query: "title=Ruby"})
103
- sru.search
104
- sru.manifestations.size.should eq 18
105
- sru.manifestations.first.titles.first.should eq 'Ruby'
106
- sru = Sru.new({query: "title=^ruby"})
107
- sru.search
108
- sru.manifestations.size.should eq 9
109
- sru = Sru.new({query: 'title ALL "awk sed"'})
110
- sru.search
111
- sru.manifestations.size.should eq 2
112
- sru.manifestations.collect{|m| m.id}.should eq [184, 116]
113
- sru = Sru.new({query: 'title ANY "ruby awk sed"'})
114
- sru.search
115
- sru.manifestations.size.should eq 22
116
- sru = Sru.new({query: 'isbn=9784756137470'})
117
- sru.search
118
- sru.manifestations.first.id.should eq 114
119
- sru = Sru.new({query: "creator=テスト"})
120
- sru.search
121
- sru.manifestations.size.should eq 1
122
- end
123
-
124
- it "should search date in sru" do
125
- sru = Sru.new({query: "from = 2000-09 AND until = 2000-11-01"})
126
- sru.search
127
- sru.manifestations.size.should eq 1
128
- sru.manifestations.first.id.should eq 120
129
- sru = Sru.new({query: "from = 1993-02-24"})
130
- sru.search
131
- sru.manifestations.size.should eq 5
132
- sru = Sru.new({query: "until = 2006-08-06"})
133
- sru.search
134
- sru.manifestations.size.should eq 4
135
- end
136
-
137
- it "should accept sort_by in sru" do
138
- sru = Sru.new({query: "title=Ruby"})
139
- sru.sort_by.should eq({sort_by: 'created_at', order: 'desc'})
140
- sru = Sru.new({query: 'title=Ruby AND sortBy="title/sort.ascending"', sortKeys: 'creator,0', version: '1.2'})
141
- sru.sort_by.should eq({sort_by: 'sort_title', order: 'asc'})
142
- sru = Sru.new({query: 'title=Ruby AND sortBy="title/sort.ascending"', sortKeys: 'creator,0', version: '1.1'})
143
- sru.sort_by.should eq({sort_by: 'creator', order: 'desc'})
144
- sru = Sru.new({query: 'title=Ruby AND sortBy="title/sort.ascending"', sortKeys: 'creator,1', version: '1.1'})
145
- sru.sort_by.should eq({sort_by: 'creator', order: 'asc'})
146
- sru = Sru.new({query: 'title=Ruby AND sortBy="title'})
147
- sru.sort_by.should eq({sort_by: 'sort_title', order: 'asc'})
148
- # TODO ソート基準が入手しやすさの場合の処理
149
- end
150
-
151
- it "should accept ranges in sru" do
152
- sru = Sru.new({query: "from = 1993-02-24 AND until = 2006-08-06 AND title=プログラミング"})
153
- sru.search
154
- sru.manifestations.size.should eq 2
155
- sru = Sru.new({query: "until = 2000 AND title=プログラミング"})
156
- sru.search
157
- sru.manifestations.size.should eq 1
158
- sru = Sru.new({query: "from = 2006 AND title=プログラミング"})
159
- sru.search
160
- sru.manifestations.size.should eq 1
161
- sru = Sru.new({query: "from = 2007 OR title=awk"})
162
- sru.search
163
- sru.manifestations.size.should eq 6
164
- end
165
-
166
101
  it "should_get_number_of_pages" do
167
102
  manifestations(:manifestation_00001).number_of_pages.should eq 100
168
103
  end
@@ -261,7 +196,7 @@ describe Manifestation, solr: true do
261
196
  lines = Manifestation.export()
262
197
  csv = CSV.parse(lines, headers: true, col_sep: "\t")
263
198
  m = csv.find{|row| row["manifestation_id"].to_i == manifestation.id }
264
- expect(m["isbn"]).to eq "9784043898039//9784840239219"
199
+ expect(m["identifier:isbn"]).to eq "9784043898039//9784840239219"
265
200
  end
266
201
 
267
202
  it "should respect the role of the user" do
@@ -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
@@ -380,7 +380,11 @@ resource_import_file_test_description test\\ntest test\\ntest test_description t
380
380
  item_00003.include_supplements.should be_truthy
381
381
 
382
382
  Item.find_by(item_identifier: '00004').include_supplements.should be_falsy
383
- Item.find_by(item_identifier: '00025').call_number.should eq "547|ヤ"
383
+
384
+ item_00025 = Item.find_by(item_identifier: '00025')
385
+ expect(item_00025.manifestation.original_title).to eq "テスト4"
386
+ expect(item_00025.manifestation.subjects.pluck(:term)).to eq ['test2', 'test3']
387
+ expect(item_00025.call_number).to eq "547|ヤ"
384
388
  end
385
389
 
386
390
  it "should update custom values", vcr: true do
@@ -17,6 +17,7 @@ RSpec.describe "item_custom_properties/index", type: :view do
17
17
  end
18
18
 
19
19
  it "renders a list of item_custom_properties" do
20
+ allow(view).to receive(:policy).and_return double(create?: true, update?: true, destroy?: true)
20
21
  render
21
22
  assert_select "tr>td", text: "name1".to_s, count: 1
22
23
  assert_select "tr>td", text: "MyText".to_s, count: 2
@@ -0,0 +1,15 @@
1
+ require "rails_helper.rb"
2
+
3
+ describe "items/index.json.jbuilder", solr: true do
4
+ before(:each) do
5
+ item = FactoryBot.create(:item)
6
+ @items = assign(:items, [item] )
7
+ end
8
+
9
+ it "should export JSON format" do
10
+ params[:format] = "json"
11
+ render
12
+ expect(rendered).not_to match(/memo/)
13
+ end
14
+ end
15
+
@@ -0,0 +1,15 @@
1
+ require 'rails_helper'
2
+
3
+ describe "items/show.json.jbuilder" do
4
+ fixtures :all
5
+
6
+ before(:each) do
7
+ assign(:item, FactoryBot.create(:item))
8
+ end
9
+
10
+ it "renders a template" do
11
+ render
12
+ expect(rendered).to match(/item_identifier/)
13
+ expect(rendered).not_to match(/memo/)
14
+ end
15
+ end