Skip to content

Instantly share code, notes, and snippets.

@quinn
Created April 12, 2018 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quinn/0e2c6cf4013336242dbab5a4809b55b8 to your computer and use it in GitHub Desktop.
Save quinn/0e2c6cf4013336242dbab5a4809b55b8 to your computer and use it in GitHub Desktop.
class FakeModel
DataArray = []
class << self
def arel_table; end
def relation_delegate_class(_arg)
MockRelationDelegate
end
def all(*_args)
self
end
alias unscoped all
alias extending! all
alias merge all
alias limit all
def eager_loading?
true
end
def connection
self
end
def table_name
""
end
def primary_key
:id
end
def schema_cache
self
end
def columns_hash(*_args)
HashWithIndifferentAccess.new(id: :id)
end
def substitute_at(*_args)
self
end
def bind_values
@bind_values ||= []
end
attr_writer :bind_values
def where(*_args)
self
end
def to_a
bind = bind_values.first
DataArray.select { |f| f[bind.first] == bind.second }.map { |f| make(f) }
end
end
class MockRelationDelegate
def initialize(*_args); end
def merge!(arg)
arg
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment