rof 1.0.7 → 1.2.0

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.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +9 -7
  3. data/LICENSE +201 -16
  4. data/Rakefile +46 -0
  5. data/bin/csv_to_rof +1 -2
  6. data/bin/fedora_to_rof +7 -1
  7. data/bin/jsonld_to_rof +26 -0
  8. data/bin/osf_to_rof +6 -2
  9. data/bin/rof +5 -19
  10. data/lib/rof.rb +2 -6
  11. data/lib/rof/access.rb +1 -1
  12. data/lib/rof/cli.rb +104 -67
  13. data/lib/rof/compare_rof.rb +68 -39
  14. data/lib/rof/filter.rb +21 -0
  15. data/lib/rof/filters.rb +38 -0
  16. data/lib/rof/filters/bendo.rb +15 -17
  17. data/lib/rof/filters/date_stamp.rb +5 -4
  18. data/lib/rof/filters/file_to_url.rb +5 -3
  19. data/lib/rof/filters/label.rb +9 -7
  20. data/lib/rof/filters/work.rb +7 -5
  21. data/lib/rof/ingest.rb +5 -0
  22. data/lib/rof/osf_context.rb +2 -2
  23. data/lib/rof/rdf_context.rb +2 -0
  24. data/lib/rof/translator.rb +18 -0
  25. data/lib/rof/translators.rb +23 -0
  26. data/lib/rof/{translate_csv.rb → translators/csv_to_rof.rb} +4 -3
  27. data/lib/rof/translators/fedora_to_rof.rb +244 -0
  28. data/lib/rof/translators/jsonld_to_rof.rb +112 -0
  29. data/lib/rof/translators/jsonld_to_rof/accumulator.rb +175 -0
  30. data/lib/rof/translators/jsonld_to_rof/predicate_handler.rb +223 -0
  31. data/lib/rof/translators/jsonld_to_rof/predicate_object_handler.rb +125 -0
  32. data/lib/rof/translators/jsonld_to_rof/statement_handler.rb +91 -0
  33. data/lib/rof/translators/osf_to_rof.rb +191 -0
  34. data/lib/rof/utility.rb +44 -1
  35. data/lib/rof/version.rb +1 -1
  36. data/rof.gemspec +10 -2
  37. data/spec/coverage_helper.rb +17 -0
  38. data/spec/fixtures/for_utility_load_items_from_json_file/multiple_items.json +8 -0
  39. data/spec/fixtures/for_utility_load_items_from_json_file/parse_error.json +3 -0
  40. data/spec/fixtures/for_utility_load_items_from_json_file/single_item.json +3 -0
  41. data/spec/fixtures/jsonld_to_rof/0g354f18610.jsonld +113 -0
  42. data/spec/fixtures/jsonld_to_rof/0g354f18610.rof +96 -0
  43. data/spec/fixtures/jsonld_to_rof/2j62s467216.jsonld +113 -0
  44. data/spec/fixtures/jsonld_to_rof/2j62s467216.rof +93 -0
  45. data/spec/fixtures/jsonld_to_rof/2v23vt16z2z.jsonld +70 -0
  46. data/spec/fixtures/jsonld_to_rof/2v23vt16z2z.rof +87 -0
  47. data/spec/fixtures/jsonld_to_rof/cr56n01253w.jsonld +84 -0
  48. data/spec/fixtures/jsonld_to_rof/cr56n01253w.rof +95 -0
  49. data/spec/fixtures/jsonld_to_rof/h989r21069m.jsonld +84 -0
  50. data/spec/fixtures/jsonld_to_rof/h989r21069m.rof +98 -0
  51. data/spec/fixtures/jsonld_to_rof/js956d59913.jsonld +79 -0
  52. data/spec/fixtures/jsonld_to_rof/js956d59913.rof +89 -0
  53. data/spec/fixtures/jsonld_to_rof/m039k358q5c.jsonld +80 -0
  54. data/spec/fixtures/jsonld_to_rof/m039k358q5c.rof +64 -0
  55. data/spec/fixtures/jsonld_to_rof/nk322b9161g.jsonld +89 -0
  56. data/spec/fixtures/jsonld_to_rof/nk322b9161g.rof +69 -0
  57. data/spec/fixtures/jsonld_to_rof/p8418k7430d.jsonld +84 -0
  58. data/spec/fixtures/jsonld_to_rof/p8418k7430d.rof +67 -0
  59. data/spec/fixtures/jsonld_to_rof/xg94hm53h0c.jsonld +98 -0
  60. data/spec/fixtures/jsonld_to_rof/xg94hm53h0c.rof +110 -0
  61. data/spec/fixtures/jsonld_to_rof/zk51vd69n1r.jsonld +94 -0
  62. data/spec/fixtures/jsonld_to_rof/zk51vd69n1r.rof +121 -0
  63. data/spec/fixtures/osf/phz6b.tar.gz +0 -0
  64. data/spec/lib/rof/access_spec.rb +30 -23
  65. data/spec/lib/rof/cli_spec.rb +83 -60
  66. data/spec/lib/rof/compare_rof_spec.rb +35 -24
  67. data/spec/lib/rof/filter_spec.rb +10 -0
  68. data/spec/lib/rof/filters/bendo_spec.rb +42 -0
  69. data/spec/lib/rof/filters/date_stamp_spec.rb +9 -5
  70. data/spec/lib/rof/filters/file_to_url_spec.rb +7 -3
  71. data/spec/lib/rof/filters/label_spec.rb +121 -77
  72. data/spec/lib/rof/filters/work_spec.rb +7 -4
  73. data/spec/lib/rof/filters_spec.rb +14 -0
  74. data/spec/lib/rof/translator_spec.rb +15 -0
  75. data/spec/lib/rof/{translate_csv_spec.rb → translators/csv_to_rof_spec.rb} +14 -14
  76. data/spec/lib/rof/translators/fedora_to_rof_spec.rb +64 -0
  77. data/spec/lib/rof/translators/jsonld_to_rof/accumulator_spec.rb +121 -0
  78. data/spec/lib/rof/translators/jsonld_to_rof/predicate_handler_spec.rb +73 -0
  79. data/spec/lib/rof/translators/jsonld_to_rof/predicate_object_handler_spec.rb +48 -0
  80. data/spec/lib/rof/translators/jsonld_to_rof/statement_handler_spec.rb +40 -0
  81. data/spec/lib/rof/translators/jsonld_to_rof_spec.rb +120 -0
  82. data/spec/lib/rof/{osf_to_rof_spec.rb → translators/osf_to_rof_spec.rb} +55 -25
  83. data/spec/lib/rof/translators_spec.rb +14 -0
  84. data/spec/lib/rof/utility_spec.rb +47 -1
  85. data/spec/spec_helper.rb +1 -1
  86. data/spec/support/an_rof_filter.rb +10 -0
  87. metadata +186 -15
  88. data/lib/rof/get_from_fedora.rb +0 -211
  89. data/lib/rof/osf_to_rof.rb +0 -123
  90. data/spec/lib/rof/get_from_fedora_spec.rb +0 -22
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ module ROF
4
+ RSpec.describe Filter do
5
+ subject { described_class.new }
6
+ it 'defines an abstract #process method' do
7
+ expect { subject.process({}) }.to raise_error(NotImplementedError)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require 'rof/filters/bendo'
3
+ require 'support/an_rof_filter'
4
+
5
+ RSpec.describe ROF::Filters::Bendo do
6
+ it_behaves_like "an ROF::Filter"
7
+ let(:bendo){ nil }
8
+ let(:valid_options) { { bendo_info: bendo} }
9
+
10
+ it 'requires bendo_info to initialize' do
11
+ expect { described_class.new({}) }.to raise_error(KeyError)
12
+ end
13
+ describe '#process' do
14
+ subject { described_class.new(bendo_info: bendo).process(original_object_list) }
15
+ let(:original_object_list) do
16
+ [
17
+ { "content-meta" => { "URL" => "bendo:/item/12345/a/file.txt" } },
18
+ { "not_gonna_change" => { "URL" => "bendo:/item/12345/a/file.txt" } },
19
+ { "content-meta" => { "URL" => "somewhere:/item/12345/a/file.txt" } }
20
+ ]
21
+ end
22
+
23
+ context 'if bendo is set' do
24
+ let(:bendo) { 'http://bendo.host' }
25
+ it 'will replace "bendo:" with the given bendo string' do
26
+ expected_object_list = [
27
+ { "content-meta" => { "URL" => "#{bendo}/item/12345/a/file.txt" } },
28
+ { "not_gonna_change" => { "URL" => "bendo:/item/12345/a/file.txt" } },
29
+ { "content-meta" => { "URL" => "somewhere:/item/12345/a/file.txt" } }
30
+ ]
31
+ expect(subject).to eq(expected_object_list)
32
+ end
33
+ end
34
+
35
+ context 'if bendo is not set' do
36
+ let(:bendo) { nil }
37
+ it 'will not replace "bendo:" in any of the data entries' do
38
+ expect(subject).to eq(original_object_list)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,19 +1,23 @@
1
1
  require 'spec_helper'
2
+ require 'support/an_rof_filter'
2
3
 
3
4
  module ROF
4
5
  module Filters
5
6
  describe DateStamp do
7
+ it_behaves_like "an ROF::Filter"
8
+ let(:valid_options) { {} }
9
+
6
10
  before(:all) do
7
11
  @today = Date.new(2015, 1, 23)
8
12
  @today_s = "2015-01-23Z"
9
- @w = DateStamp.new(@today)
13
+ @w = DateStamp.new(as_of: @today)
10
14
  end
11
15
 
12
16
  it "it adds a metadata section if needed" do
13
17
  items = [{
14
18
  "type" => "ABC"
15
19
  }]
16
- after = @w.process(items, '')
20
+ after = @w.process(items)
17
21
  expect(after.length).to eq(1)
18
22
  expect(after.first).to eq({
19
23
  "type" => "ABC",
@@ -32,7 +36,7 @@ module ROF
32
36
  "dc:title" => "something"
33
37
  }
34
38
  }]
35
- after = @w.process(items, '')
39
+ after = @w.process(items)
36
40
  expect(after.length).to eq(1)
37
41
  expect(after.first).to eq({
38
42
  "type" => "BCD",
@@ -52,7 +56,7 @@ module ROF
52
56
  "dc:dateSubmitted" => "any date"
53
57
  }
54
58
  }]
55
- after = @w.process(items, '')
59
+ after = @w.process(items)
56
60
  expect(after.length).to eq(1)
57
61
  expect(after.first).to eq({
58
62
  "type" => "CDE",
@@ -73,7 +77,7 @@ module ROF
73
77
  "dc:modified" => "any date"
74
78
  }
75
79
  }]
76
- after = @w.process(items, '')
80
+ after = @w.process(items)
77
81
  expect(after.length).to eq(1)
78
82
  expect(after.first).to eq({
79
83
  "type" => "CDE",
@@ -1,8 +1,12 @@
1
1
  require 'spec_helper'
2
+ require 'support/an_rof_filter'
2
3
 
3
4
  module ROF
4
5
  module Filters
5
6
  describe FileToUrl do
7
+ it_behaves_like "an ROF::Filter"
8
+ let(:valid_options) { {} }
9
+
6
10
  before(:all) do
7
11
  @w = FileToUrl.new
8
12
  end
@@ -11,7 +15,7 @@ module ROF
11
15
  items = [{
12
16
  "type" => "ABC"
13
17
  }]
14
- after = @w.process(items, '')
18
+ after = @w.process(items)
15
19
  expect(after.length).to eq(1)
16
20
  expect(after.first).to eq({
17
21
  "type" => "ABC"
@@ -27,7 +31,7 @@ module ROF
27
31
  "bendo-item" => "12345",
28
32
  "thumbnail-content" => "a_file.png"
29
33
  }]
30
- after = @w.process(items, '')
34
+ after = @w.process(items)
31
35
  expect(after.length).to eq(2)
32
36
  expect(after.first).to eq({
33
37
  "type" => "ABC",
@@ -49,7 +53,7 @@ module ROF
49
53
  "content-meta" => {
50
54
  "mime-type" => "image/png"
51
55
  }}]
52
- after = @w.process(items, '')
56
+ after = @w.process(items)
53
57
  expect(after.length).to eq(2)
54
58
  expect(after.first).to eq({
55
59
  "bendo-item" => "12345",
@@ -1,93 +1,137 @@
1
1
  require 'spec_helper'
2
+ require 'support/an_rof_filter'
2
3
 
3
4
  module ROF
4
5
  module Filters
5
- describe Label do
6
+ RSpec.describe Label do
7
+ it_behaves_like "an ROF::Filter"
8
+ let(:valid_options) { { id_list: ids } }
6
9
  let(:ids) { ["101", "102", "103", "104", "105"] }
7
- before(:each) {
8
- @labeler = Label.new(nil, id_list: ids)
9
- }
10
- it "ignores non-fojects" do
11
- list = [{"type" => "not fobject"}]
12
- expect(@labeler.process(list, '')).to eq([{"type" => "not fobject"}])
13
- end
14
- it "skips already assigned ids" do
15
- list = [{"type" => "fobject", "pid" => "123"}]
16
- expect(@labeler.process(list, '')).to eq([{"type" => "fobject", "pid" => "123", "bendo-item" => "123"}])
17
- end
18
- it "assignes missing pids" do
19
- list = [{"type" => "fobject"}]
20
- expect(@labeler.process(list, '')).to eq([{"type" => "fobject", "pid" => "101", "bendo-item" => "101"}])
21
- end
22
- it "assignes pids which are labels" do
23
- list = [{"type" => "fobject", "pid" => "$(zzz)"}]
24
- expect(@labeler.process(list, '')).to eq([{"type" => "fobject", "pid" => "101", "bendo-item" => "101"}])
25
- end
26
- it "resolves loops" do
27
- list = [{"type" => "fobject",
28
- "pid" => "$(zzz)",
29
- "rels-ext" => {
30
- "partOf" => ["123", "$(zzz)"]
31
- }}]
32
- expect(@labeler.process(list, '')).to eq([{"type" => "fobject",
33
- "pid" => "101",
34
- "bendo-item"=>"101",
35
- "rels-ext" => {
36
- "partOf" => ["123", "101"]}}])
10
+
11
+ context 'initialization options' do
12
+ it 'can be initialized with a list of IDs' do
13
+ expect { Label.new(valid_options) }.not_to raise_error
14
+ end
15
+ it 'can be initialized with a noid_server and pool_name' do
16
+ noid_server = double
17
+ pool_name = double
18
+ expect(described_class::NoidsPool).to receive(:new).with(noid_server, pool_name)
19
+ expect { Label.new(noid_server: noid_server, pool_name: pool_name) }.not_to raise_error
20
+ end
21
+ it 'will fail if not given a list of IDs nor a noid_server' do
22
+ expect { Label.new }.to raise_error(described_class::NoPool)
23
+ end
37
24
  end
38
- it "handles multiple items" do
39
- list = [{"type" => "fobject",
40
- "pid" => "$(zzz)",
25
+
26
+ describe '#process' do
27
+ before(:each) {
28
+ @labeler = Label.new(id_list: ids)
29
+ }
30
+
31
+ it "ignores non-fojects" do
32
+ list = [{"type" => "not fobject"}]
33
+ expect(@labeler.process(list)).to eq([{"type" => "not fobject"}])
34
+ end
35
+ it "skips already assigned ids" do
36
+ list = [{"type" => "fobject", "pid" => "123"}]
37
+ expect(@labeler.process(list)).to eq([{"type" => "fobject", "pid" => "123", "bendo-item" => "123"}])
38
+ end
39
+ it "assignes missing pids" do
40
+ list = [{"type" => "fobject"}]
41
+ expect(@labeler.process(list)).to eq([{"type" => "fobject", "pid" => "101", "bendo-item" => "101"}])
42
+ end
43
+ it "assignes pids which are labels" do
44
+ list = [{"type" => "fobject", "pid" => "$(zzz)"}]
45
+ expect(@labeler.process(list)).to eq([{"type" => "fobject", "pid" => "101", "bendo-item" => "101"}])
46
+ end
47
+ it "resolves loops" do
48
+ list = [{"type" => "fobject",
49
+ "pid" => "$(zzz)",
50
+ "rels-ext" => {
51
+ "partOf" => ["123", "$(zzz)"]
52
+ }}]
53
+ expect(@labeler.process(list)).to eq([{"type" => "fobject",
54
+ "pid" => "101",
55
+ "bendo-item"=>"101",
56
+ "rels-ext" => {
57
+ "partOf" => ["123", "101"]}}])
58
+ end
59
+ it "handles multiple items" do
60
+ list = [{"type" => "fobject",
61
+ "pid" => "$(zzz)",
62
+ "rels-ext" => {
63
+ "partOf" => ["123", "$(zzz)"]
64
+ }},
65
+ {"type" => "fobject",
66
+ "rels-ext" => { "memberOf" => ["$(zzz)"]}}]
67
+ expect(@labeler.process(list)).to eq([
68
+ {"type" => "fobject",
69
+ "pid" => "101",
70
+ "bendo-item" => "101",
41
71
  "rels-ext" => {
42
- "partOf" => ["123", "$(zzz)"]
72
+ "partOf" => ["123", "101"]
43
73
  }},
44
74
  {"type" => "fobject",
45
- "rels-ext" => { "memberOf" => ["$(zzz)"]}}]
46
- expect(@labeler.process(list, '')).to eq([
47
- {"type" => "fobject",
48
- "pid" => "101",
49
- "bendo-item" => "101",
50
- "rels-ext" => {
51
- "partOf" => ["123", "101"]
52
- }},
53
- {"type" => "fobject",
54
- "pid" => "102",
55
- "bendo-item" => "101",
56
- "rels-ext" => {
57
- "memberOf" => ["101"]
58
- }}
59
- ])
60
- end
61
- it "errors on undefined labels" do
62
- list = [{"type" => "fobject",
75
+ "pid" => "102",
76
+ "bendo-item" => "101",
63
77
  "rels-ext" => {
64
- "partOf" => ["123", "$(zzz)"]
65
- }}]
66
- expect { @labeler.process(list, '') }.to raise_error(Label::MissingLabel)
67
- end
78
+ "memberOf" => ["101"]
79
+ }}
80
+ ])
81
+ end
82
+ it "errors on undefined labels" do
83
+ list = [{"type" => "fobject",
84
+ "rels-ext" => {
85
+ "partOf" => ["123", "$(zzz)"]
86
+ }}]
87
+ expect { @labeler.process(list) }.to raise_error(Label::MissingLabel)
88
+ end
68
89
 
69
- it "replaces labels in arrays" do
70
- list = ["a", "something $(b) and $(a)", "$(not a label)"]
71
- labels = {"a" => "abc", "b" => "qwe"}
72
- expect(@labeler.replace_labels(list, labels, false)).to eq(["a", "something qwe and abc", "$(not a label)"])
90
+ it "replaces labels in arrays" do
91
+ list = ["a", "something $(b) and $(a)", "$(not a label)"]
92
+ labels = {"a" => "abc", "b" => "qwe"}
93
+ expect(@labeler.replace_labels(list, labels, false)).to eq(["a", "something qwe and abc", "$(not a label)"])
73
94
 
74
- hash = {"$(a)" => "this should $(b)", sym: :symbol, b: {b: "$(a) $(z)"}}
75
- expect(@labeler.replace_labels(hash, labels, false)).to eq({
76
- "$(a)" => "this should qwe",
77
- sym: :symbol,
78
- b: {b: "abc $(z)"}
79
- })
80
- end
95
+ hash = {"$(a)" => "this should $(b)", sym: :symbol, b: {b: "$(a) $(z)"}}
96
+ expect(@labeler.replace_labels(hash, labels, false)).to eq({
97
+ "$(a)" => "this should qwe",
98
+ sym: :symbol,
99
+ b: {b: "abc $(z)"}
100
+ })
101
+ end
81
102
 
82
- it "handles pids in isMemberOf" do
83
- list = [
84
- {"type" => "fobject", "pid" => "$(zzz)"},
85
- {"type" => "fobject", "rels-ext" => { "isMemberOfCollection" => ["$(zzz)"]}}
86
- ]
87
- expect(@labeler.process(list, '')).to eq([
88
- {"type" => "fobject", "pid" => "101", "bendo-item" =>"101"},
89
- {"type" => "fobject", "pid" => "102", "bendo-item" =>"101", "rels-ext" => { "isMemberOfCollection" => ["101"]}}
90
- ])
103
+ it "handles pids in isMemberOf" do
104
+ list = [
105
+ {"type" => "fobject", "pid" => "$(zzz)"},
106
+ {"type" => "fobject", "rels-ext" => { "isMemberOfCollection" => ["$(zzz)"]}}
107
+ ]
108
+ expect(@labeler.process(list)).to eq([
109
+ {"type" => "fobject", "pid" => "101", "bendo-item" =>"101"},
110
+ {"type" => "fobject", "pid" => "102", "bendo-item" =>"101", "rels-ext" => { "isMemberOfCollection" => ["101"]}}
111
+ ])
112
+ end
113
+ end
114
+ end
115
+ RSpec.describe Label::NoidsPool do
116
+ let(:noids_server_url) { 'https://noids.library.nd.edu' }
117
+ let(:pool_name) { 'rof' }
118
+ let(:inner_pool) { double(mint: [double], closed?: double) }
119
+ let(:connection) { double('Noids Conneciton', get_pool: inner_pool) }
120
+ before do
121
+ expect(NoidsClient::Connection).to receive(:new).with(noids_server_url).and_return(connection)
122
+ expect(connection).to receive(:get_pool).with(pool_name).and_return(inner_pool)
123
+ end
124
+ describe '#shift' do
125
+ subject { described_class.new(noids_server_url, pool_name).shift }
126
+ it "returns the first value of the inner pool's #mint method" do
127
+ expect(subject).to eq(inner_pool.mint.first)
128
+ end
129
+ end
130
+ describe '#empty?' do
131
+ subject { described_class.new(noids_server_url, pool_name).empty? }
132
+ it 'returns whether the inner pool is closed' do
133
+ expect(subject).to eq(inner_pool.closed?)
134
+ end
91
135
  end
92
136
  end
93
137
  end
@@ -1,10 +1,13 @@
1
1
  require 'spec_helper'
2
+ require 'support/an_rof_filter'
2
3
 
3
4
  module ROF
4
5
  module Filters
5
6
  describe Work do
7
+ it_behaves_like "an ROF::Filter"
8
+ let(:valid_options) { { file_name: '' } }
6
9
  it "handles variant work types" do
7
- w = Work.new
10
+ w = Work.new(valid_options)
8
11
 
9
12
  item = {"type" => "Work", "owner" => "user1"}
10
13
  after = w.process_one_work(item)
@@ -32,7 +35,7 @@ module ROF
32
35
  end
33
36
 
34
37
  it "makes the first file be the representative" do
35
- w = Work.new
38
+ w = Work.new(valid_options)
36
39
 
37
40
  item = {"type" => "Work", "owner" => "user1", "files" => ["a.txt", "b.jpeg"]}
38
41
  after = w.process_one_work(item)
@@ -50,7 +53,7 @@ module ROF
50
53
  end
51
54
 
52
55
  it "decodes files correctly" do
53
- w = Work.new
56
+ w = Work.new(valid_options)
54
57
 
55
58
  item = {
56
59
  "type" => "Work",
@@ -72,7 +75,7 @@ module ROF
72
75
  expect(after.length).to eq(3)
73
76
  expect(after[0]).to include("type" => "fobject",
74
77
  "af-model" => "GenericWork",
75
- "rels-ext" => {},
78
+ "rels-ext" => {},
76
79
  "pid" => "$(pid--0)")
77
80
  expect(after[1]).to include("type" => "fobject",
78
81
  "af-model" => "GenericFile",
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ module ROF
4
+ RSpec.describe Filters do
5
+ describe '.for' do
6
+ it 'raises an exception when one is not registered' do
7
+ expect { described_class.for('obviously-not-valid') }.to raise_error(described_class::UnknownFilterError)
8
+ end
9
+ it 'instantiates a valid filter' do
10
+ expect(described_class.for('datestamp')).to be_a(ROF::Filters::DateStamp)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ require 'rof/translator'
3
+
4
+ module ROF
5
+ RSpec.describe Translator do
6
+ let(:input) { double }
7
+ let(:config) { double }
8
+ describe '.call' do
9
+ subject { described_class.call(input, config) }
10
+ it 'is an abstract method' do
11
+ expect { subject }.to raise_error(NotImplementedError)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,30 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
- module ROF
3
+ module ROF::Translators
4
4
  describe "translate CSV" do
5
5
  it "requires the columns type and owner" do
6
6
  s = "dc:title,access,owner"
7
- expect{TranslateCSV.run(s)}.to raise_error(ROF::TranslateCSV::MissingOwnerOrType)
7
+ expect{CsvToRof.call(s)}.to raise_error(ROF::Translators::CsvToRof::MissingOwnerOrType)
8
8
 
9
9
  s = "dc:title,access,type"
10
- expect{TranslateCSV.run(s)}.to raise_error(ROF::TranslateCSV::MissingOwnerOrType)
10
+ expect{CsvToRof.call(s)}.to raise_error(ROF::Translators::CsvToRof::MissingOwnerOrType)
11
11
 
12
12
  s = "dc:title,type,owner,access"
13
- expect(TranslateCSV.run(s)).to eq([])
13
+ expect(CsvToRof.call(s)).to eq([])
14
14
  end
15
15
 
16
16
  it "requires rows to have an owner and type" do
17
17
  s = %q{type,owner
18
18
  Work,
19
19
  }
20
- expect{TranslateCSV.run(s)}.to raise_error(ROF::TranslateCSV::MissingOwnerOrType)
20
+ expect{CsvToRof.call(s)}.to raise_error(ROF::Translators::CsvToRof::MissingOwnerOrType)
21
21
  end
22
22
 
23
23
  it "deocdes the access field into rights" do
24
24
  s = %q{type,owner,access
25
25
  Work,user1,"private;edit=user2,user3"
26
26
  }
27
- rof = TranslateCSV.run(s)
27
+ rof = CsvToRof.call(s)
28
28
  expect(rof).to eq([{"type" => "Work", "owner" => "user1", "rights" => {"edit" => ["user1", "user2", "user3"]}}])
29
29
  end
30
30
 
@@ -32,13 +32,13 @@ module ROF
32
32
  s = %q{type,owner,dc:title,foaf:name
33
33
  Work,user1,"Q, A Letter",Jane Smith|Zander
34
34
  }
35
- rof = TranslateCSV.run(s)
35
+ rof = CsvToRof.call(s)
36
36
  expect(rof).to eq([{
37
37
  "type" => "Work",
38
38
  "owner" => "user1",
39
39
  "rights" => {"edit" => ["user1"]},
40
40
  "metadata" => {
41
- "@context" => RdfContext,
41
+ "@context" => ROF::RdfContext,
42
42
  "dc:title" => "Q, A Letter",
43
43
  "foaf:name" => ["Jane Smith", "Zander"]}
44
44
  }])
@@ -48,7 +48,7 @@ module ROF
48
48
  s = %q{type,owner,curate_id
49
49
  Work,user1,abcdefg
50
50
  }
51
- rof = TranslateCSV.run(s)
51
+ rof = CsvToRof.call(s)
52
52
  expect(rof).to eq([{
53
53
  "type" => "Work",
54
54
  "owner" => "user1",
@@ -61,13 +61,13 @@ module ROF
61
61
  s = %q{type,owner,dc:title,foaf:name
62
62
  Work,user1,"Q, A Letter",Jane Smith | Zander
63
63
  }
64
- rof = TranslateCSV.run(s)
64
+ rof = CsvToRof.call(s)
65
65
  expect(rof).to eq([{
66
66
  "type" => "Work",
67
67
  "owner" => "user1",
68
68
  "rights" => {"edit" => ["user1"]},
69
69
  "metadata" => {
70
- "@context" => RdfContext,
70
+ "@context" => ROF::RdfContext,
71
71
  "dc:title" => "Q, A Letter",
72
72
  "foaf:name" => ["Jane Smith", "Zander"]}
73
73
  }])
@@ -78,13 +78,13 @@ module ROF
78
78
  Work,user1,"Q, A Letter",thumb
79
79
  +,user1,,extra file.txt
80
80
  }
81
- rof = TranslateCSV.run(s)
81
+ rof = CsvToRof.call(s)
82
82
  expect(rof).to eq([{
83
83
  "type" => "Work",
84
84
  "owner" => "user1",
85
85
  "rights" => {"edit" => ["user1"]},
86
86
  "metadata" => {
87
- "@context" => RdfContext,
87
+ "@context" => ROF::RdfContext,
88
88
  "dc:title" => "Q, A Letter"},
89
89
  "files" => [
90
90
  "thumb",
@@ -101,7 +101,7 @@ module ROF
101
101
  s = %q{type,owner,dc:title,files
102
102
  +,user1,,extra file.txt
103
103
  }
104
- expect {TranslateCSV.run(s)}.to raise_error(ROF::TranslateCSV::NoPriorWork)
104
+ expect {CsvToRof.call(s)}.to raise_error(ROF::Translators::CsvToRof::NoPriorWork)
105
105
  end
106
106
 
107
107