refactor test using let and subject instead of before
This commit is contained in:
parent
7f3737b13f
commit
d86a768590
1 changed files with 11 additions and 9 deletions
|
|
@ -1,23 +1,25 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe ActsAsTaggableOn::Tag, :type => :model do
|
describe ActsAsTaggableOn::Tag, :type => :model do
|
||||||
|
|
||||||
|
subject(:tag) { ActsAsTaggableOn::Tag }
|
||||||
|
|
||||||
describe '.autocomplete' do
|
describe '.autocomplete' do
|
||||||
before do
|
let!(:tag_cats) { tag.create(:name => "cats") }
|
||||||
@tag = ActsAsTaggableOn::Tag.create(:name => "cats")
|
|
||||||
end
|
|
||||||
it 'downcases the tag name' do
|
it 'downcases the tag name' do
|
||||||
expect(ActsAsTaggableOn::Tag.autocomplete("CATS")).to eq([@tag])
|
expect(tag.autocomplete("CATS")).to eq([tag_cats])
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does an end where on tags' do
|
it 'does an end where on tags' do
|
||||||
expect(ActsAsTaggableOn::Tag.autocomplete("CAT")).to eq([@tag])
|
expect(tag.autocomplete("CAT")).to eq([tag_cats])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".normalize" do
|
describe ".normalize" do
|
||||||
it "removes leading hash symbols" do
|
it "removes leading hash symbols" do
|
||||||
expect(ActsAsTaggableOn::Tag.normalize("#mytag")).to eq("mytag")
|
expect(tag.normalize("#mytag")).to eq("mytag")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "removes punctuation and whitespace" do
|
it "removes punctuation and whitespace" do
|
||||||
|
|
@ -33,13 +35,13 @@ describe ActsAsTaggableOn::Tag, :type => :model do
|
||||||
'hash#inside' => 'hashinside',
|
'hash#inside' => 'hashinside',
|
||||||
'f!u@n#k$y%-<c>^h&a*r(a)c{t}e[r]s' => 'funky-characters'
|
'f!u@n#k$y%-<c>^h&a*r(a)c{t}e[r]s' => 'funky-characters'
|
||||||
}.each do |invalid, normalized|
|
}.each do |invalid, normalized|
|
||||||
expect(ActsAsTaggableOn::Tag.normalize(invalid)).to eq(normalized)
|
expect(tag.normalize(invalid)).to eq(normalized)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'allows for love' do
|
it 'allows for love' do
|
||||||
expect(ActsAsTaggableOn::Tag.normalize("<3")).to eq("<3")
|
expect(tag.normalize("<3")).to eq("<3")
|
||||||
expect(ActsAsTaggableOn::Tag.normalize("#<3")).to eq("<3")
|
expect(tag.normalize("#<3")).to eq("<3")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue