Commit 4cd8de53 authored by Benjamin Neff's avatar Benjamin Neff Committed by Dennis Schubert

Refactor taggable tests to use `let`

parent f883c6ed
......@@ -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
......@@ -245,30 +245,31 @@ 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 }
it "allows 5 tags" do
object.tag_string = "#one #two #three #four #five"
@object.valid?
@object.errors.full_messages
object.valid?
object.errors.full_messages
expect(@object).to be_valid
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_should_behave_like "it is taggable"
end
describe "#tombstone!" do
......
......@@ -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
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment