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 end
Then /^the original query should remain unchanged$/ do Then /^the original query should remain unchanged$/ do
@query.should_not eql @new_query @query.opts({}).should_not eql @new_query.opts({})
end end
Then /^should initialize with an attribute and an operator$/ do 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 = Selector.new(:attribute => attribute, :operator => 'equal')
selector_hash.update({ selector => value }) selector_hash.update({ selector => value })
end end
@where.merge! selector_hash Query.new @model, opts(:where => @where.merge(selector_hash))
Query.new @model, opts
end end
def opts def opts new_opts
{ :where => @where, { :where => {}.merge(@where),
:order_by => @order_by, :order_by => @order_by,
:offset => @offset, :offset => @offset,
:limit => @limit :limit => @limit
} }.merge(new_opts)
end end
def order_by(field) def order_by(field)
@order_by = field.is_a?(Symbol) ? {field => :asc} : field Query.new @model, opts(:order_by => field.is_a?(Symbol) ? {field => :asc} : field)
Query.new @model, opts
end end
def offset(number) def offset(number)
@offset = number Query.new @model, opts(:offset => number)
Query.new @model, opts
end end
def limit(number) def limit(number)
@limit = number Query.new @model, opts(:limit => number)
Query.new @model, opts
end end
def first def first