Skip to content

Commit

Permalink
[webui] Adapt search controller test case
Browse files Browse the repository at this point in the history
  • Loading branch information
hennevogel authored and adrianschroeter committed Feb 19, 2013
1 parent d400142 commit b5d5746
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 32 deletions.
5 changes: 0 additions & 5 deletions src/webui/app/assets/stylesheets/search.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,9 @@
}

.data-title {
color: #690;
margin-bottom: -10px;
}

.data-name {
display: none;
}

.data-description {
margin-bottom: 30px;
}
16 changes: 8 additions & 8 deletions src/webui/app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ def search
collection = find_cached(Collection, :what => what, :predicate => "[#{predicate}]", :expires_in => 5.minutes)
reweigh(collection, what)
end

if @results.length < 1
flash[:note] = "Your search did not return any results."
end
if @results.length > 200
@results = @results[0..199]
flash[:note] = "Your search returned more than 200 results. Please be more precise."
end
end
logger.debug "Found #{@results.length} search results: #{@results.inspect}"
if @results.length < 1
flash[:note] = "Your search did not return any results."
end
if @results.length > 200
@results = @results[0..199]
flash[:note] = "Your search returned more than 200 results. Please be more precise."
end
end

Expand Down
25 changes: 13 additions & 12 deletions src/webui/app/views/search/_results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
<% else %>
<% title = "" %>
<% end %>
<h6>
<h6 class="data-title">
<%= image_tag('project.png', class: 'project') %>
<%= link_to result[:data].to_hash['name'], { :controller => 'project', :action => :show, :project => result[:data],}, :title => title, class: "data-title"-%>
<span class="data-name"><%= result[:data].to_hash['name'] %></span>
<%= link_to result[:data].to_hash['name'], { :controller => 'project', :action => :show, :project => result[:data],}, :title => title, class: "project"-%>
</h6>
<% elsif result[:type] == 'package' %>
<div class="search_result">
Expand All @@ -20,13 +19,11 @@
<% else %>
<% title = "" -%>
<% end %>
<h6>
<h6 class="data-title">
<%= image_tag('package.png', class: 'package') %>
<%= link_to result[:data].to_hash['name'], { :controller => 'package', :action => :show, :package => result[:data].name, :project => result[:data].project }, :title => title, class: 'data-title'-%>
<%= link_to result[:data].to_hash['name'], { :controller => 'package', :action => :show, :package => result[:data].name, :project => result[:data].project }, :title => title, class: 'package'-%>
</h6>
<p>
in project <span class="data-project"><%= result[:data].project %></span>
</p>
<% descr = "in project <span class=\"project\">#{result[:data].project}</span>" %>
<% elsif result[:type] == 'owner' %>
<div class="search_result">
<h6>
Expand Down Expand Up @@ -54,18 +51,22 @@
<% end %>
</p>
<% end %>
<% if result[:data].has_element?( 'description' ) && !result[:data].description.to_s.empty? %>
<% descr = h result[:data].description.to_s.dup[0,80] + "..." %>
<% else %>
<% descr = h excerpt(result[:data].description.to_s.dup, @search_text, 150 ) %>
<% end %>
<% if descr %>
<p class="data-description">
<% descr.split(/\n/).each do |line| -%>
<%= highlight(line, @search_text) -%>
<% end %>
<%= highlight(line, @search_text) -%>
<% end %>
</p>
<% else %>
<p class="data-description">
...
</p>
<% end %>

</div>
<% end %>
</div>
Expand Down
13 changes: 6 additions & 7 deletions src/webui/test/functional/search_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ def search_results
case theclass
when "project"
{ :type => :project,
:project_name => row.find("a.data-title")[:title],
:project_title => row.find("a.data-title").text
:project_name => row.find("a.project").text,
:project_title => row.find("a.project")[:title]
}
when "package"
{ :type => :package,
:package_name => row.find("a.data-title")[:title],
:project_name => row.find("span.data-project").text
:package_name => row.find("a.package").text,
:project_name => row.find("span.project").text
}
else
fail "Unrecognized result icon. #{alt}"
Expand Down Expand Up @@ -239,14 +239,13 @@ def search_results
visit search_path

search(
text: "вокябюч",
:text => "вокябюч",
:for => [:projects, :packages],
:in => [:name, :title, :description])

results = search_results
page.must_have_text "Этёам вокябюч еюж эи"
page.must_have_text "窞綆腤 埱娵徖 渮湸湤 殠 唲堔"
results.include?(:type => :project, :project_name => "home:tom")
results.include?(:type => :project, :project_name => "home:tom", :project_title => "Этёам вокябюч еюж эи")
results.count.must_equal 1
end

Expand Down

0 comments on commit b5d5746

Please sign in to comment.