Merge branch 'next-minor' into develop

This commit is contained in:
Dennis Schubert 2018-02-27 00:48:47 +01:00
commit c4839613ea
No known key found for this signature in database
GPG key ID: 5A0304BEA7966D7E
5 changed files with 54 additions and 48 deletions

View file

@ -11,7 +11,7 @@ class Profile < ApplicationRecord
include Diaspora::Taggable
attr_accessor :tag_string
acts_as_taggable_on :tags
acts_as_ordered_taggable
extract_tags_from :tag_string
validates :tag_list, :length => { :maximum => 5 }

View file

@ -119,13 +119,8 @@ describe Comment, type: :model do
end
describe "tags" do
let(:object) { build(:comment) }
before do
# shared_behaviors/taggable.rb is still using instance variables, so we need to define them here.
# Suggestion: refactor all specs using shared_behaviors/taggable.rb to use "let"
@object = object
it_should_behave_like "it is taggable" do
let(:object) { build(:comment) }
end
it_should_behave_like "it is taggable"
end
end

View file

@ -245,30 +245,42 @@ describe Profile, :type => :model do
end
end
describe 'tags' do
before do
person = FactoryGirl.build(:person)
@object = person.profile
end
it 'allows 5 tags' do
@object.tag_string = '#one #two #three #four #five'
describe "tags" do
let(:object) { FactoryGirl.build(:person).profile }
@object.valid?
@object.errors.full_messages
it "allows 5 tags" do
object.tag_string = "#one #two #three #four #five"
expect(@object).to be_valid
object.valid?
object.errors.full_messages
expect(object).to be_valid
end
it 'strips more than 5 tags' do
@object.tag_string = '#one #two #three #four #five #six'
@object.save
expect(@object.tags.count).to eq(5)
it "strips more than 5 tags" do
object.tag_string = "#one #two #three #four #five #six"
object.save
expect(object.tags.count).to eq(5)
end
it 'should require tag name not be more than 255 characters long' do
@object.tag_string = "##{'a' * (255+1)}"
@object.save
expect(@object).not_to be_valid
it "should require tag name not be more than 255 characters long" do
object.tag_string = "##{'a' * (255 + 1)}"
object.save
expect(object).not_to be_valid
end
it_should_behave_like 'it is taggable'
it "keeps the order of the tag_string" do
ActsAsTaggableOn::Tag.create(name: "test2")
ActsAsTaggableOn::Tag.create(name: "test1")
string = "#test1 #test2"
object.tag_string = string
object.save
expect(Profile.find(object.id).tag_string).to eq(string)
end
it_should_behave_like "it is taggable"
end
describe "#tombstone!" do

View file

@ -171,10 +171,9 @@ describe StatusMessage, type: :model do
end
describe "tags" do
before do
@object = FactoryGirl.build(:status_message)
it_should_behave_like "it is taggable" do
let(:object) { build(:status_message) }
end
it_should_behave_like "it is taggable"
it "associates different-case tags to the same tag entry" do
assert_equal ActsAsTaggableOn.force_lowercase, true

View file

@ -25,14 +25,14 @@ shared_examples_for "it is taggable" do
before do
@str = tag_list.map {|tag| "##{tag}" }.join(" ")
@object.send(@object.class.field_with_tags_setter, @str)
@object.build_tags
@object.save!
object.send(object.class.field_with_tags_setter, @str)
object.build_tags
object.save!
end
it "supports non-ascii characters" do
tag_list.each do |tag|
expect(@object.tags.reload.map(&:name)).to include(tag)
expect(object.tags.reload.map(&:name)).to include(tag)
end
end
@ -97,12 +97,12 @@ shared_examples_for "it is taggable" do
describe '#build_tags' do
it 'builds the tags' do
@object.send(@object.class.field_with_tags_setter, '#what')
@object.build_tags
expect(@object.tag_list).to eq(['what'])
object.send(object.class.field_with_tags_setter, "#what")
object.build_tags
expect(object.tag_list).to eq(["what"])
expect {
@object.save
}.to change{@object.tags.count}.by(1)
object.save
}.to change { object.tags.count }.by(1)
end
end
@ -111,8 +111,8 @@ shared_examples_for "it is taggable" do
str = '#what #hey #that"smybike. #@hey ##boo # #THATWASMYBIKE #vöglein #hey#there #135440we #abc/23 ### #h!gh #ok? #see: #re:publica'
arr = ['what', 'hey', 'that', 'THATWASMYBIKE', 'vöglein', '135440we', 'abc', 'h', 'ok', 'see', 're']
@object.send(@object.class.field_with_tags_setter, str)
expect(@object.tag_strings).to match_array(arr)
object.send(object.class.field_with_tags_setter, str)
expect(object.tag_strings).to match_array(arr)
end
it 'extracts tags despite surrounding text' do
@ -154,9 +154,9 @@ shared_examples_for "it is taggable" do
"\u202a#\u200eUSA\u202c" => 'USA'
}
expected.each do |text,hashtag|
@object.send @object.class.field_with_tags_setter, text
expect(@object.tag_strings).to eq([hashtag].compact)
expected.each do |text, hashtag|
object.send(object.class.field_with_tags_setter, text)
expect(object.tag_strings).to eq([hashtag].compact)
end
end
@ -164,16 +164,16 @@ shared_examples_for "it is taggable" do
str = '#what #what #what #whaaaaaaaaaat'
arr = ['what','whaaaaaaaaaat']
@object.send(@object.class.field_with_tags_setter, str)
expect(@object.tag_strings).to match_array(arr)
object.send(object.class.field_with_tags_setter, str)
expect(object.tag_strings).to match_array(arr)
end
it 'is case insensitive' do
str = '#what #wHaT #WHAT'
arr = ['what']
@object.send(@object.class.field_with_tags_setter, str)
expect(@object.tag_strings).to match_array(arr)
object.send(object.class.field_with_tags_setter, str)
expect(object.tag_strings).to match_array(arr)
end
end
end