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') 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') 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') 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') 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 dbb1ee269fa4a6ee097dfea5f77bb2c9428af93b Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 10 Dec 2018 22:53:25 +0100 Subject: Improve e-mail MX validator and add tests (#9489) --- app/models/user.rb | 6 ++- app/validators/email_mx_validator.rb | 19 ++++++-- spec/validators/email_mx_validator_spec.rb | 75 ++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 spec/validators/email_mx_validator_spec.rb (limited to 'spec') diff --git a/app/models/user.rb b/app/models/user.rb index f4130d7b1..44e0d1113 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -73,7 +73,7 @@ class User < ApplicationRecord validates :locale, inclusion: I18n.available_locales.map(&:to_s), if: :locale? validates_with BlacklistedEmailValidator, if: :email_changed? - validates_with EmailMxValidator, if: :email_changed? + validates_with EmailMxValidator, if: :validate_email_dns? scope :recent, -> { order(id: :desc) } scope :admins, -> { where(admin: true) } @@ -360,4 +360,8 @@ class User < ApplicationRecord def needs_feed_update? last_sign_in_at < ACTIVE_DURATION.ago end + + def validate_email_dns? + email_changed? && !(Rails.env.test? || Rails.env.development?) + end end diff --git a/app/validators/email_mx_validator.rb b/app/validators/email_mx_validator.rb index 8d1e58b38..5b4c684b2 100644 --- a/app/validators/email_mx_validator.rb +++ b/app/validators/email_mx_validator.rb @@ -4,7 +4,6 @@ require 'resolv' class EmailMxValidator < ActiveModel::Validator def validate(user) - return if Rails.env.test? || Rails.env.development? user.errors.add(:email, I18n.t('users.invalid_email')) if invalid_mx?(user.email) end @@ -15,13 +14,23 @@ class EmailMxValidator < ActiveModel::Validator return true if domain.nil? - records = Resolv::DNS.new.getresources(domain, Resolv::DNS::Resource::IN::MX).to_a.map { |e| e.exchange.to_s } - records = Resolv::DNS.new.getresources(domain, Resolv::DNS::Resource::IN::A).to_a.map { |e| e.address.to_s } if records.empty? + hostnames = [] + ips = [] - records.empty? || on_blacklist?(records) + Resolv::DNS.open do |dns| + dns.timeouts = 1 + + hostnames = dns.getresources(domain, Resolv::DNS::Resource::IN::MX).to_a.map { |e| e.exchange.to_s } + + ([domain] + hostnames).uniq.each do |hostname| + ips.concat(dns.getresources(hostname, Resolv::DNS::Resource::IN::A).to_a.map { |e| e.address.to_s }) + end + end + + ips.empty? || on_blacklist?(hostnames + ips) end def on_blacklist?(values) - EmailDomainBlock.where(domain: values).any? + EmailDomainBlock.where(domain: values.uniq).any? end end diff --git a/spec/validators/email_mx_validator_spec.rb b/spec/validators/email_mx_validator_spec.rb new file mode 100644 index 000000000..bc68f63cf --- /dev/null +++ b/spec/validators/email_mx_validator_spec.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe EmailMxValidator do + describe '#validate' do + let(:user) { double(email: 'foo@example.com', errors: double(add: nil)) } + + it 'adds an error if there are no DNS records for the e-mail domain' do + resolver = double + + allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::MX).and_return([]) + allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::A).and_return([]) + allow(resolver).to receive(:timeouts=).and_return(nil) + allow(Resolv::DNS).to receive(:open).and_yield(resolver) + + subject.validate(user) + expect(user.errors).to have_received(:add) + end + + it 'adds an error if a MX record exists but does not lead to an IP' do + resolver = double + + allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::MX).and_return([double(exchange: 'mail.example.com')]) + allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::A).and_return([]) + allow(resolver).to receive(:getresources).with('mail.example.com', Resolv::DNS::Resource::IN::A).and_return([]) + allow(resolver).to receive(:timeouts=).and_return(nil) + allow(Resolv::DNS).to receive(:open).and_yield(resolver) + + subject.validate(user) + expect(user.errors).to have_received(:add) + end + + it 'adds an error if the A record is blacklisted' do + EmailDomainBlock.create!(domain: '1.2.3.4') + resolver = double + + allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::MX).and_return([]) + allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::A).and_return([double(address: '1.2.3.4')]) + allow(resolver).to receive(:timeouts=).and_return(nil) + allow(Resolv::DNS).to receive(:open).and_yield(resolver) + + subject.validate(user) + expect(user.errors).to have_received(:add) + end + + it 'adds an error if the MX record is blacklisted' do + EmailDomainBlock.create!(domain: '2.3.4.5') + resolver = double + + allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::MX).and_return([double(exchange: 'mail.example.com')]) + allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::A).and_return([]) + allow(resolver).to receive(:getresources).with('mail.example.com', Resolv::DNS::Resource::IN::A).and_return([double(address: '2.3.4.5')]) + allow(resolver).to receive(:timeouts=).and_return(nil) + allow(Resolv::DNS).to receive(:open).and_yield(resolver) + + subject.validate(user) + expect(user.errors).to have_received(:add) + end + + it 'adds an error if the MX hostname is blacklisted' do + EmailDomainBlock.create!(domain: 'mail.example.com') + resolver = double + + allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::MX).and_return([double(exchange: 'mail.example.com')]) + allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::A).and_return([]) + allow(resolver).to receive(:getresources).with('mail.example.com', Resolv::DNS::Resource::IN::A).and_return([double(address: '2.3.4.5')]) + allow(resolver).to receive(:timeouts=).and_return(nil) + allow(Resolv::DNS).to receive(:open).and_yield(resolver) + + subject.validate(user) + expect(user.errors).to have_received(:add) + end + end +end -- cgit From 7d00e4edbd0bef8791d8efee7665eb13bb256d7a Mon Sep 17 00:00:00 2001 From: Adam Copp Date: Tue, 11 Dec 2018 04:30:57 +0000 Subject: Make custom emoji domains case insensitive #9351 (#9474) * Make custom emoji domains case sensitive #9351 * Fixup style in downcase_domain to comply with codeclimate. * switch if! to unless * Don't use transactions, operate in batches. Also revert spurious schema change. --- app/models/custom_emoji.rb | 6 ++++++ app/models/custom_emoji_filter.rb | 2 +- db/migrate/20181207011115_downcase_custom_emoji_domains.rb | 7 +++++++ db/schema.rb | 2 +- spec/models/custom_emoji_spec.rb | 9 +++++++++ 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20181207011115_downcase_custom_emoji_domains.rb (limited to 'spec') diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb index b99ed01f0..d3cc70504 100644 --- a/app/models/custom_emoji.rb +++ b/app/models/custom_emoji.rb @@ -31,6 +31,8 @@ class CustomEmoji < ApplicationRecord has_attached_file :image, styles: { static: { format: 'png', convert_options: '-coalesce -strip' } } + before_validation :downcase_domain + validates_attachment :image, content_type: { content_type: 'image/png' }, presence: true, size: { less_than: LIMIT } validates :shortcode, uniqueness: { scope: :domain }, format: { with: /\A#{SHORTCODE_RE_FRAGMENT}\z/ }, length: { minimum: 2 } @@ -73,4 +75,8 @@ class CustomEmoji < ApplicationRecord def remove_entity_cache Rails.cache.delete(EntityCache.instance.to_key(:emoji, shortcode, domain)) end + + def downcase_domain + self.domain = domain.downcase unless domain.nil? + end end diff --git a/app/models/custom_emoji_filter.rb b/app/models/custom_emoji_filter.rb index c4bc310bb..7649055d2 100644 --- a/app/models/custom_emoji_filter.rb +++ b/app/models/custom_emoji_filter.rb @@ -26,7 +26,7 @@ class CustomEmojiFilter when 'remote' CustomEmoji.remote when 'by_domain' - CustomEmoji.where(domain: value) + CustomEmoji.where(domain: value.downcase) when 'shortcode' CustomEmoji.search(value) else diff --git a/db/migrate/20181207011115_downcase_custom_emoji_domains.rb b/db/migrate/20181207011115_downcase_custom_emoji_domains.rb new file mode 100644 index 000000000..c9db3800d --- /dev/null +++ b/db/migrate/20181207011115_downcase_custom_emoji_domains.rb @@ -0,0 +1,7 @@ +class DowncaseCustomEmojiDomains < ActiveRecord::Migration[5.2] + disable_ddl_transaction! + + def change + CustomEmoji.in_batches.update_all('domain = lower(domain)') + end +end diff --git a/db/schema.rb b/db/schema.rb index 6d643c27c..51ac43e1d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_12_04_215309) do +ActiveRecord::Schema.define(version: 2018_12_07_011115) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/spec/models/custom_emoji_spec.rb b/spec/models/custom_emoji_spec.rb index 320a258d3..9de218b4f 100644 --- a/spec/models/custom_emoji_spec.rb +++ b/spec/models/custom_emoji_spec.rb @@ -75,4 +75,13 @@ RSpec.describe CustomEmoji, type: :model do end end end + + describe 'pre_validation' do + let(:custom_emoji) { Fabricate(:custom_emoji, domain: 'wWw.MaStOdOn.CoM') } + + it 'should downcase' do + custom_emoji.valid? + expect(custom_emoji.domain).to eq('www.mastodon.com') + 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') 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') 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') 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') 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') 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