active-fedora 7.0.0.pre3 → 7.0.0.rc1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 326d249cd4fae27ff020852f7f76213ebc79f29f
4
- data.tar.gz: 4a71080c33394383361845919afe864472eedf27
3
+ metadata.gz: 155ad613119b5eb0ce0333d32c7bb0fb67009847
4
+ data.tar.gz: d02a5f3a7617168e35a90ff28dec878ef8ec46cf
5
5
  SHA512:
6
- metadata.gz: 0191dcb8e84050abc5869f1ec0d5003195774421929e1ddb8e7f31d461eca505458af240f3ca9f4eefee323c62d819bf34b8cf9a12fdbf1c118ce4ab5c9040c2
7
- data.tar.gz: 21202208679bb2bd1982377c60a597ab07bc70923d68bedeb31e45476e1b984b530e80e6d44357a2b567ffb83badc7a04bbd3f1a90079aa3be4ea5e340ac6fdb
6
+ metadata.gz: 0ce6042eaaeca85fc1d000a6fdb593e8ef30cf7fd614e5f9a0a973fa5e33ff3b3a4c9d85ad02e2e9f4d5be3a7742d63f3634181842910aad93efb5d223557bbd
7
+ data.tar.gz: 798590c4f7b93fe8b3cde0149162806bf7f6da20cbac133bdf11eb17ef18fce5cb3004a149c68243e29e3600b3c6ff1fbca9ddf126af320b1c6da4be1ac25702
@@ -21,7 +21,7 @@ module ActiveFedora
21
21
  if @datastream.respond_to?(:primary_solr_name)
22
22
  @datastream.primary_solr_name(field)
23
23
  else
24
- raise IllegalOperation, "the datastream '#{datastream_class}' doesn't respond to 'primary_solr_name'"
24
+ raise NoMethodError, "the datastream '#{datastream_class}' doesn't respond to 'primary_solr_name'"
25
25
  end
26
26
  end
27
27
 
@@ -29,7 +29,7 @@ module ActiveFedora
29
29
  if datastream_class.respond_to?(:type)
30
30
  datastream_class.type(field)
31
31
  else
32
- raise IllegalOperation, "the datastream '#{datastream_class}' doesn't respond to 'type'"
32
+ raise NoMethodError, "the datastream '#{datastream_class}' doesn't respond to 'type'"
33
33
  end
34
34
  end
35
35
 
@@ -53,21 +53,24 @@ module ActiveFedora
53
53
  this = self
54
54
  self.reader = lambda do |*opts|
55
55
  if inner_object.is_a? SolrDigitalObject
56
- # Look in the cache
57
- # TODO catch a non-cached error and try fedora.
58
- inner_object.fetch(this.field)
56
+ begin
57
+ # Look in the cache
58
+ return inner_object.fetch(this.field)
59
+ rescue NoMethodError => e
60
+ # couldn't get it from solr, so try from fedora.
61
+ logger.info "Couldn't get #{this.field} out of solr, because #{e.message}. Trying another way."
62
+ end
63
+ end
64
+ # Load from fedora
65
+ ds = datastream_for_attribute(this.dsid)
66
+ if ds.kind_of?(ActiveFedora::RDFDatastream)
67
+ ds.send(this.field)
59
68
  else
60
- # Load from fedora
61
- ds = datastream_for_attribute(this.dsid)
62
- if ds.kind_of?(ActiveFedora::RDFDatastream)
63
- ds.send(this.field)
69
+ terminology = this.at || [this.field]
70
+ if terminology.length == 1 && opts.present?
71
+ ds.send(terminology.first, *opts)
64
72
  else
65
- terminology = this.at || [this.field]
66
- if terminology.length == 1 && opts.present?
67
- ds.send(terminology.first, *opts)
68
- else
69
- ds.send(:term_values, *terminology)
70
- end
73
+ ds.send(:term_values, *terminology)
71
74
  end
72
75
  end
73
76
  end
@@ -413,6 +413,7 @@ module ActiveFedora
413
413
 
414
414
  #override OM::XML::term_values so can lazy load from solr if this datastream initialized using +from_solr+
415
415
  def term_values(*term_pointer)
416
+ # TODO if we can add primary_solr_name onto OmDatastream, we may be able to do away with get_values_from_solr.
416
417
  if @internal_solr_doc
417
418
  #lazy load values from solr on demand
418
419
  get_values_from_solr(*term_pointer)
@@ -16,6 +16,13 @@ module ActiveFedora
16
16
  @values = {}
17
17
  end
18
18
 
19
+ # This method gets called on clone
20
+ def initialize_copy(other)
21
+ # Dup the values
22
+ @values = Hash[@values]
23
+ reset
24
+ end
25
+
19
26
  # Tries to create a new record with the same scoped attributes
20
27
  # defined in the relation. Returns the initialized object if validation fails.
21
28
  #
@@ -43,19 +50,6 @@ module ActiveFedora
43
50
  self
44
51
  end
45
52
 
46
- # Limits the number of returned records to the value specified
47
- #
48
- # @option [Integer] value the number of records to return
49
- #
50
- # @example
51
- # Person.where(name_t: 'Jones').limit(10)
52
- # => [#<Person @id="foo:123" @name='Jones'>, #<Person @id="foo:125" @name='Jones'>, ...]
53
- def limit(value)
54
- relation = clone
55
- relation.limit_value = value
56
- relation
57
- end
58
-
59
53
  # Limits the returned records to those that match the provided search conditions
60
54
  #
61
55
  # @option [Hash] opts a hash of solr conditions
@@ -37,6 +37,22 @@ module ActiveFedora
37
37
  @values[:limit] = value
38
38
  end
39
39
 
40
+ # Limits the number of returned records to the value specified
41
+ #
42
+ # @option [Integer] value the number of records to return
43
+ #
44
+ # @example
45
+ # Person.where(name_t: 'Jones').limit(10)
46
+ # => [#<Person @id="foo:123" @name='Jones'>, #<Person @id="foo:125" @name='Jones'>, ...]
47
+ def limit(value)
48
+ spawn.limit!(value)
49
+ end
50
+
51
+ def limit!(value)
52
+ self.limit_value = value
53
+ self
54
+ end
55
+
40
56
  def none! # :nodoc:
41
57
  extending!(NullRelation)
42
58
  end
@@ -43,17 +43,16 @@ module ActiveFedora
43
43
  self
44
44
  end
45
45
 
46
- def fetch(field)
46
+ def fetch(field, default=[])
47
47
  attribute = original_class.defined_attributes[field]
48
48
  field_name = attribute.primary_solr_name
49
- if field_name
50
- val = solr_doc.fetch field_name
51
- case attribute.type
52
- when :date
53
- val.is_a?(Array) ? val.map{|v| Date.parse v} : Date.parse(val)
54
- else
55
- val
56
- end
49
+ raise KeyError, "Tried to fetch `#{field}' from solr, but it isn't indexed." unless field_name
50
+ val = solr_doc.fetch field_name, default
51
+ case attribute.type
52
+ when :date
53
+ val.is_a?(Array) ? val.map{|v| Date.parse v} : Date.parse(val)
54
+ else
55
+ val
57
56
  end
58
57
  end
59
58
 
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "7.0.0.pre3"
2
+ VERSION = "7.0.0.rc1"
3
3
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe "Loading from solr" do
4
4
  before do
5
- class MyDatastream < ActiveFedora::NtriplesRDFDatastream
5
+ class MyRdfDatastream < ActiveFedora::NtriplesRDFDatastream
6
6
  map_predicates do |map|
7
7
  map.title(in: RDF::DC) do |index|
8
8
  index.as :stored_searchable, :facetable
@@ -20,21 +20,31 @@ describe "Loading from solr" do
20
20
  map.related_url(to: "seeAlso", in: RDF::RDFS)
21
21
  end
22
22
  end
23
+ class MyOmDatastream < ActiveFedora::OmDatastream
24
+ set_terminology do |t|
25
+ t.root(path: "animals")
26
+ t.duck(index_as: :stored_searchable)
27
+ end
28
+ end
23
29
  class RdfTest < ActiveFedora::Base
24
- has_metadata :name=>'rdf', :type=>MyDatastream
30
+ has_metadata 'rdf', type: MyRdfDatastream
31
+ has_metadata 'om', type: MyOmDatastream
25
32
  has_attributes :based_near, :related_url, :part, :date_uploaded, datastream: 'rdf', multiple: true
26
33
  has_attributes :title, :identifier, datastream: 'rdf', multiple: false
34
+ has_attributes :duck, datastream: 'om', multiple: false
27
35
  end
28
36
  end
29
37
 
30
38
  let!(:original) { RdfTest.create!(title: "PLAN 9 FROM OUTER SPACE",
31
39
  date_uploaded: Date.parse('1959-01-01'),
40
+ duck: "quack",
32
41
  identifier: 12345) }
33
42
 
34
43
  after do
35
44
  original.destroy
36
45
  Object.send(:remove_const, :RdfTest)
37
- Object.send(:remove_const, :MyDatastream)
46
+ Object.send(:remove_const, :MyRdfDatastream)
47
+ Object.send(:remove_const, :MyOmDatastream)
38
48
  end
39
49
 
40
50
  it "should be able to get indexed properties without loading from fedora" do
@@ -43,6 +53,9 @@ describe "Loading from solr" do
43
53
  expect(obj.title).to eq "PLAN 9 FROM OUTER SPACE"
44
54
  expect(obj.date_uploaded).to eq [Date.parse('1959-01-01')]
45
55
  expect(obj.identifier).to eq 12345
46
- expect(obj.part).to be_nil # since it wasn't indexed
56
+ expect{obj.part}.to raise_error KeyError, "Tried to fetch `part' from solr, but it isn't indexed."
57
+ expect(ActiveFedora::DatastreamAttribute.logger).to receive(:info).with "Couldn't get duck out of solr, because the datastream 'MyOmDatastream' doesn't respond to 'primary_solr_name'. Trying another way."
58
+ expect(obj.duck).to eq 'quack'
47
59
  end
60
+
48
61
  end
@@ -84,6 +84,12 @@ describe "scoped queries" do
84
84
  it "should chain count" do
85
85
  ModelIntegrationSpec::Basic.where(ActiveFedora::SolrService.solr_name('bar', type: :string) => 'Peanuts').count.should == 2
86
86
  end
87
+
88
+ it "calling first should not affect the relation's ability to get all results later" do
89
+ relation = ModelIntegrationSpec::Basic.where(ActiveFedora::SolrService.solr_name('bar', type: :string) => 'Peanuts')
90
+ expect {relation.first}.not_to change {relation.to_a.size}
91
+ end
92
+
87
93
  end
88
94
 
89
95
  describe "when one of the objects in solr isn't in fedora" do
@@ -18,6 +18,47 @@ describe ActiveFedora::SolrDigitalObject do
18
18
  end
19
19
  end
20
20
 
21
+ describe "fetch" do
22
+ before do
23
+ class MyDatastream
24
+ def initialize(_, _)
25
+ end
26
+
27
+ def primary_solr_name(field)
28
+ return if field == :publisher
29
+ "#{field}_tesim"
30
+ end
31
+ def self.type(field)
32
+ :string
33
+ end
34
+ end
35
+ class MyModel < ActiveFedora::Base
36
+ has_metadata 'descMetadata', type: MyDatastream
37
+ has_attributes :title, :author, :publisher, datastream: 'descMetadata'
38
+ end
39
+
40
+ end
41
+ after do
42
+ Object.send(:remove_const, :MyModel)
43
+ Object.send(:remove_const, :MyDatastream)
44
+ end
45
+ subject { ActiveFedora::SolrDigitalObject.new({'title_tesim' => 'foo'},{'datastreams'=>{}}, MyModel) }
46
+ it "the default should be nil" do
47
+ expect(subject.fetch('author')).to be_empty
48
+ end
49
+ it "should grab values" do
50
+ expect(subject.fetch('title')).to eq 'foo'
51
+ end
52
+ it "should grab values" do
53
+ expect(subject.fetch('title')).to eq 'foo'
54
+ end
55
+
56
+ it "should raise an error if the field isn't indexed" do
57
+ expect{subject.fetch('publisher')}.to raise_error KeyError, "Tried to fetch `publisher' from solr, but it isn't indexed."
58
+ end
59
+
60
+ end
61
+
21
62
  describe "initializing" do
22
63
  describe "without a datastream in the ds spec and an xml mime type in the solr doc" do
23
64
  before do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0.pre3
4
+ version: 7.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-01-17 00:00:00.000000000 Z
13
+ date: 2014-01-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr