Merge commit '20b1e55f24a87868d661fc7b033bbbbd48b1a918' into glitch-soc/merge-upstream

This commit is contained in:
Claire committed 2024-05-01 18:42:26 +02:00
commit 9ce82a35cb
46 files changed
+226 -204

No files matched your search

@@ -225,39 +225,4 @@ describe ApplicationController do
include_examples 'respond_with_error', 422
end
describe 'cache_collection' do
subject do
Class.new(ApplicationController) do
public :cache_collection
end
end
shared_examples 'receives :with_includes' do |fabricator, klass|
it 'uses raw if it is not an ActiveRecord::Relation' do
record = Fabricate(fabricator)
expect(subject.new.cache_collection([record], klass)).to eq [record]
end
end
shared_examples 'cacheable' do |fabricator, klass|
include_examples 'receives :with_includes', fabricator, klass
it 'calls cache_ids of raw if it is an ActiveRecord::Relation' do
record = Fabricate(fabricator)
relation = klass.none
allow(relation).to receive(:cache_ids).and_return([record])
expect(subject.new.cache_collection(relation, klass)).to eq [record]
end
end
it 'returns raw unless class responds to :with_includes' do
raw = Object.new
expect(subject.new.cache_collection(raw, Object)).to eq raw
end
context 'with a Status' do
include_examples 'cacheable', :status, Status
end
end
end
@@ -1,5 +1,5 @@
# frozen_string_literal: true
Fabricator(:preview_card_provider) do
domain { Faker::Internet.domain_name }
domain { sequence(:domain) { |i| "#{i}#{Faker::Internet.domain_name}" } }
end
@@ -1,5 +1,5 @@
# frozen_string_literal: true
Fabricator(:unavailable_domain) do
domain { Faker::Internet.domain_name }
domain { sequence(:domain) { |i| "#{i}#{Faker::Internet.domain_name}" } }
end
-1
View File
@@ -27,7 +27,6 @@ RSpec.describe HomeFeed do
results = subject.get(3)
expect(results.map(&:id)).to eq [3, 2]
expect(results.first.attributes.keys).to eq %w(id updated_at)
end
end
+37 -5
View File
@@ -107,12 +107,36 @@ RSpec.describe User do
end
end
describe 'inactive' do
it 'returns a relation of inactive users' do
specified = Fabricate(:user, current_sign_in_at: 15.days.ago)
Fabricate(:user, current_sign_in_at: 6.days.ago)
describe 'signed_in_recently' do
it 'returns a relation of users who have signed in during the recent period' do
recent_sign_in_user = Fabricate(:user, current_sign_in_at: within_duration_window_days.ago)
Fabricate(:user, current_sign_in_at: exceed_duration_window_days.ago)
expect(described_class.inactive).to contain_exactly(specified)
expect(described_class.signed_in_recently)
.to contain_exactly(recent_sign_in_user)
end
end
describe 'not_signed_in_recently' do
it 'returns a relation of users who have not signed in during the recent period' do
no_recent_sign_in_user = Fabricate(:user, current_sign_in_at: exceed_duration_window_days.ago)
Fabricate(:user, current_sign_in_at: within_duration_window_days.ago)
expect(described_class.not_signed_in_recently)
.to contain_exactly(no_recent_sign_in_user)
end
end
describe 'account_not_suspended' do
it 'returns with linked accounts that are not suspended' do
suspended_account = Fabricate(:account, suspended_at: 10.days.ago)
non_suspended_account = Fabricate(:account, suspended_at: nil)
suspended_user = Fabricate(:user, account: suspended_account)
non_suspended_user = Fabricate(:user, account: non_suspended_account)
expect(described_class.account_not_suspended)
.to include(non_suspended_user)
.and not_include(suspended_user)
end
end
@@ -137,6 +161,14 @@ RSpec.describe User do
expect(described_class.matches_ip('2160:2160::/32')).to contain_exactly(user1)
end
end
def exceed_duration_window_days
described_class::ACTIVE_DURATION + 2.days
end
def within_duration_window_days
described_class::ACTIVE_DURATION - 2.days
end
end
describe 'blacklist' do
@@ -3,13 +3,14 @@
require 'rails_helper'
describe 'Using OAuth from an external app' do
let(:client_app) { Doorkeeper::Application.create!(name: 'test', redirect_uri: 'http://localhost/', scopes: 'read') }
let(:client_app) { Doorkeeper::Application.create!(name: 'test', redirect_uri: 'http://localhost/health', scopes: 'read') }
context 'when the user is already logged in' do
let!(:user) { Fabricate(:user) }
before do
sign_in user, scope: :user
visit new_user_session_path
fill_in_auth_details(user.email, user.password)
end
it 'when accepting the authorization request' do
@@ -164,20 +165,19 @@ describe 'Using OAuth from an external app' do
expect(Doorkeeper::AccessGrant.exists?(application: client_app, resource_owner_id: user.id)).to be false
end
end
private
def fill_in_auth_details(email, password)
fill_in 'user_email', with: email
fill_in 'user_password', with: password
click_on I18n.t('auth.login')
end
def fill_in_otp_details(value)
fill_in 'user_otp_attempt', with: value
click_on I18n.t('auth.login')
end
# TODO: external auth
end
private
def fill_in_auth_details(email, password)
fill_in 'user_email', with: email
fill_in 'user_password', with: password
click_on I18n.t('auth.login')
end
def fill_in_otp_details(value)
fill_in 'user_otp_attempt', with: value
click_on I18n.t('auth.login')
end
end