Skip to content

Commit

Permalink
Add optional argument to all to_json methods as a defense against A…
Browse files Browse the repository at this point in the history
…ctiveSupport

ActiveSupport, in many cases, calls `to_json` methods with arguments.

This patch adds optional argument to all `to_json` methods to guard against that.
  • Loading branch information
karmi committed Oct 19, 2012
1 parent 68e474a commit fffbcb1
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/tire/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def to_hash
end
end

def to_json
def to_json(options={})
payload = to_hash
# TODO: Remove when deprecated interface is removed
if payload.is_a?(String)
Expand Down
2 changes: 1 addition & 1 deletion lib/tire/search/facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def filter(type, options={})
self
end

def to_json
def to_json(options={})
to_hash.to_json
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tire/search/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(type, *options)
@hash = { type => value }
end

def to_json
def to_json(options={})
to_hash.to_json
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tire/search/highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(*args)
end
end

def to_json
def to_json(options={})
to_hash.to_json
end

Expand Down
6 changes: 3 additions & 3 deletions lib/tire/search/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def to_hash
@value
end

def to_json
def to_json(options={})
to_hash.to_json
end

Expand Down Expand Up @@ -156,7 +156,7 @@ def to_hash
@value
end

def to_json
def to_json(options={})
to_hash.to_json
end
end
Expand All @@ -177,7 +177,7 @@ def to_hash
@value.update(@options)
end

def to_json
def to_json(options={})
to_hash.to_json
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tire/search/script_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(name, options)
@hash = { name => options }
end

def to_json
def to_json(options={})
to_hash.to_json
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tire/search/sort.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def to_ary
@value
end

def to_json
def to_json(options={})
@value.to_json
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(attributes={})
attributes.each { |k,v| instance_variable_set(:"@#{k}", v) }
end

def to_json
def to_json(options={})
{ :id => @id, :title => @title, :body => @body }.to_json
end

Expand Down

0 comments on commit fffbcb1

Please sign in to comment.