Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Neff <benjamin@coding4coffee.ch>2018-02-26 03:57:24 +0300
committerDennis Schubert <mail@dennis-schubert.de>2018-02-27 02:48:08 +0300
commit4cd8de532740079ad8541ce460cc7add0462ebf3 (patch)
tree743d97546134d0648d8794f095ba3cd4823ba254
parentf883c6ede2d7acf61a2320ce27e316e866da50e4 (diff)
Refactor taggable tests to use `let`
-rw-r--r--spec/models/comment_spec.rb9
-rw-r--r--spec/models/profile_spec.rb39
-rw-r--r--spec/models/status_message_spec.rb5
-rw-r--r--spec/shared_behaviors/taggable.rb36
4 files changed, 42 insertions, 47 deletions
diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb
index 9b426b224..5f57e4884 100644
--- a/spec/models/comment_spec.rb
+++ b/spec/models/comment_spec.rb
@@ -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
diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb
index a6d941d1d..00a160bac 100644
--- a/spec/models/profile_spec.rb
+++ b/spec/models/profile_spec.rb
@@ -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
diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb
index bd9d809ce..0fcab057f 100644
--- a/spec/models/status_message_spec.rb
+++ b/spec/models/status_message_spec.rb
@@ -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
diff --git a/spec/shared_behaviors/taggable.rb b/spec/shared_behaviors/taggable.rb
index 6652d0766..ac5a1a2f9 100644
--- a/spec/shared_behaviors/taggable.rb
+++ b/spec/shared_behaviors/taggable.rb
@@ -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