From 09c3c96607c95bf380ace9c109f2672703c679b9 Mon Sep 17 00:00:00 2001 From: ysksn Date: Fri, 11 Jan 2019 16:26:03 +0900 Subject: Add specs for Admin::AccountAction (#9767) --- spec/models/admin/account_action_spec.rb | 127 +++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) (limited to 'spec') diff --git a/spec/models/admin/account_action_spec.rb b/spec/models/admin/account_action_spec.rb index 8c55cf4dd..a3db60cfc 100644 --- a/spec/models/admin/account_action_spec.rb +++ b/spec/models/admin/account_action_spec.rb @@ -1,4 +1,131 @@ require 'rails_helper' RSpec.describe Admin::AccountAction, type: :model do + let(:account_action) { described_class.new } + + describe '#save!' do + subject { account_action.save! } + let(:account) { Fabricate(:account, user: Fabricate(:user, admin: true)) } + let(:target_account) { Fabricate(:account, user: Fabricate(:user)) } + let(:type) { 'disable' } + + before do + account_action.assign_attributes( + type: type, + current_account: account, + target_account: target_account + ) + end + + context 'type is "disable"' do + let(:type) { 'disable' } + + it 'disable user' do + subject + expect(target_account.user).to be_disabled + end + end + + context 'type is "silence"' do + let(:type) { 'silence' } + + it 'silences account' do + subject + expect(target_account).to be_silenced + end + end + + context 'type is "suspend"' do + let(:type) { 'suspend' } + + it 'suspends account' do + subject + expect(target_account).to be_suspended + end + + it 'queues Admin::SuspensionWorker by 1' do + Sidekiq::Testing.fake! do + expect do + subject + end.to change { Admin::SuspensionWorker.jobs.size }.by 1 + end + end + end + + it 'creates Admin::ActionLog' do + expect do + subject + end.to change { Admin::ActionLog.count }.by 1 + end + + it 'calls queue_email!' do + expect(account_action).to receive(:queue_email!) + subject + end + + it 'calls process_reports!' do + expect(account_action).to receive(:process_reports!) + subject + end + end + + describe '#report' do + subject { account_action.report } + + context 'report_id.present?' do + before do + account_action.report_id = Fabricate(:report).id + end + + it 'returns Report' do + expect(subject).to be_instance_of Report + end + end + + context '!report_id.present?' do + it 'returns nil' do + expect(subject).to be_nil + end + end + end + + describe '#with_report?' do + subject { account_action.with_report? } + + context '!report.nil?' do + before do + account_action.report_id = Fabricate(:report).id + end + + it 'returns true' do + expect(subject).to be true + end + end + + context '!(!report.nil?)' do + it 'returns false' do + expect(subject).to be false + end + end + end + + describe '.types_for_account' do + subject { described_class.types_for_account(account) } + + context 'account.local?' do + let(:account) { Fabricate(:account, domain: nil) } + + it 'returns ["none", "disable", "silence", "suspend"]' do + expect(subject).to eq %w(none disable silence suspend) + end + end + + context '!account.local?' do + let(:account) { Fabricate(:account, domain: 'hoge.com') } + + it 'returns ["silence", "suspend"]' do + expect(subject).to eq %w(silence suspend) + end + end + end end -- cgit From c059999ab3c2469df36e4fe9a62e6c2b4e7558bc Mon Sep 17 00:00:00 2001 From: ysksn Date: Fri, 11 Jan 2019 16:28:09 +0900 Subject: Add a spec for Admin::ActionLog (#9775) --- spec/models/admin/action_log_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec') diff --git a/spec/models/admin/action_log_spec.rb b/spec/models/admin/action_log_spec.rb index 81d7e1be3..3495cc514 100644 --- a/spec/models/admin/action_log_spec.rb +++ b/spec/models/admin/action_log_spec.rb @@ -1,4 +1,12 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Admin::ActionLog, type: :model do + describe '#action' do + it 'returns action' do + action_log = described_class.new(action: 'hoge') + expect(action_log.action).to be :hoge + end + end end -- cgit From 5c5e14c816eb0871344bb69a96bc4bb38e0d3061 Mon Sep 17 00:00:00 2001 From: "Renato \"Lond\" Cerqueira" Date: Mon, 14 Jan 2019 17:28:41 +0100 Subject: Fix undefined method error in sidekiq (#9807) * Fix undefined method error in sidekiq Body can be not nil but still be empty, which causes a `NoMethodError: undefined method `[]' for nil:NilClass` further in the code. This checks for an empty body to avoid the issue. * Fix codeclimate issue --- app/services/fetch_oembed_service.rb | 2 +- spec/fixtures/requests/oembed_json_empty.html | 7 +++++++ spec/services/fetch_oembed_service_spec.rb | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/requests/oembed_json_empty.html (limited to 'spec') diff --git a/app/services/fetch_oembed_service.rb b/app/services/fetch_oembed_service.rb index 9ddf9b13b..10176cfb9 100644 --- a/app/services/fetch_oembed_service.rb +++ b/app/services/fetch_oembed_service.rb @@ -43,7 +43,7 @@ class FetchOEmbedService res.code != 200 ? nil : res.body_with_limit end - validate(parse_for_format(body)) unless body.nil? + validate(parse_for_format(body)) if body.present? rescue Oj::ParseError, Ox::ParseError nil end diff --git a/spec/fixtures/requests/oembed_json_empty.html b/spec/fixtures/requests/oembed_json_empty.html new file mode 100644 index 000000000..4b02413aa --- /dev/null +++ b/spec/fixtures/requests/oembed_json_empty.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/spec/services/fetch_oembed_service_spec.rb b/spec/services/fetch_oembed_service_spec.rb index 706eb3f2a..5789fb53b 100644 --- a/spec/services/fetch_oembed_service_spec.rb +++ b/spec/services/fetch_oembed_service_spec.rb @@ -8,6 +8,7 @@ describe FetchOEmbedService, type: :service do before do stub_request(:get, "https://host.test/provider.json").to_return(status: 404) stub_request(:get, "https://host.test/provider.xml").to_return(status: 404) + stub_request(:get, "https://host.test/empty_provider.json").to_return(status: 200) end describe 'discover_provider' do @@ -93,6 +94,23 @@ describe FetchOEmbedService, type: :service do expect(subject.call('https://host.test/oembed.html')).to be_nil end end + + context 'Empty JSON provider is discoverable' do + before do + stub_request(:get, 'https://host.test/oembed.html').to_return( + status: 200, + headers: { 'Content-Type': 'text/html' }, + body: request_fixture('oembed_json_empty.html') + ) + end + + it 'returns new OEmbed::Provider for JSON provider' do + subject.call('https://host.test/oembed.html') + expect(subject.endpoint_url).to eq 'https://host.test/empty_provider.json' + expect(subject.format).to eq :json + end + end + end context 'when status code is not 200' do -- cgit From ecf40d09ed42c15f1379718d70142434a72986f5 Mon Sep 17 00:00:00 2001 From: Moritz Heiber Date: Tue, 15 Jan 2019 23:11:46 +0100 Subject: Disable Same-Site cookie implementation to fix SSO issues on WebKit browsers (#9819) --- config/initializers/devise.rb | 2 -- config/initializers/session_store.rb | 2 +- spec/rails_helper.rb | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) (limited to 'spec') diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 3e4c9a79d..cd9bacf68 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -10,7 +10,6 @@ Warden::Manager.after_set_user except: :fetch do |user, warden| expires: 1.year.from_now, httponly: true, secure: (Rails.env.production? || ENV['LOCAL_HTTPS'] == 'true'), - same_site: :lax, } end @@ -21,7 +20,6 @@ Warden::Manager.after_fetch do |user, warden| expires: 1.year.from_now, httponly: true, secure: (Rails.env.production? || ENV['LOCAL_HTTPS'] == 'true'), - same_site: :lax, } else warden.logout diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index c0757b6b5..3dc0edd6f 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.session_store :cookie_store, key: '_mastodon_session', secure: (Rails.env.production? || ENV['LOCAL_HTTPS'] == 'true'), same_site: :lax +Rails.application.config.session_store :cookie_store, key: '_mastodon_session', secure: (Rails.env.production? || ENV['LOCAL_HTTPS'] == 'true') diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 1ded751ab..3a5e7491e 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -29,7 +29,6 @@ Devise::Test::ControllerHelpers.module_eval do value: resource.activate_session(warden.request), expires: 1.year.from_now, httponly: true, - same_site: :lax, } end end -- cgit