diff --git a/app/contexts/search_context.rb b/app/contexts/search_context.rb index 6e5e8c5e9b5ee7e1a9b28ed9dac5cec8fe7113df..9becb8d674f2380c2a7e309fbc52aa9d6502ddef 100644 --- a/app/contexts/search_context.rb +++ b/app/contexts/search_context.rb @@ -13,6 +13,7 @@ class SearchContext result[:projects] = Project.where(id: project_ids).search(query).limit(10) result[:merge_requests] = MergeRequest.where(project_id: project_ids).search(query).limit(10) result[:issues] = Issue.where(project_id: project_ids).search(query).limit(10) + result[:wiki_pages] = Wiki.where(project_id: project_ids).search(query).limit(10) result end @@ -20,7 +21,8 @@ class SearchContext @result ||= { projects: [], merge_requests: [], - issues: [] + issues: [], + wiki_pages: [] } end end diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 1dc8507e019073dec2b0081d8ba7d8c90d3286a0..4f45f9ddccb204c779d68cd67d979d38a7351500 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -5,5 +5,6 @@ class SearchController < ApplicationController @projects = result[:projects] @merge_requests = result[:merge_requests] @issues = result[:issues] + @wiki_pages = result[:wiki_pages] end end diff --git a/app/models/wiki.rb b/app/models/wiki.rb index b1f41d636c72118be35f0026fb830e6b9551624e..895c2896462f33b25884a1da0c7311a0a79a3b05 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -15,6 +15,12 @@ class Wiki < ActiveRecord::Base slug end + class << self + def search(query) + where("title like :query OR content like :query", query: "%#{query}%") + end + end + protected def self.regenerate_from wiki diff --git a/app/views/search/show.html.haml b/app/views/search/show.html.haml index d85c24ec1057f2ba277cf744abcbb5c9a7f15f64..0d5f545850a1c599298a2dc212ef8e99f826dd80 100644 --- a/app/views/search/show.html.haml +++ b/app/views/search/show.html.haml @@ -9,7 +9,7 @@ %br %h3 Search results - %small (#{@projects.count + @merge_requests.count + @issues.count}) + %small (#{@projects.count + @merge_requests.count + @issues.count + @wiki_pages.count}) %hr .search_results .row @@ -69,6 +69,23 @@ %tr %td %h4.nothing_here_message No Issues + .span6 + %table + %thead + %tr + %th Wiki + %tbody + - @wiki_pages.each do |wiki_page| + %tr + %td + = link_to project_wiki_path(wiki_page.project, wiki_page) do + %strong.term= truncate wiki_page.title, length: 40 + %strong.right + %span.label= wiki_page.project.name + - if @wiki_pages.blank? + %tr + %td + %h4.nothing_here_message No wiki pages :javascript $(function() { $(".search_results .term").highlight("#{params[:search]}"); diff --git a/features/dashboard/search.feature b/features/dashboard/search.feature index 91d870f46f3bf57c6c6baeb70a151f7723572e99..9813d9d1e7c8f8d4bdebc0150d422390e799fa27 100644 --- a/features/dashboard/search.feature +++ b/features/dashboard/search.feature @@ -2,8 +2,13 @@ Feature: Dashboard Search Background: Given I sign in as a user And I own project "Shop" + And Project "Shop" has wiki page "Contibuting guide" And I visit dashboard search page Scenario: I should see project I am looking for Given I search for "Sho" Then I should see "Shop" project link + + Scenario: I should see wiki page I am looking for + Given I search for "Contibuting" + Then I should see "Contibuting guide" wiki link \ No newline at end of file diff --git a/features/steps/dashboard/dashboard_search.rb b/features/steps/dashboard/dashboard_search.rb index e35858985d688a89b7c965468dacb7e7417764bc..e902e40456fd615e8ad8d597316553c23980c058 100644 --- a/features/steps/dashboard/dashboard_search.rb +++ b/features/steps/dashboard/dashboard_search.rb @@ -15,4 +15,21 @@ class DashboardSearch < Spinach::FeatureSteps @project = Factory :project, :name => "Shop" @project.add_access(@user, :admin) end + + Given 'I search for "Contibuting"' do + fill_in "dashboard_search", :with => "Contibuting" + click_button "Search" + end + + And 'Project "Shop" has wiki page "Contibuting guide"' do + @wiki_page = Factory :wiki, :project => @project, + :title => "Contibuting guide", + :slug => "contributing" + end + + Then 'I should see "Contibuting guide" wiki link' do + page.should have_link "Contibuting guide" + end + + end