Sha256: 1e4c2836347cdefaae47143b53dea0671384b7ebe316f28f509bd9dc50d297b3

Contents?: true

Size: 795 Bytes

Versions: 1

Compression:

Stored size: 795 Bytes

Contents

require 'active_record'
require 'i18n'
require 'active_support/core_ext'
require 'simple_slug'

# just silence warning
I18n.enforce_available_locales = false

class RspecActiveModelBase
  include ActiveModel::Model
  include ActiveModel::AttributeMethods
  extend ActiveModel::Callbacks

  include SimpleSlug::ModelAddition

  define_model_callbacks :validation, :save, :destroy

  attr_accessor :id, :slug, :name, :created_at

  def self.create(attributes, *)
    record = new(attributes)
    record.save
    record
  end

  def save
    run_callbacks(:validation) { run_callbacks(:save) { } }
  end

  def destroy
    run_callbacks(:destroy) { @destroyed = true }
  end

  def persisted?
    true
  end

  def slug_changed?
    slug.present?
  end

  def destroyed?
    !!@destroyed
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_slug-0.0.1 spec/spec_helper.rb