diff options
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 |