Merge commit '0dac31dfd588e4cd866f382ed001a9535f06234a' into glitch-soc/merge-upstream
This commit is contained in:
commit
c8f365fd1d
79 files changed
+843
-227
No files matched your search
@@ -72,4 +72,58 @@ RSpec.describe Collection do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#tag_name=' do
|
||||
context 'when the collection is new and has no tag' do
|
||||
subject { Fabricate.build(:collection) }
|
||||
|
||||
context 'when the tag exists' do
|
||||
let!(:tag) { Fabricate.create(:tag, name: 'people') }
|
||||
|
||||
it 'correctly assigns the existing tag' do
|
||||
subject.tag_name = '#people'
|
||||
|
||||
expect(subject.tag).to eq tag
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the tag does not exist' do
|
||||
it 'creates and assigns a new tag' do
|
||||
expect do
|
||||
subject.tag_name = '#people'
|
||||
end.to change(Tag, :count).by(1)
|
||||
|
||||
expect(subject.tag).to be_present
|
||||
expect(subject.tag.name).to eq 'people'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the collection is persisted and has a tag' do
|
||||
subject { Fabricate(:collection, tag:) }
|
||||
|
||||
let!(:tag) { Fabricate(:tag, name: 'people') }
|
||||
|
||||
context 'when the new tag is the same' do
|
||||
it 'does not change the object' do
|
||||
subject.tag_name = '#People'
|
||||
|
||||
expect(subject.tag).to eq tag
|
||||
expect(subject).to_not be_changed
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the new tag is different' do
|
||||
it 'creates and assigns a new tag' do
|
||||
expect do
|
||||
subject.tag_name = '#bots'
|
||||
end.to change(Tag, :count).by(1)
|
||||
|
||||
expect(subject.tag).to be_present
|
||||
expect(subject.tag.name).to eq 'bots'
|
||||
expect(subject).to be_changed
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
+27
-16
@@ -57,6 +57,11 @@ RSpec.describe Tag do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Normalizations' do
|
||||
it { is_expected.to normalize(:display_name).from('#HelloWorld').to('HelloWorld') }
|
||||
it { is_expected.to normalize(:display_name).from('Hello❤️World').to('HelloWorld') }
|
||||
end
|
||||
|
||||
describe 'HASHTAG_RE' do
|
||||
subject { described_class::HASHTAG_RE }
|
||||
|
||||
@@ -251,17 +256,29 @@ RSpec.describe Tag do
|
||||
end
|
||||
|
||||
describe '.find_or_create_by_names' do
|
||||
let(:upcase_string) { 'abcABCabcABCやゆよ' }
|
||||
let(:downcase_string) { 'abcabcabcabcやゆよ' }
|
||||
context 'when called with a block' do
|
||||
let(:upcase_string) { 'abcABCabcABCやゆよ' }
|
||||
let(:downcase_string) { 'abcabcabcabcやゆよ' }
|
||||
let(:args) { [upcase_string, downcase_string] }
|
||||
|
||||
it 'runs a passed block once per tag regardless of duplicates' do
|
||||
count = 0
|
||||
|
||||
described_class.find_or_create_by_names([upcase_string, downcase_string]) do |_tag|
|
||||
count += 1
|
||||
it 'runs the block once per normalized tag regardless of duplicates' do
|
||||
expect { |block| described_class.find_or_create_by_names(args, &block) }
|
||||
.to yield_control.once
|
||||
end
|
||||
end
|
||||
|
||||
expect(count).to eq 1
|
||||
context 'when passed an array' do
|
||||
it 'creates multiples tags' do
|
||||
expect { described_class.find_or_create_by_names(%w(tips tags toes)) }
|
||||
.to change(described_class, :count).by(3)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when passed a string' do
|
||||
it 'creates a single tag' do
|
||||
expect { described_class.find_or_create_by_names('test') }
|
||||
.to change(described_class, :count).by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -270,16 +287,10 @@ RSpec.describe Tag do
|
||||
tag_name_upper = 'Rails'
|
||||
tag_name_lower = 'rails'
|
||||
|
||||
threads = []
|
||||
|
||||
2.times do |i|
|
||||
threads << Thread.new do
|
||||
described_class.find_or_create_by_names(i.zero? ? tag_name_upper : tag_name_lower)
|
||||
end
|
||||
multi_threaded_execution(2) do |index|
|
||||
described_class.find_or_create_by_names(index.zero? ? tag_name_upper : tag_name_lower)
|
||||
end
|
||||
|
||||
threads.each(&:join)
|
||||
|
||||
tags = described_class.where('lower(name) = ?', tag_name_lower.downcase)
|
||||
expect(tags.count).to eq(1)
|
||||
expect(tags.first.name.downcase).to eq(tag_name_lower.downcase)
|
||||
|
||||
Reference in new issue
Block a user