Add models to represent "Collections" (#36977)
This commit is contained in:
1 parent
cfa4f402ef
commit
7ffa5fa0c4
12 files changed
+291
-1
No files matched your search
@@ -17,3 +17,7 @@ Fabricator(:account) do
|
||||
discoverable true
|
||||
indexable true
|
||||
end
|
||||
|
||||
Fabricator(:remote_account, from: :account) do
|
||||
domain 'example.com'
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
Fabricator(:collection) do
|
||||
account { Fabricate.build(:account) }
|
||||
name { sequence(:name) { |i| "Collection ##{i}" } }
|
||||
description 'People to follow'
|
||||
local true
|
||||
sensitive false
|
||||
discoverable true
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
Fabricator(:collection_item) do
|
||||
collection { Fabricate.build(:collection) }
|
||||
account { Fabricate.build(:account) }
|
||||
position 1
|
||||
state :accepted
|
||||
end
|
||||
|
||||
Fabricator(:unverified_remote_collection_item, from: :collection_item) do
|
||||
account nil
|
||||
state :pending
|
||||
object_uri { Fabricate.build(:remote_account).uri }
|
||||
approval_uri { sequence(:uri) { |i| "https://example.com/authorizations/#{i}" } }
|
||||
end
|
||||
@@ -0,0 +1,41 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe CollectionItem do
|
||||
describe 'Validations' do
|
||||
subject { Fabricate.build(:collection_item) }
|
||||
|
||||
it { is_expected.to define_enum_for(:state) }
|
||||
|
||||
it { is_expected.to validate_numericality_of(:position).only_integer.is_greater_than(0) }
|
||||
|
||||
context 'when account inclusion is accepted' do
|
||||
subject { Fabricate.build(:collection_item, state: :accepted) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:account) }
|
||||
end
|
||||
|
||||
context 'when item is local and account is remote' do
|
||||
subject { Fabricate.build(:collection_item, account: remote_account) }
|
||||
|
||||
let(:remote_account) { Fabricate.build(:remote_account) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:activity_uri) }
|
||||
end
|
||||
|
||||
context 'when item is not local' do
|
||||
subject { Fabricate.build(:collection_item, collection: remote_collection) }
|
||||
|
||||
let(:remote_collection) { Fabricate.build(:collection, local: false) }
|
||||
|
||||
it { is_expected.to validate_absence_of(:approval_uri) }
|
||||
end
|
||||
|
||||
context 'when account is not present' do
|
||||
subject { Fabricate.build(:unverified_remote_collection_item) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:object_uri) }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,45 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Collection do
|
||||
describe 'Validations' do
|
||||
subject { Fabricate.build :collection }
|
||||
|
||||
it { is_expected.to validate_presence_of(:name) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:description) }
|
||||
|
||||
context 'when collection is remote' do
|
||||
subject { Fabricate.build :collection, local: false }
|
||||
|
||||
it { is_expected.to validate_presence_of(:uri) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:original_number_of_items) }
|
||||
end
|
||||
|
||||
context 'when using a hashtag as category' do
|
||||
subject { Fabricate.build(:collection, tag:) }
|
||||
|
||||
context 'when hashtag is usable' do
|
||||
let(:tag) { Fabricate.build(:tag) }
|
||||
|
||||
it { is_expected.to be_valid }
|
||||
end
|
||||
|
||||
context 'when hashtag is not usable' do
|
||||
let(:tag) { Fabricate.build(:tag, usable: false) }
|
||||
|
||||
it { is_expected.to_not be_valid }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there are more items than allowed' do
|
||||
subject { Fabricate.build(:collection, collection_items:) }
|
||||
|
||||
let(:collection_items) { Fabricate.build_times(described_class::MAX_ITEMS + 1, :collection_item, collection: nil) }
|
||||
|
||||
it { is_expected.to_not be_valid }
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user