aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorArthur Klepchukov <arthur.klepchukov@gmail.com>2009-03-07 13:52:17 +0000
committerPratik Naik <pratiknaik@gmail.com>2009-03-07 13:52:17 +0000
commitccb0a92fa2ba0bf7be50033090c3a861e6d907be (patch)
tree6657a66b2c19c3437837f6f2a38672d1b6827953 /activerecord/test
parentf36513653fceb01691288dfdebfdc56d17dc85c9 (diff)
downloadrails-ccb0a92fa2ba0bf7be50033090c3a861e6d907be.tar.gz
rails-ccb0a92fa2ba0bf7be50033090c3a861e6d907be.tar.bz2
rails-ccb0a92fa2ba0bf7be50033090c3a861e6d907be.zip
Ensure validates_uniqueness_of considers limit on the field. [#1042 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/validations_test.rb9
-rw-r--r--activerecord/test/models/event.rb3
-rw-r--r--activerecord/test/schema/schema.rb4
3 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb
index 8ef5dc09c5..f87168860f 100644
--- a/activerecord/test/cases/validations_test.rb
+++ b/activerecord/test/cases/validations_test.rb
@@ -8,6 +8,7 @@ require 'models/warehouse_thing'
require 'models/guid'
require 'models/owner'
require 'models/pet'
+require 'models/event'
# The following methods in Topic are used in test_conditional_validation_*
class Topic
@@ -530,6 +531,14 @@ class ValidationsTest < ActiveRecord::TestCase
end
end
+ def test_validate_uniqueness_with_limit
+ # Event.title is limited to 5 characters
+ e1 = Event.create(:title => "abcde")
+ assert e1.valid?, "Could not create an event with a unique, 5 character title"
+ e2 = Event.create(:title => "abcdefgh")
+ assert !e2.valid?, "Created an event whose title, with limit taken into account, is not unique"
+ end
+
def test_validate_straight_inheritance_uniqueness
w1 = IneptWizard.create(:name => "Rincewind", :city => "Ankh-Morpork")
assert w1.valid?, "Saving w1"
diff --git a/activerecord/test/models/event.rb b/activerecord/test/models/event.rb
new file mode 100644
index 0000000000..99fa0feeb7
--- /dev/null
+++ b/activerecord/test/models/event.rb
@@ -0,0 +1,3 @@
+class Event < ActiveRecord::Base
+ validates_uniqueness_of :title
+end \ No newline at end of file
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index 74a893983f..9ebf1d82be 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -155,6 +155,10 @@ ActiveRecord::Schema.define do
t.integer :course_id, :null => false
end
+ create_table :events, :force => true do |t|
+ t.string :title, :limit => 5
+ end
+
create_table :funny_jokes, :force => true do |t|
t.string :name
end