enju_biblio 0.1.0.pre69 → 0.1.0.pre70

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/items_controller.rb +5 -5
  3. data/app/controllers/manifestations_controller.rb +10 -85
  4. data/app/controllers/resource_import_files_controller.rb +1 -0
  5. data/app/models/enju_biblio/ability.rb +29 -19
  6. data/app/models/manifestation.rb +38 -11
  7. data/app/models/resource_import_file.rb +35 -12
  8. data/app/models/resource_import_file_state_machine.rb +1 -1
  9. data/app/views/agent_types/_form.html.erb +2 -1
  10. data/app/views/agents/_form.html.erb +1 -1
  11. data/app/views/import_requests/new.html.erb +2 -2
  12. data/app/views/items/_form.html.erb +7 -0
  13. data/app/views/items/edit.html.erb +0 -1
  14. data/app/views/items/new.html.erb +0 -1
  15. data/app/views/manifestations/_colorbox.html.erb +5 -0
  16. data/app/views/manifestations/_export_detail.html.erb +7 -0
  17. data/app/views/manifestations/_export_list.html.erb +6 -0
  18. data/app/views/manifestations/_manifestation.txt.erb +1 -0
  19. data/app/views/manifestations/index.html.erb +1 -0
  20. data/app/views/manifestations/index.txt.erb +2 -4
  21. data/app/views/manifestations/show.html.erb +2 -5
  22. data/app/views/manifestations/show.txt.erb +2 -0
  23. data/app/views/resource_import_files/_results.html.erb +23 -0
  24. data/app/views/resource_import_files/new.html.erb +2 -0
  25. data/app/views/resource_import_files/show.html.erb +8 -12
  26. data/app/views/resource_import_results/_list.html.erb +26 -0
  27. data/app/views/resource_import_results/_list_lines.html.erb +25 -0
  28. data/app/views/resource_import_results/index.html.erb +3 -30
  29. data/app/views/resource_import_results/show.html.erb +1 -1
  30. data/config/locales/translation_en.yml +8 -5
  31. data/config/locales/translation_ja.yml +4 -1
  32. data/lib/enju_biblio/version.rb +1 -1
  33. data/spec/cassette_library/ResourceImportFile/when_its_mode_is_create_/ISBN_import/with_record_not_found/should_record_an_error_message.yml +155 -0
  34. data/spec/cassette_library/ResourceImportFile/when_its_mode_is_create_/when_it_has_only_isbn/should_be_imported.yml +464 -374
  35. data/spec/cassette_library/ResourceImportFile/when_its_mode_is_create_/when_it_is_written_in_shift_jis/should_be_imported.yml +232 -159
  36. data/spec/cassette_library/ResourceImportFile/when_its_mode_is_create_/when_it_is_written_in_utf-8/should_be_imported.yml +234 -161
  37. data/spec/cassette_library/ResourceImportFile/when_its_mode_is_create_/when_it_is_written_in_utf-8/should_send_message_when_import_is_completed.yml +234 -163
  38. data/spec/controllers/agent_types_controller_spec.rb +5 -0
  39. data/spec/controllers/content_types_controller_spec.rb +7 -0
  40. data/spec/controllers/frequencies_controller_spec.rb +7 -0
  41. data/spec/controllers/items_controller_spec.rb +18 -0
  42. data/spec/controllers/manifestations_controller_spec.rb +30 -0
  43. data/spec/factories/classification.rb +6 -0
  44. data/spec/fixtures/items.yml +2 -0
  45. data/spec/models/manifestation_spec.rb +16 -0
  46. data/spec/models/resource_export_file_spec.rb +19 -0
  47. data/spec/models/resource_import_file_spec.rb +58 -0
  48. data/spec/views/resource_import_files/index.html.erb_spec.rb +19 -0
  49. data/spec/views/resource_import_files/show.html.erb_spec.erb +27 -0
  50. data/spec/views/resource_import_results/index.html.erb_spec.rb +32 -0
  51. data/spec/views/resource_import_results/show.html.erb_spec.erb +27 -0
  52. metadata +427 -407
@@ -223,6 +223,22 @@ describe Manifestation, :solr => true do
223
223
  # #manifestation.volume_number.should eq 1
224
224
  #end
225
225
 
226
+ context ".export" do
227
+ it "should export a header line" do
228
+ lines = Manifestation.export
229
+ (header, *lines) = lines.split(/\r?\n/)
230
+ header = header.split(/\t/)
231
+ expect(header.size).to eq lines.first.split(/\t/).size
232
+ expect(header).to include "manifestation_id"
233
+ expect(header).to include "manifestation_created_at"
234
+ expect(header).to include "manifestation_updated_at"
235
+ expect(header).to include "item_created_at"
236
+ expect(header).to include "item_updated_at"
237
+ expect(header).to include "item_id"
238
+ expect(header).to include "manifestation_identifier"
239
+ end
240
+ end
241
+
226
242
  if defined?(EnjuCirculation)
227
243
  it "should respond to is_checked_out_by?" do
228
244
  manifestations(:manifestation_00001).is_checked_out_by?(users(:admin)).should be_truthy
@@ -13,6 +13,25 @@ describe ResourceExportFile do
13
13
  Message.count.should eq message_count + 1
14
14
  Message.order(:id).last.subject.should eq 'エクスポートが完了しました'
15
15
  end
16
+
17
+ context "NCID export" do
18
+ it "should export NCID value" do
19
+ manifestation = FactoryGirl.create(:manifestation)
20
+ ncid = IdentifierType.where(name: "ncid").first
21
+ identifier = FactoryGirl.create(:identifier, identifier_type: ncid, body: "BA91833159")
22
+ manifestation.identifiers << identifier
23
+ manifestation.save!
24
+ export_file = ResourceExportFile.new
25
+ export_file.user = users(:admin)
26
+ export_file.save!
27
+ export_file.export!
28
+ file = export_file.resource_export
29
+ expect(file).to be_truthy
30
+ lines = File.open(file.path).readlines.map(&:chomp)
31
+ expect(lines.first.split(/\t/)).to include "ncid"
32
+ expect(lines.last.split(/\t/)).to include "BA91833159"
33
+ end
34
+ end
16
35
  end
17
36
 
18
37
  # == Schema Information
@@ -131,6 +131,47 @@ describe ResourceImportFile do
131
131
  Message.count.should eq old_message_count + 1
132
132
  Message.order(:id).last.subject.should eq 'インポートが完了しました'
133
133
  end
134
+
135
+ it "should be searchable right after the import", solr: true do
136
+ @file.import_start
137
+ Manifestation.search{ keywords "10101" }.total.should > 0
138
+ Manifestation.search{ keywords "10101", :fields => [:item_identifier] }.total.should > 0
139
+ Manifestation.search{ keywords "item_identifier_sm:10101" }.total.should > 0
140
+ end
141
+ end
142
+
143
+ describe "ISBN import" do
144
+ context "with record not found" do
145
+ it "should record an error message", vcr: true do
146
+ file = ResourceImportFile.create resource_import: StringIO.new("isbn\n9780007264551"), user: users(:admin)
147
+ result = file.import_start
148
+ expect(result[:failed]).to eq 1
149
+ resource_import_result = file.resource_import_results.last
150
+ expect(resource_import_result.error_message).not_to be_empty
151
+ end
152
+ end
153
+ context "with ISBN invalid" do
154
+ it "should record an error message", vcr: true do
155
+ file = ResourceImportFile.create resource_import: StringIO.new("isbn\n978000726455x"), user: users(:admin)
156
+ result = file.import_start
157
+ expect(result[:failed]).to eq 1
158
+ resource_import_result = file.resource_import_results.last
159
+ expect(resource_import_result.error_message).not_to be_empty
160
+ end
161
+ end
162
+ end
163
+
164
+ describe "NCID import" do
165
+ it "should import ncid value" do
166
+ file = ResourceImportFile.create resource_import: StringIO.new("original_title\tncid\noriginal_title_ncid\tBA67656964\n"), user: users(:admin)
167
+ result = file.import_start
168
+ expect(result[:manifestation_imported]).to eq 1
169
+ resource_import_result = file.resource_import_results.last
170
+ expect(resource_import_result.error_message).to be_blank
171
+ expect(resource_import_result.manifestation).not_to be_blank
172
+ manifestation = resource_import_result.manifestation
173
+ expect(manifestation.identifier_contents(:ncid).first).to eq "BA67656964"
174
+ end
134
175
  end
135
176
 
136
177
  describe "when it is written in shift_jis" do
@@ -190,6 +231,8 @@ describe ResourceImportFile do
190
231
  it "should update items", vcr: true do
191
232
  @file = ResourceImportFile.create resource_import: File.new("#{Rails.root.to_s}/../../examples/item_update_file.tsv"), edit_mode: 'update'
192
233
  @file.modify
234
+ expect(@file.resource_import_results.first).to be_truthy
235
+ expect(@file.resource_import_results.first.body).to match /item_identifier/
193
236
  item_00001 = Item.where(item_identifier: '00001').first
194
237
  item_00001.manifestation.creators.order('agents.id').collect(&:full_name).should eq ['たなべ', 'こうすけ']
195
238
  item_00001.binding_item_identifier.should eq '900001'
@@ -204,6 +247,7 @@ describe ResourceImportFile do
204
247
  item_00003.include_supplements.should be_truthy
205
248
 
206
249
  Item.where(item_identifier: '00004').first.include_supplements.should be_falsy
250
+ Item.where(item_identifier: '00025').first.call_number.should eq "547|ヤ"
207
251
  end
208
252
 
209
253
  #it "should update series_statement", vcr: true do
@@ -213,6 +257,20 @@ describe ResourceImportFile do
213
257
  # manifestation.reload
214
258
  # manifestation.series_statements.should eq [SeriesStatement.find(2)]
215
259
  #end
260
+
261
+ describe "NCID import" do
262
+ it "should import ncid value" do
263
+ file = ResourceImportFile.create resource_import: StringIO.new("manifestation_id\tncid\n1\tBA67656964\n"), user: users(:admin), edit_mode: 'update'
264
+ result = file.import_start
265
+ #expect(result[:manifestation_found]).to eq 1
266
+ expect(file.error_message).to be_nil
267
+ resource_import_result = file.resource_import_results.last
268
+ expect(resource_import_result.error_message).to be_blank
269
+ expect(resource_import_result.manifestation).not_to be_blank
270
+ manifestation = resource_import_result.manifestation
271
+ expect(manifestation.identifier_contents(:ncid).first).to eq "BA67656964"
272
+ end
273
+ end
216
274
  end
217
275
 
218
276
  describe "when its mode is 'destroy'" do
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe "resource_import_files/index" do
4
+ fixtures :all
5
+
6
+ before(:each) do
7
+ assign(:resource_import_files, ResourceImportFile.page(1))
8
+ admin = User.find('enjuadmin')
9
+ view.stub(:current_resource).and_return(admin)
10
+ @ability = EnjuLeaf::Ability.new(admin, '0.0.0.0')
11
+ @ability.extend(CanCan::Ability)
12
+ controller.stub(:current_ability) { @ability }
13
+ end
14
+
15
+ it "renders a list of resource_import_files" do
16
+ render
17
+ expect(rendered).to match /MyString/
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe "resource_import_files/show" do
4
+ fixtures :all
5
+
6
+ before(:each) do
7
+ file = resource_import_files(:resource_import_file_00001)
8
+ assign(:resource_import_file, file)
9
+ assign(:resource_import_results,
10
+ Kaminari.paginate_array(file.resource_import_results).page(1))
11
+ admin = User.find('enjuadmin')
12
+ view.stub(:current_user).and_return(admin)
13
+ @ability = EnjuLeaf::Ability.new(admin, '0.0.0.0')
14
+ @ability.extend(CanCan::Ability)
15
+ controller.stub(:current_ability) { @ability }
16
+ end
17
+
18
+ it "renders a resource_import_file" do
19
+ render
20
+ expect(rendered).to match /MyString/
21
+ end
22
+ it "renders a list of resource_import_results" do
23
+ render
24
+ expect(rendered).to match /<table/
25
+ expect(rendered).to render_template "resource_import_files/_results"
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe "resource_import_results/index" do
4
+ fixtures :all
5
+
6
+ before(:each) do
7
+ assign(:resource_import_results, ResourceImportResult.page(1))
8
+ admin = User.find('enjuadmin')
9
+ view.stub(:current_resource).and_return(admin)
10
+ @ability = EnjuLeaf::Ability.new(admin, '0.0.0.0')
11
+ @ability.extend(CanCan::Ability)
12
+ controller.stub(:current_ability) { @ability }
13
+ end
14
+
15
+ it "renders a list of resource_import_results" do
16
+ render
17
+ expect(rendered).to match /MyString/
18
+ end
19
+
20
+ context "with @resource_import_file" do
21
+ before(:each) do
22
+ @resource_import_file = ResourceImportFile.find(1)
23
+ @resource_import_results = ResourceImportResult.where(resource_import_file_id: 1).page(1)
24
+ end
25
+ it "renders a list of resource_import_results for the resource_import_file" do
26
+ render
27
+ expect(view).to render_template "resource_import_results/_list_lines"
28
+ expect(rendered).to match /MyString/
29
+ expect(rendered).to match /<td>1<\/td>/
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe "resource_import_results/show" do
4
+ fixtures :all
5
+
6
+ before(:each) do
7
+ @resource_import_result = resource_import_results(:one)
8
+ admin = User.find('enjuadmin')
9
+ view.stub(:current_user).and_return(admin)
10
+ @ability = EnjuLeaf::Ability.new(admin, '0.0.0.0')
11
+ @ability.extend(CanCan::Ability)
12
+ controller.stub(:current_ability) { @ability }
13
+ end
14
+
15
+ it "renders a resource_import_result" do
16
+ render
17
+ expect(rendered).to match /MyString/
18
+ end
19
+ it "renders even if a resource_import_file is deleted" do
20
+ #@resource_import_result.resource_import_file = nil
21
+ @resource_import_result.resource_import_file.delete
22
+ @resource_import_result.resource_import_file = nil
23
+ STDERR.puts @resource_import_result.inspect
24
+ render
25
+ expect(rendered).to match /MyText/
26
+ end
27
+ end