diff options
author | Thibaut Girka <thib@sitedethib.com> | 2018-08-18 18:04:49 +0200 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2018-08-18 18:04:49 +0200 |
commit | bfeac6747a58b660f0d1b3766c7cfb3ea2655fce (patch) | |
tree | e9d1366c30b94df21ec767276fbde175428399fb /spec | |
parent | 7423c0c1308555db3072ae64141250fdd33ce235 (diff) | |
parent | 298ee84488758fc08a0ae9233e04c9637aa2fe02 (diff) |
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts: .circleci/config.yml app/controllers/authorize_follows_controller.rb app/javascript/packs/public.js Moved new stuff from packs/public.js to core/public.js. Added appropriate use_pack in new controllers.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/authorize_interactions_controller_spec.rb (renamed from spec/controllers/authorize_follows_controller_spec.rb) | 31 | ||||
-rw-r--r-- | spec/controllers/intents_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/status_spec.rb | 21 |
3 files changed, 38 insertions, 16 deletions
diff --git a/spec/controllers/authorize_follows_controller_spec.rb b/spec/controllers/authorize_interactions_controller_spec.rb index 52971c724..81fd9ceb7 100644 --- a/spec/controllers/authorize_follows_controller_spec.rb +++ b/spec/controllers/authorize_interactions_controller_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe AuthorizeFollowsController do +describe AuthorizeInteractionsController do render_views describe 'GET #show' do @@ -39,19 +39,19 @@ describe AuthorizeFollowsController do expect(service).to have_received(:call).with('missing@hostname') end - it 'sets account from url' do + it 'sets resource from url' do account = Account.new service = double - allow(FetchRemoteAccountService).to receive(:new).and_return(service) + allow(ResolveURLService).to receive(:new).and_return(service) allow(service).to receive(:call).with('http://example.com').and_return(account) get :show, params: { acct: 'http://example.com' } expect(response).to have_http_status(200) - expect(assigns(:account)).to eq account + expect(assigns(:resource)).to eq account end - it 'sets account from acct uri' do + it 'sets resource from acct uri' do account = Account.new service = double allow(ResolveAccountService).to receive(:new).and_return(service) @@ -60,7 +60,7 @@ describe AuthorizeFollowsController do get :show, params: { acct: 'acct:found@hostname' } expect(response).to have_http_status(200) - expect(assigns(:account)).to eq account + expect(assigns(:resource)).to eq account end end end @@ -75,8 +75,8 @@ describe AuthorizeFollowsController do end describe 'when signed in' do - let(:user) { Fabricate(:user) } - let(:account) { Fabricate(:account, user: user) } + let!(:user) { Fabricate(:user) } + let!(:account) { user.account } before do sign_in(user) @@ -84,25 +84,26 @@ describe AuthorizeFollowsController do it 'shows error when account not found' do service = double - allow(FollowService).to receive(:new).and_return(service) - allow(service).to receive(:call).with(account, 'user@hostname').and_return(nil) + + allow(ResolveAccountService).to receive(:new).and_return(service) + allow(service).to receive(:call).with('user@hostname').and_return(nil) post :create, params: { acct: 'acct:user@hostname' } - expect(service).to have_received(:call).with(account, 'user@hostname') expect(response).to render_template(:error) end it 'follows account when found' do target_account = Fabricate(:account) - result_account = double(target_account: target_account) service = double - allow(FollowService).to receive(:new).and_return(service) - allow(service).to receive(:call).with(account, 'user@hostname').and_return(result_account) + + allow(ResolveAccountService).to receive(:new).and_return(service) + allow(service).to receive(:call).with('user@hostname').and_return(target_account) post :create, params: { acct: 'acct:user@hostname' } - expect(service).to have_received(:call).with(account, 'user@hostname') + expect(service).to have_received(:call).with('user@hostname') + expect(account.following?(target_account)).to be true expect(response).to render_template(:success) end end diff --git a/spec/controllers/intents_controller_spec.rb b/spec/controllers/intents_controller_spec.rb index 3dde7f835..ddfd5ea36 100644 --- a/spec/controllers/intents_controller_spec.rb +++ b/spec/controllers/intents_controller_spec.rb @@ -13,7 +13,7 @@ RSpec.describe IntentsController, type: :controller do context 'when host is follow' do let(:uri) { 'web+mastodon://follow?uri=test' } - it { is_expected.to redirect_to authorize_follow_path(acct: 'test') } + it { is_expected.to redirect_to authorize_interaction_path(uri: 'test') } end context 'when host is share' do diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb index 0e2bb0675..3467342ee 100644 --- a/spec/models/status_spec.rb +++ b/spec/models/status_spec.rb @@ -182,6 +182,27 @@ RSpec.describe Status, type: :model do reblog.destroy expect(subject.reblogs_count).to eq 0 end + + it 'does not fail when original is deleted before reblog' do + reblog = Fabricate(:status, account: bob, reblog: subject) + expect(subject.reblogs_count).to eq 1 + expect { subject.destroy }.to_not raise_error + expect(Status.find_by(id: reblog.id)).to be_nil + end + end + + describe '#replies_count' do + it 'is the number of replies' do + reply = Fabricate(:status, account: bob, thread: subject) + expect(subject.replies_count).to eq 1 + end + + it 'is decremented when reply is removed' do + reply = Fabricate(:status, account: bob, thread: subject) + expect(subject.replies_count).to eq 1 + reply.destroy + expect(subject.replies_count).to eq 0 + end end describe '#favourites_count' do |