diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-06-01 09:38:09 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-06-01 09:38:09 +0100 |
commit | 9d60525b5fc14b4b6f3ed9ba8ea874d6e76b4f78 (patch) | |
tree | 5a711cacac76a83ad12551023da8524f94e7365b /activemodel/test/models | |
parent | dc7323efd34327c13d26031b68e51314c24360f6 (diff) | |
parent | 9537fd0e3a7625afe4bee75d749647ca1837195a (diff) | |
download | rails-9d60525b5fc14b4b6f3ed9ba8ea874d6e76b4f78.tar.gz rails-9d60525b5fc14b4b6f3ed9ba8ea874d6e76b4f78.tar.bz2 rails-9d60525b5fc14b4b6f3ed9ba8ea874d6e76b4f78.zip |
Merge commit 'mainstream/master'
Diffstat (limited to 'activemodel/test/models')
-rw-r--r-- | activemodel/test/models/developer.rb | 6 | ||||
-rw-r--r-- | activemodel/test/models/person.rb | 5 | ||||
-rw-r--r-- | activemodel/test/models/reply.rb | 34 | ||||
-rw-r--r-- | activemodel/test/models/topic.rb | 9 |
4 files changed, 54 insertions, 0 deletions
diff --git a/activemodel/test/models/developer.rb b/activemodel/test/models/developer.rb new file mode 100644 index 0000000000..5e6eefeed1 --- /dev/null +++ b/activemodel/test/models/developer.rb @@ -0,0 +1,6 @@ +class Developer < ActiveRecord::Base + validates_inclusion_of :salary, :in => 50000..200000 + validates_length_of :name, :within => 3..20 + + attr_accessor :name_confirmation +end diff --git a/activemodel/test/models/person.rb b/activemodel/test/models/person.rb new file mode 100644 index 0000000000..d98420f900 --- /dev/null +++ b/activemodel/test/models/person.rb @@ -0,0 +1,5 @@ +class Person + include ActiveModel::Validations + + attr_accessor :title, :karma +end diff --git a/activemodel/test/models/reply.rb b/activemodel/test/models/reply.rb new file mode 100644 index 0000000000..acfd801674 --- /dev/null +++ b/activemodel/test/models/reply.rb @@ -0,0 +1,34 @@ +require 'models/topic' + +class Reply < Topic + validate :errors_on_empty_content + validate_on_create :title_is_wrong_create + + validate :check_empty_title + validate_on_create :check_content_mismatch + validate_on_update :check_wrong_update + + attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read + + def check_empty_title + errors[:title] << "Empty" unless attribute_present?("title") + end + + def errors_on_empty_content + errors[:content] << "Empty" unless attribute_present?("content") + end + + def check_content_mismatch + if attribute_present?("title") && attribute_present?("content") && content == "Mismatch" + errors[:title] << "is Content Mismatch" + end + end + + def title_is_wrong_create + errors[:title] << "is Wrong Create" if attribute_present?("title") && title == "Wrong Create" + end + + def check_wrong_update + errors[:title] << "is Wrong Update" if attribute_present?("title") && title == "Wrong Update" + end +end diff --git a/activemodel/test/models/topic.rb b/activemodel/test/models/topic.rb new file mode 100644 index 0000000000..1350aa17e7 --- /dev/null +++ b/activemodel/test/models/topic.rb @@ -0,0 +1,9 @@ +class Topic < ActiveRecord::Base + def condition_is_true + true + end + + def condition_is_true_but_its_not + false + end +end |