ratom 0.3.0 → 0.3.1
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 +5 -0
- data/lib/atom.rb +13 -2
- data/lib/atom/pub.rb +46 -17
- data/lib/atom/version.rb +1 -1
- data/lib/atom/xml/parser.rb +23 -17
- data/spec/atom/pub_spec.rb +217 -169
- metadata +1 -1
data/History.txt
CHANGED
data/lib/atom.rb
CHANGED
|
@@ -147,6 +147,13 @@ module Atom # :nodoc:
|
|
|
147
147
|
super(xml.read_string)
|
|
148
148
|
parse(xml, :once => true)
|
|
149
149
|
end
|
|
150
|
+
|
|
151
|
+
def to_xml(nodeonly = true, name = 'content', namespace = nil)
|
|
152
|
+
node = XML::Node.new(name)
|
|
153
|
+
node['xmlns'] = namespace
|
|
154
|
+
node << self.to_s
|
|
155
|
+
node
|
|
156
|
+
end
|
|
150
157
|
end
|
|
151
158
|
|
|
152
159
|
# Html content within an Atom document.
|
|
@@ -167,7 +174,7 @@ module Atom # :nodoc:
|
|
|
167
174
|
end
|
|
168
175
|
end
|
|
169
176
|
|
|
170
|
-
def to_xml(nodeonly = true, name = 'content') # :nodoc:
|
|
177
|
+
def to_xml(nodeonly = true, name = 'content', namespace = nil) # :nodoc:
|
|
171
178
|
require 'iconv'
|
|
172
179
|
# Convert from utf-8 to utf-8 as a way of making sure the content is UTF-8.
|
|
173
180
|
#
|
|
@@ -180,6 +187,7 @@ module Atom # :nodoc:
|
|
|
180
187
|
node = XML::Node.new(name)
|
|
181
188
|
node << Iconv.iconv('utf-8', 'utf-8', self.to_s)
|
|
182
189
|
node['type'] = 'html'
|
|
190
|
+
node['xmlns'] = namespace
|
|
183
191
|
node['xml:lang'] = self.xml_lang
|
|
184
192
|
node
|
|
185
193
|
rescue Iconv::IllegalSequence => e
|
|
@@ -210,10 +218,11 @@ module Atom # :nodoc:
|
|
|
210
218
|
while xml.read == 1 && xml.depth > starting_depth; end
|
|
211
219
|
end
|
|
212
220
|
|
|
213
|
-
def to_xml(nodeonly = true, name = 'content')
|
|
221
|
+
def to_xml(nodeonly = true, name = 'content', namespace = nil)
|
|
214
222
|
node = XML::Node.new(name)
|
|
215
223
|
node['type'] = 'xhtml'
|
|
216
224
|
node['xml:lang'] = self.xml_lang
|
|
225
|
+
node['xmlns'] = namespace
|
|
217
226
|
|
|
218
227
|
div = XML::Node.new('div')
|
|
219
228
|
div['xmlns'] = XHTML
|
|
@@ -287,6 +296,7 @@ module Atom # :nodoc:
|
|
|
287
296
|
|
|
288
297
|
loadable!
|
|
289
298
|
|
|
299
|
+
namespace Atom::NAMESPACE
|
|
290
300
|
element :id, :rights
|
|
291
301
|
element :generator, :class => Generator
|
|
292
302
|
element :title, :subtitle, :class => Content
|
|
@@ -403,6 +413,7 @@ module Atom # :nodoc:
|
|
|
403
413
|
def_delegators :@links, :alternate, :self, :alternates, :enclosures, :edit_link, :via
|
|
404
414
|
|
|
405
415
|
loadable!
|
|
416
|
+
namespace Atom::NAMESPACE
|
|
406
417
|
element :title, :id, :summary
|
|
407
418
|
element :updated, :published, :class => Time, :content_only => true
|
|
408
419
|
element :content, :class => Content
|
data/lib/atom/pub.rb
CHANGED
|
@@ -24,6 +24,7 @@ module Atom
|
|
|
24
24
|
|
|
25
25
|
class Service
|
|
26
26
|
include Atom::Xml::Parseable
|
|
27
|
+
namespace Atom::Pub::NAMESPACE
|
|
27
28
|
elements :workspaces
|
|
28
29
|
loadable! do |reader, message, severity, base, line|
|
|
29
30
|
if severity == XML::Reader::SEVERITY_ERROR
|
|
@@ -31,51 +32,77 @@ module Atom
|
|
|
31
32
|
end
|
|
32
33
|
end
|
|
33
34
|
|
|
34
|
-
def initialize(xml)
|
|
35
|
+
def initialize(xml = nil)
|
|
35
36
|
@workspaces = []
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
|
|
38
|
+
if xml
|
|
39
|
+
begin
|
|
40
|
+
if next_node_is?(xml, 'service', Atom::Pub::NAMESPACE)
|
|
41
|
+
xml.read
|
|
42
|
+
parse(xml)
|
|
43
|
+
else
|
|
44
|
+
raise ArgumentError, "XML document was missing atom:service"
|
|
45
|
+
end
|
|
46
|
+
ensure
|
|
47
|
+
xml.close
|
|
42
48
|
end
|
|
43
|
-
ensure
|
|
44
|
-
xml.close
|
|
45
49
|
end
|
|
50
|
+
|
|
51
|
+
yield(self) if block_given?
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class Category
|
|
56
|
+
include Atom::Xml::Parseable
|
|
57
|
+
def initialize(o)
|
|
58
|
+
o.read
|
|
59
|
+
parse(o, :once => true)
|
|
46
60
|
end
|
|
47
61
|
end
|
|
48
62
|
|
|
49
|
-
class Categories
|
|
63
|
+
class Categories < DelegateClass(Array)
|
|
50
64
|
include Atom::Xml::Parseable
|
|
65
|
+
elements :categories, :class => Category
|
|
51
66
|
|
|
52
67
|
def initialize(o)
|
|
68
|
+
super([])
|
|
53
69
|
o.read
|
|
54
70
|
parse(o)
|
|
55
71
|
end
|
|
56
|
-
|
|
72
|
+
|
|
73
|
+
def categories; self; end
|
|
57
74
|
end
|
|
58
75
|
|
|
59
76
|
class Workspace
|
|
60
77
|
include Atom::Xml::Parseable
|
|
61
|
-
element :title, :class => Content
|
|
78
|
+
element :title, :class => Content, :namespace => Atom::NAMESPACE
|
|
62
79
|
elements :collections
|
|
63
80
|
|
|
64
|
-
def initialize(o)
|
|
81
|
+
def initialize(o = nil)
|
|
65
82
|
@collections = []
|
|
66
|
-
|
|
67
|
-
|
|
83
|
+
|
|
84
|
+
case o
|
|
85
|
+
when XML::Reader
|
|
86
|
+
o.read
|
|
87
|
+
parse(o)
|
|
88
|
+
when Hash
|
|
89
|
+
o.each do |k, v|
|
|
90
|
+
self.send("#{k}=".to_sym, v)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
yield(self) if block_given?
|
|
68
95
|
end
|
|
69
96
|
end
|
|
70
97
|
|
|
71
98
|
class Collection
|
|
72
99
|
include Atom::Xml::Parseable
|
|
73
100
|
attribute :href
|
|
101
|
+
element :title, :class => Content, :namespace => Atom::NAMESPACE
|
|
74
102
|
element :categories, :class => Categories
|
|
75
|
-
element :title, :class => Content
|
|
76
103
|
elements :accepts, :content_only => true
|
|
77
104
|
|
|
78
|
-
def initialize(o)
|
|
105
|
+
def initialize(o = nil)
|
|
79
106
|
@accepts = []
|
|
80
107
|
case o
|
|
81
108
|
when XML::Reader
|
|
@@ -89,6 +116,8 @@ module Atom
|
|
|
89
116
|
self.send("#{k}=", v)
|
|
90
117
|
end
|
|
91
118
|
end
|
|
119
|
+
|
|
120
|
+
yield(self) if block_given?
|
|
92
121
|
end
|
|
93
122
|
|
|
94
123
|
def feed
|
data/lib/atom/version.rb
CHANGED
data/lib/atom/xml/parser.rb
CHANGED
|
@@ -68,6 +68,7 @@ module Atom
|
|
|
68
68
|
def o.attributes; @attributes ||= []; end
|
|
69
69
|
def element_specs; self.class.element_specs; end
|
|
70
70
|
def attributes; self.class.attributes; end
|
|
71
|
+
def o.namespace(ns = @namespace); @namespace = ns; end
|
|
71
72
|
end
|
|
72
73
|
o.send(:extend, DeclarationMethods)
|
|
73
74
|
end
|
|
@@ -84,27 +85,32 @@ module Atom
|
|
|
84
85
|
end
|
|
85
86
|
end
|
|
86
87
|
|
|
87
|
-
def to_xml(nodeonly = false, root_name = self.class.name.demodulize.downcase)
|
|
88
|
-
|
|
88
|
+
def to_xml(nodeonly = false, root_name = self.class.name.demodulize.downcase, namespace = nil)
|
|
89
89
|
node = XML::Node.new(root_name)
|
|
90
|
-
node['xmlns'] =
|
|
90
|
+
node['xmlns'] = self.class.namespace unless nodeonly || !self.class.respond_to?(:namespace)
|
|
91
91
|
|
|
92
|
-
self.class.element_specs.values.each do |spec|
|
|
93
|
-
if spec.
|
|
94
|
-
if attribute
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
n << attribute
|
|
102
|
-
node << n
|
|
103
|
-
end
|
|
92
|
+
self.class.element_specs.values.select {|s| s.single? }.each do |spec|
|
|
93
|
+
if attribute = self.send(spec.attribute)
|
|
94
|
+
if attribute.respond_to?(:to_xml)
|
|
95
|
+
node << attribute.to_xml(true, spec.name, spec.options[:namespace])
|
|
96
|
+
else
|
|
97
|
+
n = XML::Node.new(spec.name)
|
|
98
|
+
n['xmlns'] = spec.options[:namespace]
|
|
99
|
+
n << (attribute.is_a?(Time)? attribute.xmlschema : attribute.to_s)
|
|
100
|
+
node << n
|
|
104
101
|
end
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
self.class.element_specs.values.select {|s| !s.single? }.each do |spec|
|
|
106
|
+
self.send(spec.attribute).each do |attribute|
|
|
107
|
+
if attribute.respond_to?(:to_xml)
|
|
107
108
|
node << attribute.to_xml(true, spec.name.singularize)
|
|
109
|
+
else
|
|
110
|
+
n = XML::Node.new(spec.name.singularize)
|
|
111
|
+
n['xmlns'] = spec.options[:namespace]
|
|
112
|
+
n << attribute.to_s
|
|
113
|
+
node << n
|
|
108
114
|
end
|
|
109
115
|
end
|
|
110
116
|
end
|
data/spec/atom/pub_spec.rb
CHANGED
|
@@ -12,215 +12,263 @@ require 'atom/version'
|
|
|
12
12
|
require 'uri'
|
|
13
13
|
require 'net/http'
|
|
14
14
|
|
|
15
|
+
shared_examples_for 'parser of spec/app/service.xml' do
|
|
16
|
+
it "should have 2 workspaces" do
|
|
17
|
+
@service.should have(2).workspaces
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should have a title" do
|
|
21
|
+
@workspace.title.should == "Main Site"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should have 2 collections" do
|
|
25
|
+
@workspace.should have(2).collections
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should have the right href" do
|
|
29
|
+
@collection1.href.should == 'http://example.org/blog/main'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should have categories" do
|
|
33
|
+
@collection1.categories.should_not be_nil
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should have a title" do
|
|
37
|
+
@collection1.title.should == 'My Blog Entries'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should have a title" do
|
|
41
|
+
@collection2.title.should == 'Pictures'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should have the right href" do
|
|
45
|
+
@collection2.href.should == 'http://example.org/blog/pic'
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "should not have categories" do
|
|
49
|
+
@collection2.categories.should be_nil
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "should have 3 accepts" do
|
|
53
|
+
@collection2.should have(3).accepts
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "should accept 'image/png'" do
|
|
57
|
+
@collection2.accepts.should include('image/png')
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "should accept 'image/jpeg'" do
|
|
61
|
+
@collection2.accepts.should include('image/jpeg')
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "should accept 'image/gif'" do
|
|
65
|
+
@collection2.accepts.should include('image/gif')
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "should have a title on workspace 2" do
|
|
69
|
+
@workspace2.title.should == 'Sidebar Blog'
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "should have 1 collection on workspace 2" do
|
|
73
|
+
@workspace2.should have(1).collections
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "should have a title on collection 3" do
|
|
77
|
+
@collection3.title.should == 'Remaindered Links'
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "should have 1 accept on collection 3" do
|
|
81
|
+
@collection3.should have(1).accepts
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "should accept 'application/atom+xml;type=entry'" do
|
|
85
|
+
@collection3.accepts.should include('application/atom+xml;type=entry')
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "should have categories" do
|
|
89
|
+
@collection3.categories.should_not be_nil
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
15
93
|
describe Atom::Pub do
|
|
16
94
|
describe Atom::Pub::Service do
|
|
17
|
-
|
|
18
|
-
|
|
95
|
+
it "should load from a URL" do
|
|
96
|
+
uri = URI.parse('http://example.com/service.xml')
|
|
97
|
+
response = Net::HTTPSuccess.new(nil, nil, nil)
|
|
98
|
+
response.stub!(:body).and_return(File.read('spec/app/service.xml'))
|
|
99
|
+
Net::HTTP.should_receive(:get_response).with(uri).and_return(response)
|
|
100
|
+
Atom::Pub::Service.load_service(uri).should be_an_instance_of(Atom::Pub::Service)
|
|
19
101
|
end
|
|
102
|
+
|
|
103
|
+
it "should raise ArgumentError with a non-http URL" do
|
|
104
|
+
lambda { Atom::Pub::Service.load_service(URI.parse('file:/tmp')) }.should raise_error(ArgumentError)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "should be able to be created without xml" do
|
|
108
|
+
lambda { Atom::Pub::Service.new }.should_not raise_error
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "should yield in the initializer" do
|
|
112
|
+
yielded = false
|
|
113
|
+
Atom::Pub::Service.new do
|
|
114
|
+
yielded = true
|
|
115
|
+
end
|
|
20
116
|
|
|
21
|
-
|
|
22
|
-
@service.should have(2).workspaces
|
|
117
|
+
yielded.should be_true
|
|
23
118
|
end
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
119
|
+
|
|
120
|
+
it "should parse it's output" do
|
|
121
|
+
orig = File.read('spec/app/service.xml')
|
|
122
|
+
svc = Atom::Pub::Service.load_service(orig)
|
|
123
|
+
xml = svc.to_xml
|
|
124
|
+
lambda do
|
|
125
|
+
Atom::Pub::Service.load_service(xml)
|
|
126
|
+
end.should_not raise_error
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
describe "load_service" do
|
|
130
|
+
before(:all) do
|
|
131
|
+
@service = Atom::Pub::Service.load_service(File.open('spec/app/service.xml'))
|
|
27
132
|
@workspace = @service.workspaces.first
|
|
133
|
+
@workspace2 = @service.workspaces[1]
|
|
134
|
+
@collection1 = @workspace.collections.first
|
|
135
|
+
@collection2 = @workspace.collections[1]
|
|
136
|
+
@collection3 = @workspace2.collections.first
|
|
28
137
|
end
|
|
138
|
+
|
|
139
|
+
it_should_behave_like 'parser of spec/app/service.xml'
|
|
140
|
+
end
|
|
29
141
|
|
|
30
|
-
|
|
31
|
-
|
|
142
|
+
describe "#to_xml" do
|
|
143
|
+
before(:each) do
|
|
144
|
+
@svc = Atom::Pub::Service.load_service(File.read('spec/app/service.xml'))
|
|
145
|
+
@xml = @svc.to_xml
|
|
146
|
+
@service = Atom::Pub::Service.load_service(@xml)
|
|
147
|
+
@workspace = @service.workspaces.first
|
|
148
|
+
@workspace2 = @service.workspaces[1]
|
|
149
|
+
@collection1 = @workspace.collections.first
|
|
150
|
+
@collection2 = @workspace.collections[1]
|
|
151
|
+
@collection3 = @workspace2.collections.first
|
|
32
152
|
end
|
|
33
153
|
|
|
34
|
-
it "should
|
|
35
|
-
|
|
154
|
+
it "should put title in Atom namespace" do
|
|
155
|
+
# TODO fix this to use a prefix?
|
|
156
|
+
@xml.should match(%r{title xmlns="#{Atom::NAMESPACE}"})
|
|
36
157
|
end
|
|
37
|
-
|
|
38
|
-
describe 'first collection' do
|
|
39
|
-
before(:each) do
|
|
40
|
-
@collection = @workspace.collections.first
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it "should have the right href" do
|
|
44
|
-
@collection.href.should == 'http://example.org/blog/main'
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "should have categories" do
|
|
48
|
-
@collection.categories.should_not be_nil
|
|
49
|
-
end
|
|
50
158
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
159
|
+
it_should_behave_like 'parser of spec/app/service.xml'
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
describe Atom::Pub::Collection do
|
|
164
|
+
describe '.new' do
|
|
165
|
+
it "should set the href from the hash" do
|
|
166
|
+
collection = Atom::Pub::Collection.new(:href => 'http://example.org/blog')
|
|
167
|
+
collection.href.should == 'http://example.org/blog'
|
|
54
168
|
end
|
|
55
|
-
|
|
56
|
-
describe 'second collection' do
|
|
57
|
-
before(:each) do
|
|
58
|
-
@collection = @workspace.collections[1]
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "should have a title" do
|
|
62
|
-
@collection.title.should == 'Pictures'
|
|
63
|
-
end
|
|
64
169
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
it "should not have categories" do
|
|
70
|
-
@collection.categories.should be_nil
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it "should have 3 accepts" do
|
|
74
|
-
@collection.should have(3).accepts
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it "should accept 'image/png'" do
|
|
78
|
-
@collection.accepts.should include('image/png')
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "should accept 'image/jpeg'" do
|
|
82
|
-
@collection.accepts.should include('image/jpeg')
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "should accept 'image/gif'" do
|
|
86
|
-
@collection.accepts.should include('image/gif')
|
|
170
|
+
it "should set the href from a block" do
|
|
171
|
+
collection = Atom::Pub::Collection.new do |c|
|
|
172
|
+
c.href = "http://example.org/blog"
|
|
87
173
|
end
|
|
174
|
+
collection.href.should == 'http://example.org/blog'
|
|
88
175
|
end
|
|
89
176
|
end
|
|
90
|
-
|
|
91
|
-
describe '
|
|
177
|
+
|
|
178
|
+
describe '#publish' do
|
|
92
179
|
before(:each) do
|
|
93
|
-
@
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
180
|
+
@collection = Atom::Pub::Collection.new(:href => 'http://example.org/blog')
|
|
181
|
+
@request_headers = {'Accept' => 'application/atom+xml',
|
|
182
|
+
'Content-Type' => 'application/atom+xml;type=entry',
|
|
183
|
+
'User-Agent' => "rAtom #{Atom::VERSION::STRING}"
|
|
184
|
+
}
|
|
98
185
|
end
|
|
99
|
-
|
|
100
|
-
it "should
|
|
101
|
-
|
|
186
|
+
|
|
187
|
+
it "should return the feed" do
|
|
188
|
+
response = Net::HTTPSuccess.new(nil, nil, nil)
|
|
189
|
+
response.stub!(:body).and_return(File.read('spec/fixtures/simple_single_entry.atom'))
|
|
190
|
+
Net::HTTP.should_receive(:get_response).with(URI.parse(@collection.href)).and_return(response)
|
|
191
|
+
@collection.feed.should be_an_instance_of(Atom::Feed)
|
|
102
192
|
end
|
|
103
193
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
it "should have a title" do
|
|
110
|
-
@collection.title.should == 'Remaindered Links'
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
it "should have 1 accept" do
|
|
114
|
-
@collection.should have(1).accepts
|
|
115
|
-
end
|
|
194
|
+
it "should send a POST request when an entry is published" do
|
|
195
|
+
entry = Atom::Entry.load_entry(File.open('spec/fixtures/entry.atom'))
|
|
196
|
+
|
|
197
|
+
response = mock_response(Net::HTTPCreated, entry.to_xml.to_s)
|
|
116
198
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
199
|
+
http = mock('http')
|
|
200
|
+
http.should_receive(:post).with('/blog', entry.to_xml.to_s, @request_headers).and_return(response)
|
|
201
|
+
Net::HTTP.should_receive(:start).with('example.org', 80).and_yield(http)
|
|
120
202
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
end
|
|
203
|
+
created = @collection.publish(entry)
|
|
204
|
+
created.should == entry
|
|
124
205
|
end
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
describe Atom::Pub::Service do
|
|
129
|
-
it "should load from a URL" do
|
|
130
|
-
uri = URI.parse('http://example.com/service.xml')
|
|
131
|
-
response = Net::HTTPSuccess.new(nil, nil, nil)
|
|
132
|
-
response.stub!(:body).and_return(File.read('spec/app/service.xml'))
|
|
133
|
-
Net::HTTP.should_receive(:get_response).with(uri).and_return(response)
|
|
134
|
-
Atom::Pub::Service.load_service(uri).should be_an_instance_of(Atom::Pub::Service)
|
|
135
|
-
end
|
|
136
206
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
describe Atom::Pub::Collection do
|
|
143
|
-
before(:each) do
|
|
144
|
-
@collection = Atom::Pub::Collection.new(:href => 'http://example.org/blog')
|
|
145
|
-
@request_headers = {'Accept' => 'application/atom+xml',
|
|
146
|
-
'Content-Type' => 'application/atom+xml;type=entry',
|
|
147
|
-
'User-Agent' => "rAtom #{Atom::VERSION::STRING}"
|
|
148
|
-
}
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
it "should set the href from the hash" do
|
|
152
|
-
@collection.href.should == 'http://example.org/blog'
|
|
153
|
-
end
|
|
207
|
+
it "should behave well when no content is returned" do
|
|
208
|
+
entry = Atom::Entry.load_entry(File.open('spec/fixtures/entry.atom'))
|
|
209
|
+
|
|
210
|
+
response = mock_response(Net::HTTPCreated, " ")
|
|
154
211
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
212
|
+
http = mock('http')
|
|
213
|
+
http.should_receive(:post).with('/blog', entry.to_xml.to_s, @request_headers).and_return(response)
|
|
214
|
+
Net::HTTP.should_receive(:start).with('example.org', 80).and_yield(http)
|
|
215
|
+
|
|
216
|
+
created = @collection.publish(entry)
|
|
217
|
+
created.should == entry
|
|
218
|
+
end
|
|
161
219
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
response = mock_response(Net::HTTPCreated, entry.to_xml.to_s)
|
|
220
|
+
it "should raise error when response is not HTTPCreated" do
|
|
221
|
+
entry = Atom::Entry.load_entry(File.open('spec/fixtures/entry.atom'))
|
|
222
|
+
response = mock_response(Net::HTTPPreconditionFailed, "")
|
|
166
223
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
224
|
+
http = mock('http')
|
|
225
|
+
http.should_receive(:post).with('/blog', entry.to_xml.to_s, @request_headers).and_return(response)
|
|
226
|
+
Net::HTTP.should_receive(:start).with('example.org', 80).and_yield(http)
|
|
170
227
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
end
|
|
228
|
+
lambda { @collection.publish(entry) }.should raise_error(Atom::Pub::ProtocolError)
|
|
229
|
+
end
|
|
174
230
|
|
|
175
|
-
|
|
176
|
-
|
|
231
|
+
it "should copy Location into edit link of entry" do
|
|
232
|
+
entry = Atom::Entry.load_entry(File.open('spec/fixtures/entry.atom'))
|
|
177
233
|
|
|
178
|
-
|
|
234
|
+
response = mock_response(Net::HTTPCreated, entry.to_xml.to_s, 'Location' => 'http://example.org/edit/entry1.atom')
|
|
179
235
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
236
|
+
http = mock('http')
|
|
237
|
+
http.should_receive(:post).with('/blog', entry.to_xml.to_s, @request_headers).and_return(response)
|
|
238
|
+
Net::HTTP.should_receive(:start).with('example.org', 80).and_yield(http)
|
|
183
239
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
240
|
+
created = @collection.publish(entry)
|
|
241
|
+
created.edit_link.should_not be_nil
|
|
242
|
+
created.edit_link.href.should == 'http://example.org/edit/entry1.atom'
|
|
243
|
+
end
|
|
187
244
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
245
|
+
it "should update the entry when response is different" do
|
|
246
|
+
entry = Atom::Entry.load_entry(File.open('spec/fixtures/entry.atom'))
|
|
247
|
+
response = mock_response(Net::HTTPCreated, File.read('spec/fixtures/created_entry.atom'),
|
|
248
|
+
'Location' => 'http://example.org/edit/atom')
|
|
191
249
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
250
|
+
http = mock('http')
|
|
251
|
+
http.should_receive(:post).with('/blog', entry.to_xml.to_s, @request_headers).and_return(response)
|
|
252
|
+
Net::HTTP.should_receive(:start).with('example.org', 80).and_yield(http)
|
|
195
253
|
|
|
196
|
-
|
|
254
|
+
created = @collection.publish(entry)
|
|
255
|
+
created.should == Atom::Entry.load_entry(File.open('spec/fixtures/created_entry.atom'))
|
|
256
|
+
end
|
|
197
257
|
end
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
http.should_receive(:post).with('/blog', entry.to_xml.to_s, @request_headers).and_return(response)
|
|
206
|
-
Net::HTTP.should_receive(:start).with('example.org', 80).and_yield(http)
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
describe Atom::Pub::Workspace do
|
|
261
|
+
it "should do the block initialization thing" do
|
|
262
|
+
workspace = Atom::Pub::Workspace.new do |w|
|
|
263
|
+
w.title = "Title"
|
|
264
|
+
end
|
|
207
265
|
|
|
208
|
-
|
|
209
|
-
created.edit_link.should_not be_nil
|
|
210
|
-
created.edit_link.href.should == 'http://example.org/edit/entry1.atom'
|
|
266
|
+
workspace.title.should == "Title"
|
|
211
267
|
end
|
|
212
268
|
|
|
213
|
-
it "should
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
'Location' => 'http://example.org/edit/atom')
|
|
217
|
-
|
|
218
|
-
http = mock('http')
|
|
219
|
-
http.should_receive(:post).with('/blog', entry.to_xml.to_s, @request_headers).and_return(response)
|
|
220
|
-
Net::HTTP.should_receive(:start).with('example.org', 80).and_yield(http)
|
|
221
|
-
|
|
222
|
-
created = @collection.publish(entry)
|
|
223
|
-
created.should == Atom::Entry.load_entry(File.open('spec/fixtures/created_entry.atom'))
|
|
269
|
+
it "should do the hash initialization thing" do
|
|
270
|
+
workspace = Atom::Pub::Workspace.new(:title => 'Title')
|
|
271
|
+
workspace.title.should == "Title"
|
|
224
272
|
end
|
|
225
273
|
end
|
|
226
274
|
|