Skip to content

Commit

Permalink
Making search results friendlier for ActiveSupport's memoisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Jan 17, 2010
1 parent 8f1afbb commit f49730e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/thinking_sphinx/search.rb
Expand Up @@ -80,6 +80,12 @@ def to_a
@array
end

def freeze
populate
@array.freeze
self
end

# Indication of whether the request has been made to Sphinx for the search
# query.
#
Expand Down
20 changes: 20 additions & 0 deletions spec/thinking_sphinx/search_spec.rb
Expand Up @@ -1172,6 +1172,26 @@
}.should_not be_nil
end
end

describe '#freeze' do
before :each do
@search = ThinkingSphinx::Search.new
end

it "should populate the result set" do
@search.freeze
@search.should be_populated
end

it "should freeze the underlying array" do
@search.freeze
@search.to_a.should be_frozen
end

it "should return the Search object" do
@search.freeze.should be_a(ThinkingSphinx::Search)
end
end
end

describe ThinkingSphinx::Search, "playing nice with Search model" do
Expand Down

0 comments on commit f49730e

Please sign in to comment.