Sha256: ab544f9ea54e0fcda635a4351b82f655283687711f98366a40718cb55d19a32c

Contents?: true

Size: 1.2 KB

Versions: 17

Compression:

Stored size: 1.2 KB

Contents

class ModelStub < ActiveRecord::Base
  has_one :other_model, :class_name => 'ModelStub'
  has_many :other_models, :class_name => 'ModelStub'
  
  cattr_accessor :stubbed_columns
  self.stubbed_columns = [:a, :b, :c, :d, :id]
  attr_accessor *self.stubbed_columns
  
  @@nested_scope_calls = []
  cattr_accessor :nested_scope_calls
  
  scope :a_is_defined, lambda { where.not(:a => nil) }
  scope :b_like, lambda { |pattern| where("b like ?", pattern) }
  
  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

  def other_model=(val)
    @other_model = val
  end
  def other_model
    @other_model || nil
  end

  def other_models=(val)
    @other_models = val
  end
  def other_models
    @other_models || []
  end

  def self.columns
    @columns ||= self.stubbed_columns.map{|c| ColumnMock.new(c.to_s, '', 'varchar(255)') }
  end

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

  # column-level security methods, used for testing
  def self.a_authorized_for_bar?(user)
    true
  end
  def self.b_authorized?(user)
    false
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
active_scaffold-3.4.17 test/model_stub.rb
active_scaffold-3.4.16 test/model_stub.rb
active_scaffold-3.4.14 test/model_stub.rb
active_scaffold-3.4.13 test/model_stub.rb
active_scaffold-3.4.12 test/model_stub.rb
active_scaffold-3.4.11 test/model_stub.rb
active_scaffold-3.4.10 test/model_stub.rb
active_scaffold-3.4.9 test/model_stub.rb
active_scaffold-3.4.8 test/model_stub.rb
active_scaffold-3.4.7 test/model_stub.rb
active_scaffold-3.4.5 test/model_stub.rb
active_scaffold-3.4.4 test/model_stub.rb
active_scaffold-3.4.3 test/model_stub.rb
active_scaffold-3.4.2 test/model_stub.rb
active_scaffold-3.4.1 test/model_stub.rb
active_scaffold-3.4.0.1 test/model_stub.rb
active_scaffold-3.4.0 test/model_stub.rb