Skip to content

Commit 253ab26

Browse files
committed
Adding more tests for helpers
1 parent b640f35 commit 253ab26

File tree

3 files changed

+95
-26
lines changed

3 files changed

+95
-26
lines changed

app/helpers/atom_builder_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def stream_updated_at
33
@account.stream_entries.last ? (@account.updated_at > @account.stream_entries.last.created_at ? @account.updated_at : @account.stream_entries.last.created_at) : @account.updated_at
44
end
55

6-
def entry(xml, is_root, &block)
6+
def entry(xml, is_root = false, &block)
77
if is_root
88
root_tag(xml, :entry, &block)
99
else

config/environments/test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Configure static file server for tests with Cache-Control for performance.
1616
config.serve_static_files = true
1717
config.static_cache_control = 'public, max-age=3600'
18+
config.assets.digest = false
1819

1920
# Show full error reports and disable caching.
2021
config.consider_all_requests_local = true

spec/helpers/atom_builder_helper_spec.rb

+93-25
Original file line numberDiff line numberDiff line change
@@ -6,95 +6,148 @@
66
end
77

88
describe '#entry' do
9-
pending
9+
it 'creates an entry' do
10+
expect(used_in_builder { |xml| helper.entry(xml) }).to match '<entry/>'
11+
end
1012
end
1113

1214
describe '#feed' do
13-
pending
15+
it 'creates a feed' do
16+
expect(used_in_builder { |xml| helper.feed(xml) }).to match '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:media="http://purl.org/syndication/atommedia"/>'
17+
end
1418
end
1519

1620
describe '#unique_id' do
17-
pending
21+
it 'creates an id' do
22+
time = Time.now
23+
expect(used_in_builder { |xml| helper.unique_id(xml, time, 1, 'Status') }).to match "<id>#{helper.unique_tag(time, 1, 'Status')}</id>"
24+
end
1825
end
1926

2027
describe '#simple_id' do
21-
pending
28+
it 'creates an id' do
29+
expect(used_in_builder { |xml| helper.simple_id(xml, 1) }).to match '<id>1</id>'
30+
end
2231
end
2332

2433
describe '#published_at' do
25-
pending
34+
it 'creates a published tag' do
35+
time = Time.now
36+
expect(used_in_builder { |xml| helper.published_at(xml, time) }).to match "<published>#{time.iso8601}</published>"
37+
end
2638
end
2739

2840
describe '#updated_at' do
29-
pending
41+
it 'creates an updated tag' do
42+
time = Time.now
43+
expect(used_in_builder { |xml| helper.updated_at(xml, time) }).to match "<updated>#{time.iso8601}</updated>"
44+
end
3045
end
3146

3247
describe '#verb' do
33-
pending
48+
it 'creates an entry' do
49+
expect(used_with_namespaces { |xml| helper.verb(xml, 'verb') }).to match '<activity:verb>http://activitystrea.ms/schema/1.0/verb</activity:verb>'
50+
end
3451
end
3552

3653
describe '#content' do
37-
pending
54+
it 'creates a content' do
55+
expect(used_in_builder { |xml| helper.content(xml, 'foo') }).to match '<content type="html">foo</content>'
56+
end
3857
end
3958

4059
describe '#title' do
41-
pending
60+
it 'creates a title' do
61+
expect(used_in_builder { |xml| helper.title(xml, 'foo') }).to match '<title>foo</title>'
62+
end
4263
end
4364

4465
describe '#author' do
45-
pending
66+
it 'creates an author' do
67+
expect(used_in_builder { |xml| helper.author(xml) }).to match '<author/>'
68+
end
4669
end
4770

4871
describe '#target' do
49-
pending
72+
it 'creates a target' do
73+
expect(used_with_namespaces { |xml| helper.target(xml) }).to match '<activity:object/>'
74+
end
5075
end
5176

5277
describe '#object_type' do
53-
pending
78+
it 'creates an object type' do
79+
expect(used_with_namespaces { |xml| helper.object_type(xml, 'test') }).to match '<activity:object-type>http://activitystrea.ms/schema/1.0/test</activity:object-type>'
80+
end
5481
end
5582

5683
describe '#uri' do
57-
pending
84+
it 'creates a uri' do
85+
expect(used_in_builder { |xml| helper.uri(xml, 1) }).to match '<uri>1</uri>'
86+
end
5887
end
5988

6089
describe '#name' do
61-
pending
90+
it 'creates a name' do
91+
expect(used_in_builder { |xml| helper.name(xml, 1) }).to match '<name>1</name>'
92+
end
6293
end
6394

6495
describe '#summary' do
65-
pending
96+
it 'creates a summary' do
97+
expect(used_in_builder { |xml| helper.summary(xml, 1) }).to match '<summary>1</summary>'
98+
end
6699
end
67100

68101
describe '#subtitle' do
69-
pending
102+
it 'creates a subtitle' do
103+
expect(used_in_builder { |xml| helper.subtitle(xml, 1) }).to match '<subtitle>1</subtitle>'
104+
end
70105
end
71106

72107
describe '#link_alternate' do
73-
pending
108+
it 'creates a link' do
109+
expect(used_in_builder { |xml| helper.link_alternate(xml, 1) }).to match '<link rel="alternate" type="text/html" href="1"/>'
110+
end
74111
end
75112

76113
describe '#link_self' do
77-
pending
114+
it 'creates a link' do
115+
expect(used_in_builder { |xml| helper.link_self(xml, 1) }).to match '<link rel="self" type="application/atom+xml" href="1"/>'
116+
end
78117
end
79118

80119
describe '#link_hub' do
81-
pending
120+
it 'creates a link' do
121+
expect(used_in_builder { |xml| helper.link_hub(xml, 1) }).to match '<link rel="hub" href="1"/>'
122+
end
82123
end
83124

84125
describe '#link_salmon' do
85-
pending
126+
it 'creates a link' do
127+
expect(used_in_builder { |xml| helper.link_salmon(xml, 1) }).to match '<link rel="salmon" href="1"/>'
128+
end
86129
end
87130

88131
describe '#portable_contact' do
89-
pending
132+
let(:account) { Fabricate(:account, username: 'alice', display_name: 'Alice in Wonderland') }
133+
134+
it 'creates portable contacts entries' do
135+
expect(used_with_namespaces { |xml| helper.portable_contact(xml, account) }).to match '<poco:displayName>Alice in Wonderland</poco:displayName>'
136+
end
90137
end
91138

92139
describe '#in_reply_to' do
93-
pending
140+
it 'creates a thread' do
141+
expect(used_with_namespaces { |xml| helper.in_reply_to(xml, 'uri', 'url') }).to match '<thr:in-reply-to ref="uri" href="url" type="text/html"/>'
142+
end
94143
end
95144

96145
describe '#link_mention' do
97-
pending
146+
let(:account) { Fabricate(:account, username: 'alice') }
147+
148+
it 'creates a link' do
149+
expect(used_in_builder { |xml| helper.link_mention(xml, account) }).to match '<link rel="mentioned" href="http://test.host/users/alice"/>'
150+
end
98151
end
99152

100153
describe '#disambiguate_uri' do
@@ -114,10 +167,25 @@
114167
end
115168

116169
describe '#link_avatar' do
117-
pending
170+
let(:account) { Fabricate(:account, username: 'alice') }
171+
172+
it 'creates a link' do
173+
expect(used_with_namespaces { |xml| helper.link_avatar(xml, account) }).to match '<link rel="avatar" type="" media:width="300" media:height="300" href="http://test.host/assets/avatars/missing.png"/>'
174+
end
118175
end
119176

120177
describe '#logo' do
121-
pending
178+
it 'creates a logo' do
179+
expect(used_in_builder { |xml| helper.logo(xml, 1) }).to match '<logo>1</logo>'
180+
end
181+
end
182+
183+
def used_in_builder(&block)
184+
builder = Nokogiri::XML::Builder.new(&block)
185+
builder.doc.root.to_xml
186+
end
187+
188+
def used_with_namespaces(&block)
189+
used_in_builder { |xml| helper.entry(xml, true, &block) }
122190
end
123191
end

0 commit comments

Comments
 (0)