diff options
Diffstat (limited to 'activemodel/test/models')
-rw-r--r-- | activemodel/test/models/administrator.rb | 10 | ||||
-rw-r--r-- | activemodel/test/models/blog_post.rb | 13 | ||||
-rw-r--r-- | activemodel/test/models/custom_reader.rb | 4 | ||||
-rw-r--r-- | activemodel/test/models/person.rb | 4 | ||||
-rw-r--r-- | activemodel/test/models/person_with_validator.rb | 15 | ||||
-rw-r--r-- | activemodel/test/models/sheep.rb | 1 | ||||
-rw-r--r-- | activemodel/test/models/topic.rb | 21 | ||||
-rw-r--r-- | activemodel/test/models/track_back.rb | 7 | ||||
-rw-r--r-- | activemodel/test/models/user.rb | 8 | ||||
-rw-r--r-- | activemodel/test/models/visitor.rb | 9 |
10 files changed, 88 insertions, 4 deletions
diff --git a/activemodel/test/models/administrator.rb b/activemodel/test/models/administrator.rb new file mode 100644 index 0000000000..a48f8b064f --- /dev/null +++ b/activemodel/test/models/administrator.rb @@ -0,0 +1,10 @@ +class Administrator + include ActiveModel::Validations + include ActiveModel::SecurePassword + include ActiveModel::MassAssignmentSecurity + + attr_accessor :name, :password_digest + attr_accessible :name + + has_secure_password +end diff --git a/activemodel/test/models/blog_post.rb b/activemodel/test/models/blog_post.rb new file mode 100644 index 0000000000..d289177259 --- /dev/null +++ b/activemodel/test/models/blog_post.rb @@ -0,0 +1,13 @@ +module Blog + def self._railtie + Object.new + end + + def self.table_name_prefix + "blog_" + end + + class Post + extend ActiveModel::Naming + end +end diff --git a/activemodel/test/models/custom_reader.rb b/activemodel/test/models/custom_reader.rb index 14a8be9ebc..2fbcf79c3d 100644 --- a/activemodel/test/models/custom_reader.rb +++ b/activemodel/test/models/custom_reader.rb @@ -4,11 +4,11 @@ class CustomReader def initialize(data = {}) @data = data end - + def []=(key, value) @data[key] = value end - + def read_attribute_for_validation(key) @data[key] end diff --git a/activemodel/test/models/person.rb b/activemodel/test/models/person.rb index cf16a38618..e896e90f98 100644 --- a/activemodel/test/models/person.rb +++ b/activemodel/test/models/person.rb @@ -9,5 +9,9 @@ class Person end end +class Person::Gender + extend ActiveModel::Translation +end + class Child < Person end diff --git a/activemodel/test/models/person_with_validator.rb b/activemodel/test/models/person_with_validator.rb index f9763ea853..505ed880c1 100644 --- a/activemodel/test/models/person_with_validator.rb +++ b/activemodel/test/models/person_with_validator.rb @@ -1,11 +1,24 @@ class PersonWithValidator include ActiveModel::Validations - + class PresenceValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) record.errors[attribute] << "Local validator#{options[:custom]}" if value.blank? end end + class LikeValidator < ActiveModel::EachValidator + def initialize(options) + @with = options[:with] + super + end + + def validate_each(record, attribute, value) + unless value[@with] + record.errors.add attribute, "does not appear to be like #{@with}" + end + end + end + attr_accessor :title, :karma end diff --git a/activemodel/test/models/sheep.rb b/activemodel/test/models/sheep.rb index 175dbe6477..7aba055c4f 100644 --- a/activemodel/test/models/sheep.rb +++ b/activemodel/test/models/sheep.rb @@ -1,4 +1,3 @@ class Sheep extend ActiveModel::Naming end -
\ No newline at end of file diff --git a/activemodel/test/models/topic.rb b/activemodel/test/models/topic.rb index f25b774cd7..c9af78f595 100644 --- a/activemodel/test/models/topic.rb +++ b/activemodel/test/models/topic.rb @@ -1,7 +1,15 @@ class Topic include ActiveModel::Validations + include ActiveModel::Validations::Callbacks + + def self._validates_default_keys + super | [ :message ] + end attr_accessor :title, :author_name, :content, :approved + attr_accessor :after_validation_performed + + after_validation :perform_after_validation def initialize(attributes = {}) attributes.each do |key, value| @@ -16,4 +24,17 @@ class Topic def condition_is_true_but_its_not false end + + def perform_after_validation + self.after_validation_performed = true + end + + def my_validation + errors.add :title, "is missing" unless title + end + + def my_validation_with_arg(attr) + errors.add attr, "is missing" unless send(attr) + end + end diff --git a/activemodel/test/models/track_back.rb b/activemodel/test/models/track_back.rb index d137e4ff8f..768c96ecf0 100644 --- a/activemodel/test/models/track_back.rb +++ b/activemodel/test/models/track_back.rb @@ -1,4 +1,11 @@ class Post class TrackBack + def to_model + NamedTrackBack.new + end + end + + class NamedTrackBack + extend ActiveModel::Naming end end
\ No newline at end of file diff --git a/activemodel/test/models/user.rb b/activemodel/test/models/user.rb new file mode 100644 index 0000000000..e221bb8091 --- /dev/null +++ b/activemodel/test/models/user.rb @@ -0,0 +1,8 @@ +class User + include ActiveModel::Validations + include ActiveModel::SecurePassword + + has_secure_password + + attr_accessor :password_digest, :password_salt +end diff --git a/activemodel/test/models/visitor.rb b/activemodel/test/models/visitor.rb new file mode 100644 index 0000000000..36c0a16688 --- /dev/null +++ b/activemodel/test/models/visitor.rb @@ -0,0 +1,9 @@ +class Visitor + include ActiveModel::Validations + include ActiveModel::SecurePassword + include ActiveModel::MassAssignmentSecurity + + has_secure_password + + attr_accessor :password_digest +end |