Sha256: 5ca9538635429ca6b0ef9151b4512988362f1ce432c46821203a9edadb69d728

Contents?: true

Size: 1.41 KB

Versions: 36

Compression:

Stored size: 1.41 KB

Contents

class ModelStub < ActiveRecord::Base
  validates :b, :presence => true
  has_one :other_model, :class_name => 'ModelStub'
  has_many :other_models, :class_name => 'ModelStub'

  cattr_accessor :stubbed_columns
  self.stubbed_columns = %i[a b c d id created_at]
  attr_accessor(*stubbed_columns)
  self.primary_key = :id

  @@nested_scope_calls = []
  cattr_accessor :nested_scope_calls

  def self.a_is_defined
    @@nested_scope_calls << :a_is_defined
    self
  end

  def self.b_like(pattern)
    @@nested_scope_calls << :b_like
    self
  end

  attr_writer :other_model
  def other_model
    @other_model || nil
  end

  attr_writer :other_models
  def other_models
    @other_models || []
  end

  def self.columns
    @columns ||= stubbed_columns.map do |c|
      column = ColumnMock.new(c.to_s, '', 'varchar(255)')
      column.primary = true if c.to_s == primary_key.to_s && column.respond_to?(:primary=)
      column
    end
  end

  def self.columns_hash
    @columns_hash ||= columns.each_with_object({}) { |column, hash| hash[column.name.to_s] = column }
  end

  if respond_to? :type_for_attribute
    def self.type_for_attribute(attribute_name)
      defined?(ActiveModel::Type) ? ActiveModel::Type::String.new : super
    end
  end

  # column-level security methods, used for testing
  def self.a_authorized_for_bar?
    true
  end

  def self.b_authorized?
    false
  end

  def self.c_authorized_for_create?
    false
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
active_scaffold-3.7.8 test/model_stub.rb
active_scaffold-3.7.7 test/model_stub.rb
active_scaffold-3.7.6 test/model_stub.rb
active_scaffold-3.7.5 test/model_stub.rb
active_scaffold-3.7.2 test/model_stub.rb
active_scaffold-3.7.1 test/model_stub.rb
active_scaffold-3.7.0 test/model_stub.rb
active_scaffold-3.6.20 test/model_stub.rb
active_scaffold-3.6.19 test/model_stub.rb
active_scaffold-3.6.17 test/model_stub.rb
active_scaffold-3.6.15 test/model_stub.rb
active_scaffold-3.6.14 test/model_stub.rb
active_scaffold-3.6.13 test/model_stub.rb
active_scaffold-3.6.12 test/model_stub.rb
active_scaffold-3.6.11.1 test/model_stub.rb
active_scaffold-3.6.11 test/model_stub.rb
active_scaffold-3.6.10 test/model_stub.rb
active_scaffold-3.6.9 test/model_stub.rb
active_scaffold-3.6.8 test/model_stub.rb
active_scaffold-3.6.6 test/model_stub.rb