active-fedora 4.0.0.rc9 → 4.0.0.rc10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active-fedora (4.0.0.rc9)
4
+ active-fedora (4.0.0.rc10)
5
5
  activeresource (>= 3.0.0)
6
6
  activesupport (>= 3.0.0)
7
7
  equivalent-xml
@@ -1,4 +1,4 @@
1
- 4.0.0.rc9
1
+ 4.0.0.rc10
2
2
  Removed deprecations
3
3
  * allowing :fedora level in fedora.yml
4
4
  * automatic includes of Relationships and FileMethods is removed
@@ -14,6 +14,10 @@ Find raises ObjectNotFoundError when the object isn't found
14
14
  Removed dependency on solrizer-fedora
15
15
  Avoid unnecessary reload of RELS-EXT when typecasting
16
16
  HYDRA-754 Delegate discovery of config parameters to a separate module to allow for non-file-based configuration
17
+ HYDRA-753 has_metadata should accept :versionable as part of the spec.
18
+ HYDRA-755 Instantiate un-spec'ed datastreams in SolrDigitalObject
19
+ HYDRA-758 Added ActiveFedora::Base.exists?
20
+ Fixes for Ruby 1.9 compatibility
17
21
 
18
22
  3.3.2
19
23
  HYDRA-745 No need to require :url be present on external datastreams
@@ -370,7 +370,7 @@ module ActiveFedora
370
370
  raise "Solr document record id and pid do not match" unless pid == solr_doc[SOLR_DOCUMENT_ID]
371
371
  end
372
372
 
373
- obj = self.allocate.init_with(SolrDigitalObject.new(solr_doc))
373
+ obj = self.allocate.init_with(SolrDigitalObject.new(solr_doc, self))
374
374
  #set by default to load any dependent relationship objects from solr as well
375
375
  #need to call rels_ext once so it exists when iterating over datastreams
376
376
  obj.rels_ext
@@ -78,7 +78,7 @@ module ActiveFedora
78
78
  ds = ds_spec[:type].new(inner_object, name)
79
79
  ds.dsLabel = ds_spec[:label] if ds_spec[:label].present?
80
80
  ds.controlGroup = ds_spec[:control_group]
81
- ds.versionable = ds_spec[:versionable]
81
+ ds.versionable = ds_spec[:versionable] unless ds_spec[:versionable].nil?
82
82
  additional_attributes_for_external_and_redirect_control_groups(ds, ds_spec)
83
83
  ds
84
84
  end
@@ -252,7 +252,9 @@ module ActiveFedora
252
252
  # @option args [Boolean] :versionable (true) Should versioned datastreams be stored
253
253
  # @yield block executed by some kinds of datastreams
254
254
  def has_metadata(args, &block)
255
- ds_specs[args[:name]]= {:type => args[:type], :label => args.fetch(:label,""), :control_group => args.fetch(:control_group,"X"), :disseminator => args.fetch(:disseminator,""), :url => args.fetch(:url,""),:block => block}
255
+ spec = {:type => args[:type], :label => args.fetch(:label,""), :control_group => args.fetch(:control_group,"X"), :disseminator => args.fetch(:disseminator,""), :url => args.fetch(:url,""),:block => block}
256
+ spec[:versionable] = args[:versionable] if args.has_key? :versionable
257
+ ds_specs[args[:name]]= spec
256
258
  end
257
259
 
258
260
  # Specify the attributes of a file bearing datastream
@@ -114,6 +114,13 @@ module ActiveFedora
114
114
  end
115
115
  end
116
116
 
117
+ # Returns true if the pid exists in the repository
118
+ # @param[String] pid
119
+ # @return[boolean]
120
+ def exists?(pid)
121
+ inner = DigitalObject.find(self, pid)
122
+ !inner.new?
123
+ end
117
124
 
118
125
  def find_model(pid)
119
126
  ActiveSupport::Deprecation.warn("find_model is deprecated. Use find instead")
@@ -2,6 +2,24 @@ require 'rdf'
2
2
 
3
3
  module ActiveFedora
4
4
  class RDFDatastream < Datastream
5
+ # this enables a cleaner API for solr integration
6
+ class IndexObject
7
+ attr_accessor :data_type, :behaviors
8
+ def initialize
9
+ @behaviors = [:searchable]
10
+ @data_type = :string
11
+ end
12
+ def as(*args)
13
+ @behaviors = args
14
+ end
15
+ def type(sym)
16
+ @data_type = sym
17
+ end
18
+ def defaults
19
+ :noop
20
+ end
21
+ end
22
+
5
23
  module ModelMethods
6
24
  extend ActiveSupport::Concern
7
25
  module ClassMethods
@@ -24,57 +42,64 @@ module ActiveFedora
24
42
  def map_predicates(&block)
25
43
  yield self
26
44
  end
27
- def method_missing(name, *args)
45
+ def method_missing(name, *args, &block)
28
46
  args = args.first if args.respond_to? :first
29
47
  raise "mapping must specify RDF vocabulary as :in argument" unless args.has_key? :in
30
48
  vocab = args[:in]
31
49
  predicate = args.fetch(:to, name)
32
- data_type = args.fetch(:type, :string)
33
50
  raise "Vocabulary '#{vocab.inspect}' does not define property '#{predicate.inspect}'" unless vocab.respond_to? predicate
51
+ indexing = false
52
+ if block_given?
53
+ # needed for solrizer integration
54
+ indexing = true
55
+ iobj = IndexObject.new
56
+ yield iobj
57
+ data_type = iobj.data_type
58
+ behaviors = iobj.behaviors
59
+ end
60
+ # needed for AF::Predicates integration & drives all other
61
+ # functionality below
34
62
  vocab = vocab.to_s
35
- # this is needed for AF::Predicates integration
36
- # stuff data_type in there too for to_solr support
37
- if config
63
+ if config
38
64
  if config[:predicate_mapping].has_key? vocab
39
65
  config[:predicate_mapping][vocab][name] = predicate
40
- config[:predicate_mapping][vocab]["#{name}type".to_sym] = data_type
41
66
  else
42
- config[:predicate_mapping][vocab] = { name => predicate, "#{name}type".to_sym => data_type }
43
- end
67
+ config[:predicate_mapping][vocab] = { name => predicate }
68
+ end
69
+ # stuff data_type and behaviors in there for to_solr support
70
+ config[:predicate_mapping][vocab]["#{name}type".to_sym] = data_type if indexing
71
+ config[:predicate_mapping][vocab]["#{name}behaviors".to_sym] = behaviors if indexing
44
72
  else
45
73
  config = {
46
74
  :default_namespace => vocab,
47
75
  :predicate_mapping => {
48
- vocab => { name => predicate, "#{name}type".to_sym => data_type }
76
+ vocab => { name => predicate }
49
77
  }
50
78
  }
79
+ # stuff data_type and behaviors in there for to_solr support
80
+ config[:predicate_mapping][vocab]["#{name}type".to_sym] = data_type if indexing
81
+ config[:predicate_mapping][vocab]["#{name}behaviors".to_sym] = behaviors if indexing
51
82
  end
52
83
  end
53
84
  end
54
85
  end
55
-
56
86
  class TermProxy
57
87
  # @param [Symbol, RDF::URI] predicate the predicate to insert into the graph
58
88
  # @param [ActiveFedora::RelationshipGraph] graph the graph
59
89
  # @param [Array] values an array of object values
60
- include Enumerable
90
+ instance_methods.each { |m| undef_method m unless m.to_s =~ /^(?:nil\?|send|object_id|to_a)$|^__|^respond_to|proxy_/ }
91
+
61
92
  def initialize(graph, predicate, values=[])
62
93
  @graph = graph
63
94
  @predicate = predicate
64
95
  @values = values
65
96
  end
66
- def each(&block)
67
- @values.each { |value| block.call(value) }
68
- end
69
97
  def <<(*values)
70
98
  @values.concat(values)
71
99
  values.each { |value| @graph.add(@predicate, value, true) }
72
100
  @graph.dirty = true
73
101
  @values
74
102
  end
75
- def ==(other)
76
- other == @values
77
- end
78
103
  def delete(*values)
79
104
  values.each do |value|
80
105
  unless @values.delete(value).nil?
@@ -84,9 +109,25 @@ module ActiveFedora
84
109
  end
85
110
  @values
86
111
  end
87
- def empty?
88
- @values.empty?
112
+ def method_missing(method, *args)
113
+ unless @values.respond_to?(method)
114
+ message = "undefined method `#{method.to_s}' for \"#{@values}\":#{@values.class.to_s}"
115
+ raise NoMethodError, message
116
+ end
117
+
118
+ if block_given?
119
+ @values.send(method, *args) { |*block_args| yield(*block_args) }
120
+ else
121
+ @values.send(method, *args)
122
+ end
123
+
89
124
  end
125
+ # def empty?
126
+ # @values.empty?
127
+ # end
128
+ # def to_s
129
+ # @values.to_s
130
+ # end
90
131
  end
91
132
 
92
133
  include ModelMethods
@@ -107,29 +148,34 @@ module ActiveFedora
107
148
  end
108
149
  end
109
150
 
110
- # returns a Hash, e.g.: {field => {:values => values, :type => type}, ...}
151
+ # returns a Hash, e.g.: {field => {:values => [], :type => :something, :behaviors => []}, ...}
111
152
  def fields
112
153
  field_map = {}
113
154
  graph.relationships.each do |predicate, values|
114
155
  vocab_sym, name = predicate.qname
115
156
  vocabs_list = self.class.vocabularies.select { |ns, v| v.__prefix__ == vocab_sym }
116
157
  vocab = vocabs_list.first.first.to_s
117
- mapped_names = self.class.config[:predicate_mapping][vocab].select {|k, v| v.to_s == name.to_s}
158
+ vocab_hash = self.class.config[:predicate_mapping][vocab]
159
+ mapped_names = vocab_hash.select {|k, v| v.to_s == name.to_s}
118
160
  name = mapped_names.first.first.to_s
119
- type = self.class.config[:predicate_mapping][vocab]["#{name}type".to_sym]
120
- field_map[name.to_sym] = {:values => values.map {|v| v.to_s}, :type => type}
161
+ next unless vocab_hash.has_key?("#{name}type".to_sym) and vocab_hash.has_key?("#{name}behaviors".to_sym)
162
+ type = vocab_hash["#{name}type".to_sym]
163
+ behaviors = vocab_hash["#{name}behaviors".to_sym]
164
+ field_map[name.to_sym] = {:values => values.map {|v| v.to_s}, :type => type, :behaviors => behaviors}
121
165
  end
122
166
  field_map
123
167
  end
124
168
 
125
169
  def to_solr(solr_doc = Hash.new) # :nodoc:
126
170
  fields.each do |field_key, field_info|
127
- if field_info.has_key?(:values) && !field_info[:values].nil?
128
- field_symbol = ActiveFedora::SolrService.solr_name(field_key, field_info[:type])
129
- values = field_info[:values]
130
- values = [values] unless values.respond_to? :each
131
- values.each do |val|
132
- ::Solrizer::Extractor.insert_solr_field_value(solr_doc, field_symbol, val)
171
+ values = field_info.fetch(:values, false)
172
+ if values
173
+ field_info[:behaviors].each do |index_type|
174
+ field_symbol = ActiveFedora::SolrService.solr_name(field_key, field_info[:type], index_type)
175
+ values = [values] unless values.respond_to? :each
176
+ values.each do |val|
177
+ ::Solrizer::Extractor.insert_solr_field_value(solr_doc, field_symbol, val)
178
+ end
133
179
  end
134
180
  end
135
181
  end
@@ -140,7 +186,7 @@ module ActiveFedora
140
186
  def find_predicate(predicate)
141
187
  predicate = predicate.to_sym unless predicate.kind_of? RDF::URI
142
188
  result = ActiveFedora::Predicates.find_predicate(predicate)
143
- RDF::URI(result.reverse.to_s)
189
+ RDF::URI(result.reverse.join)
144
190
  end
145
191
 
146
192
  def graph
@@ -166,8 +212,10 @@ module ActiveFedora
166
212
  ensure_loaded
167
213
  predicate = find_predicate(predicate) unless predicate.kind_of? RDF::URI
168
214
  graph.delete(predicate)
215
+
216
+ args = [args] unless args.respond_to? :each
169
217
  args.each do |arg|
170
- graph.add(predicate, arg, true)
218
+ graph.add(predicate, arg, true) unless arg.empty?
171
219
  end
172
220
  graph.dirty = true
173
221
  return TermProxy.new(graph, predicate, args)
@@ -1,25 +1,37 @@
1
1
  module ActiveFedora
2
2
  class SolrDigitalObject
3
- attr_reader :pid, :label, :state, :ownerId, :profile, :datastreams
3
+ attr_reader :pid, :label, :state, :ownerId, :profile, :datastreams, :solr_doc
4
4
 
5
- def initialize(solr_doc)
5
+ def initialize(solr_doc, klass=ActiveFedora::Base)
6
+ @solr_doc = solr_doc
6
7
  @pid = solr_doc[SOLR_DOCUMENT_ID]
7
8
  profile_attrs = solr_doc.keys.select { |k| k =~ /^objProfile_/ }
8
9
  @profile = {}
9
10
  profile_attrs.each do |key|
10
11
  attr_name = key.split(/_/)[1..-2].join('_')
11
- @profile[attr_name] = solr_doc[key].to_s
12
+ @profile[attr_name] = Array(solr_doc[key]).first.to_s
12
13
  end
13
14
  @profile['objCreateDate'] ||= Time.now.xmlschema
14
15
  @profile['objLastModDate'] ||= @profile['objCreateDate']
15
-
16
+
16
17
  @datastreams = {}
18
+
19
+ dsids = @solr_doc.keys.collect { |k| k.scan(/^(.+)_dsProfile_/).flatten.first }.compact.uniq
20
+ missing = dsids-klass.ds_specs.keys
21
+ missing.each do |dsid|
22
+ mime_key = ActiveFedora::SolrService.solr_name("#{dsid}_dsProfile_dsMIME",:symbol)
23
+ mime_type = Array(@solr_doc[mime_key]).first
24
+ ds_class = mime_type =~ /[\/\+]xml$/ ? NokogiriDatastream : Datastream
25
+ @datastreams[dsid] = ds_class.new(self, dsid)
26
+ end
27
+
17
28
  @label = @profile['objLabel']
18
29
  @state = @profile['objState']
19
30
  @ownerId = @profile['objOwnerId']
20
31
  end
21
-
32
+
22
33
  def freeze
34
+ @finished = true
23
35
  @profile.freeze
24
36
  @datastreams.freeze
25
37
  self
@@ -29,5 +41,8 @@ module ActiveFedora
29
41
  false
30
42
  end
31
43
 
44
+ def repository
45
+ @finished ? ActiveFedora::Base.connection_for_pid(self.pid) : nil
46
+ end
32
47
  end
33
48
  end
@@ -24,7 +24,6 @@ module ActiveFedora
24
24
  args = args.dup
25
25
  args.merge!(:url=>host)
26
26
  @conn = RSolr.connect args
27
- # @conn = Solr::Connection.new(host, opts)
28
27
  end
29
28
 
30
29
  def self.instance
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "4.0.0.rc9"
2
+ VERSION = "4.0.0.rc10"
3
3
  end
@@ -217,10 +217,8 @@ describe ActiveFedora::Base do
217
217
  it "should expose the DC datastream" do
218
218
  dc = @test_object.dc
219
219
  dc.should be_a_kind_of(ActiveFedora::Datastream)
220
- #dc["identifier"].should_not be_nil
221
220
  rexml = REXML::Document.new(dc.content)
222
221
  rexml.root.elements["dc:identifier"].get_text.should_not be_nil
223
- #dc.elements["dc:identifier"].should_not be_nil
224
222
  end
225
223
  end
226
224
 
@@ -671,4 +669,13 @@ describe ActiveFedora::Base do
671
669
 
672
670
  end
673
671
  end
672
+
673
+ describe "#exists?" do
674
+ it "should return true for objects that exist" do
675
+ ActiveFedora::Base.exists?('hydrangea:fixture_mods_article1').should be_true
676
+ end
677
+ it "should return false for objects that dont exist" do
678
+ ActiveFedora::Base.exists?('nil:object').should be_false
679
+ end
680
+ end
674
681
  end
@@ -51,10 +51,4 @@ describe 'bugs' do
51
51
  x.datastreams['someData'].fubar_values.should == ["meh"]
52
52
  x.save
53
53
  end
54
- it "should update the index, even if there is no metadata" do
55
- pending
56
- oh = FooHistory.new
57
- oh.save
58
- end
59
-
60
54
  end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'spec/samples/models/hydrangea_article'
2
+ #require 'spec/samples/models/hydrangea_article'
3
3
 
4
4
  include ActiveFedora::Model
5
5
  include Mocha::API
@@ -73,6 +73,11 @@ describe ActiveFedora::SolrService do
73
73
  end
74
74
  end
75
75
 
76
+ it 'should instantiate all datastreams in the solr doc, even ones undeclared by the class' do
77
+ obj = ActiveFedora::Base.load_instance_from_solr "hydrangea:fixture_mods_article1"
78
+ obj.datastreams.keys.should include('descMetadata')
79
+ end
80
+
76
81
  it 'should #reify a lightweight object as a new instance' do
77
82
  query = "id\:#{ActiveFedora::SolrService.escape_uri_for_query(@foo_object.pid)}"
78
83
  solr_result = ActiveFedora::SolrService.query(query)
@@ -1,6 +1,6 @@
1
1
  require "active-fedora"
2
- require 'spec/samples/hydra-mods_article_datastream.rb'
3
- require 'spec/samples/hydra-rights_metadata_datastream.rb'
2
+ require 'samples/hydra-mods_article_datastream.rb'
3
+ require 'samples/hydra-rights_metadata_datastream.rb'
4
4
 
5
5
  # This Model is used to load & index the hydrangea:fixture_mods_article1 fixture for use in tests.
6
6
  #
@@ -1,2 +1,2 @@
1
1
  # require all of the files in the samples directory
2
- require 'spec/samples/models/hydrangea_article'
2
+ require 'samples/models/hydrangea_article'
@@ -61,7 +61,6 @@ describe ActiveFedora::Base do
61
61
  it "should be a supported method" do
62
62
  @base.should respond_to(:collection_members_remove)
63
63
  end
64
- it "should remove hasCollectionMember for the given object/pid"
65
64
  end
66
65
  end
67
66
 
@@ -415,7 +415,10 @@ describe ActiveFedora::Base do
415
415
  @test_object.save
416
416
  end
417
417
  it "should NOT update solr index if no MetadataDatastreams have changed" do
418
- pending "Rels-ext is getting automatically added so we can't test this."
418
+ stub_ingest(@this_pid)
419
+ stub_add_ds(@this_pid, ['ds1', 'RELS-EXT'])
420
+ @test_object.save
421
+ @test_object.expects(:new_object?).returns(false).twice
419
422
  ActiveFedora::DigitalObject.any_instance.stubs(:save)
420
423
  mock1 = mock("ds1")
421
424
  mock1.expects( :changed?).returns(false).at_least_once
@@ -16,6 +16,10 @@ describe ActiveFedora::Datastreams do
16
16
  ds = @test_object.datastream_from_spec({:type=>ActiveFedora::Datastream, :versionable=>true}, 'test')
17
17
  ds.versionable.should be_true
18
18
  end
19
+ it "should default versionable to true" do
20
+ ds = @test_object.datastream_from_spec({:type=>ActiveFedora::Datastream}, 'test')
21
+ ds.versionable.should be_true
22
+ end
19
23
 
20
24
  end
21
25
 
@@ -33,6 +37,39 @@ describe ActiveFedora::Datastreams do
33
37
  #ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(@this_pid)
34
38
  end
35
39
 
40
+ describe "updates the spec" do
41
+ before do
42
+ class FooHistory < ActiveFedora::Base
43
+ end
44
+ end
45
+ after do
46
+ Object.send(:remove_const, :FooHistory)
47
+ end
48
+ subject { FooHistory}
49
+ it "should update the ds_spec" do
50
+ FooHistory.ds_specs.keys.should == ['RELS-EXT']
51
+ FooHistory.has_metadata :type=>ActiveFedora::Datastream, :name=>'new_ds'
52
+ FooHistory.ds_specs.keys.should include 'new_ds'
53
+ end
54
+ it "should be able to set a type" do
55
+ FooHistory.has_metadata :type=>ActiveFedora::Datastream, :name=>'new_ds', :control_group=>'R'
56
+ FooHistory.ds_specs['new_ds'][:control_group].should == 'R'
57
+ end
58
+ it "should be able to set versionable to false" do
59
+ FooHistory.has_metadata :type=>ActiveFedora::Datastream, :name=>'new_ds', :versionable=>false
60
+ FooHistory.ds_specs['new_ds'][:versionable].should be_false
61
+ end
62
+ it "should be able to set versionable to true" do
63
+ FooHistory.has_metadata :type=>ActiveFedora::Datastream, :name=>'new_ds', :versionable=>true
64
+ FooHistory.ds_specs['new_ds'][:versionable].should be_true
65
+ end
66
+ it "should not set versionable if it's not supplied" do
67
+ FooHistory.has_metadata :type=>ActiveFedora::Datastream, :name=>'new_ds'
68
+ FooHistory.ds_specs['new_ds'].keys.should_not include :versionable
69
+ end
70
+
71
+ end
72
+
36
73
  describe "creates datastreams" do
37
74
  before do
38
75
  class FooHistory < ActiveFedora::Base
@@ -40,14 +77,9 @@ describe ActiveFedora::Datastreams do
40
77
  m.field "fubar", :string
41
78
  m.field "swank", :text
42
79
  end
43
- has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText" do |m|
44
- m.field "fubar", :text
45
- end
46
80
  has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText2", :label=>"withLabel" do |m|
47
81
  m.field "fubar", :text
48
82
  end
49
- delegate :fubar, :to=>'withText'
50
- delegate :swank, :to=>'someData'
51
83
  end
52
84
  stub_ingest(@this_pid)
53
85
  stub_add_ds(@this_pid, ['RELS-EXT', 'someData', 'withText', 'withText2'])
@@ -106,6 +138,7 @@ describe ActiveFedora::Datastreams do
106
138
  @n.datastreams["UKETD_DC"].dsLocation.should == "sub_url/objects/#{@this_pid}/methods/hull-sDef:uketdObject/getUKETDMetadata"
107
139
  end
108
140
 
141
+
109
142
  context ":control_group => 'E'" do
110
143
  before do
111
144
  stub_get(@this_pid)
@@ -82,14 +82,6 @@ describe ActiveFedora::MetadataDatastream do
82
82
  @test_ds.should be_dirty
83
83
  end
84
84
 
85
- it "should support single-value arguments (as opposed to a hash of values with array indexes as keys)" do
86
- # In other words, { "fubar"=>"dork" } should have the same effect as { "fubar"=>{"0"=>"dork"} }
87
- pending "this should be working, but for some reason, the updates don't stick"
88
- result = @test_ds.update_indexed_attributes( { "fubar"=>"dork" } )
89
- result.should == {"fubar"=>{"0"=>"dork"}}
90
- @test_ds.fubar_values.should == ["dork"]
91
- end
92
-
93
85
  it "should work for text fields" do
94
86
  att= {"swank"=>{"-1"=>"mork", "1"=>"york"}}
95
87
  result = @test_ds.update_indexed_attributes(att)
@@ -113,12 +105,6 @@ describe ActiveFedora::MetadataDatastream do
113
105
  result.should == {"swank"=>{"2"=>"mork"}}
114
106
  end
115
107
 
116
- it "should return accurate response when multiple values have been added in a single run" do
117
- pending
118
- att= {"swank"=>{"-1"=>"mork", "0"=>"york"}}
119
- @test_ds.update_indexed_attributes(att).should == {"swank"=>{"0"=>"york", "1"=>"mork"}}
120
- end
121
-
122
108
  it "should deal gracefully with adding new values at explicitly declared indexes" do
123
109
  @test_ds.fubar_values = ["all", "for", "the"]
124
110
  att = {"fubar"=>{"3"=>'glory'}}
@@ -346,8 +332,6 @@ describe ActiveFedora::MetadataDatastream do
346
332
  solr_doc["empty_field_t"].should be_nil
347
333
  end
348
334
 
349
- it "should allow multiple values for a single field"
350
-
351
335
  it 'should append create keys in format field_name + _ + field_type' do
352
336
  @test_ds.stubs(:fields).returns(@sample_fields)
353
337
 
@@ -34,8 +34,8 @@ describe ActiveFedora::NtriplesRDFDatastream do
34
34
  @subject.based_near.should == ["New York, NY, US"]
35
35
  @subject.related_url.should == ["http://google.com/"]
36
36
  end
37
- it "should return fields that are TermProxies" do
38
- @subject.created.should be_kind_of ActiveFedora::RDFDatastream::TermProxy
37
+ it "should return fields that are not TermProxies" do
38
+ @subject.created.should be_kind_of Array
39
39
  end
40
40
  it "should have method missing" do
41
41
  lambda{@subject.frank}.should raise_exception ActiveFedora::UnregisteredPredicateError
@@ -56,7 +56,7 @@ describe ActiveFedora::NtriplesRDFDatastream do
56
56
  end
57
57
 
58
58
  describe "a new instance" do
59
- before do
59
+ before(:each) do
60
60
  class MyDatastream < ActiveFedora::NtriplesRDFDatastream
61
61
  register_vocabularies RDF::DC
62
62
  map_predicates do |map|
@@ -66,36 +66,59 @@ describe ActiveFedora::NtriplesRDFDatastream do
66
66
  @subject = MyDatastream.new(@inner_object, 'mixed_rdf')
67
67
  @subject.stubs(:pid => 'test:1')
68
68
  end
69
+ after(:each) do
70
+ Object.send(:remove_const, :MyDatastream)
71
+ end
69
72
  it "should save and reload" do
70
73
  @subject.publisher = ["St. Martin's Press"]
71
74
  @subject.save
72
75
  end
73
- end
76
+ it "should support to_s method" do
77
+ @subject.publisher.to_s.should == [].to_s
78
+ @subject.publisher = "Bob"
79
+ @subject.publisher.to_s.should == ["Bob"].to_s
80
+ @subject.publisher << "Jim"
81
+ @subject.publisher.to_s.should == ["Bob", "Jim"].to_s
82
+ end
83
+ end
74
84
 
75
85
  describe "solr integration" do
76
86
  before(:all) do
77
87
  class MyDatastream < ActiveFedora::NtriplesRDFDatastream
78
88
  register_vocabularies RDF::DC, RDF::FOAF, RDF::RDFS
79
89
  map_predicates do |map|
80
- map.created(:in => RDF::DC, :type => :date)
81
- map.title(:in => RDF::DC, :type => :text)
82
- map.publisher(:in => RDF::DC)
83
- map.based_near(:in => RDF::FOAF, :type => :text)
84
- map.related_url(:to => "seeAlso", :in => RDF::RDFS, :type => :string)
90
+ map.created(:in => RDF::DC) do |index|
91
+ index.as :sortable, :displayable
92
+ index.type :date
93
+ end
94
+ map.title(:in => RDF::DC) do |index|
95
+ index.as :searchable, :displayable, :sortable
96
+ index.type :text
97
+ end
98
+ map.publisher(:in => RDF::DC) do |index|
99
+ index.as :facetable, :sortable, :searchable, :displayable
100
+ end
101
+ map.based_near(:in => RDF::FOAF) do |index|
102
+ index.as :displayable, :facetable, :searchable
103
+ index.type :text
104
+ end
105
+ map.related_url(:to => "seeAlso", :in => RDF::RDFS) do |index|
106
+ index.defaults
107
+ end
108
+ map.rights(:in => RDF::DC)
85
109
  end
86
110
  end
87
111
  @subject = MyDatastream.new(@inner_object, 'solr_rdf')
88
112
  @subject.content = File.new('spec/fixtures/solr_rdf_descMetadata.nt').read
89
113
  @subject.stubs(:pid => 'test:1')
90
114
  @subject.stubs(:new? => false)
91
- @sample_fields = {:publisher => {:values => ["publisher1"], :type => :string},
92
- :based_near => {:values => ["coverage1", "coverage2"], :type => :text},
93
- :created => {:values => "fake-date", :type => :date},
94
- :title => {:values => "fake-title", :type => :text},
95
- :related_url => {:values => "http://example.org/", :type => :string},
96
- :empty_field => {:values => []}
115
+ @sample_fields = {:publisher => {:values => ["publisher1"], :type => :string, :behaviors => [:facetable, :sortable, :searchable, :displayable]},
116
+ :based_near => {:values => ["coverage1", "coverage2"], :type => :text, :behaviors => [:displayable, :facetable, :searchable]},
117
+ :created => {:values => "fake-date", :type => :date, :behaviors => [:sortable, :displayable]},
118
+ :title => {:values => "fake-title", :type => :text, :behaviors => [:searchable, :displayable, :sortable]},
119
+ :related_url => {:values => "http://example.org/", :type =>:string, :behaviors => [:searchable]},
120
+ :empty_field => {:values => [], :type => :string, :behaviors => [:searchable]}
97
121
  }
98
- @sample_xml = XmlSimple.xml_in("<fields><based_near>coverage1</based_near><based_near>coverage2</based_near><created>fake-date</created><publisher>publisher1</publisher><related_url>http://example.org/</related_url><title>fake-title</title></fields>")
99
122
  end
100
123
  after(:all) do
101
124
  # Revert to default mappings after running tests
@@ -117,9 +140,17 @@ describe ActiveFedora::NtriplesRDFDatastream do
117
140
  @subject.expects(:fields).returns(@sample_fields)
118
141
  solr_doc = @subject.to_solr
119
142
  solr_doc["publisher_t"].should == ["publisher1"]
143
+ solr_doc["publisher_sort"].should == ["publisher1"]
144
+ solr_doc["publisher_display"].should == ["publisher1"]
145
+ solr_doc["publisher_facet"].should == ["publisher1"]
120
146
  solr_doc["based_near_t"].sort.should == ["coverage1", "coverage2"]
121
- solr_doc["created_dt"].should == ["fake-date"]
147
+ solr_doc["based_near_display"].sort.should == ["coverage1", "coverage2"]
148
+ solr_doc["based_near_facet"].sort.should == ["coverage1", "coverage2"]
149
+ solr_doc["created_sort"].should == ["fake-date"]
150
+ solr_doc["created_display"].should == ["fake-date"]
122
151
  solr_doc["title_t"].should == ["fake-title"]
152
+ solr_doc["title_sort"].should == ["fake-title"]
153
+ solr_doc["title_display"].should == ["fake-title"]
123
154
  solr_doc["related_url_t"].should == ["http://example.org/"]
124
155
  solr_doc["empty_field_t"].should be_nil
125
156
  end
@@ -130,9 +161,9 @@ describe ActiveFedora::NtriplesRDFDatastream do
130
161
  #should have these
131
162
  @subject.to_solr["publisher_t"].should_not be_nil
132
163
  @subject.to_solr["based_near_t"].should_not be_nil
133
- @subject.to_solr["created_dt"].should_not be_nil
134
164
  @subject.to_solr["title_t"].should_not be_nil
135
-
165
+ @subject.to_solr["related_url_t"].should_not be_nil
166
+
136
167
  #should NOT have these
137
168
  @subject.to_solr["narrator"].should be_nil
138
169
  @subject.to_solr["empty_field"].should be_nil
@@ -142,11 +173,11 @@ describe ActiveFedora::NtriplesRDFDatastream do
142
173
  ActiveFedora::SolrService.load_mappings(File.join(File.dirname(__FILE__), "..", "..", "config", "solr_mappings_af_0.1.yml"))
143
174
  @subject.stubs(:fields).returns(@sample_fields)
144
175
  solr_doc = @subject.to_solr
145
-
176
+
146
177
  #should have these
147
178
  solr_doc["publisher_field"].should == ["publisher1"]
148
179
  solr_doc["based_near_field"].sort.should == ["coverage1", "coverage2"]
149
- solr_doc["created_date"].should == ["fake-date"]
180
+ solr_doc["created_display"].should == ["fake-date"]
150
181
  solr_doc["title_field"].should == ["fake-title"]
151
182
 
152
183
  solr_doc["title_t"].should be_nil
@@ -157,15 +188,6 @@ describe ActiveFedora::NtriplesRDFDatastream do
157
188
  # Reload default mappings
158
189
  ActiveFedora::SolrService.load_mappings
159
190
  end
160
- it 'should append _dt to dates' do
161
- ActiveFedora::SolrService.load_mappings
162
- @subject.expects(:fields).returns(@sample_fields).at_least_once
163
- @subject.to_solr["created_dt"].should_not be_nil
164
-
165
- #should NOT have these
166
- @subject.to_solr["created"].should be_nil
167
- @subject.to_solr["created_date"].should be_nil
168
- end
169
191
  describe "with an actual object" do
170
192
  before(:all) do
171
193
  @obj = MyDatastream.new(@inner_object, 'solr_rdf')
@@ -174,6 +196,7 @@ describe ActiveFedora::NtriplesRDFDatastream do
174
196
  @obj.publisher = "Bob's Blogtastic Publishing"
175
197
  @obj.based_near = ["Tacoma, WA", "Renton, WA"]
176
198
  @obj.related_url = "http://example.org/blogtastic/"
199
+ @obj.rights = "Totally open, y'all"
177
200
  @obj.save
178
201
  end
179
202
  describe ".fields()" do
@@ -201,14 +224,22 @@ describe ActiveFedora::NtriplesRDFDatastream do
201
224
  end
202
225
  describe ".to_solr()" do
203
226
  it "should return the right # of fields" do
204
- @obj.to_solr.keys.count.should == 5
227
+ @obj.to_solr.keys.count.should == 13
205
228
  end
206
229
  it "should return the right fields" do
207
230
  @obj.to_solr.keys.should include("related_url_t")
208
231
  @obj.to_solr.keys.should include("publisher_t")
209
- @obj.to_solr.keys.should include("created_dt")
232
+ @obj.to_solr.keys.should include("publisher_sort")
233
+ @obj.to_solr.keys.should include("publisher_display")
234
+ @obj.to_solr.keys.should include("publisher_facet")
235
+ @obj.to_solr.keys.should include("created_sort")
236
+ @obj.to_solr.keys.should include("created_display")
210
237
  @obj.to_solr.keys.should include("title_t")
238
+ @obj.to_solr.keys.should include("title_sort")
239
+ @obj.to_solr.keys.should include("title_display")
211
240
  @obj.to_solr.keys.should include("based_near_t")
241
+ @obj.to_solr.keys.should include("based_near_facet")
242
+ @obj.to_solr.keys.should include("based_near_display")
212
243
  end
213
244
  it "should return the right values" do
214
245
  @obj.to_solr["related_url_t"].should == ["http://example.org/blogtastic/"]
@@ -15,25 +15,10 @@ describe ActiveFedora::Property do
15
15
  ActiveFedora::Property.should respond_to(:new)
16
16
  end
17
17
 
18
- describe '.new' do
19
-
20
- it 'should use assertions to check types of incoming args'
21
-
22
- # This could rely on property_set and in turn serialize to a 'properties' metadata datastream...
23
- it 'should add corresponding field to the properties datastream'
24
-
25
- it 'should add field to repository indexer (ie. solr)'
26
- end
27
-
28
18
  it 'should provide .name' do
29
19
  ActiveFedora::Property.should respond_to(:name)
30
20
  end
31
21
 
32
- describe '.name' do
33
- it 'should return the value of the name attribute' do
34
-
35
- end
36
- end
37
22
 
38
23
  it 'should provide .instance_variable_name' do
39
24
  #ActiveFedora::Property.should respond_to(:instance_variable_name)
@@ -48,7 +48,14 @@ describe ActiveFedora::ServiceDefinitions do
48
48
  obj.document_style_1({:format=>'xml'})
49
49
  end
50
50
  it "should call the appropriate rubydora rest api method with a block" do
51
- pending "how to mock the passed block to rubydora"
51
+ Rubydora::Repository.any_instance.stubs(:dissemination).with({:pid=>'monkey:99',:sdef=>'test:12', :method=>'getDocumentStyle1'}).yields "ping!","pang!"
52
+ obj = Test.new()
53
+ obj.stubs(:pid).returns('monkey:99')
54
+ block_response = ""
55
+ obj.document_style_1 {|res,req|
56
+ block_response += 'pong!' if res == "ping!" and req == "pang!"
57
+ }
58
+ block_response.should == "pong!"
52
59
  end
53
60
  end
54
61
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15424135
4
+ hash: 15424129
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 4
8
8
  - 0
9
9
  - 0
10
10
  - rc
11
- - 9
12
- version: 4.0.0.rc9
11
+ - 10
12
+ version: 4.0.0.rc10
13
13
  platform: ruby
14
14
  authors:
15
15
  - Matt Zumwalt
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2012-03-08 00:00:00 Z
22
+ date: 2012-03-12 00:00:00 Z
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
25
25
  prerelease: false