From ae3d2f446a60269740a72969d74fa57168530c97 Mon Sep 17 00:00:00 2001 From: ysksn Date: Mon, 10 Dec 2018 01:19:28 +0900 Subject: Add specs for Admin::InvitesController (#9471) --- spec/controllers/admin/invites_controller_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/admin/invites_controller_spec.rb b/spec/controllers/admin/invites_controller_spec.rb index 34b51a6aa..449a699e4 100644 --- a/spec/controllers/admin/invites_controller_spec.rb +++ b/spec/controllers/admin/invites_controller_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe Admin::InvitesController do @@ -40,4 +42,18 @@ describe Admin::InvitesController do expect(invite.reload).to be_expired end end + + describe 'POST #deactivate_all' do + it 'expires all invites, then redirects to admin_invites_path' do + invites = Fabricate.times(2, :invite, expires_at: nil) + + post :deactivate_all + + invites.each do |invite| + expect(invite.reload).to be_expired + end + + expect(response).to redirect_to admin_invites_path + end + end end -- cgit From 361818e931eff47db937ffa18d89575e2a9dd5be Mon Sep 17 00:00:00 2001 From: ysksn Date: Tue, 11 Dec 2018 05:37:38 +0900 Subject: Fix Admin::TagsController#unhide (#9481) --- app/controllers/admin/tags_controller.rb | 2 +- spec/controllers/admin/tags_controller_spec.rb | 71 ++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 spec/controllers/admin/tags_controller_spec.rb (limited to 'spec/controllers') diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb index 3f2256566..e9f4f2cfa 100644 --- a/app/controllers/admin/tags_controller.rb +++ b/app/controllers/admin/tags_controller.rb @@ -18,7 +18,7 @@ module Admin def unhide authorize @tag, :unhide? - @tag.account_tag_stat.update!(hidden: true) + @tag.account_tag_stat.update!(hidden: false) redirect_to admin_tags_path(@filter_params) end diff --git a/spec/controllers/admin/tags_controller_spec.rb b/spec/controllers/admin/tags_controller_spec.rb new file mode 100644 index 000000000..3af994071 --- /dev/null +++ b/spec/controllers/admin/tags_controller_spec.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Admin::TagsController, type: :controller do + render_views + + before do + sign_in Fabricate(:user, admin: true) + end + + describe 'GET #index' do + before do + account_tag_stat = Fabricate(:tag).account_tag_stat + account_tag_stat.update(hidden: hidden, accounts_count: 1) + get :index, params: { hidden: hidden } + end + + context 'with hidden tags' do + let(:hidden) { true } + + it 'returns status 200' do + expect(response).to have_http_status(200) + end + end + + context 'without hidden tags' do + let(:hidden) { false } + + it 'returns status 200' do + expect(response).to have_http_status(200) + end + end + end + + describe 'POST #hide' do + let(:tag) { Fabricate(:tag) } + + before do + tag.account_tag_stat.update(hidden: false) + post :hide, params: { id: tag.id } + end + + it 'hides tag' do + tag.reload + expect(tag).to be_hidden + end + + it 'redirects to admin_tags_path' do + expect(response).to redirect_to(admin_tags_path(controller.instance_variable_get(:@filter_params))) + end + end + + describe 'POST #unhide' do + let(:tag) { Fabricate(:tag) } + + before do + tag.account_tag_stat.update(hidden: true) + post :unhide, params: { id: tag.id } + end + + it 'unhides tag' do + tag.reload + expect(tag).not_to be_hidden + end + + it 'redirects to admin_tags_path' do + expect(response).to redirect_to(admin_tags_path(controller.instance_variable_get(:@filter_params))) + end + end +end -- cgit From 6eae8f77afd60d40c62d4c2f7e5731607f6f6163 Mon Sep 17 00:00:00 2001 From: ysksn Date: Tue, 11 Dec 2018 05:38:21 +0900 Subject: Add spec for Admin::SuspentionsController#new (#9483) --- spec/controllers/admin/suspensions_controller_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/admin/suspensions_controller_spec.rb b/spec/controllers/admin/suspensions_controller_spec.rb index babb1ed96..1bc33e490 100644 --- a/spec/controllers/admin/suspensions_controller_spec.rb +++ b/spec/controllers/admin/suspensions_controller_spec.rb @@ -7,6 +7,13 @@ describe Admin::SuspensionsController do sign_in Fabricate(:user, admin: true), scope: :user end + describe 'GET #new' do + it 'returns 200' do + get :new, params: { account_id: Fabricate(:account).id, report_id: Fabricate(:report).id } + expect(response).to have_http_status(200) + end + end + describe 'POST #create' do it 'redirects to admin accounts page' do account = Fabricate(:account, suspended: false) -- cgit From ed24bb2c3ecf82521be0685f59ecdee77c6fff39 Mon Sep 17 00:00:00 2001 From: ysksn Date: Tue, 11 Dec 2018 05:39:25 +0900 Subject: Add specs for activitypub collections controller (#9484) * Add specs for ActivityPub::CollectionsController#show * Raise ActiveRecord::RecordNotFound Raising ActiveRecord::NotFound raises NameError: uninitialized constant ActiveRecord::NotFound. --- .../activitypub/collections_controller.rb | 4 ++-- .../activitypub/collections_controller_spec.rb | 25 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 spec/controllers/activitypub/collections_controller_spec.rb (limited to 'spec/controllers') diff --git a/app/controllers/activitypub/collections_controller.rb b/app/controllers/activitypub/collections_controller.rb index 96bf901a7..995da9c55 100644 --- a/app/controllers/activitypub/collections_controller.rb +++ b/app/controllers/activitypub/collections_controller.rb @@ -31,7 +31,7 @@ class ActivityPub::CollectionsController < Api::BaseController when 'featured' @account.pinned_statuses.count else - raise ActiveRecord::NotFound + raise ActiveRecord::RecordNotFound end end @@ -42,7 +42,7 @@ class ActivityPub::CollectionsController < Api::BaseController scope.merge!(@account.pinned_statuses) end else - raise ActiveRecord::NotFound + raise ActiveRecord::RecordNotFound end end diff --git a/spec/controllers/activitypub/collections_controller_spec.rb b/spec/controllers/activitypub/collections_controller_spec.rb new file mode 100644 index 000000000..34114cc85 --- /dev/null +++ b/spec/controllers/activitypub/collections_controller_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe ActivityPub::CollectionsController, type: :controller do + describe 'POST #show' do + let(:account) { Fabricate(:account) } + + context 'id is "featured"' do + it 'returns 200 with "application/activity+json"' do + post :show, params: { id: 'featured', account_username: account.username } + + expect(response).to have_http_status(200) + expect(response.content_type).to eq 'application/activity+json' + end + end + + context 'id is not "featured"' do + it 'returns 404' do + post :show, params: { id: 'hoge', account_username: account.username } + expect(response).to have_http_status(404) + end + end + end +end -- cgit From 795bac44fd0191a7927e09337c9e13718af56dc1 Mon Sep 17 00:00:00 2001 From: ysksn Date: Thu, 13 Dec 2018 10:53:52 +0900 Subject: Add spec for Settings::ExportsController#create (#9512) --- .../controllers/settings/exports_controller_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/settings/exports_controller_spec.rb b/spec/controllers/settings/exports_controller_spec.rb index b7cab4d8f..a46fe095d 100644 --- a/spec/controllers/settings/exports_controller_spec.rb +++ b/spec/controllers/settings/exports_controller_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe Settings::ExportsController do @@ -28,4 +30,23 @@ describe Settings::ExportsController do end end end + + describe 'POST #create' do + before do + sign_in Fabricate(:user), scope: :user + end + + it 'redirects to settings_export_path' do + post :create + expect(response).to redirect_to(settings_export_path) + end + + it 'queues BackupWorker job by 1' do + Sidekiq::Testing.fake! do + expect do + post :create + end.to change(BackupWorker.jobs, :size).by(1) + end + end + end end -- cgit From 769c2d2680c365cfafb35e27bc1d3b39deac118e Mon Sep 17 00:00:00 2001 From: Sumit Khanna Date: Thu, 13 Dec 2018 22:07:21 -0600 Subject: Error message for avatar image that's too large. #9204 (#9518) * Error message for avatar image that's too large. #9204 * Code climate/formatting * Removed avatar error message * Moved valid image dimentions check to update service * removed unnescessary begin block * code climate formatting * code climate indent fix --- app/services/update_account_service.rb | 3 +++ .../settings/profiles_controller_spec.rb | 22 +++++++++++++++++++++ spec/fixtures/files/4096x4097.png | Bin 0 -> 58859 bytes 3 files changed, 25 insertions(+) create mode 100644 spec/fixtures/files/4096x4097.png (limited to 'spec/controllers') diff --git a/app/services/update_account_service.rb b/app/services/update_account_service.rb index 36665177d..01756a73d 100644 --- a/app/services/update_account_service.rb +++ b/app/services/update_account_service.rb @@ -12,6 +12,9 @@ class UpdateAccountService < BaseService check_links(account) process_hashtags(account) end + rescue Mastodon::DimensionsValidationError => de + account.errors.add(:avatar, de.message) + false end private diff --git a/spec/controllers/settings/profiles_controller_spec.rb b/spec/controllers/settings/profiles_controller_spec.rb index a453200af..5b1fe3aca 100644 --- a/spec/controllers/settings/profiles_controller_spec.rb +++ b/spec/controllers/settings/profiles_controller_spec.rb @@ -26,4 +26,26 @@ RSpec.describe Settings::ProfilesController, type: :controller do expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id) end end + + describe 'PUT #update with new profile image' do + it 'updates profile image' do + allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async) + account = Fabricate(:account, user: @user, display_name: 'AvatarTest') + expect(account.avatar.instance.avatar_file_name).to be_nil + + put :update, params: { account: { avatar: fixture_file_upload('files/avatar.gif', 'image/gif') } } + expect(response).to redirect_to(settings_profile_path) + expect(account.reload.avatar.instance.avatar_file_name).not_to be_nil + expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id) + end + end + + describe 'PUT #update with oversized image' do + it 'gives the user an error message' do + allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async) + account = Fabricate(:account, user: @user, display_name: 'AvatarTest') + put :update, params: { account: { avatar: fixture_file_upload('files/4096x4097.png', 'image/png') } } + expect(response.body).to include('images are not supported') + end + end end diff --git a/spec/fixtures/files/4096x4097.png b/spec/fixtures/files/4096x4097.png new file mode 100644 index 000000000..d1110cc2d Binary files /dev/null and b/spec/fixtures/files/4096x4097.png differ -- cgit From c1600a0f69c1453c76c3baf45c41271c7b526146 Mon Sep 17 00:00:00 2001 From: ysksn Date: Sat, 15 Dec 2018 04:36:18 +0900 Subject: Add spec for Admin::DashboardController#index (#9523) --- spec/controllers/admin/dashboard_controller_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 spec/controllers/admin/dashboard_controller_spec.rb (limited to 'spec/controllers') diff --git a/spec/controllers/admin/dashboard_controller_spec.rb b/spec/controllers/admin/dashboard_controller_spec.rb new file mode 100644 index 000000000..73b50e721 --- /dev/null +++ b/spec/controllers/admin/dashboard_controller_spec.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Admin::DashboardController, type: :controller do + describe 'GET #index' do + it 'returns 200' do + sign_in Fabricate(:user, admin: true) + get :index + + expect(response).to have_http_status(200) + end + end +end -- cgit From 458e2b0c5b982999d0bd6695b96da9ccfca66664 Mon Sep 17 00:00:00 2001 From: ysksn Date: Sat, 15 Dec 2018 04:36:40 +0900 Subject: Add specs for RemoteInteractionController (#9524) --- .../remote_interaction_controller_spec.rb | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 spec/controllers/remote_interaction_controller_spec.rb (limited to 'spec/controllers') diff --git a/spec/controllers/remote_interaction_controller_spec.rb b/spec/controllers/remote_interaction_controller_spec.rb new file mode 100644 index 000000000..bb0074b11 --- /dev/null +++ b/spec/controllers/remote_interaction_controller_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe RemoteInteractionController, type: :controller do + render_views + + let(:status) { Fabricate(:status) } + + describe 'GET #new' do + it 'returns 200' do + get :new, params: { id: status.id } + expect(response).to have_http_status(200) + end + end + + describe 'POST #create' do + context '@remote_follow is valid' do + it 'returns 302' do + allow_any_instance_of(RemoteFollow).to receive(:valid?) { true } + allow_any_instance_of(RemoteFollow).to receive(:addressable_template) do + Addressable::Template.new('https://hoge.com') + end + + post :create, params: { id: status.id, remote_follow: { acct: '@hoge' } } + expect(response).to have_http_status(302) + end + end + + context '@remote_follow is invalid' do + it 'returns 200' do + allow_any_instance_of(RemoteFollow).to receive(:valid?) { false } + post :create, params: { id: status.id, remote_follow: { acct: '@hoge' } } + + expect(response).to have_http_status(200) + end + end + end +end -- cgit From 3c31c28605a8934ee509ddeb9b7b3ebb8d1c40ba Mon Sep 17 00:00:00 2001 From: ysksn Date: Sat, 15 Dec 2018 04:37:01 +0900 Subject: Add spec for Admin::ActionLogsController#index (#9522) --- spec/controllers/admin/action_logs_controller_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 spec/controllers/admin/action_logs_controller_spec.rb (limited to 'spec/controllers') diff --git a/spec/controllers/admin/action_logs_controller_spec.rb b/spec/controllers/admin/action_logs_controller_spec.rb new file mode 100644 index 000000000..4720ed2e2 --- /dev/null +++ b/spec/controllers/admin/action_logs_controller_spec.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Admin::ActionLogsController, type: :controller do + describe 'GET #index' do + it 'returns 200' do + sign_in Fabricate(:user, admin: true) + get :index, params: { page: 1 } + + expect(response).to have_http_status(200) + end + end +end -- cgit