Gab Social. All are welcome.
This commit is contained in:
40
spec/requests/account_show_page_spec.rb
Normal file
40
spec/requests/account_show_page_spec.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'The account show page' do
|
||||
it 'Has an h-feed with correct number of h-entry objects in it' do
|
||||
alice = Fabricate(:account, username: 'alice', display_name: 'Alice')
|
||||
_status = Fabricate(:status, account: alice, text: 'Hello World')
|
||||
_status2 = Fabricate(:status, account: alice, text: 'Hello World Again')
|
||||
_status3 = Fabricate(:status, account: alice, text: 'Are You Still There World?')
|
||||
|
||||
get '/@alice'
|
||||
|
||||
expect(h_feed_entries.size).to eq(3)
|
||||
end
|
||||
|
||||
it 'has valid opengraph tags' do
|
||||
alice = Fabricate(:account, username: 'alice', display_name: 'Alice')
|
||||
_status = Fabricate(:status, account: alice, text: 'Hello World')
|
||||
|
||||
get '/@alice'
|
||||
|
||||
expect(head_meta_content('og:title')).to match alice.display_name
|
||||
expect(head_meta_content('og:type')).to eq 'profile'
|
||||
expect(head_meta_content('og:image')).to match '.+'
|
||||
expect(head_meta_content('og:url')).to match 'http://.+'
|
||||
end
|
||||
|
||||
def head_meta_content(property)
|
||||
head_section.meta("[@property='#{property}']")[:content]
|
||||
end
|
||||
|
||||
def head_section
|
||||
Nokogiri::Slop(response.body).html.head
|
||||
end
|
||||
|
||||
def h_feed_entries
|
||||
Nokogiri::HTML(response.body).search('.h-feed .h-entry')
|
||||
end
|
||||
end
|
||||
21
spec/requests/catch_all_route_request_spec.rb
Normal file
21
spec/requests/catch_all_route_request_spec.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "The catch all route" do
|
||||
describe "with a simple value" do
|
||||
it "returns a 404 page as html" do
|
||||
get "/test"
|
||||
|
||||
expect(response.status).to eq 404
|
||||
expect(response.content_type).to eq "text/html"
|
||||
end
|
||||
end
|
||||
|
||||
describe "with an implied format" do
|
||||
it "returns a 404 page as html" do
|
||||
get "/test.test"
|
||||
|
||||
expect(response.status).to eq 404
|
||||
expect(response.content_type).to eq "text/html"
|
||||
end
|
||||
end
|
||||
end
|
||||
12
spec/requests/host_meta_request_spec.rb
Normal file
12
spec/requests/host_meta_request_spec.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "The host_meta route" do
|
||||
describe "requested without accepts headers" do
|
||||
it "returns an xml response" do
|
||||
get host_meta_url
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to eq "application/xrd+xml"
|
||||
end
|
||||
end
|
||||
end
|
||||
33
spec/requests/link_headers_spec.rb
Normal file
33
spec/requests/link_headers_spec.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Link headers' do
|
||||
describe 'on the account show page' do
|
||||
let(:account) { Fabricate(:account, username: 'test') }
|
||||
|
||||
before do
|
||||
get short_account_path(username: account)
|
||||
end
|
||||
|
||||
it 'contains webfinger url in link header' do
|
||||
link_header = link_header_with_type('application/xrd+xml')
|
||||
|
||||
expect(link_header.href).to match 'http://www.example.com/.well-known/webfinger?resource=acct%3Atest%40cb6e6126.ngrok.io'
|
||||
expect(link_header.attr_pairs.first).to eq %w(rel lrdd)
|
||||
end
|
||||
|
||||
it 'contains atom url in link header' do
|
||||
link_header = link_header_with_type('application/atom+xml')
|
||||
|
||||
expect(link_header.href).to eq 'http://www.example.com/users/test.atom'
|
||||
expect(link_header.attr_pairs.first).to eq %w(rel alternate)
|
||||
end
|
||||
|
||||
def link_header_with_type(type)
|
||||
response.headers['Link'].links.find do |link|
|
||||
link.attr_pairs.any? { |pair| pair == ['type', type] }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
38
spec/requests/localization_spec.rb
Normal file
38
spec/requests/localization_spec.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Localization' do
|
||||
after(:all) do
|
||||
I18n.locale = I18n.default_locale
|
||||
end
|
||||
|
||||
it 'uses a specific region when provided' do
|
||||
headers = { 'Accept-Language' => 'zh-HK' }
|
||||
|
||||
get "/about", headers: headers
|
||||
|
||||
expect(response.body).to include(
|
||||
I18n.t('about.tagline', locale: 'zh-HK')
|
||||
)
|
||||
end
|
||||
|
||||
it 'falls back to a locale when region missing' do
|
||||
headers = { 'Accept-Language' => 'es-FAKE' }
|
||||
|
||||
get "/about", headers: headers
|
||||
|
||||
expect(response.body).to include(
|
||||
I18n.t('about.tagline', locale: 'es')
|
||||
)
|
||||
end
|
||||
it 'falls back to english when locale is missing' do
|
||||
headers = { 'Accept-Language' => '12-FAKE' }
|
||||
|
||||
get "/about", headers: headers
|
||||
|
||||
expect(response.body).to include(
|
||||
I18n.t('about.tagline', locale: 'en')
|
||||
)
|
||||
end
|
||||
end
|
||||
48
spec/requests/webfinger_request_spec.rb
Normal file
48
spec/requests/webfinger_request_spec.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'The webfinger route' do
|
||||
let(:alice) { Fabricate(:account, username: 'alice') }
|
||||
|
||||
describe 'requested with standard accepts headers' do
|
||||
it 'returns a json response' do
|
||||
get webfinger_url(resource: alice.to_webfinger_s)
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to eq 'application/jrd+json'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'asking for xml format' do
|
||||
it 'returns an xml response for xml format' do
|
||||
get webfinger_url(resource: alice.to_webfinger_s, format: :xml)
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to eq 'application/xrd+xml'
|
||||
end
|
||||
|
||||
it 'returns an xml response for xml accept header' do
|
||||
headers = { 'HTTP_ACCEPT' => 'application/xrd+xml' }
|
||||
get webfinger_url(resource: alice.to_webfinger_s), headers: headers
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to eq 'application/xrd+xml'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'asking for json format' do
|
||||
it 'returns a json response for json format' do
|
||||
get webfinger_url(resource: alice.to_webfinger_s, format: :json)
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to eq 'application/jrd+json'
|
||||
end
|
||||
|
||||
it 'returns a json response for json accept header' do
|
||||
headers = { 'HTTP_ACCEPT' => 'application/jrd+json' }
|
||||
get webfinger_url(resource: alice.to_webfinger_s), headers: headers
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to eq 'application/jrd+json'
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user