diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/auth/registrations_controller_spec.rb | 7 | ||||
-rw-r--r-- | spec/controllers/media_controller_spec.rb | 37 | ||||
-rw-r--r-- | spec/helpers/instance_helper_spec.rb | 33 | ||||
-rw-r--r-- | spec/helpers/site_title_helper_spec.rb | 15 | ||||
-rw-r--r-- | spec/i18n_spec.rb | 16 | ||||
-rw-r--r-- | spec/lib/atom_serializer_spec.rb | 21 | ||||
-rw-r--r-- | spec/requests/webfinger_request_spec.rb | 45 | ||||
-rw-r--r-- | spec/routing/well_known_routes_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/account_search_service_spec.rb | 12 |
9 files changed, 140 insertions, 48 deletions
diff --git a/spec/controllers/auth/registrations_controller_spec.rb b/spec/controllers/auth/registrations_controller_spec.rb index 6b26e6693..c2141766e 100644 --- a/spec/controllers/auth/registrations_controller_spec.rb +++ b/spec/controllers/auth/registrations_controller_spec.rb @@ -16,9 +16,12 @@ RSpec.describe Auth::RegistrationsController, type: :controller do end describe 'POST #create' do + let(:accept_language) { Rails.application.config.i18n.available_locales.sample.to_s } + before do Setting.open_registrations = true request.env["devise.mapping"] = Devise.mappings[:user] + request.headers["Accept-Language"] = accept_language post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678' } } end @@ -27,7 +30,9 @@ RSpec.describe Auth::RegistrationsController, type: :controller do end it 'creates user' do - expect(User.find_by(email: 'test@example.com')).to_not be_nil + user = User.find_by(email: 'test@example.com') + expect(user).to_not be_nil + expect(user.locale).to eq(accept_language) end end end diff --git a/spec/controllers/media_controller_spec.rb b/spec/controllers/media_controller_spec.rb new file mode 100644 index 000000000..ebf6aa006 --- /dev/null +++ b/spec/controllers/media_controller_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe MediaController do + describe '#show' do + it 'redirects to the file url when attached to a status' do + status = Fabricate(:status) + media_attachment = Fabricate(:media_attachment, status: status) + get :show, params: { id: media_attachment.to_param } + + expect(response).to redirect_to(media_attachment.file.url(:original)) + end + + it 'responds with missing when there is not an attached status' do + media_attachment = Fabricate(:media_attachment, status: nil) + get :show, params: { id: media_attachment.to_param } + + expect(response).to have_http_status(:missing) + end + + it 'raises when shortcode cant be found' do + get :show, params: { id: 'missing' } + + expect(response).to have_http_status(:missing) + end + + it 'raises when not permitted to view' do + status = Fabricate(:status) + media_attachment = Fabricate(:media_attachment, status: status) + allow_any_instance_of(Status).to receive(:permitted?).and_return(false) + get :show, params: { id: media_attachment.to_param } + + expect(response).to have_http_status(:missing) + end + end +end diff --git a/spec/helpers/instance_helper_spec.rb b/spec/helpers/instance_helper_spec.rb new file mode 100644 index 000000000..c42ed6938 --- /dev/null +++ b/spec/helpers/instance_helper_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe InstanceHelper do + describe 'site_title' do + it 'Uses the Setting.site_title value when it exists' do + Setting.site_title = 'New site title' + + expect(helper.site_title).to eq 'New site title' + end + + it 'returns empty string when Setting.site_title is nil' do + Setting.site_title = nil + + expect(helper.site_title).to eq '' + end + end + + describe 'site_hostname' do + around(:each) do |example| + before = Rails.configuration.x.local_domain + example.run + Rails.configuration.x.local_domain = before + end + + it 'returns the local domain value' do + Rails.configuration.x.local_domain = 'example.com' + + expect(helper.site_hostname).to eq 'example.com' + end + end +end diff --git a/spec/helpers/site_title_helper_spec.rb b/spec/helpers/site_title_helper_spec.rb deleted file mode 100644 index 8cfd9cba1..000000000 --- a/spec/helpers/site_title_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require "rails_helper" - -describe "site_title" do - it "Uses the Setting.site_title value when it exists" do - Setting.site_title = "New site title" - - expect(helper.site_title).to eq "New site title" - end - - it "returns empty string when Setting.site_title is nil" do - Setting.site_title = nil - - expect(helper.site_title).to eq "" - end -end diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb deleted file mode 100644 index 138d25569..000000000 --- a/spec/i18n_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true -require 'i18n/tasks' - -RSpec.describe 'I18n' do - let(:i18n) { I18n::Tasks::BaseTask.new } - let(:missing_keys) { i18n.missing_keys } - let(:unused_keys) { i18n.unused_keys } - - xit 'does not have missing keys' do - expect(missing_keys).to be_empty, "Missing #{missing_keys.leaves.count} i18n keys, run `i18n-tasks missing' to show them" - end - - xit 'does not have unused keys' do - expect(unused_keys).to be_empty, "#{unused_keys.leaves.count} unused i18n keys, run `i18n-tasks unused' to show them" - end -end diff --git a/spec/lib/atom_serializer_spec.rb b/spec/lib/atom_serializer_spec.rb new file mode 100644 index 000000000..0009e41a9 --- /dev/null +++ b/spec/lib/atom_serializer_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe AtomSerializer do + describe '#author' do + it 'returns dumpable XML with emojis' do + account = Fabricate(:account, display_name: '💩') + xml = AtomSerializer.render(AtomSerializer.new.author(account)) + + expect(xml).to be_a String + expect(xml).to match(/<poco:displayName>💩<\/poco:displayName>/) + end + + it 'returns dumpable XML with invalid characters like \b and \v' do + account = Fabricate(:account, display_name: "im l33t\b haxo\b\vr") + xml = AtomSerializer.render(AtomSerializer.new.author(account)) + + expect(xml).to be_a String + expect(xml).to match(/<poco:displayName>im l33t haxor<\/poco:displayName>/) + end + end +end diff --git a/spec/requests/webfinger_request_spec.rb b/spec/requests/webfinger_request_spec.rb index b5690d22f..a17d6cc22 100644 --- a/spec/requests/webfinger_request_spec.rb +++ b/spec/requests/webfinger_request_spec.rb @@ -1,33 +1,48 @@ -require "rails_helper" +require 'rails_helper' -describe "The webfinger route" do +describe 'The webfinger route' do let(:alice) { Fabricate(:account, username: 'alice') } - describe "requested without accepts headers" do - it "returns a json response" do - get webfinger_url, params: { resource: alice.to_webfinger_s } + 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(:success) - expect(response.content_type).to eq "application/jrd+json" + expect(response.content_type).to eq 'application/jrd+json' end end - describe "requested with html in accepts headers" do - it "returns a json response" do - headers = { 'HTTP_ACCEPT' => 'text/html' } - get webfinger_url, params: { resource: alice.to_webfinger_s }, headers: headers + 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(:success) + 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(:success) - expect(response.content_type).to eq "application/jrd+json" + expect(response.content_type).to eq 'application/xrd+xml' end end - describe "requested with xml format" do - it "returns an xml response" do - get webfinger_url(resource: alice.to_webfinger_s, format: :xml) + 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(:success) + 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(:success) - expect(response.content_type).to eq "application/xrd+xml" + expect(response.content_type).to eq 'application/jrd+json' end end end diff --git a/spec/routing/well_known_routes_spec.rb b/spec/routing/well_known_routes_spec.rb index 9540c3de3..2e25605c2 100644 --- a/spec/routing/well_known_routes_spec.rb +++ b/spec/routing/well_known_routes_spec.rb @@ -10,6 +10,6 @@ end describe 'the webfinger route' do it 'routes to correct place with json format' do expect(get('/.well-known/webfinger')). - to route_to('well_known/webfinger#show', format: 'json') + to route_to('well_known/webfinger#show') end end diff --git a/spec/services/account_search_service_spec.rb b/spec/services/account_search_service_spec.rb index fa421c443..723623833 100644 --- a/spec/services/account_search_service_spec.rb +++ b/spec/services/account_search_service_spec.rb @@ -25,6 +25,18 @@ describe AccountSearchService do end describe 'searching local and remote users' do + describe "when only '@'" do + before do + allow(Account).to receive(:find_remote) + allow(Account).to receive(:search_for) + subject.call('@', 10) + end + + it 'uses find_remote with empty query to look for local accounts' do + expect(Account).to have_received(:find_remote).with('', nil) + end + end + describe 'when no domain' do before do allow(Account).to receive(:find_remote) |