diff options
author | reverite <samantha@chalker.io> | 2019-03-15 05:54:30 -0700 |
---|---|---|
committer | reverite <samantha@chalker.io> | 2019-03-15 05:54:30 -0700 |
commit | 75eeb003b09c53d3b4e98046d1c20b0ad8a887bb (patch) | |
tree | d2ae669ee583c613a474f8698b7ea718da803819 /spec | |
parent | 41d1369391d70a9cd25bdf96cfe567975793ef5a (diff) | |
parent | c2fa0f7c40bcc4064e8baaa221665eadd391c001 (diff) |
Merge remote-tracking branch 'glitch/master' into production
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/accounts_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/controllers/admin/settings_controller_spec.rb | 16 | ||||
-rw-r--r-- | spec/controllers/auth/registrations_controller_spec.rb | 20 | ||||
-rw-r--r-- | spec/controllers/concerns/account_controller_concern_spec.rb | 16 | ||||
-rw-r--r-- | spec/helpers/application_helper_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/account_spec.rb | 5 | ||||
-rw-r--r-- | spec/presenters/instance_presenter_spec.rb | 28 | ||||
-rw-r--r-- | spec/requests/localization_spec.rb | 9 | ||||
-rw-r--r-- | spec/services/app_sign_up_service_spec.rb | 4 | ||||
-rw-r--r-- | spec/views/about/show.html.haml_spec.rb | 36 |
10 files changed, 60 insertions, 80 deletions
diff --git a/spec/controllers/accounts_controller_spec.rb b/spec/controllers/accounts_controller_spec.rb index 3ba5d8aec..b728d719f 100644 --- a/spec/controllers/accounts_controller_spec.rb +++ b/spec/controllers/accounts_controller_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe AccountsController, type: :controller do render_views - let(:alice) { Fabricate(:account, username: 'alice') } + let(:alice) { Fabricate(:account, username: 'alice', user: Fabricate(:user)) } let(:eve) { Fabricate(:user) } describe 'GET #show' do diff --git a/spec/controllers/admin/settings_controller_spec.rb b/spec/controllers/admin/settings_controller_spec.rb index eaf99679a..34f6bbdae 100644 --- a/spec/controllers/admin/settings_controller_spec.rb +++ b/spec/controllers/admin/settings_controller_spec.rb @@ -62,22 +62,6 @@ RSpec.describe Admin::SettingsController, type: :controller do expect(Setting.site_title).to eq 'New title' end end - - context do - around do |example| - open_registrations = Setting.open_registrations - example.run - Setting.open_registrations = open_registrations - end - - it 'typecasts open_registrations to boolean' do - Setting.open_registrations = false - patch :update, params: { form_admin_settings: { open_registrations: '1' } } - - expect(response).to redirect_to(edit_admin_settings_path) - expect(Setting.open_registrations).to eq true - end - end end end end diff --git a/spec/controllers/auth/registrations_controller_spec.rb b/spec/controllers/auth/registrations_controller_spec.rb index eeb01d5ad..1095df034 100644 --- a/spec/controllers/auth/registrations_controller_spec.rb +++ b/spec/controllers/auth/registrations_controller_spec.rb @@ -5,14 +5,14 @@ RSpec.describe Auth::RegistrationsController, type: :controller do shared_examples 'checks for enabled registrations' do |path| around do |example| - open_registrations = Setting.open_registrations + registrations_mode = Setting.registrations_mode example.run - Setting.open_registrations = open_registrations + Setting.registrations_mode = registrations_mode end it 'redirects if it is in single user mode while it is open for registration' do Fabricate(:account) - Setting.open_registrations = true + Setting.registrations_mode = 'open' expect(Rails.configuration.x).to receive(:single_user_mode).and_return(true) get path @@ -21,7 +21,7 @@ RSpec.describe Auth::RegistrationsController, type: :controller do end it 'redirects if it is not open for registration while it is not in single user mode' do - Setting.open_registrations = false + Setting.registrations_mode = 'none' expect(Rails.configuration.x).to receive(:single_user_mode).and_return(false) get path @@ -55,13 +55,13 @@ RSpec.describe Auth::RegistrationsController, type: :controller do context do around do |example| - open_registrations = Setting.open_registrations + registrations_mode = Setting.registrations_mode example.run - Setting.open_registrations = open_registrations + Setting.registrations_mode = registrations_mode end it 'returns http success' do - Setting.open_registrations = true + Setting.registrations_mode = 'open' get :new expect(response).to have_http_status(200) end @@ -83,13 +83,13 @@ RSpec.describe Auth::RegistrationsController, type: :controller do context do around do |example| - open_registrations = Setting.open_registrations + registrations_mode = Setting.registrations_mode example.run - Setting.open_registrations = open_registrations + Setting.registrations_mode = registrations_mode end subject do - Setting.open_registrations = true + Setting.registrations_mode = 'open' request.headers["Accept-Language"] = accept_language post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678' } } end diff --git a/spec/controllers/concerns/account_controller_concern_spec.rb b/spec/controllers/concerns/account_controller_concern_spec.rb index 93685103f..ea2b4a2a1 100644 --- a/spec/controllers/concerns/account_controller_concern_spec.rb +++ b/spec/controllers/concerns/account_controller_concern_spec.rb @@ -17,7 +17,15 @@ describe ApplicationController, type: :controller do context 'when account is suspended' do it 'returns http gone' do - account = Fabricate(:account, suspended: true) + account = Fabricate(:account, suspended: true, user: Fabricate(:user)) + get 'success', params: { account_username: account.username } + expect(response).to have_http_status(410) + end + end + + context 'when account is deleted by owner' do + it 'returns http gone' do + account = Fabricate(:account, suspended: true, user: nil) get 'success', params: { account_username: account.username } expect(response).to have_http_status(410) end @@ -25,19 +33,19 @@ describe ApplicationController, type: :controller do context 'when account is not suspended' do it 'assigns @account' do - account = Fabricate(:account) + account = Fabricate(:account, user: Fabricate(:user)) get 'success', params: { account_username: account.username } expect(assigns(:account)).to eq account end it 'sets link headers' do - account = Fabricate(:account, username: 'username') + account = Fabricate(:account, username: 'username', user: Fabricate(:user)) get 'success', params: { account_username: 'username' } expect(response.headers['Link'].to_s).to eq '<http://test.host/.well-known/webfinger?resource=acct%3Ausername%40cb6e6126.ngrok.io>; rel="lrdd"; type="application/xrd+xml", <http://test.host/users/username.atom>; rel="alternate"; type="application/atom+xml", <https://cb6e6126.ngrok.io/users/username>; rel="alternate"; type="application/activity+json"' end it 'returns http success' do - account = Fabricate(:account) + account = Fabricate(:account, user: Fabricate(:user)) get 'success', params: { account_username: account.username } expect(response).to have_http_status(200) end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 61780b46b..f09e32ecc 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -69,7 +69,7 @@ describe ApplicationHelper do describe 'open_registrations?' do it 'returns true when open for registrations' do without_partial_double_verification do - expect(Setting).to receive(:open_registrations).and_return(true) + expect(Setting).to receive(:registrations_mode).and_return('open') end expect(helper.open_registrations?).to eq true @@ -77,7 +77,7 @@ describe ApplicationHelper do it 'returns false when closed for registrations' do without_partial_double_verification do - expect(Setting).to receive(:open_registrations).and_return(false) + expect(Setting).to receive(:registrations_mode).and_return('none') end expect(helper.open_registrations?).to eq false diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index a43421b76..379872316 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -558,6 +558,11 @@ RSpec.describe Account, type: :model do expect(account).to model_have_error_on_field(:username) end + it 'squishes the username before validation' do + account = Fabricate(:account, domain: nil, username: " \u3000bob \t \u00a0 \n ") + expect(account.username).to eq 'bob' + end + context 'when is local' do it 'is invalid if the username is not unique in case-insensitive comparison among local accounts' do account_1 = Fabricate(:account, username: 'the_doctor') diff --git a/spec/presenters/instance_presenter_spec.rb b/spec/presenters/instance_presenter_spec.rb index ccc558f71..81d8d0e98 100644 --- a/spec/presenters/instance_presenter_spec.rb +++ b/spec/presenters/instance_presenter_spec.rb @@ -33,34 +33,6 @@ describe InstancePresenter do context do around do |example| - open_registrations = Setting.open_registrations - example.run - Setting.open_registrations = open_registrations - end - - it "delegates open_registrations to Setting" do - Setting.open_registrations = false - - expect(instance_presenter.open_registrations).to eq false - end - end - - context do - around do |example| - closed_registrations_message = Setting.closed_registrations_message - example.run - Setting.closed_registrations_message = closed_registrations_message - end - - it "delegates closed_registrations_message to Setting" do - Setting.closed_registrations_message = "Closed message" - - expect(instance_presenter.closed_registrations_message).to eq "Closed message" - end - end - - context do - around do |example| site_contact_email = Setting.site_contact_email example.run Setting.site_contact_email = site_contact_email diff --git a/spec/requests/localization_spec.rb b/spec/requests/localization_spec.rb index f625a93a4..496a885e8 100644 --- a/spec/requests/localization_spec.rb +++ b/spec/requests/localization_spec.rb @@ -11,8 +11,9 @@ describe 'Localization' do headers = { 'Accept-Language' => 'zh-HK' } get "/about", headers: headers + expect(response.body).to include( - I18n.t('about.about_mastodon_html', locale: 'zh-HK') + I18n.t('about.tagline', locale: 'zh-HK') ) end @@ -20,16 +21,18 @@ describe 'Localization' do headers = { 'Accept-Language' => 'es-FAKE' } get "/about", headers: headers + expect(response.body).to include( - I18n.t('about.about_mastodon_html', locale: 'es') + 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.about_mastodon_html', locale: 'en') + I18n.t('about.tagline', locale: 'en') ) end end diff --git a/spec/services/app_sign_up_service_spec.rb b/spec/services/app_sign_up_service_spec.rb index d480df348..7948bb53b 100644 --- a/spec/services/app_sign_up_service_spec.rb +++ b/spec/services/app_sign_up_service_spec.rb @@ -8,8 +8,10 @@ RSpec.describe AppSignUpService, type: :service do describe '#call' do it 'returns nil when registrations are closed' do - Setting.open_registrations = false + tmp = Setting.registrations_mode + Setting.registrations_mode = 'none' expect(subject.call(app, good_params)).to be_nil + Setting.registrations_mode = tmp end it 'raises an error when params are missing' do diff --git a/spec/views/about/show.html.haml_spec.rb b/spec/views/about/show.html.haml_spec.rb index 65124fcf2..26b131977 100644 --- a/spec/views/about/show.html.haml_spec.rb +++ b/spec/views/about/show.html.haml_spec.rb @@ -8,24 +8,30 @@ describe 'about/show.html.haml', without_verify_partial_doubles: true do before do allow(view).to receive(:site_hostname).and_return('example.com') allow(view).to receive(:site_title).and_return('example site') + allow(view).to receive(:new_user).and_return(User.new) + allow(view).to receive(:use_seamless_external_login?).and_return(false) end it 'has valid open graph tags' do - instance_presenter = double(:instance_presenter, - site_title: 'something', - site_short_description: 'something', - site_description: 'something', - version_number: '1.0', - source_url: 'https://github.com/tootsuite/mastodon', - open_registrations: false, - thumbnail: nil, - hero: nil, - mascot: nil, - user_count: 0, - status_count: 0, - commit_hash: commit_hash, - contact_account: nil, - closed_registrations_message: 'yes') + instance_presenter = double( + :instance_presenter, + site_title: 'something', + site_short_description: 'something', + site_description: 'something', + version_number: '1.0', + source_url: 'https://github.com/tootsuite/mastodon', + open_registrations: false, + thumbnail: nil, + hero: nil, + mascot: nil, + user_count: 420, + status_count: 69, + active_user_count: 420, + commit_hash: commit_hash, + contact_account: nil, + sample_accounts: [] + ) + assign(:instance_presenter, instance_presenter) render |