diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-06-02 12:36:36 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-06-02 12:36:36 -0300 |
commit | fd3c55f09fdfb45c33a5383af2c0b9ddf8f63e90 (patch) | |
tree | 89f6b8eeae81ba9e9f3c43667b234b64a776e649 /activemodel/test/models | |
parent | 5255a81b808c2c947d58df979e6436b1fe1d8157 (diff) | |
parent | 196f780e30fcece25e4d09c12f9b9f7374ebed29 (diff) | |
download | rails-fd3c55f09fdfb45c33a5383af2c0b9ddf8f63e90.tar.gz rails-fd3c55f09fdfb45c33a5383af2c0b9ddf8f63e90.tar.bz2 rails-fd3c55f09fdfb45c33a5383af2c0b9ddf8f63e90.zip |
Merge commit 'rails/master'
Conflicts:
activerecord/lib/active_record.rb
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 |