This repository has been archived on 2019-05-14. You can view files and clone it, but cannot push or open issues or pull requests.
mastodon/spec/helpers/atom_builder_helper_spec.rb

188 lines
5.7 KiB
Ruby
Raw Normal View History

2016-02-22 15:00:20 +00:00
require 'rails_helper'
RSpec.describe AtomBuilderHelper, type: :helper do
2016-02-26 14:28:08 +00:00
describe '#stream_updated_at' do
pending
end
describe '#entry' do
2016-03-20 12:50:22 +00:00
it 'creates an entry' do
expect(used_in_builder { |xml| helper.entry(xml) }).to match '<entry/>'
end
2016-02-26 14:28:08 +00:00
end
describe '#feed' do
2016-03-20 12:50:22 +00:00
it 'creates a feed' do
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" xmlns:ostatus="http://ostatus.org/schema/1.0"/>'
2016-03-20 12:50:22 +00:00
end
2016-02-26 14:28:08 +00:00
end
describe '#unique_id' do
2016-03-20 12:50:22 +00:00
it 'creates an id' do
time = Time.now
expect(used_in_builder { |xml| helper.unique_id(xml, time, 1, 'Status') }).to match "<id>#{TagManager.instance.unique_tag(time, 1, 'Status')}</id>"
2016-03-20 12:50:22 +00:00
end
2016-02-26 14:28:08 +00:00
end
describe '#simple_id' do
2016-03-20 12:50:22 +00:00
it 'creates an id' do
expect(used_in_builder { |xml| helper.simple_id(xml, 1) }).to match '<id>1</id>'
end
2016-02-26 14:28:08 +00:00
end
describe '#published_at' do
2016-03-20 12:50:22 +00:00
it 'creates a published tag' do
time = Time.now
expect(used_in_builder { |xml| helper.published_at(xml, time) }).to match "<published>#{time.iso8601}</published>"
end
2016-02-26 14:28:08 +00:00
end
describe '#updated_at' do
2016-03-20 12:50:22 +00:00
it 'creates an updated tag' do
time = Time.now
expect(used_in_builder { |xml| helper.updated_at(xml, time) }).to match "<updated>#{time.iso8601}</updated>"
end
2016-02-26 14:28:08 +00:00
end
describe '#verb' do
2016-03-20 12:50:22 +00:00
it 'creates an entry' do
expect(used_with_namespaces { |xml| helper.verb(xml, :post) }).to match '<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>'
2016-03-20 12:50:22 +00:00
end
2016-02-26 14:28:08 +00:00
end
describe '#content' do
2016-03-20 12:50:22 +00:00
it 'creates a content' do
expect(used_in_builder { |xml| helper.content(xml, 'foo') }).to match '<content type="html">foo</content>'
end
2016-02-26 14:28:08 +00:00
end
describe '#title' do
2016-03-20 12:50:22 +00:00
it 'creates a title' do
expect(used_in_builder { |xml| helper.title(xml, 'foo') }).to match '<title>foo</title>'
end
2016-02-26 14:28:08 +00:00
end
describe '#author' do
2016-03-20 12:50:22 +00:00
it 'creates an author' do
expect(used_in_builder { |xml| helper.author(xml) }).to match '<author/>'
end
2016-02-26 14:28:08 +00:00
end
describe '#target' do
2016-03-20 12:50:22 +00:00
it 'creates a target' do
expect(used_with_namespaces { |xml| helper.target(xml) }).to match '<activity:object/>'
end
2016-02-26 14:28:08 +00:00
end
describe '#object_type' do
2016-03-20 12:50:22 +00:00
it 'creates an object type' do
expect(used_with_namespaces { |xml| helper.object_type(xml, :person) }).to match '<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>'
2016-03-20 12:50:22 +00:00
end
2016-02-26 14:28:08 +00:00
end
describe '#uri' do
2016-03-20 12:50:22 +00:00
it 'creates a uri' do
expect(used_in_builder { |xml| helper.uri(xml, 1) }).to match '<uri>1</uri>'
end
2016-02-26 14:28:08 +00:00
end
describe '#name' do
2016-03-20 12:50:22 +00:00
it 'creates a name' do
expect(used_in_builder { |xml| helper.name(xml, 1) }).to match '<name>1</name>'
end
2016-02-26 14:28:08 +00:00
end
describe '#summary' do
2016-03-20 12:50:22 +00:00
it 'creates a summary' do
expect(used_in_builder { |xml| helper.summary(xml, 1) }).to match '<summary>1</summary>'
end
2016-02-26 14:28:08 +00:00
end
describe '#subtitle' do
2016-03-20 12:50:22 +00:00
it 'creates a subtitle' do
expect(used_in_builder { |xml| helper.subtitle(xml, 1) }).to match '<subtitle>1</subtitle>'
end
2016-02-26 14:28:08 +00:00
end
describe '#link_alternate' do
2016-03-20 12:50:22 +00:00
it 'creates a link' do
expect(used_in_builder { |xml| helper.link_alternate(xml, 1) }).to match '<link rel="alternate" type="text/html" href="1"/>'
end
2016-02-26 14:28:08 +00:00
end
describe '#link_self' do
2016-03-20 12:50:22 +00:00
it 'creates a link' do
expect(used_in_builder { |xml| helper.link_self(xml, 1) }).to match '<link rel="self" type="application/atom+xml" href="1"/>'
end
2016-02-26 14:28:08 +00:00
end
describe '#link_hub' do
2016-03-20 12:50:22 +00:00
it 'creates a link' do
expect(used_in_builder { |xml| helper.link_hub(xml, 1) }).to match '<link rel="hub" href="1"/>'
end
2016-02-26 14:28:08 +00:00
end
describe '#link_salmon' do
2016-03-20 12:50:22 +00:00
it 'creates a link' do
expect(used_in_builder { |xml| helper.link_salmon(xml, 1) }).to match '<link rel="salmon" href="1"/>'
end
2016-02-26 14:28:08 +00:00
end
describe '#portable_contact' do
2016-03-20 12:50:22 +00:00
let(:account) { Fabricate(:account, username: 'alice', display_name: 'Alice in Wonderland') }
it 'creates portable contacts entries' do
expect(used_with_namespaces { |xml| helper.portable_contact(xml, account) }).to match '<poco:displayName>Alice in Wonderland</poco:displayName>'
end
2016-02-26 14:28:08 +00:00
end
describe '#in_reply_to' do
2016-03-20 12:50:22 +00:00
it 'creates a thread' do
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"/>'
end
2016-02-26 14:28:08 +00:00
end
describe '#link_mention' do
2016-03-20 12:50:22 +00:00
let(:account) { Fabricate(:account, username: 'alice') }
it 'creates a link' do
expect(used_in_builder { |xml| helper.link_mention(xml, account) }).to match '<link rel="mentioned" href="https://cb6e6126.ngrok.io/users/alice" ostatus:object-type="http://activitystrea.ms/schema/1.0/person"/>'
2016-03-20 12:50:22 +00:00
end
2016-02-26 14:28:08 +00:00
end
describe '#include_author' do
pending
end
describe '#include_entry' do
pending
end
describe '#link_avatar' do
2016-03-20 12:50:22 +00:00
let(:account) { Fabricate(:account, username: 'alice') }
it 'creates a link' do
2016-09-08 16:23:59 +00:00
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/avatars/large/missing.png"/>'
2016-03-20 12:50:22 +00:00
end
end
describe '#link_enclosure' do
pending
end
describe '#logo' do
2016-03-20 12:50:22 +00:00
it 'creates a logo' do
expect(used_in_builder { |xml| helper.logo(xml, 1) }).to match '<logo>1</logo>'
end
end
def used_in_builder(&block)
builder = Nokogiri::XML::Builder.new(&block)
builder.doc.root.to_xml
end
def used_with_namespaces(&block)
used_in_builder { |xml| helper.entry(xml, true, &block) }
end
2016-02-22 15:00:20 +00:00
end