diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-10 16:02:11 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-10 16:02:11 +0000 |
commit | aaf9a45ca9ce5ceb67b7d4ae0dff350389b72c69 (patch) | |
tree | c2c443eae085e4fe528cd1223ed15147706dc7c7 /activerecord/test | |
parent | 0b92b7de2f752bee6c4c950ac9090e5bce3b63bf (diff) | |
download | rails-aaf9a45ca9ce5ceb67b7d4ae0dff350389b72c69.tar.gz rails-aaf9a45ca9ce5ceb67b7d4ae0dff350389b72c69.tar.bz2 rails-aaf9a45ca9ce5ceb67b7d4ae0dff350389b72c69.zip |
Added Base.validate_uniqueness thatv alidates whether the value of the specified attributes are unique across the system. Useful for making sure that only one user can be named "davidhh".
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@108 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/finder_test.rb | 10 | ||||
-rwxr-xr-x | activerecord/test/validations_test.rb | 18 |
2 files changed, 28 insertions, 0 deletions
diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb index ff0ab56909..ca78fbe651 100755 --- a/activerecord/test/finder_test.rb +++ b/activerecord/test/finder_test.rb @@ -95,6 +95,16 @@ class FinderTest < Test::Unit::TestCase Company.find_first(["id=?", 2, 3, 4]) } end + + def test_bind_variables_with_quotes + Company.create("name" => "37signals' go'es agains") + assert Company.find_first(["name = ?", "37signals' go'es agains"]) + end + + def test_named_bind_variables_with_quotes + Company.create("name" => "37signals' go'es agains") + assert Company.find_first(["name = :name", {:name => "37signals' go'es agains"}]) + end def test_named_bind_variables assert_kind_of Firm, Company.find_first(["name = :name", { :name => "37signals" }]) diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb index 2d6c795d92..1abdfa062d 100755 --- a/activerecord/test/validations_test.rb +++ b/activerecord/test/validations_test.rb @@ -172,4 +172,22 @@ class ValidationsTest < Test::Unit::TestCase assert t.save end + + def test_validate_uniqueness + Topic.validate_uniqueness(:title) + + t = Topic.new("title" => "I'm unique!") + assert t.save, "Should save t as unique" + + t.content = "Remaining unique" + assert t.save, "Should still save t as unique" + + t2 = Topic.new("title" => "I'm unique!") + assert !t2.valid?, "Shouldn't be valid" + assert !t2.save, "Shouldn't save t2 as unique" + assert_equal "has already been taken", t2.errors.on(:title) + + t2.title = "Now Im really also unique" + assert t2.save, "Should now save t2 as unique" + end end
\ No newline at end of file |