active-fedora 6.0.0.rc3 → 6.0.0.rc4
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.
- data/History.txt +2 -0
- data/active-fedora.gemspec +2 -0
- data/lib/active_fedora/delegating.rb +51 -18
- data/lib/active_fedora/rdf_node.rb +0 -1
- data/lib/active_fedora/rspec_matchers.rb +8 -0
- data/lib/active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher.rb +33 -0
- data/lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb +45 -0
- data/lib/active_fedora/rspec_matchers/have_predicate_matcher.rb +47 -0
- data/lib/active_fedora/rspec_matchers/match_fedora_datastream_matcher.rb +41 -0
- data/lib/active_fedora/version.rb +1 -1
- data/spec/integration/ntriples_datastream_spec.rb +7 -10
- data/spec/unit/base_delegate_spec.rb +5 -0
- data/spec/unit/rdf_datastream_spec.rb +5 -0
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +41 -0
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +42 -0
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +42 -0
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +44 -0
- metadata +47 -2
data/History.txt
CHANGED
|
@@ -4,6 +4,8 @@ Added support for RDF lists
|
|
|
4
4
|
RDF does not index terms by default
|
|
5
5
|
count is now a scoped query.
|
|
6
6
|
ActiveFedora::Base.reindex_everything
|
|
7
|
+
RDF terms can store empty string
|
|
8
|
+
Access properties by using hash notation.
|
|
7
9
|
|
|
8
10
|
5.6.1
|
|
9
11
|
Fixed delegating enumerable methods (join, [], each_with_index, to_a, etc) on an RdfNode::TermProxy
|
data/active-fedora.gemspec
CHANGED
|
@@ -34,6 +34,8 @@ Gem::Specification.new do |s|
|
|
|
34
34
|
s.add_development_dependency("jettywrapper", ">=1.2.0")
|
|
35
35
|
s.add_development_dependency("rspec", ">= 2.9.0")
|
|
36
36
|
s.add_development_dependency("equivalent-xml")
|
|
37
|
+
s.add_development_dependency("rest-client")
|
|
38
|
+
s.add_development_dependency("webmock")
|
|
37
39
|
|
|
38
40
|
s.files = `git ls-files`.split("\n")
|
|
39
41
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
@@ -2,18 +2,38 @@ module ActiveFedora
|
|
|
2
2
|
module Delegating
|
|
3
3
|
extend ActiveSupport::Concern
|
|
4
4
|
|
|
5
|
-
included do
|
|
6
|
-
class_attribute :delegate_registry
|
|
7
|
-
self.delegate_registry = []
|
|
8
|
-
end
|
|
9
|
-
|
|
10
5
|
# Calling inspect may trigger a bunch of loads, but it's mainly for debugging, so no worries.
|
|
11
6
|
def inspect
|
|
12
|
-
values = delegate_registry.map {|r| "#{r}:#{send(r).inspect}"}
|
|
7
|
+
values = self.class.delegate_registry.map {|r| "#{r}:#{send(r).inspect}"}
|
|
13
8
|
"#<#{self.class} pid:\"#{pretty_pid}\", #{values.join(', ')}>"
|
|
14
9
|
end
|
|
15
10
|
|
|
11
|
+
def [](key)
|
|
12
|
+
array_reader(key)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def []=(key, value)
|
|
16
|
+
array_setter(key, value)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
def array_reader(field)
|
|
21
|
+
instance_exec(&self.class.delegates[field][:reader])
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def array_setter(field, args)
|
|
25
|
+
instance_exec(args, &self.class.delegates[field][:setter])
|
|
26
|
+
end
|
|
27
|
+
|
|
16
28
|
module ClassMethods
|
|
29
|
+
def delegates
|
|
30
|
+
@delegates ||= {}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def delegates= val
|
|
34
|
+
@delegates = val
|
|
35
|
+
end
|
|
36
|
+
|
|
17
37
|
# Provides a delegate class method to expose methods in metadata streams
|
|
18
38
|
# as member of the base object. Pass the target datastream via the
|
|
19
39
|
# <tt>:to</tt> argument. If you want to return a unique result, (e.g. string
|
|
@@ -34,10 +54,13 @@ module ActiveFedora
|
|
|
34
54
|
# foo.field2 # => NoMethodError: undefined method `field2' for #<Foo:0x1af30c>
|
|
35
55
|
|
|
36
56
|
def delegate(field, args ={})
|
|
37
|
-
|
|
57
|
+
create_delegate_reader(field, args)
|
|
38
58
|
create_delegate_setter(field, args)
|
|
39
59
|
end
|
|
40
60
|
|
|
61
|
+
def delegate_registry
|
|
62
|
+
self.delegates.keys
|
|
63
|
+
end
|
|
41
64
|
|
|
42
65
|
# Allows you to delegate multiple terminologies to the same datastream, instead
|
|
43
66
|
# having to call the method each time for each term. The target datastream is the
|
|
@@ -60,28 +83,34 @@ module ActiveFedora
|
|
|
60
83
|
def delegate_to(datastream,fields,args={})
|
|
61
84
|
fields.each do |f|
|
|
62
85
|
args.merge!({:to=>datastream})
|
|
63
|
-
|
|
86
|
+
create_delegate_reader(f, args)
|
|
64
87
|
create_delegate_setter(f, args)
|
|
65
88
|
end
|
|
66
89
|
end
|
|
67
90
|
|
|
68
91
|
private
|
|
69
|
-
def
|
|
70
|
-
self.
|
|
71
|
-
|
|
92
|
+
def create_delegate_reader(field, args)
|
|
93
|
+
self.delegates[field] ||= {}
|
|
94
|
+
self.delegates[field][:reader] = lambda do
|
|
72
95
|
ds = self.send(args[:to])
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
96
|
+
if ds.kind_of?(ActiveFedora::RDFDatastream)
|
|
97
|
+
ds.send(field)
|
|
98
|
+
else
|
|
99
|
+
terminology = args[:at] || [field]
|
|
100
|
+
ds.send(:term_values, *terminology)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
define_method field do
|
|
105
|
+
val = self[field]
|
|
79
106
|
args[:unique] ? val.first : val
|
|
80
107
|
end
|
|
81
108
|
end
|
|
82
109
|
|
|
110
|
+
|
|
83
111
|
def create_delegate_setter(field, args)
|
|
84
|
-
|
|
112
|
+
self.delegates[field] ||= {}
|
|
113
|
+
self.delegates[field][:setter] = lambda do |v|
|
|
85
114
|
ds = self.send(args[:to])
|
|
86
115
|
if ds.kind_of?(ActiveFedora::RDFDatastream)
|
|
87
116
|
ds.send("#{field}=", v)
|
|
@@ -90,7 +119,11 @@ module ActiveFedora
|
|
|
90
119
|
ds.send(:update_indexed_attributes, {terminology => v})
|
|
91
120
|
end
|
|
92
121
|
end
|
|
122
|
+
define_method "#{field}=".to_sym do |v|
|
|
123
|
+
self[field]=v
|
|
124
|
+
end
|
|
93
125
|
end
|
|
126
|
+
|
|
94
127
|
end
|
|
95
128
|
end
|
|
96
129
|
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# RSpec matcher to spec delegations.
|
|
2
|
+
RSpec::Matchers.define :belong_to_associated_active_fedora_object do |association_name|
|
|
3
|
+
match do |subject|
|
|
4
|
+
@association_name = association_name
|
|
5
|
+
if @association_name.nil? || @expected_object.nil?
|
|
6
|
+
raise(
|
|
7
|
+
ArgumentError,
|
|
8
|
+
"subject.should belong_to_associated_active_fedora_object(<association_name>).with_object(<object>)"
|
|
9
|
+
)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
@subject = subject.class.find(subject.pid)
|
|
13
|
+
@actual_object = @subject.send(@association_name)
|
|
14
|
+
|
|
15
|
+
@expected_object == @actual_object
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
chain(:with_object) { |object| @expected_object = object }
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
description do
|
|
22
|
+
"#{@subject.class} PID=#{@subject.pid} association: #{@association_name.inspect} matches ActiveFedora"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
failure_message_for_should do |text|
|
|
26
|
+
"expected #{@subject.class} PID=#{@subject.pid} association: #{@association_name.inspect} to match"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
failure_message_for_should_not do |text|
|
|
30
|
+
"expected #{@subject.class} PID=#{@subject.pid} association: #{@association_name.inspect} to NOT match"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# RSpec matcher to spec delegations.
|
|
2
|
+
|
|
3
|
+
RSpec::Matchers.define :have_many_associated_active_fedora_objects do |association_name|
|
|
4
|
+
match do |subject|
|
|
5
|
+
@association_name = association_name
|
|
6
|
+
if @association_name.nil? || !@expected_objects.respond_to?(:count)
|
|
7
|
+
raise(
|
|
8
|
+
ArgumentError,
|
|
9
|
+
"subject.should have_many_associated_active_fedora_objects(<association_name>).with_objects(<objects[]>)"
|
|
10
|
+
)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
@subject = subject.class.find(subject.pid)
|
|
14
|
+
@actual_objects = @subject.send(@association_name)
|
|
15
|
+
|
|
16
|
+
if @expected_objects
|
|
17
|
+
actual_count = @actual_objects.count
|
|
18
|
+
expected_count = @expected_objects.count
|
|
19
|
+
if actual_count != expected_count
|
|
20
|
+
raise(
|
|
21
|
+
RSpec::Expectations::ExpectationNotMetError,
|
|
22
|
+
"#{@subject.class} PID=#{@subject.pid} relationship: #{@association_name.inspect} count <Expected Count: #{expected_count}> <Actual: #{actual_count}>"
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
intersection = @actual_objects & @expected_objects
|
|
26
|
+
intersection.count == @expected_objects.count
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
chain(:with_objects) { |objects| @expected_objects = objects }
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
description do
|
|
34
|
+
"#{@subject.class} PID=#{@subject.pid} association: #{@association_name.inspect} matches ActiveFedora"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
failure_message_for_should do |text|
|
|
38
|
+
"expected #{@subject.class} PID=#{@subject.pid} association: #{@association_name.inspect} to match"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
failure_message_for_should_not do |text|
|
|
42
|
+
"expected #{@subject.class} PID=#{@subject.pid} association: #{@association_name.inspect} to NOT match"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# RSpec matcher to spec delegations.
|
|
2
|
+
|
|
3
|
+
RSpec::Matchers.define :have_predicate do |predicate|
|
|
4
|
+
match do |subject|
|
|
5
|
+
@predicate = predicate
|
|
6
|
+
if @predicate.nil? || !@expected_objects.respond_to?(:count)
|
|
7
|
+
raise(
|
|
8
|
+
ArgumentError,
|
|
9
|
+
"subject.should have_predicate(<predicate>).with_objects(<objects[]>)"
|
|
10
|
+
)
|
|
11
|
+
end
|
|
12
|
+
@subject = subject.class.find(subject.pid)
|
|
13
|
+
@actual_objects = @subject.relationships(predicate)
|
|
14
|
+
|
|
15
|
+
if @expected_objects
|
|
16
|
+
actual_count = @actual_objects.count
|
|
17
|
+
expected_count = @expected_objects.count
|
|
18
|
+
if actual_count != expected_count
|
|
19
|
+
raise(
|
|
20
|
+
RSpec::Expectations::ExpectationNotMetError,
|
|
21
|
+
"#{@subject.class} PID=#{@subject.pid} relationship: #{@predicate.inspect} count <Expected Count: #{expected_count}> <Actual: #{actual_count}>"
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
intersection = @actual_objects.collect do |ao|
|
|
25
|
+
internal_uri = ao.respond_to?(:internal_uri) ? ao.internal_uri : ao
|
|
26
|
+
end & @expected_objects
|
|
27
|
+
|
|
28
|
+
intersection.count == @expected_objects.count
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
chain(:with_objects) { |objects| @expected_objects = objects }
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
description do
|
|
36
|
+
"#{@subject.class} PID=#{@subject.pid} relationship: #{@predicate.inspect} matches Fedora"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
failure_message_for_should do |text|
|
|
40
|
+
"expected #{@subject.class} PID=#{@subject.pid} relationship: #{@predicate.inspect} to match"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
failure_message_for_should_not do |text|
|
|
44
|
+
"expected #{@subject.class} PID=#{@subject.pid} relationship: #{@predicate.inspect} to NOT match"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# RSpec matcher to spec delegations.
|
|
2
|
+
|
|
3
|
+
RSpec::Matchers.define :match_fedora_datastream do |method|
|
|
4
|
+
match do |object|
|
|
5
|
+
@method = method
|
|
6
|
+
@object = object
|
|
7
|
+
if @expected_xml.nil?
|
|
8
|
+
raise(
|
|
9
|
+
ArgumentError,
|
|
10
|
+
"match_fedora_datastream(<datastream_name>).with(<expected_xml>)"
|
|
11
|
+
)
|
|
12
|
+
end
|
|
13
|
+
expected = Nokogiri::XML(@expected_xml)
|
|
14
|
+
|
|
15
|
+
base_url = ActiveFedora.config.credentials[:url]
|
|
16
|
+
@fedora_datastream_url = File.join(
|
|
17
|
+
base_url, 'objects', @object.pid.to_s,'datastreams', @method, 'content'
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
response = RestClient.get(@fedora_datastream_url)
|
|
21
|
+
|
|
22
|
+
actual = Nokogiri::XML(response.body)
|
|
23
|
+
|
|
24
|
+
EquivalentXml.equivalent?(expected, actual, :normalize_whitespace => true)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
chain(:with) { |expected_xml| @expected_xml = expected_xml }
|
|
28
|
+
|
|
29
|
+
description do
|
|
30
|
+
"#{@object.class} PID=#{@object.pid} datastream: #{@method.inspect} matches Fedora"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
failure_message_for_should do |text|
|
|
34
|
+
"expected #{@object.class} PID=#{@object.pid} datastream: #{@method.inspect} to match Fedora"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
failure_message_for_should_not do |text|
|
|
38
|
+
"expected #{@object.class} PID=#{@object.pid} datastream: #{@method.inspect} to NOT match Fedora"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
@@ -117,13 +117,6 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
|
117
117
|
@subject.part << "thing 2"
|
|
118
118
|
@subject.part.should == ["thing 1", "thing 2"]
|
|
119
119
|
end
|
|
120
|
-
it "should delete a value" do
|
|
121
|
-
@subject.title = "Hamlet"
|
|
122
|
-
@subject.save
|
|
123
|
-
@subject.title = ""
|
|
124
|
-
@subject.save
|
|
125
|
-
@subject.title.should be_nil
|
|
126
|
-
end
|
|
127
120
|
|
|
128
121
|
it "should be able to save a blank document" do
|
|
129
122
|
@subject.title = ""
|
|
@@ -170,13 +163,17 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
|
170
163
|
@subject.title = "Hamlet"
|
|
171
164
|
@subject.related_url = "http://psu.edu/"
|
|
172
165
|
@subject.related_url << "http://projecthydra.org/"
|
|
173
|
-
|
|
166
|
+
|
|
174
167
|
@subject.title.should == "Hamlet"
|
|
175
168
|
@subject.related_url.should include("http://psu.edu/")
|
|
176
169
|
@subject.related_url.should include("http://projecthydra.org/")
|
|
177
|
-
|
|
170
|
+
|
|
171
|
+
@subject.title = "" #empty string can be meaningful, don't assume delete.
|
|
172
|
+
@subject.title.should == ''
|
|
173
|
+
|
|
174
|
+
@subject.title = nil
|
|
178
175
|
@subject.related_url.delete("http://projecthydra.org/")
|
|
179
|
-
|
|
176
|
+
|
|
180
177
|
@subject.title.should be_nil
|
|
181
178
|
@subject.related_url.should == ["http://psu.edu/"]
|
|
182
179
|
end
|
|
@@ -50,6 +50,7 @@ describe ActiveFedora::Base do
|
|
|
50
50
|
before :each do
|
|
51
51
|
@n = BarHistory2.new()
|
|
52
52
|
end
|
|
53
|
+
|
|
53
54
|
it "should save a delegated property uniquely" do
|
|
54
55
|
@n.fubar="Quack"
|
|
55
56
|
@n.fubar.should == "Quack"
|
|
@@ -69,6 +70,10 @@ describe ActiveFedora::Base do
|
|
|
69
70
|
@n.duck.should == ["Quack", "Peep"]
|
|
70
71
|
end
|
|
71
72
|
|
|
73
|
+
it "should accept the array getters and setters" do
|
|
74
|
+
@n[:duck]= ["Cluck", "Gobble"]
|
|
75
|
+
@n[:duck].should == ["Cluck", "Gobble"]
|
|
76
|
+
end
|
|
72
77
|
end
|
|
73
78
|
end
|
|
74
79
|
|
|
@@ -29,5 +29,10 @@ describe ActiveFedora::RDFDatastream do
|
|
|
29
29
|
@obj.inner_object.repository.should_not_receive(:datastream_dissemination).with(hash_including(:dsid=>'descMetadata'))
|
|
30
30
|
subject.should_not be_content_changed
|
|
31
31
|
end
|
|
32
|
+
|
|
33
|
+
it "should allow asserting an empty string" do
|
|
34
|
+
@obj.descMetadata.title = ['']
|
|
35
|
+
@obj.descMetadata.title.should == ['']
|
|
36
|
+
end
|
|
32
37
|
end
|
|
33
38
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require 'ostruct'
|
|
3
|
+
require "active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher"
|
|
4
|
+
|
|
5
|
+
describe RSpec::Matchers, "belong_to_associated_active_fedora_object_matcher" do
|
|
6
|
+
subject { OpenStruct.new(:pid => pid )}
|
|
7
|
+
let(:pid) { 123 }
|
|
8
|
+
let(:object1) { Object.new }
|
|
9
|
+
let(:object2) { Object.new }
|
|
10
|
+
let(:association) { :association }
|
|
11
|
+
|
|
12
|
+
it 'should match when association is properly stored in fedora' do
|
|
13
|
+
subject.class.should_receive(:find).with(pid).and_return(subject)
|
|
14
|
+
subject.should_receive(association).and_return(object1)
|
|
15
|
+
subject.should belong_to_associated_active_fedora_object(association).with_object(object1)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'should not match when association is different' do
|
|
19
|
+
subject.class.should_receive(:find).with(pid).and_return(subject)
|
|
20
|
+
subject.should_receive(association).and_return(object1)
|
|
21
|
+
lambda {
|
|
22
|
+
subject.should belong_to_associated_active_fedora_object(association).with_object(object2)
|
|
23
|
+
}.should (
|
|
24
|
+
raise_error(
|
|
25
|
+
RSpec::Expectations::ExpectationNotMetError,
|
|
26
|
+
/expected #{subject.class} PID=#{pid} association: #{association.inspect}/
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'should require :with_object option' do
|
|
32
|
+
lambda {
|
|
33
|
+
subject.should belong_to_associated_active_fedora_object(association)
|
|
34
|
+
}.should(
|
|
35
|
+
raise_error(
|
|
36
|
+
ArgumentError,
|
|
37
|
+
"subject.should belong_to_associated_active_fedora_object(<association_name>).with_object(<object>)"
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require 'ostruct'
|
|
3
|
+
require "active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher"
|
|
4
|
+
|
|
5
|
+
describe RSpec::Matchers, "have_many_associated_active_fedora_objects_matcher" do
|
|
6
|
+
subject { OpenStruct.new(:pid => pid )}
|
|
7
|
+
let(:pid) { 123 }
|
|
8
|
+
let(:object1) { Object.new }
|
|
9
|
+
let(:object2) { Object.new }
|
|
10
|
+
let(:object3) { Object.new }
|
|
11
|
+
let(:association) { :association }
|
|
12
|
+
|
|
13
|
+
it 'should match when association is properly stored in fedora' do
|
|
14
|
+
subject.class.should_receive(:find).with(pid).and_return(subject)
|
|
15
|
+
subject.should_receive(association).and_return([object1,object2])
|
|
16
|
+
subject.should have_many_associated_active_fedora_objects(association).with_objects([object1, object2])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'should not match when association is different' do
|
|
20
|
+
subject.class.should_receive(:find).with(pid).and_return(subject)
|
|
21
|
+
subject.should_receive(association).and_return([object1,object3])
|
|
22
|
+
lambda {
|
|
23
|
+
subject.should have_many_associated_active_fedora_objects(association).with_objects([object1, object2])
|
|
24
|
+
}.should (
|
|
25
|
+
raise_error(
|
|
26
|
+
RSpec::Expectations::ExpectationNotMetError,
|
|
27
|
+
/expected #{subject.class} PID=#{pid} association: #{association.inspect}/
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'should require :with_objects option' do
|
|
33
|
+
lambda {
|
|
34
|
+
subject.should have_many_associated_active_fedora_objects(association)
|
|
35
|
+
}.should(
|
|
36
|
+
raise_error(
|
|
37
|
+
ArgumentError,
|
|
38
|
+
"subject.should have_many_associated_active_fedora_objects(<association_name>).with_objects(<objects[]>)"
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require 'ostruct'
|
|
3
|
+
require "active_fedora/rspec_matchers/have_predicate_matcher"
|
|
4
|
+
|
|
5
|
+
describe RSpec::Matchers, "have_predicate_matcher" do
|
|
6
|
+
subject { OpenStruct.new(:pid => pid )}
|
|
7
|
+
let(:pid) { 123 }
|
|
8
|
+
let(:object1) { Object.new }
|
|
9
|
+
let(:object2) { Object.new }
|
|
10
|
+
let(:object3) { Object.new }
|
|
11
|
+
let(:predicate) { :predicate }
|
|
12
|
+
|
|
13
|
+
it 'should match when relationship is "what we have in Fedora"' do
|
|
14
|
+
subject.class.should_receive(:find).with(pid).and_return(subject)
|
|
15
|
+
subject.should_receive(:relationships).with(predicate).and_return([object1,object2])
|
|
16
|
+
subject.should have_predicate(predicate).with_objects([object1, object2])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'should not match when relationship is different' do
|
|
20
|
+
subject.class.should_receive(:find).with(pid).and_return(subject)
|
|
21
|
+
subject.should_receive(:relationships).with(predicate).and_return([object1,object3])
|
|
22
|
+
lambda {
|
|
23
|
+
subject.should have_predicate(predicate).with_objects([object1, object2])
|
|
24
|
+
}.should (
|
|
25
|
+
raise_error(
|
|
26
|
+
RSpec::Expectations::ExpectationNotMetError,
|
|
27
|
+
/expected #{subject.class} PID=#{pid} relationship: #{predicate.inspect}/
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'should require :with_objects option' do
|
|
33
|
+
lambda {
|
|
34
|
+
subject.should have_predicate(predicate)
|
|
35
|
+
}.should(
|
|
36
|
+
raise_error(
|
|
37
|
+
ArgumentError,
|
|
38
|
+
"subject.should have_predicate(<predicate>).with_objects(<objects[]>)"
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require 'ostruct'
|
|
3
|
+
require 'webmock/rspec'
|
|
4
|
+
WebMock.allow_net_connect!
|
|
5
|
+
require "active_fedora/rspec_matchers/match_fedora_datastream_matcher"
|
|
6
|
+
|
|
7
|
+
describe RSpec::Matchers, "match_fedora_datastream" do
|
|
8
|
+
let(:pid) { 123 }
|
|
9
|
+
let(:expected_xml) { '<xml><node>Value</node></xml>' }
|
|
10
|
+
let(:datastream_name) { 'metadata' }
|
|
11
|
+
let(:datastream_url) {
|
|
12
|
+
File.join(ActiveFedora.config.credentials[:url], 'objects', pid.to_s,'datastreams', datastream_name, 'content')
|
|
13
|
+
}
|
|
14
|
+
subject { OpenStruct.new(:pid => pid )}
|
|
15
|
+
|
|
16
|
+
it 'should match based on request' do
|
|
17
|
+
stub_request(:get, datastream_url).to_return(:body => expected_xml, :status => 200)
|
|
18
|
+
subject.should match_fedora_datastream(datastream_name).with(expected_xml)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'should handle non-matching requests' do
|
|
22
|
+
stub_request(:get, datastream_url).to_return(:body => "<parent>#{expected_xml}</parent>", :status => 200)
|
|
23
|
+
lambda {
|
|
24
|
+
subject.should match_fedora_datastream(datastream_name).with(expected_xml)
|
|
25
|
+
}.should(
|
|
26
|
+
raise_error(
|
|
27
|
+
RSpec::Expectations::ExpectationNotMetError,
|
|
28
|
+
/expected #{subject.class} PID=#{pid} datastream: #{datastream_name.inspect} to match Fedora/
|
|
29
|
+
)
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'should require :with option' do
|
|
34
|
+
stub_request(:get, datastream_url).to_return(:body => "<parent>#{expected_xml}</parent>", :status => 200)
|
|
35
|
+
lambda {
|
|
36
|
+
subject.should match_fedora_datastream(datastream_name)
|
|
37
|
+
}.should(
|
|
38
|
+
raise_error(
|
|
39
|
+
ArgumentError,
|
|
40
|
+
"match_fedora_datastream(<datastream_name>).with(<expected_xml>)"
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
end
|
|
44
|
+
end
|
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: 6.0.0.
|
|
4
|
+
version: 6.0.0.rc4
|
|
5
5
|
prerelease: 6
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -11,7 +11,7 @@ authors:
|
|
|
11
11
|
autorequire:
|
|
12
12
|
bindir: bin
|
|
13
13
|
cert_chain: []
|
|
14
|
-
date: 2013-02-
|
|
14
|
+
date: 2013-02-25 00:00:00.000000000 Z
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
17
17
|
name: rsolr
|
|
@@ -317,6 +317,38 @@ dependencies:
|
|
|
317
317
|
- - ! '>='
|
|
318
318
|
- !ruby/object:Gem::Version
|
|
319
319
|
version: '0'
|
|
320
|
+
- !ruby/object:Gem::Dependency
|
|
321
|
+
name: rest-client
|
|
322
|
+
requirement: !ruby/object:Gem::Requirement
|
|
323
|
+
none: false
|
|
324
|
+
requirements:
|
|
325
|
+
- - ! '>='
|
|
326
|
+
- !ruby/object:Gem::Version
|
|
327
|
+
version: '0'
|
|
328
|
+
type: :development
|
|
329
|
+
prerelease: false
|
|
330
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
331
|
+
none: false
|
|
332
|
+
requirements:
|
|
333
|
+
- - ! '>='
|
|
334
|
+
- !ruby/object:Gem::Version
|
|
335
|
+
version: '0'
|
|
336
|
+
- !ruby/object:Gem::Dependency
|
|
337
|
+
name: webmock
|
|
338
|
+
requirement: !ruby/object:Gem::Requirement
|
|
339
|
+
none: false
|
|
340
|
+
requirements:
|
|
341
|
+
- - ! '>='
|
|
342
|
+
- !ruby/object:Gem::Version
|
|
343
|
+
version: '0'
|
|
344
|
+
type: :development
|
|
345
|
+
prerelease: false
|
|
346
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
347
|
+
none: false
|
|
348
|
+
requirements:
|
|
349
|
+
- - ! '>='
|
|
350
|
+
- !ruby/object:Gem::Version
|
|
351
|
+
version: '0'
|
|
320
352
|
description: ActiveFedora provides for creating and managing objects in the Fedora
|
|
321
353
|
Repository Architecture.
|
|
322
354
|
email:
|
|
@@ -392,6 +424,11 @@ files:
|
|
|
392
424
|
- lib/active_fedora/relation.rb
|
|
393
425
|
- lib/active_fedora/relationship_graph.rb
|
|
394
426
|
- lib/active_fedora/rels_ext_datastream.rb
|
|
427
|
+
- lib/active_fedora/rspec_matchers.rb
|
|
428
|
+
- lib/active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher.rb
|
|
429
|
+
- lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
|
|
430
|
+
- lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
|
|
431
|
+
- lib/active_fedora/rspec_matchers/match_fedora_datastream_matcher.rb
|
|
395
432
|
- lib/active_fedora/rubydora_connection.rb
|
|
396
433
|
- lib/active_fedora/semantic_node.rb
|
|
397
434
|
- lib/active_fedora/service_definitions.rb
|
|
@@ -546,6 +583,10 @@ files:
|
|
|
546
583
|
- spec/unit/rdfxml_rdf_datastream_spec.rb
|
|
547
584
|
- spec/unit/relationship_graph_spec.rb
|
|
548
585
|
- spec/unit/rels_ext_datastream_spec.rb
|
|
586
|
+
- spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb
|
|
587
|
+
- spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb
|
|
588
|
+
- spec/unit/rspec_matchers/have_predicate_matcher_spec.rb
|
|
589
|
+
- spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb
|
|
549
590
|
- spec/unit/rubydora_connection_spec.rb
|
|
550
591
|
- spec/unit/semantic_node_spec.rb
|
|
551
592
|
- spec/unit/serializers_spec.rb
|
|
@@ -703,6 +744,10 @@ test_files:
|
|
|
703
744
|
- spec/unit/rdfxml_rdf_datastream_spec.rb
|
|
704
745
|
- spec/unit/relationship_graph_spec.rb
|
|
705
746
|
- spec/unit/rels_ext_datastream_spec.rb
|
|
747
|
+
- spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb
|
|
748
|
+
- spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb
|
|
749
|
+
- spec/unit/rspec_matchers/have_predicate_matcher_spec.rb
|
|
750
|
+
- spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb
|
|
706
751
|
- spec/unit/rubydora_connection_spec.rb
|
|
707
752
|
- spec/unit/semantic_node_spec.rb
|
|
708
753
|
- spec/unit/serializers_spec.rb
|