Skip to content

Commit

Permalink
Merge pull request #235 from ootoovak/master
Browse files Browse the repository at this point in the history
Add a check so tag names can not be longer than 255 characters
  • Loading branch information
artemk committed Mar 25, 2012
2 parents 1338cb8 + 2077ae9 commit 7d023cf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/acts_as_taggable_on/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Tag < ::ActiveRecord::Base

validates_presence_of :name
validates_uniqueness_of :name
validates_length_of :name, :maximum => 255

### SCOPES:

Expand Down Expand Up @@ -73,4 +74,4 @@ def comparable_name(str)
end
end
end
end
end
10 changes: 10 additions & 0 deletions spec/acts_as_taggable_on/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@
@tag.errors[:name].should == []
end

it "should limit the name length to 255 or less characters" do
@tag.name = "fgkgnkkgjymkypbuozmwwghblmzpqfsgjasflblywhgkwndnkzeifalfcpeaeqychjuuowlacmuidnnrkprgpcpybarbkrmziqihcrxirlokhnzfvmtzixgvhlxzncyywficpraxfnjptxxhkqmvicbcdcynkjvziefqzyndxkjmsjlvyvbwraklbalykyxoliqdlreeykuphdtmzfdwpphmrqvwvqffojkqhlzvinqajsxbszyvrqqyzusxranr"
@tag.valid?
@tag.errors[:name].should == ["is too long (maximum is 255 characters)"]

@tag.name = "fgkgnkkgjymkypbuozmwwghblmzpqfsgjasflblywhgkwndnkzeifalfcpeaeqychjuuowlacmuidnnrkprgpcpybarbkrmziqihcrxirlokhnzfvmtzixgvhlxzncyywficpraxfnjptxxhkqmvicbcdcynkjvziefqzyndxkjmsjlvyvbwraklbalykyxoliqdlreeykuphdtmzfdwpphmrqvwvqffojkqhlzvinqajsxbszyvrqqyzusxran"
@tag.valid?
@tag.errors[:name].should == []
end

it "should equal a tag with the same name" do
@tag.name = "awesome"
new_tag = ActsAsTaggableOn::Tag.new(:name => "awesome")
Expand Down

0 comments on commit 7d023cf

Please sign in to comment.