test_model_naming

test_model_naming() Instance Public methods Naming Model.model_name must return a string with some convenience methods: :human, :singular and :plural. Check ActiveModel::Naming for more information.

test_persisted?

test_persisted?() Instance Public methods Responds to persisted? Returns a boolean that specifies whether the object has been persisted yet. This is used when calculating the URL for an object. If the object is not persisted, a form for that object, for instance, will route to the create action. If it is persisted, a form for the object will routes to the update action.

test_to_key

test_to_key() Instance Public methods Responds to to_key Returns an Enumerable of all (primary) key attributes or nil if model.persisted? is false. This is used by dom_id to generate unique ids for the object.

test_to_param

test_to_param() Instance Public methods Responds to to_param Returns a string representing the object's key suitable for use in URLs or nil if model.persisted? is false. Implementers can decide to either raise an exception or provide a default in case the record uses a composite primary key. There are no tests for this behavior in lint because it doesn't make sense to force any of the possible implementation strategies on the implementer. However, if the resource is not persisted?,

test_to_partial_path

test_to_partial_path() Instance Public methods Responds to to_partial_path Returns a string giving a relative path. This is used for looking up partials. For example, a BlogPost model might return âblog_posts/blog_postâ

new

new(params={}) Class Public methods Initializes a new model with the given params. class Person include ActiveModel::Model attr_accessor :name, :age end person = Person.new(name: 'bob', age: '18') person.name # => "bob" person.age # => 18

persisted?

persisted?() Instance Public methods Indicates if the model is persisted. Default is false. class Person include ActiveModel::Model attr_accessor :id, :name end person = Person.new(id: 1, name: 'bob') person.persisted? # => false

new

new(klass, namespace = nil, name = nil) Class Public methods Returns a new ActiveModel::Name instance. By default, the namespace and name option will take the namespace and name of the given class respectively. module Foo class Bar end end ActiveModel::Name.new(Foo::Bar).to_s # => "Foo::Bar"

!~

!~(regexp) Instance Public methods Equivalent to String#!~. Match the class name against the given regexp. Returns true if there is no match, otherwise false. class BlogPost extend ActiveModel::Naming end BlogPost.model_name !~ /Post/ # => false BlogPost.model_name !~ /\d/ # => true

<=>

==(other) Instance Public methods Equivalent to String#<=>. class BlogPost extend ActiveModel::Naming end BlogPost.model_name <=> 'BlogPost' # => 0 BlogPost.model_name <=> 'Blog' # => 1 BlogPost.model_name <=> 'BlogPosts' # => -1