ddr-models 2.4.0.rc1 → 2.4.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1f085bb5aae0c19afb4bb644fd674800bce2a9e
4
- data.tar.gz: 11d41a2e56d71b9087d5cc8d7154f52c86a2f28c
3
+ metadata.gz: f1c49fbe59e6c5428bb0bc0386cc8540645a68a4
4
+ data.tar.gz: 2d4611d4cb06dd91ff9cada3c9e9cf6f4ec27ced
5
5
  SHA512:
6
- metadata.gz: 50dd901a973431067800bbbbc33f1f4b9fb2fd8f1a53eb6797132197b410bccefdf9a6f5d6d5717d6c03441e0bded2e4e0ce59e5394e929f1b26d2809194c0bc
7
- data.tar.gz: 587d288987202fd4c8f9375bdd4d37e1bcc044ac11573a76d7b84730618ee2cbd234f0c4cb7e8e845ec8b69711c468ac824f5640de47822981aaa0ffaa353dac
6
+ metadata.gz: 26122a595e168eebe097b956e44f91e4b06465fe62c02a443036a3b848b436987fecceab9fc007608216fd2c255b27d810b0ecbe548997a503a07e02a48fb434
7
+ data.tar.gz: 28c0e57885bab002e0309f293b72c6f53c51cbbd9227a0fcd50411c267c3b61167c7089e9cf1ba445d590ebad8051171acd009401a875304b644e85ef3f13ddc
@@ -62,6 +62,7 @@ module Ddr
62
62
  autoload :HasStructMetadata
63
63
  autoload :HasThumbnail
64
64
  autoload :Indexing
65
+ autoload :NotFoundError, 'ddr/models/error'
65
66
  autoload :SolrDocument
66
67
  autoload :StructDiv
67
68
  autoload :Structure
@@ -7,8 +7,10 @@ module Ddr::Models
7
7
 
8
8
  def self.call(obj)
9
9
  if obj.admin_set
10
- get(:find, code: obj.admin_set)
10
+ new get(:find, code: obj.admin_set)
11
11
  end
12
+ rescue ActiveResource::ResourceNotFound => e
13
+ raise Ddr::Models::NotFoundError, e
12
14
  end
13
15
 
14
16
  def to_s
@@ -6,7 +6,9 @@ module Ddr::Models
6
6
  self.site = ENV["DDR_AUX_API_URL"]
7
7
 
8
8
  def self.call(slug)
9
- get(:find, slug: slug)
9
+ new get(:find, slug: slug)
10
+ rescue ActiveResource::ResourceNotFound => e
11
+ raise Ddr::Models::NotFoundError, e
10
12
  end
11
13
 
12
14
  def to_s
@@ -11,5 +11,8 @@ module Ddr
11
11
 
12
12
  # Content model casting error
13
13
  class ContentModelError < Error; end
14
+
15
+ # A model instance was not found
16
+ class NotFoundError < Error; end
14
17
  end
15
18
  end
@@ -9,10 +9,12 @@ module Ddr::Models
9
9
 
10
10
  def self.call(obj)
11
11
  if obj.license
12
- license = get(:find, url: obj.license)
12
+ license = new get(:find, url: obj.license)
13
13
  license.pid = obj.pid
14
14
  license
15
15
  end
16
+ rescue ActiveResource::ResourceNotFound => e
17
+ raise Ddr::Models::NotFoundError, e
16
18
  end
17
19
 
18
20
  def to_s
@@ -1,5 +1,5 @@
1
1
  module Ddr
2
2
  module Models
3
- VERSION = "2.4.0.rc1"
3
+ VERSION = "2.4.0.rc2"
4
4
  end
5
5
  end
@@ -1,25 +1,43 @@
1
1
  module Ddr::Models
2
- RSpec.describe AdminSet do
2
+ RSpec.describe AdminSet, ddr_aux: true do
3
3
 
4
4
  describe ".call" do
5
- subject { described_class.call(obj) }
6
5
  let(:obj) { Item.new }
7
6
 
8
7
  describe "when the object has an admin set" do
9
- before do
10
- obj.admin_set = "dvs"
11
- allow(described_class).to receive(:get).with(:find, code: "dvs") do
12
- described_class.new("id"=>1, "code"=>"dvs", "title"=>"Data and Visualization Services", "created_at"=>"2015-09-15T16:15:58.514Z", "updated_at"=>"2015-09-15T16:15:58.514Z")
8
+ before { obj.admin_set = "dvs" }
9
+ describe "and the admin set code is found" do
10
+ before {
11
+ allow(described_class).to receive(:get).with(:find, code: "dvs") {
12
+ {"id"=>1, "code"=>"dvs", "title"=>"Data and Visualization Services", "created_at"=>"2015-09-15T16:15:58.514Z", "updated_at"=>"2015-09-15T16:15:58.514Z"}
13
+ }
14
+ }
15
+ it "returns an AdminSet instance" do
16
+ expect(described_class.call(obj)).to be_a(described_class)
17
+ end
18
+ end
19
+ describe "and the admin set is not found" do
20
+ before {
21
+ allow(described_class).to receive(:get).with(:find, code: "dvs")
22
+ .and_raise(ActiveResource::ResourceNotFound, "404")
23
+ }
24
+ it "raises an exception" do
25
+ expect { described_class.call(obj) }.to raise_error(Ddr::Models::NotFoundError)
13
26
  end
14
27
  end
15
-
16
- its(:to_s) { is_expected.to eq("Data and Visualization Services") }
17
28
  end
18
29
 
19
30
  describe "when the object does not have an admin set" do
20
- it { is_expected.to be_nil }
31
+ it "returns nil" do
32
+ expect(described_class.call(obj)).to be_nil
33
+ end
21
34
  end
22
35
  end
23
36
 
37
+ describe "instance methods" do
38
+ subject { described_class.new("id"=>1, "code"=>"dvs", "title"=>"Data and Visualization Services", "created_at"=>"2015-09-15T16:15:58.514Z", "updated_at"=>"2015-09-15T16:15:58.514Z") }
39
+ its(:to_s) { is_expected.to eq("Data and Visualization Services") }
40
+ end
41
+
24
42
  end
25
43
  end
@@ -1,20 +1,40 @@
1
1
  module Ddr::Models
2
- RSpec.describe Contact do
2
+ RSpec.describe Contact, ddr_aux: true do
3
3
 
4
4
  describe ".call" do
5
- subject { described_class.call(slug) }
6
- let(:slug) { 'abc' }
7
-
8
- before do
9
- allow(described_class).to receive(:get).with(:find, slug: slug) do
10
- described_class.new(
11
- "id"=>1, "slug"=>"abc", "name"=>"A, B, and C Services", "short_name"=>"ABCS",
12
- "url"=>"http://library.inst.edu/abc", "phone"=>"555-1234", "email"=>"abc@library.inst.edu",
13
- "ask"=>"http://library.inst.edu/abc-ask", "created_at"=>"2015-09-15T16:15:58.514Z",
14
- "updated_at"=>"2015-09-15T16:15:58.514Z")
5
+ describe "when the slug is found" do
6
+ before {
7
+ allow(described_class).to receive(:get).with(:find, slug: "abc") {
8
+ {"id"=>1, "slug"=>"abc", "name"=>"A, B, and C Services", "short_name"=>"ABCS",
9
+ "url"=>"http://library.inst.edu/abc", "phone"=>"555-1234", "email"=>"abc@library.inst.edu",
10
+ "ask"=>"http://library.inst.edu/abc-ask", "created_at"=>"2015-09-15T16:15:58.514Z",
11
+ "updated_at"=>"2015-09-15T16:15:58.514Z"}
12
+ }
13
+ }
14
+ it "returns a Contact instance" do
15
+ expect(described_class.call("abc")).to be_a(described_class)
16
+ end
17
+ end
18
+ describe "when the slug is not found" do
19
+ before {
20
+ allow(described_class).to receive(:get).with(:find, slug: "abc")
21
+ .and_raise(ActiveResource::ResourceNotFound, "404")
22
+ }
23
+ it "raises an exception" do
24
+ expect { described_class.call("abc") }.to raise_error(Ddr::Models::NotFoundError)
15
25
  end
16
26
  end
27
+ end
17
28
 
29
+ describe "instance methods" do
30
+ subject {
31
+ described_class.new(
32
+ "id"=>1, "slug"=>"abc", "name"=>"A, B, and C Services", "short_name"=>"ABCS",
33
+ "url"=>"http://library.inst.edu/abc", "phone"=>"555-1234", "email"=>"abc@library.inst.edu",
34
+ "ask"=>"http://library.inst.edu/abc-ask", "created_at"=>"2015-09-15T16:15:58.514Z",
35
+ "updated_at"=>"2015-09-15T16:15:58.514Z"
36
+ )
37
+ }
18
38
  its(:to_s) { is_expected.to eq("A, B, and C Services") }
19
39
  end
20
40
 
@@ -179,10 +179,10 @@ module Ddr::Models
179
179
  describe "contacts" do
180
180
  before do
181
181
  allow(Ddr::Models::Contact).to receive(:get).with(:find, slug: 'xa') do
182
- Ddr::Models::Contact.new('id'=>1, 'slug'=>'xa', 'name'=>'Contact A', 'short_name'=>'A')
182
+ {'id'=>1, 'slug'=>'xa', 'name'=>'Contact A', 'short_name'=>'A'}
183
183
  end
184
184
  allow(Ddr::Models::Contact).to receive(:get).with(:find, slug: 'yb') do
185
- Ddr::Models::Contact.new('id'=>1, 'slug'=>'yb', 'name'=>'Contact B', 'short_name'=>'B')
185
+ {'id'=>1, 'slug'=>'yb', 'name'=>'Contact B', 'short_name'=>'B'}
186
186
  end
187
187
  end
188
188
  describe "#research_help" do
@@ -1,26 +1,45 @@
1
1
  module Ddr::Models
2
- RSpec.describe License do
2
+ RSpec.describe License, ddr_aux: true do
3
3
 
4
4
  describe ".call" do
5
- subject { described_class.call(obj) }
6
-
7
5
  describe "when the object has a license URL" do
8
- let(:url) { "http://example.com" }
9
- let(:obj) { double(pid: "test:1", license: url) }
10
- before do
11
- allow(described_class).to receive(:get).with(:find, url: url) do
12
- described_class.new(url: url, title: "A License")
6
+ let(:obj) { double(pid: "test:1", license: "http://example.com") }
7
+ describe "and the license is found" do
8
+ before {
9
+ allow(described_class).to receive(:get).with(:find, url: "http://example.com") {
10
+ {"id"=>1, "url"=>"http://example.com", "title"=>"A License"}
11
+ }
12
+ }
13
+ it "returns a License instance" do
14
+ expect(described_class.call(obj)).to be_a(described_class)
15
+ end
16
+ it "sets `pid` to the object pid" do
17
+ expect(described_class.call(obj).pid).to eq("test:1")
18
+ end
19
+ end
20
+ describe "and the license is not found" do
21
+ before {
22
+ allow(described_class).to receive(:get).with(:find, url: "http://example.com")
23
+ .and_raise(ActiveResource::ResourceNotFound, "404")
24
+ }
25
+ it "raises an exception" do
26
+ expect { described_class.call(obj) }.to raise_error(Ddr::Models::NotFoundError)
13
27
  end
14
28
  end
15
- its(:pid) { is_expected.to eq("test:1") }
16
- its(:to_s) { is_expected.to eq("A License") }
17
29
  end
18
30
 
19
31
  describe "when the object does not have a license" do
20
32
  let(:obj) { double(pid: "test:1", license: nil) }
21
- it { is_expected.to be_nil }
33
+ it "returns nil" do
34
+ expect(described_class.call(obj)).to be_nil
35
+ end
22
36
  end
23
37
  end
24
38
 
39
+ describe "instance methods" do
40
+ subject { described_class.new("id"=>1, "url"=>"http://example.com", "title"=>"A License") }
41
+ its(:to_s) { is_expected.to eq("A License") }
42
+ end
43
+
25
44
  end
26
45
  end
@@ -129,10 +129,10 @@ RSpec.describe SolrDocument, type: :model, contacts: true do
129
129
  describe "contacts" do
130
130
  before do
131
131
  allow(Ddr::Models::Contact).to receive(:get).with(:find, slug: 'xa') do
132
- Ddr::Models::Contact.new('id'=>1, 'slug'=>'xa', 'name'=>'Contact A', 'short_name'=>'A')
132
+ {'id'=>1, 'slug'=>'xa', 'name'=>'Contact A', 'short_name'=>'A'}
133
133
  end
134
134
  allow(Ddr::Models::Contact).to receive(:get).with(:find, slug: 'yb') do
135
- Ddr::Models::Contact.new('id'=>1, 'slug'=>'yb', 'name'=>'Contact B', 'short_name'=>'B')
135
+ {'id'=>1, 'slug'=>'yb', 'name'=>'Contact B', 'short_name'=>'B'}
136
136
  end
137
137
  end
138
138
  describe "#research_help" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddr-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0.rc1
4
+ version: 2.4.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Coble
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-12-10 00:00:00.000000000 Z
12
+ date: 2015-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails