class ARMocker::Model

Object that acts as an ActiveRecord model so form objects can use them as dummy data

Public Class Methods

create(hash = {}) click to toggle source
# File lib/a_r_mocker/model.rb, line 11
def self.create(hash = {})
  new(hash.merge(_persisted: true))
end
new(hash = {}) click to toggle source
Calls superclass method
# File lib/a_r_mocker/model.rb, line 5
def initialize(hash = {})
  @persisted = hash.slice(:_persisted)
  hash = default_attributes.merge(hash)
  super
end

Public Instance Methods

to_param() click to toggle source

for generating path from object (e.g. edit_model_path(model)) For context, see ActionDispatch::Routing::RouteSet::Generator::PARAMETERIZE

# File lib/a_r_mocker/model.rb, line 27
def to_param
  id
end

Private Instance Methods

default_attributes() click to toggle source
# File lib/a_r_mocker/model.rb, line 15
        def default_attributes
  {
    new_record?: !@persisted,
    persisted?: @persisted,
    id: @persisted ? 1 : nil,
    created_at: @persisted ? Time.now : nil,
    blank?: false
  }
end