Created
April 12, 2018 15:32
-
-
Save quinn/0e2c6cf4013336242dbab5a4809b55b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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