active-fedora 9.9.1 → 9.10.0.pre1

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 (106) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -2
  3. data/.travis.yml +2 -6
  4. data/active-fedora.gemspec +9 -6
  5. data/lib/active_fedora.rb +31 -15
  6. data/lib/active_fedora/associations.rb +1 -1
  7. data/lib/active_fedora/associations/association.rb +6 -2
  8. data/lib/active_fedora/associations/belongs_to_association.rb +0 -10
  9. data/lib/active_fedora/associations/builder/association.rb +85 -12
  10. data/lib/active_fedora/associations/builder/belongs_to.rb +3 -1
  11. data/lib/active_fedora/associations/builder/collection_association.rb +4 -3
  12. data/lib/active_fedora/associations/builder/contains.rb +7 -2
  13. data/lib/active_fedora/associations/builder/directly_contains.rb +7 -3
  14. data/lib/active_fedora/associations/builder/directly_contains_one.rb +8 -4
  15. data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +6 -2
  16. data/lib/active_fedora/associations/builder/has_many.rb +6 -2
  17. data/lib/active_fedora/associations/builder/indirectly_contains.rb +7 -3
  18. data/lib/active_fedora/associations/builder/property.rb +7 -2
  19. data/lib/active_fedora/associations/builder/singular_association.rb +3 -1
  20. data/lib/active_fedora/associations/builder/singular_property.rb +3 -1
  21. data/lib/active_fedora/associations/collection_association.rb +9 -5
  22. data/lib/active_fedora/associations/collection_proxy.rb +1 -1
  23. data/lib/active_fedora/associations/contained_finder.rb +1 -2
  24. data/lib/active_fedora/associations/directly_contains_one_association.rb +1 -1
  25. data/lib/active_fedora/associations/has_many_association.rb +1 -5
  26. data/lib/active_fedora/associations/rdf.rb +1 -20
  27. data/lib/active_fedora/attached_files.rb +1 -1
  28. data/lib/active_fedora/attribute_methods.rb +18 -0
  29. data/lib/active_fedora/attributes.rb +1 -1
  30. data/lib/active_fedora/autosave_association.rb +8 -12
  31. data/lib/active_fedora/base.rb +0 -2
  32. data/lib/active_fedora/caching_connection.rb +1 -1
  33. data/lib/active_fedora/default_model_mapper.rb +24 -0
  34. data/lib/active_fedora/fedora.rb +1 -1
  35. data/lib/active_fedora/file/attributes.rb +4 -5
  36. data/lib/active_fedora/identifiable.rb +5 -0
  37. data/lib/active_fedora/indexing.rb +13 -7
  38. data/lib/active_fedora/indexing_service.rb +4 -4
  39. data/lib/active_fedora/ldp_resource.rb +1 -0
  40. data/lib/active_fedora/model.rb +18 -16
  41. data/lib/active_fedora/model_classifier.rb +77 -0
  42. data/lib/active_fedora/nested_attributes.rb +145 -18
  43. data/lib/active_fedora/persistence.rb +1 -1
  44. data/lib/active_fedora/predicates.rb +3 -0
  45. data/lib/active_fedora/qualified_dublin_core_datastream.rb +1 -1
  46. data/lib/active_fedora/query_result_builder.rb +12 -28
  47. data/lib/active_fedora/querying.rb +1 -1
  48. data/lib/active_fedora/rdf/datastream_indexing.rb +1 -1
  49. data/lib/active_fedora/reflection.rb +15 -7
  50. data/lib/active_fedora/relation.rb +17 -0
  51. data/lib/active_fedora/relation/calculations.rb +1 -5
  52. data/lib/active_fedora/relation/finder_methods.rb +39 -26
  53. data/lib/active_fedora/scoping.rb +5 -0
  54. data/lib/active_fedora/scoping/default.rb +113 -0
  55. data/lib/active_fedora/scoping/named.rb +11 -3
  56. data/lib/active_fedora/simple_datastream.rb +1 -1
  57. data/lib/active_fedora/solr_hit.rb +71 -0
  58. data/lib/active_fedora/solr_instance_loader.rb +12 -36
  59. data/lib/active_fedora/solr_query_builder.rb +20 -25
  60. data/lib/active_fedora/solr_service.rb +24 -13
  61. data/lib/active_fedora/type.rb +8 -0
  62. data/lib/active_fedora/type/boolean.rb +23 -0
  63. data/lib/active_fedora/type/value.rb +118 -0
  64. data/lib/active_fedora/validations.rb +14 -5
  65. data/lib/active_fedora/version.rb +1 -1
  66. data/lib/active_fedora/versionable.rb +8 -7
  67. data/spec/config_helper.rb +0 -5
  68. data/spec/integration/associations_spec.rb +5 -5
  69. data/spec/integration/base_spec.rb +4 -4
  70. data/spec/integration/bug_spec.rb +0 -1
  71. data/spec/integration/full_featured_model_spec.rb +4 -4
  72. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +1 -1
  73. data/spec/integration/has_many_associations_spec.rb +30 -1
  74. data/spec/integration/indirect_container_spec.rb +1 -1
  75. data/spec/integration/nested_attribute_spec.rb +6 -0
  76. data/spec/integration/ntriples_datastream_spec.rb +4 -4
  77. data/spec/integration/om_datastream_spec.rb +1 -1
  78. data/spec/integration/relation_delegation_spec.rb +1 -1
  79. data/spec/integration/scoped_query_spec.rb +12 -12
  80. data/spec/integration/solr_hit_spec.rb +52 -0
  81. data/spec/samples/hydra-mods_article_datastream.rb +2 -2
  82. data/spec/spec_helper.rb +5 -9
  83. data/spec/unit/active_fedora_spec.rb +0 -26
  84. data/spec/unit/base_spec.rb +20 -0
  85. data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -3
  86. data/spec/unit/callback_spec.rb +3 -8
  87. data/spec/unit/default_model_mapper_spec.rb +39 -0
  88. data/spec/unit/finder_methods_spec.rb +30 -6
  89. data/spec/unit/has_many_association_spec.rb +23 -1
  90. data/spec/unit/indexing_spec.rb +17 -3
  91. data/spec/unit/model_classifier_spec.rb +49 -0
  92. data/spec/unit/model_spec.rb +0 -9
  93. data/spec/unit/ntriples_datastream_spec.rb +16 -16
  94. data/spec/unit/om_datastream_spec.rb +7 -7
  95. data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -1
  96. data/spec/unit/query_result_builder_spec.rb +4 -10
  97. data/spec/unit/query_spec.rb +28 -28
  98. data/spec/unit/rdf/indexing_service_spec.rb +16 -16
  99. data/spec/unit/scoping_spec.rb +67 -0
  100. data/spec/unit/simple_datastream_spec.rb +2 -2
  101. data/spec/unit/solr_config_options_spec.rb +29 -32
  102. data/spec/unit/solr_hit_spec.rb +58 -0
  103. data/spec/unit/solr_query_builder_spec.rb +9 -1
  104. data/spec/unit/solr_service_spec.rb +19 -3
  105. metadata +73 -17
  106. data/spec/support/freeze_mocks.rb +0 -12
@@ -53,7 +53,7 @@ module ActiveFedora
53
53
  # Attempts to save the record just like Base#save but will raise a +RecordInvalid+ exception instead of returning false
54
54
  # if the record is not valid.
55
55
  def save!(options = {})
56
- perform_validations(options) ? super : raise(RecordInvalid, self)
56
+ perform_validations(options) ? super : raise_validation_error
57
57
  end
58
58
 
59
59
  # Runs all the validations within the specified context. Returns true if no errors are found,
@@ -65,11 +65,13 @@ module ActiveFedora
65
65
  # Validations with no <tt>:on</tt> option will run no matter the context. Validations with
66
66
  # some <tt>:on</tt> option will only run in the specified context.
67
67
  def valid?(context = nil)
68
- context ||= (new_record? ? :create : :update)
68
+ context ||= default_validation_context
69
69
  output = super(context)
70
70
  errors.empty? && output
71
71
  end
72
72
 
73
+ alias validate valid?
74
+
73
75
  # Test to see if the given field is required
74
76
  # @param [Symbol] key a field
75
77
  # @return [Boolean] is it required or not
@@ -79,9 +81,16 @@ module ActiveFedora
79
81
 
80
82
  protected
81
83
 
82
- def perform_validations(options = {})
83
- perform_validation = options[:validate] != false
84
- perform_validation ? valid?(options[:context]) : true
84
+ def default_validation_context
85
+ new_record? ? :create : :update
86
+ end
87
+
88
+ def raise_validation_error
89
+ raise RecordInvalid, self
90
+ end
91
+
92
+ def perform_validations(options = {}) # :nodoc:
93
+ options[:validate] == false || valid?(options[:context])
85
94
  end
86
95
  end
87
96
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "9.9.1".freeze
2
+ VERSION = "9.10.0.pre1".freeze
3
3
  end
@@ -25,10 +25,14 @@ module ActiveFedora
25
25
  # Returns an array of ActiveFedora::VersionsGraph::ResourceVersion objects.
26
26
  # Excludes auto-snapshot versions from Fedora.
27
27
  def versions(reload = false)
28
+ response = versions_request
29
+
30
+ return ActiveFedora::VersionsGraph.new unless response
31
+
28
32
  if reload
29
- @versions = ActiveFedora::VersionsGraph.new << ::RDF::Reader.for(:ttl).new(versions_request)
33
+ @versions = ActiveFedora::VersionsGraph.new << versions_request.reader
30
34
  else
31
- @versions ||= ActiveFedora::VersionsGraph.new << ::RDF::Reader.for(:ttl).new(versions_request)
35
+ @versions ||= ActiveFedora::VersionsGraph.new << versions_request.reader
32
36
  end
33
37
  end
34
38
 
@@ -57,11 +61,8 @@ module ActiveFedora
57
61
  private
58
62
 
59
63
  def versions_request
60
- return '' unless has_versions?
61
- resp = ActiveFedora.fedora.connection.get(versions_uri)
62
- raise ActiveFedoraError, status_message(resp) unless resp.success?
63
- raise ActiveFedoraError, bad_headers(resp) unless resp.headers['content-type'] == 'text/turtle'
64
- resp.body
64
+ return false unless has_versions?
65
+ ActiveFedora.fedora.connection.get(versions_uri)
65
66
  end
66
67
 
67
68
  def versions_uri
@@ -19,8 +19,3 @@ end
19
19
  def unstub_rails
20
20
  Object.send(:remove_const, :Rails) if defined?(Rails)
21
21
  end
22
-
23
- def setup_pretest_env
24
- ENV['RAILS_ENV'] = 'test'
25
- ENV['environment'] = 'test'
26
- end
@@ -234,8 +234,8 @@ describe ActiveFedora::Base do
234
234
 
235
235
  solr_resp = @library.books(response_format: :solr)
236
236
  expect(solr_resp.size).to eq 2
237
- expect(solr_resp[0]['id']).to eq @book.id
238
- expect(solr_resp[1]['id']).to eq @book2.id
237
+ expect(solr_resp[0].id).to eq @book.id
238
+ expect(solr_resp[1].id).to eq @book2.id
239
239
  end
240
240
  end
241
241
 
@@ -584,7 +584,7 @@ describe ActiveFedora::Base do
584
584
  end
585
585
 
586
586
  it "it should find the reflection that bears the predicate" do
587
- expect(MediaObject.new.association(:baubles).send(:find_reflection)).to eq Bauble.reflect_on_association(:media_object)
587
+ expect(MediaObject.new.association(:baubles).send(:find_reflection)).to eq Bauble._reflect_on_association(:media_object)
588
588
  end
589
589
  end
590
590
 
@@ -604,7 +604,7 @@ describe ActiveFedora::Base do
604
604
  end
605
605
 
606
606
  it "it should find the reflection that bears the predicate" do
607
- expect(MediaObject.new.association(:parts).send(:find_reflection)).to eq MasterFile.reflect_on_association(:media_object)
607
+ expect(MediaObject.new.association(:parts).send(:find_reflection)).to eq MasterFile._reflect_on_association(:media_object)
608
608
  end
609
609
  end
610
610
 
@@ -624,7 +624,7 @@ describe ActiveFedora::Base do
624
624
  end
625
625
 
626
626
  it "it should find the reflection that bears the predicate" do
627
- expect(MediaObject.new.association(:baubles).send(:find_reflection)).to eq MediaObject.reflect_on_association(:baubles)
627
+ expect(MediaObject.new.association(:baubles).send(:find_reflection)).to eq MediaObject._reflect_on_association(:baubles)
628
628
  end
629
629
  end
630
630
  end
@@ -22,8 +22,8 @@ describe ActiveFedora::Base do
22
22
  obj = described_class.find(@obj.id)
23
23
  expect(obj.foo).to_not be_new_record
24
24
  expect(obj.foo.person).to eq ['bob']
25
- person_field = ActiveFedora::SolrQueryBuilder.solr_name('foo__person', type: :string)
26
- solr_result = ActiveFedora::SolrService.query("{!raw f=id}#{@obj.id}", fl: "id #{person_field}").first
25
+ person_field = ActiveFedora.index_field_mapper.solr_name('foo__person', type: :string)
26
+ solr_result = ActiveFedora::SolrService.query("{!field f=id}#{@obj.id}", fl: "id #{person_field}").first
27
27
  expect(solr_result).to eq("id" => @obj.id, person_field => ['bob'])
28
28
  end
29
29
  end
@@ -41,7 +41,7 @@ describe ActiveFedora::Base do
41
41
  end
42
42
  it "saves the datastream." do
43
43
  expect(MockAFBaseRelationship.find(@release.id).foo.person).to eq ['frank']
44
- person_field = ActiveFedora::SolrQueryBuilder.solr_name('foo__person', type: :string)
44
+ person_field = ActiveFedora.index_field_mapper.solr_name('foo__person', type: :string)
45
45
  expect(ActiveFedora::SolrService.query("id:\"#{@release.id}\"", fl: "id #{person_field}").first).to eq("id" => @release.id, person_field => ['frank'])
46
46
  end
47
47
  end
@@ -164,7 +164,7 @@ describe ActiveFedora::Base do
164
164
  let(:obj) { ExampleBase.new }
165
165
  it "configures properties and solrize them" do
166
166
  obj.title = ["Test"]
167
- expect(obj.to_solr[ActiveFedora::SolrQueryBuilder.solr_name("title", :symbol)]).to eq ["Test"]
167
+ expect(obj.to_solr[ActiveFedora.index_field_mapper.solr_name("title", :symbol)]).to eq ["Test"]
168
168
  end
169
169
  end
170
170
 
@@ -3,7 +3,6 @@ require 'spec_helper'
3
3
  require 'active_fedora'
4
4
  require 'active_fedora/model'
5
5
  require "rexml/document"
6
- include ActiveFedora::Model
7
6
 
8
7
  describe 'bugs' do
9
8
  before do
@@ -131,11 +131,11 @@ describe ActiveFedora::Base do
131
131
 
132
132
  @test_history.save
133
133
 
134
- @solr_result = OralHistory.find_with_conditions(id: @test_history.id)[0]
134
+ @solr_result = OralHistory.search_with_conditions(id: @test_history.id)[0]
135
135
  @properties_sample_values.each_pair do |field, value|
136
136
  next if field == :hard_copy_availability # FIXME: HYDRA-824
137
137
  next if field == :location # FIXME HYDRA-825
138
- expect((@solr_result[ActiveFedora::SolrQueryBuilder.solr_name(field, type: :string)] || @solr_result[ActiveFedora::SolrQueryBuilder.solr_name(field, type: :date)])).to eq [::Solrizer::Extractor.format_node_value(value)]
138
+ expect((@solr_result[ActiveFedora.index_field_mapper.solr_name(field, type: :string)] || @solr_result[ActiveFedora.index_field_mapper.solr_name(field, type: :date)])).to eq [::Solrizer::Extractor.format_node_value(value)]
139
139
  end
140
140
 
141
141
  @dublin_core_sample_values.each_pair do |field, value|
@@ -153,8 +153,8 @@ describe ActiveFedora::Base do
153
153
  expect(dc_xml.root.elements["dcterms:subject"].text).to eq "My Subject Heading"
154
154
  end
155
155
 
156
- it "supports #find_with_conditions" do
157
- solr_result = OralHistory.find_with_conditions({})
156
+ it "supports #search_with_conditions" do
157
+ solr_result = OralHistory.search_with_conditions({})
158
158
  expect(solr_result).to_not be_nil
159
159
  end
160
160
  end
@@ -395,7 +395,7 @@ describe ActiveFedora::Base do
395
395
  end
396
396
 
397
397
  context "when the has_and_belongs_to_many provides an inverse_of" do
398
- let(:reflection) { Component.reflect_on_association(:items) }
398
+ let(:reflection) { Component._reflect_on_association(:items) }
399
399
  before do
400
400
  reflection.options[:inverse_of] = :components
401
401
  end
@@ -27,6 +27,35 @@ describe ActiveFedora::Associations::HasManyAssociation do
27
27
  end
28
28
  end
29
29
 
30
+ context "when the owner is not saved, and potential targets (Books) exist" do
31
+ let!(:book) { Book.create }
32
+ let(:library) { Library.new }
33
+ subject { library.books.count }
34
+ it "it excludes the books that aren't associated" do
35
+ expect(subject).to eq 0
36
+ end
37
+ end
38
+
39
+ context "when the owner is saved with associations" do
40
+ let(:book) { Book.create }
41
+ let!(:library) { Library.create(books: [book]) }
42
+ subject { library.reload; library.books.count }
43
+ it "it excludes the books that are associated" do
44
+ expect(subject).to eq 1
45
+ end
46
+ end
47
+
48
+ context "when the owner is not saved after checking the count" do
49
+ let!(:book) { Book.create }
50
+ let(:library) { Library.new }
51
+ it "refreshes the cache" do
52
+ expect(library.books.count).to eq 0
53
+ library.books << book
54
+ library.save!
55
+ expect(library.books.count).to eq 1
56
+ end
57
+ end
58
+
30
59
  context "loading the association prior to a save that affects the association" do
31
60
  let(:library) { Library.new }
32
61
  before do
@@ -61,7 +90,7 @@ describe ActiveFedora::Associations::HasManyAssociation do
61
90
  expect(library.books).to be_loaded
62
91
  end
63
92
  it "loads from solr" do
64
- expect(library.books.load_from_solr.map { |r| r["id"] }).to eq([book.id])
93
+ expect(library.books.load_from_solr.map(&:id)).to eq([book.id])
65
94
  end
66
95
  it "loads from solr with options" do
67
96
  expect(library.books.load_from_solr(rows: 0).size).to eq(0)
@@ -98,7 +98,7 @@ describe "Indirect containers" do
98
98
  context "when the class is implied" do
99
99
  before do
100
100
  class FooHistory < ActiveFedora::Base
101
- # TODO: inserted_content_relation can look up the predicate at options[:through].constantize.reflect_on_association(options[:foreign_key]).predicate
101
+ # TODO: inserted_content_relation can look up the predicate at options[:through].constantize._reflect_on_association(options[:foreign_key]).predicate
102
102
  indirectly_contains :related_objects,
103
103
  has_member_relation: ::RDF::URI.new('http://www.openarchives.org/ore/terms/aggregates'),
104
104
  inserted_content_relation: ::RDF::URI.new('http://www.openarchives.org/ore/terms/proxyFor'),
@@ -102,6 +102,12 @@ describe "NestedAttribute behavior" do
102
102
  it "creates a new record" do
103
103
  expect {
104
104
  car.update bars_attributes: [{ uno: "bar1 uno", _destroy: "1" }]
105
+ }.to change { car.bars(true).count }.by(1)
106
+ end
107
+
108
+ it "does not create a new record if reject_if conditions are triggered" do
109
+ expect {
110
+ car.update bars_attributes: [{ uno: "", _destroy: "1" }]
105
111
  }.not_to change { car.bars(true).count }
106
112
  end
107
113
  end
@@ -92,21 +92,21 @@ EOF
92
92
  subject.date_uploaded = [Date.parse('2012-11-02')]
93
93
  expect(subject.date_uploaded.first).to be_kind_of Date
94
94
  solr_document = subject.to_solr
95
- expect(solr_document[ActiveFedora::SolrQueryBuilder.solr_name('rdf__date_uploaded', type: :date)]).to eq ['2012-11-02T00:00:00Z']
95
+ expect(solr_document[ActiveFedora.index_field_mapper.solr_name('rdf__date_uploaded', type: :date)]).to eq ['2012-11-02T00:00:00Z']
96
96
  end
97
97
  it "handles integers" do
98
98
  subject.filesize = 12_345
99
99
  expect(subject.filesize).to be_kind_of Fixnum
100
100
  solr_document = subject.to_solr
101
- expect(solr_document[ActiveFedora::SolrQueryBuilder.solr_name('rdf__filesize', :stored_sortable, type: :integer)]).to eq '12345'
101
+ expect(solr_document[ActiveFedora.index_field_mapper.solr_name('rdf__filesize', :stored_sortable, type: :integer)]).to eq '12345'
102
102
  end
103
103
  end
104
104
 
105
105
  it "produces a solr document" do
106
106
  @subject = RdfTest.new(title: "War and Peace")
107
107
  solr_document = @subject.to_solr
108
- expect(solr_document[ActiveFedora::SolrQueryBuilder.solr_name('rdf__title', :facetable)]).to eq ["War and Peace"]
109
- expect(solr_document[ActiveFedora::SolrQueryBuilder.solr_name('rdf__title', type: :string)]).to eq ["War and Peace"]
108
+ expect(solr_document[ActiveFedora.index_field_mapper.solr_name('rdf__title', :facetable)]).to eq ["War and Peace"]
109
+ expect(solr_document[ActiveFedora.index_field_mapper.solr_name('rdf__title', type: :string)]).to eq ["War and Peace"]
110
110
  end
111
111
 
112
112
  it "sets and recall values" do
@@ -72,7 +72,7 @@ describe ActiveFedora::OmDatastream do
72
72
  obj.reload
73
73
  end
74
74
  it "solrizes terms with :type=>'date' to *_dt solr terms" do
75
- expect(obj.to_solr[ActiveFedora::SolrQueryBuilder.solr_name('desc_metadata__journal_issue_publication_date', type: :date)]).to eq ['2012-11-02T00:00:00Z']
75
+ expect(obj.to_solr[ActiveFedora.index_field_mapper.solr_name('desc_metadata__journal_issue_publication_date', type: :date)]).to eq ['2012-11-02T00:00:00Z']
76
76
  end
77
77
  end
78
78
  end
@@ -16,7 +16,7 @@ describe ActiveFedora::Model do
16
16
 
17
17
  def to_solr(doc = {})
18
18
  doc = super
19
- doc[ActiveFedora::SolrQueryBuilder.solr_name('foo', :sortable)] = doc[ActiveFedora::SolrQueryBuilder.solr_name('foo', type: :string)]
19
+ doc[ActiveFedora.index_field_mapper.solr_name('foo', :sortable)] = doc[ActiveFedora.index_field_mapper.solr_name('foo', type: :string)]
20
20
  doc
21
21
  end
22
22
  end
@@ -16,7 +16,7 @@ describe ActiveFedora::Querying do
16
16
 
17
17
  def to_solr(doc = {})
18
18
  doc = super
19
- doc[ActiveFedora::SolrQueryBuilder.solr_name('foo', :sortable)] = doc[ActiveFedora::SolrQueryBuilder.solr_name('foo', type: :string)]
19
+ doc[ActiveFedora.index_field_mapper.solr_name('foo', :sortable)] = doc[ActiveFedora.index_field_mapper.solr_name('foo', type: :string)]
20
20
  doc
21
21
  end
22
22
  end
@@ -64,12 +64,12 @@ describe ActiveFedora::Querying do
64
64
  end
65
65
 
66
66
  it "queries" do
67
- field = ActiveFedora::SolrQueryBuilder.solr_name('foo', type: :string)
67
+ field = ActiveFedora.index_field_mapper.solr_name('foo', type: :string)
68
68
  expect(ModelIntegrationSpec::Basic.where(field => 'Beta')).to eq [test_instance1]
69
69
  expect(ModelIntegrationSpec::Basic.where('foo' => 'Beta')).to eq [test_instance1]
70
70
  end
71
71
  it "orders" do
72
- expect(ModelIntegrationSpec::Basic.order(ActiveFedora::SolrQueryBuilder.solr_name('foo', :sortable) + ' asc')).to eq [test_instance2, test_instance1, test_instance3]
72
+ expect(ModelIntegrationSpec::Basic.order(ActiveFedora.index_field_mapper.solr_name('foo', :sortable) + ' asc')).to eq [test_instance2, test_instance1, test_instance3]
73
73
  end
74
74
  it "limits" do
75
75
  expect(ModelIntegrationSpec::Basic.limit(1)).to eq [test_instance1]
@@ -79,7 +79,7 @@ describe ActiveFedora::Querying do
79
79
  end
80
80
 
81
81
  it "chains queries" do
82
- expect(ModelIntegrationSpec::Basic.where(ActiveFedora::SolrQueryBuilder.solr_name('bar', type: :string) => 'Peanuts').order(ActiveFedora::SolrQueryBuilder.solr_name('foo', :sortable) + ' asc').limit(1)).to eq [test_instance2]
82
+ expect(ModelIntegrationSpec::Basic.where(ActiveFedora.index_field_mapper.solr_name('bar', type: :string) => 'Peanuts').order(ActiveFedora.index_field_mapper.solr_name('foo', :sortable) + ' asc').limit(1)).to eq [test_instance2]
83
83
  end
84
84
 
85
85
  it "wraps string conditions with parentheses" do
@@ -87,31 +87,31 @@ describe ActiveFedora::Querying do
87
87
  end
88
88
 
89
89
  it "chains where queries" do
90
- first_condition = { ActiveFedora::SolrQueryBuilder.solr_name('bar', type: :string) => 'Peanuts' }
90
+ first_condition = { ActiveFedora.index_field_mapper.solr_name('bar', type: :string) => 'Peanuts' }
91
91
  second_condition = "foo_tesim:bar"
92
92
  where_values = ModelIntegrationSpec::Basic.where(first_condition)
93
93
  .where(second_condition).where_values
94
- expect(where_values).to eq ["bar_tesim:Peanuts",
94
+ expect(where_values).to eq ["_query_:\"{!field f=bar_tesim}Peanuts\"",
95
95
  "(foo_tesim:bar)"]
96
96
  end
97
97
 
98
98
  it "chains count" do
99
- expect(ModelIntegrationSpec::Basic.where(ActiveFedora::SolrQueryBuilder.solr_name('bar', type: :string) => 'Peanuts').count).to eq 2
99
+ expect(ModelIntegrationSpec::Basic.where(ActiveFedora.index_field_mapper.solr_name('bar', type: :string) => 'Peanuts').count).to eq 2
100
100
  end
101
101
 
102
102
  it "calling first should not affect the relation's ability to get all results later" do
103
- relation = ModelIntegrationSpec::Basic.where(ActiveFedora::SolrQueryBuilder.solr_name('bar', type: :string) => 'Peanuts')
103
+ relation = ModelIntegrationSpec::Basic.where(ActiveFedora.index_field_mapper.solr_name('bar', type: :string) => 'Peanuts')
104
104
  expect { relation.first }.not_to change { relation.to_a.size }
105
105
  end
106
106
 
107
107
  it "calling where should not affect the relation's ability to get all results later" do
108
- relation = ModelIntegrationSpec::Basic.where(ActiveFedora::SolrQueryBuilder.solr_name('bar', type: :string) => 'Peanuts')
109
- expect { relation.where(ActiveFedora::SolrQueryBuilder.solr_name('foo', type: :string) => 'bar') }.not_to change { relation.to_a.size }
108
+ relation = ModelIntegrationSpec::Basic.where(ActiveFedora.index_field_mapper.solr_name('bar', type: :string) => 'Peanuts')
109
+ expect { relation.where(ActiveFedora.index_field_mapper.solr_name('foo', type: :string) => 'bar') }.not_to change { relation.to_a.size }
110
110
  end
111
111
 
112
112
  it "calling order should not affect the original order of the relation later" do
113
- relation = ModelIntegrationSpec::Basic.order(ActiveFedora::SolrQueryBuilder.solr_name('foo', :sortable) + ' asc')
114
- expect { relation.order(ActiveFedora::SolrQueryBuilder.solr_name('foo', :sortable) + ' desc') }.not_to change { relation.to_a }
113
+ relation = ModelIntegrationSpec::Basic.order(ActiveFedora.index_field_mapper.solr_name('foo', :sortable) + ' asc')
114
+ expect { relation.order(ActiveFedora.index_field_mapper.solr_name('foo', :sortable) + ' desc') }.not_to change { relation.to_a }
115
115
  end
116
116
  end
117
117
 
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::SolrHit do
4
+ before do
5
+ class Foo < ActiveFedora::Base
6
+ has_metadata 'descMetadata', type: ActiveFedora::SimpleDatastream do |m|
7
+ m.field "foo", :text
8
+ m.field "bar", :text
9
+ end
10
+ Deprecation.silence(ActiveFedora::Attributes) do
11
+ has_attributes :foo, datastream: 'descMetadata', multiple: true
12
+ has_attributes :bar, datastream: 'descMetadata', multiple: false
13
+ end
14
+ property :title, predicate: ::RDF::Vocab::DC.title, multiple: false
15
+ end
16
+ end
17
+
18
+ let(:another) { Foo.create }
19
+
20
+ let!(:obj) { Foo.create!(
21
+ id: 'test-123',
22
+ foo: ["baz"],
23
+ bar: 'quix',
24
+ title: 'My Title'
25
+ ) }
26
+
27
+ let(:profile) { { "foo" => ["baz"], "bar" => "quix", "title" => "My Title" }.to_json }
28
+ let(:doc) { { 'id' => 'test-123', 'has_model_ssim' => ['Foo'], 'object_profile_ssm' => profile } }
29
+ let(:solr_hit) { described_class.new(doc) }
30
+
31
+ after do
32
+ Object.send(:remove_const, :Foo)
33
+ end
34
+
35
+ describe "#reify" do
36
+ subject { solr_hit.reify }
37
+
38
+ it "finds the document in solr" do
39
+ expect(subject).to be_instance_of Foo
40
+ expect(subject.title).to eq 'My Title'
41
+ end
42
+ end
43
+
44
+ describe "#instantiate_with_json" do
45
+ subject { solr_hit.instantiate_with_json }
46
+
47
+ it "finds the document in solr" do
48
+ expect(subject).to be_instance_of Foo
49
+ expect(subject.title).to eq 'My Title'
50
+ end
51
+ end
52
+ end
@@ -508,8 +508,8 @@ module Hydra
508
508
  def to_solr(solr_doc = {}, opts = {})
509
509
  solr_doc = super
510
510
 
511
- ::Solrizer::Extractor.insert_solr_field_value(solr_doc, Solrizer.default_field_mapper.solr_name('object_type', :facetable), "Article")
512
- ::Solrizer::Extractor.insert_solr_field_value(solr_doc, Solrizer.default_field_mapper.solr_name('mods_journal_title_info', :facetable), "Unknown") if solr_doc["mods_journal_title_info_facet"].nil?
511
+ ::Solrizer::Extractor.insert_solr_field_value(solr_doc, ActiveFedora.index_field_mapper.solr_name('object_type', :facetable), "Article")
512
+ ::Solrizer::Extractor.insert_solr_field_value(solr_doc, ActiveFedora.index_field_mapper.solr_name('mods_journal_title_info', :facetable), "Unknown") if solr_doc["mods_journal_title_info_facet"].nil?
513
513
 
514
514
  solr_doc
515
515
  end