Actually fix the issue, rather than pretending to

This commit is contained in:
Andrew 2013-10-25 18:09:36 +11:00
parent 2e70cc5d99
commit e8de5907fa
2 changed files with 8 additions and 12 deletions

View file

@ -7,7 +7,7 @@ When /^I chain a where clause onto that query$/ do
end
Then /^the original query should remain unchanged$/ do
@query.should_not eql @new_query
@query.opts({}).should_not eql @new_query.opts({})
end
Then /^should initialize with an attribute and an operator$/ do

View file

@ -80,31 +80,27 @@ module Middleman
selector = Selector.new(:attribute => attribute, :operator => 'equal')
selector_hash.update({ selector => value })
end
@where.merge! selector_hash
Query.new @model, opts
Query.new @model, opts(:where => @where.merge(selector_hash))
end
def opts
{ :where => @where,
def opts new_opts
{ :where => {}.merge(@where),
:order_by => @order_by,
:offset => @offset,
:limit => @limit
}
}.merge(new_opts)
end
def order_by(field)
@order_by = field.is_a?(Symbol) ? {field => :asc} : field
Query.new @model, opts
Query.new @model, opts(:order_by => field.is_a?(Symbol) ? {field => :asc} : field)
end
def offset(number)
@offset = number
Query.new @model, opts
Query.new @model, opts(:offset => number)
end
def limit(number)
@limit = number
Query.new @model, opts
Query.new @model, opts(:limit => number)
end
def first