Permalink
Browse files

Get the views, and their specs, up to shape with Sunspot.

  • Loading branch information...
1 parent 6aab1a7 commit 33a8841d96ee1ad7614a849647ed943c295471e6 @nz nz committed Jul 25, 2011
@@ -8,10 +8,9 @@ def search
@search = Rubygem.search(
q: params[:q].present? ? params[:q] : '*:*'
)
+ @docs = @search.results
+ @exact = @docs.find{ |d| d.name == params[:q] }
end
- @search ||= {'response' => {}, 'response' => {'docs' => []}}
- @docs = @search['response']['docs']
- @exact = @docs.find{ |d| d.name == params[:q] }
end
end
View
@@ -24,10 +24,9 @@ class Rubygem < ActiveRecord::Base
end
def self.search(params={})
- solr_response = solr_search do
+ solr_search do
keywords params[:q]
end
- solr_response.results
end
end
@@ -11,33 +11,34 @@
<h2><%= link_to 'search', '/search' %></h2>
<h3>
for <em><%= params[:q] %></em>
- <small id="qtime">in <%= @search['responseHeader']['QTime'] %> ms</small>
+ <!-- <small id="qtime">in <%#= @search['responseHeader']['QTime'] %> ms</small> -->
</h3>
</div>
<% if @exact %>
<p>Exact match</p>
<div class="gems border">
<ol>
- <%= render 'rubygem' %>
+ <%= render @exact %>
</ol>
</div>
<% end %>
- <p class="entries">
- Displaying gems
- 1&ndash;<%= @docs.length %>
- of
- <%= number_with_delimiter @search['response']['numFound'] %> total.
- </p>
+ <% if @docs.present? %>
+ <p class="entries">
+ Displaying gems
+ 1&ndash;<%= @docs.length %>
+ <!-- of <%#= number_with_delimiter @search['response']['numFound'] %> total. -->
+ </p>
- <div class="gems border">
- <ol>
- <% @docs.each do |doc| %>
- <%= render 'rubygem', rubygem: doc %>
- <% end %>
- </ol>
- </div>
+ <div class="gems border">
+ <ol>
+ <% @docs.each do |doc| %>
+ <%= render 'rubygem', rubygem: doc %>
+ <% end %>
+ </ol>
+ </div>
+ <% end %>
<pre><%#= @search.to_yaml %></pre>
@@ -1,5 +1,19 @@
require 'spec_helper'
describe SearchController do
-
-end
+
+ render_views
+
+ describe "#search" do
+ it "should respond successfully without a query" do
+ get :search
+ response.should be_success
+ end
+
+ it "should respond successfully with a query" do
+ get :search, :q => 'test'
+ response.should be_success
+ end
+ end
+
+end
@@ -2,10 +2,8 @@
describe WebhookController do
- def post_gem
- request.env["HTTP_ACCEPT"] = "application/json"
-
- request.env["RAW_POST_DATA"] = {
+ let :gem_payload do
+ {
"name" => "rails",
"info" => "Rails is a framework for building web-application using CGI, FCGI, mod_ruby,
or WEBrick on top of either MySQL, PostgreSQL, SQLite, DB2, SQL Server, or
@@ -31,15 +29,19 @@ def post_gem
],
"development" => [ ]
}
- }.to_json
-
+ }
+ end
+
+ def post_gem
+ request.env["HTTP_ACCEPT"] = "application/json"
+ request.env["RAW_POST_DATA"] = gem_payload.to_json
post :gem
end
it "should receive a payload" do
post_gem
response.should be_success
- Rubygem.search(:q => 'rails').first.name.should == "rails"
+ Rubygem.search(:q => 'rails').results.first.name.should == "rails"
end
end

0 comments on commit 33a8841

Please sign in to comment.