ldp 0.4.1 → 0.5.0

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.
@@ -1,3 +1,3 @@
1
1
  module Ldp
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -1,5 +1,54 @@
1
1
  require 'spec_helper'
2
+ require 'capybara_discoball'
3
+ require 'derby/server'
2
4
 
3
- describe "Integration tests" do
5
+ describe 'Integration tests' do
6
+ let!(:derby_server) do
7
+ Capybara::Discoball::Runner.new(Derby::Server).boot
8
+ end
4
9
 
5
- end
10
+ let(:debug) { ENV.fetch('DEBUG', false) }
11
+
12
+ let(:client) do
13
+ Faraday.new(url: derby_server) do |faraday|
14
+ faraday.response :logger if debug
15
+ faraday.adapter Faraday.default_adapter
16
+ end
17
+ end
18
+
19
+ subject { Ldp::Client.new client }
20
+
21
+ it 'creates resources' do
22
+ subject.put '/rdf_source', ''
23
+ obj = subject.find_or_initialize('/rdf_source')
24
+ expect(obj).to be_a_kind_of Ldp::Resource::RdfSource
25
+ end
26
+
27
+ it 'creates binary resources' do
28
+ Ldp::Resource::BinarySource.new(subject, '/binary_source', 'abcdef').create
29
+
30
+ obj = subject.find_or_initialize('binary_source')
31
+ expect(obj).to be_a_kind_of Ldp::Resource::BinarySource
32
+ end
33
+
34
+ it 'creates basic containers' do
35
+ Ldp::Container::Basic.new(subject, '/basic_container').create
36
+ obj = subject.find_or_initialize('/basic_container')
37
+ expect(obj).not_to be_new
38
+ expect(obj).to be_a_kind_of Ldp::Container::Basic
39
+ end
40
+
41
+ it 'creates direct containers' do
42
+ Ldp::Container::Direct.new(subject, '/direct_container').create
43
+ obj = subject.find_or_initialize('/direct_container')
44
+ expect(obj).not_to be_new
45
+ expect(obj).to be_a_kind_of Ldp::Container::Direct
46
+ end
47
+
48
+ it 'creates indirect containers' do
49
+ Ldp::Container::Indirect.new(subject, '/indirect_container').create
50
+ obj = subject.find_or_initialize('/indirect_container')
51
+ expect(obj).not_to be_new
52
+ expect(obj).to be_a_kind_of Ldp::Container::Indirect
53
+ end
54
+ end
@@ -6,16 +6,8 @@ describe "Ldp::Client" do
6
6
  graph.dump(:ttl)
7
7
  end
8
8
 
9
-
10
- let(:paginatedGraph) do
11
- graph = RDF::Graph.new << [RDF::URI.new(""), RDF::DC.title, "Hello, world!"]
12
- graph << [RDF::URI.new("?firstPage"), RDF.type, Ldp.page]
13
- graph << [RDF::URI.new("?firstPage"), Ldp.page_of, RDF::URI.new("")]
14
- graph.dump(:ttl)
15
- end
16
-
17
9
  let(:simple_container_graph) do
18
- graph = RDF::Graph.new << [RDF::URI.new(""), RDF.type, Ldp.container]
10
+ graph = RDF::Graph.new << [RDF::URI.new(""), RDF.type, RDF::Vocab::LDP.Container]
19
11
  graph.dump(:ttl)
20
12
  end
21
13
 
@@ -63,6 +55,23 @@ describe "Ldp::Client" do
63
55
  client = Ldp::Client.new "http://example.com"
64
56
  expect(client.http.host).to eq("example.com")
65
57
  end
58
+
59
+ it 'accepts a connection and client options' do
60
+ conn = Faraday.new "http://example.com"
61
+ client = Ldp::Client.new conn, omit_ldpr_interaction_model: true
62
+ expect(client.http).to eq(conn)
63
+ expect(client.options[:omit_ldpr_interaction_model]).to eq true
64
+ end
65
+
66
+ it 'raises an ArgumentError with bad arguments' do
67
+ expect { Ldp::Client.new(nil, nil, nil) }.to raise_error ArgumentError
68
+ end
69
+ end
70
+
71
+ describe '#logger' do
72
+ it 'inherits the upstream logger' do
73
+ expect(subject.logger).to eq Ldp.logger
74
+ end
66
75
  end
67
76
 
68
77
  describe "get" do
@@ -94,12 +103,12 @@ describe "Ldp::Client" do
94
103
  end
95
104
  it "should set the include parameter" do
96
105
  subject.get "a_resource", include: "membership" do |req|
97
- expect(req.headers["Prefer"]).to match "include=\"#{Ldp.prefer_membership}\""
106
+ expect(req.headers["Prefer"]).to match "include=\"#{RDF::Vocab::LDP.PreferMembership}\""
98
107
  end
99
108
  end
100
109
  it "should set the omit parameter" do
101
110
  subject.get "a_resource", omit: "containment" do |req|
102
- expect(req.headers["Prefer"]).to match "omit=\"#{Ldp.prefer_containment}\""
111
+ expect(req.headers["Prefer"]).to match "omit=\"#{RDF::Vocab::LDP.PreferContainment}\""
103
112
  end
104
113
  end
105
114
  end
@@ -11,4 +11,29 @@ describe Ldp::Resource::BinarySource do
11
11
  expect(subject.inspect).not_to match /somecontent/
12
12
  end
13
13
 
14
+ describe '#described_by' do
15
+ context 'without a description' do
16
+ before do
17
+ allow(client).to receive(:head).and_return(double(links: { }))
18
+ end
19
+
20
+ it 'retrieves the description object' do
21
+ expect(subject.described_by).to eq nil
22
+ end
23
+ end
24
+
25
+ context 'with a description' do
26
+ before do
27
+ allow(client).to receive(:head).and_return(double(links: { 'describedby' => ['http://example.com/foo/bar/desc']}))
28
+ allow(client).to receive(:find_or_initialize).with('http://example.com/foo/bar/desc').and_return(desc)
29
+ end
30
+
31
+ let(:desc) { double }
32
+
33
+ it 'retrieves the description object' do
34
+ expect(subject.described_by).to eq desc
35
+ end
36
+ end
37
+ end
38
+
14
39
  end
@@ -46,6 +46,30 @@ describe Ldp::Resource::RdfSource do
46
46
  created_resource = obj.create
47
47
  expect(created_resource).to be_kind_of Ldp::Resource::RdfSource
48
48
  end
49
+
50
+ describe 'basic containers' do
51
+ it 'sends the requested interaction model' do
52
+ obj = Ldp::Container::Basic.new mock_client, "http://my.ldp.server/abs_url_object"
53
+ created_resource = obj.create
54
+ expect(created_resource).to be_kind_of Ldp::Container::Basic
55
+ end
56
+ end
57
+
58
+ describe 'direct containers' do
59
+ it 'sends the requested interaction model' do
60
+ obj = Ldp::Container::Direct.new mock_client, "http://my.ldp.server/abs_url_object"
61
+ created_resource = obj.create
62
+ expect(created_resource).to be_kind_of Ldp::Container::Direct
63
+ end
64
+ end
65
+
66
+ describe 'indirect containers' do
67
+ it 'sends the requested interaction model' do
68
+ obj = Ldp::Container::Indirect.new mock_client, "http://my.ldp.server/abs_url_object"
69
+ created_resource = obj.create
70
+ expect(created_resource).to be_kind_of Ldp::Container::Indirect
71
+ end
72
+ end
49
73
  end
50
74
 
51
75
  describe "#initialize" do
@@ -47,8 +47,7 @@ describe Ldp::Resource do
47
47
  context "when the resource is in the repository" do
48
48
  let(:path) { '/a_resource' }
49
49
  it "should get the response" do
50
- expect(subject.get).to be_kind_of Faraday::Response
51
- expect(subject.get.status).to eq 200
50
+ expect(subject.get).to be_kind_of Ldp::Response
52
51
  end
53
52
  end
54
53
  end
@@ -1,33 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Ldp::Response do
4
- LDP_RDF_RESOURCE_HEADERS = { "Link" => "<#{Ldp.resource.to_s}>;rel=\"type\", <#{Ldp.direct_container.to_s}>;rel=\"type\""}
5
- LDP_NON_RDF_SOURCE_HEADERS = { "Link" => "<#{Ldp.resource.to_s}>;rel=\"type\", <#{Ldp.non_rdf_source.to_s}>;rel=\"type\""}
4
+ LDP_RDF_RESOURCE_HEADERS = { "Link" => "<#{RDF::Vocab::LDP.Resource}>;rel=\"type\", <#{RDF::Vocab::LDP.DirectContainer}>;rel=\"type\""}
5
+ LDP_NON_RDF_SOURCE_HEADERS = { "Link" => "<#{RDF::Vocab::LDP.Resource}>;rel=\"type\", <#{RDF::Vocab::LDP.NonRDFSource}>;rel=\"type\""}
6
6
 
7
7
  let(:mock_response) { double("mock response", headers: {}, env: { url: "info:a" }) }
8
8
  let(:mock_client) { double(Ldp::Client) }
9
9
 
10
10
  subject do
11
- Ldp::Response.wrap mock_client, mock_response
12
- end
13
-
14
- describe ".wrap" do
15
- it "should mixin Ldp::Response into the raw response" do
16
- Ldp::Response.wrap(mock_client, mock_response)
17
- expect(mock_response).to be_a_kind_of(Ldp::Response)
18
- end
11
+ Ldp::Response.new mock_response
19
12
  end
20
13
 
21
14
  describe "#dup" do
22
15
  let(:mock_conn) { Faraday.new { |builder| builder.adapter :test, conn_stubs } }
23
16
  let(:client) { Ldp::Client.new mock_conn }
24
- let(:raw_response) { client.get "a_container" }
25
17
  let(:conn_stubs) do
26
18
  Faraday::Adapter::Test::Stubs.new do |stub|
27
19
  stub.get('/a_container') { [200, {"Link" => link}, body] }
28
20
  end
29
21
  end
30
- let(:response) { Ldp::Response.wrap mock_client, raw_response }
22
+ let(:response) { client.get "a_container" }
31
23
 
32
24
  subject { response.dup }
33
25
 
@@ -61,7 +53,7 @@ describe Ldp::Response do
61
53
  end
62
54
 
63
55
 
64
- describe ".links" do
56
+ describe "#links" do
65
57
  it "should extract link headers with relations as a hash" do
66
58
  allow(mock_response).to receive(:headers).and_return(
67
59
  "Link" => [
@@ -71,7 +63,7 @@ describe Ldp::Response do
71
63
  "<vanilla-link>"
72
64
  ]
73
65
  )
74
- h = Ldp::Response.links mock_response
66
+ h = subject.links
75
67
 
76
68
  expect(h['some-rel']).to include("xyz")
77
69
  expect(h['some-multi-rel']).to include("abc", "123")
@@ -80,21 +72,21 @@ describe Ldp::Response do
80
72
 
81
73
  it "should return an empty hash if no link headers are availabe" do
82
74
  allow(mock_response).to receive(:headers).and_return({})
83
- h = Ldp::Response.links mock_response
75
+ h = subject.links
84
76
 
85
77
  expect(h).to be_empty
86
78
  end
87
79
 
88
80
  end
89
81
 
90
- describe ".resource?" do
82
+ describe "#resource?" do
91
83
  it "should be a resource if a Link[rel=type] header asserts it is an ldp:resource" do
92
84
  allow(mock_response).to receive(:headers).and_return(
93
85
  "Link" => [
94
- "<#{Ldp.resource}>;rel=\"type\""
86
+ "<#{RDF::Vocab::LDP.Resource}>;rel=\"type\""
95
87
  ]
96
88
  )
97
- expect(Ldp::Response.resource? mock_response).to be true
89
+ expect(subject.resource?).to be true
98
90
  end
99
91
  end
100
92
 
@@ -109,14 +101,6 @@ describe Ldp::Response do
109
101
  expect(graph).to have_statement RDF::Statement.new(RDF::URI.new("info:a"), RDF::URI.new("info:b"), RDF::URI.new("info:c"))
110
102
  end
111
103
  end
112
-
113
- context "for a NonRDFSource" do
114
- it "should parse the response body for an RDF graph" do
115
- allow(mock_response).to receive(:body).and_return("<> <info:b> <info:c> .")
116
- allow(mock_response).to receive(:headers).and_return(LDP_NON_RDF_SOURCE_HEADERS)
117
- expect { subject.graph }.to raise_error Ldp::UnexpectedContentType
118
- end
119
- end
120
104
  end
121
105
 
122
106
  describe "#etag" do
@@ -142,7 +126,7 @@ describe Ldp::Response do
142
126
 
143
127
  it "should see if the response has an ldp:Page statement" do
144
128
  graph = RDF::Graph.new
145
- graph << [RDF::URI.new('info:a'), RDF.type, Ldp.page]
129
+ graph << [RDF::URI.new('info:a'), RDF.type, RDF::Vocab::LDP.Page]
146
130
  allow(mock_response).to receive(:body).and_return(graph.dump(:ttl))
147
131
  expect(subject).to have_page
148
132
  end
@@ -169,8 +153,8 @@ describe Ldp::Response do
169
153
  it "should get the ldp:Page data from the query" do
170
154
  graph = RDF::Graph.new
171
155
 
172
- graph << [RDF::URI.new('info:a'), RDF.type, Ldp.page]
173
- graph << [RDF::URI.new('info:b'), RDF.type, Ldp.page]
156
+ graph << [RDF::URI.new('info:a'), RDF.type, RDF::Vocab::LDP.Page]
157
+ graph << [RDF::URI.new('info:b'), RDF.type, RDF::Vocab::LDP.Page]
174
158
 
175
159
  allow(mock_response).to receive(:body).and_return(graph.dump(:ttl))
176
160
  allow(mock_response).to receive(:headers).and_return(LDP_RDF_RESOURCE_HEADERS)
@@ -187,4 +171,40 @@ describe Ldp::Response do
187
171
  expect(subject.subject).to eq(RDF::URI.new("http://xyz/a"))
188
172
  end
189
173
  end
174
+
175
+ describe '#content_type' do
176
+ before do
177
+ allow(mock_response).to receive(:headers).and_return(
178
+ 'Content-Type' => 'application/octet-stream'
179
+ )
180
+ end
181
+
182
+ it 'provides the content type from the response' do
183
+ expect(subject.content_type).to eq 'application/octet-stream'
184
+ end
185
+ end
186
+
187
+ describe '#content_length' do
188
+ before do
189
+ allow(mock_response).to receive(:headers).and_return(
190
+ 'Content-Length' => '123'
191
+ )
192
+ end
193
+
194
+ it 'provides the content length from the response' do
195
+ expect(subject.content_length).to eq 123
196
+ end
197
+ end
198
+
199
+ describe '#content_disposition_filename' do
200
+ before do
201
+ allow(mock_response).to receive(:headers).and_return(
202
+ 'Content-Disposition' => 'filename="xyz.txt";'
203
+ )
204
+ end
205
+
206
+ it 'provides the filename from the content disposition header' do
207
+ expect(subject.content_disposition_filename).to eq 'xyz.txt'
208
+ end
209
+ end
190
210
  end
@@ -1,6 +1,16 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
 
4
+ require 'simplecov'
5
+ require 'coveralls'
6
+
7
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
+ SimpleCov::Formatter::HTMLFormatter,
9
+ Coveralls::SimpleCov::Formatter
10
+ ]
11
+ SimpleCov.start do
12
+ add_filter 'spec/'
13
+ end
4
14
 
5
15
  require 'ldp'
6
16
  require 'faraday'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ldp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-28 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdf-vocab
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: http_logger
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: deprecation
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: slop
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +136,34 @@ dependencies:
108
136
  - - ">="
109
137
  - !ruby/object:Gem::Version
110
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: coveralls
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
111
167
  description: Linked Data Platform client library
112
168
  email:
113
169
  - chris@cbeer.info
@@ -132,12 +188,12 @@ files:
132
188
  - lib/ldp/container/basic.rb
133
189
  - lib/ldp/container/direct.rb
134
190
  - lib/ldp/container/indirect.rb
191
+ - lib/ldp/error.rb
135
192
  - lib/ldp/orm.rb
136
193
  - lib/ldp/resource.rb
137
194
  - lib/ldp/resource/binary_source.rb
138
195
  - lib/ldp/resource/rdf_source.rb
139
196
  - lib/ldp/response.rb
140
- - lib/ldp/response/paging.rb
141
197
  - lib/ldp/uri.rb
142
198
  - lib/ldp/version.rb
143
199
  - spec/lib/integration/integration_spec.rb
@@ -159,9 +215,9 @@ require_paths:
159
215
  - lib
160
216
  required_ruby_version: !ruby/object:Gem::Requirement
161
217
  requirements:
162
- - - ">="
218
+ - - "~>"
163
219
  - !ruby/object:Gem::Version
164
- version: '0'
220
+ version: '2.0'
165
221
  required_rubygems_version: !ruby/object:Gem::Requirement
166
222
  requirements:
167
223
  - - ">="
@@ -183,4 +239,3 @@ test_files:
183
239
  - spec/lib/ldp/resource_spec.rb
184
240
  - spec/lib/ldp/response_spec.rb
185
241
  - spec/spec_helper.rb
186
- has_rdoc: