Skip to content
This repository has been archived by the owner on Apr 26, 2022. It is now read-only.

Implement basic idea search #189

Merged
merged 1 commit into from
Jan 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ gem 'animation'
# asset minification
gem 'uglifier', '>= 1.0.3'

# Search
gem 'textacular', '~> 3.0'

group :development do
# better generators
Expand Down
5 changes: 4 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GIT
activerecord (>= 3.2.0, < 5.0)

GEM
remote: http://yarp.dev/
remote: https://rubygems.org/
specs:
actionmailer (4.0.2)
actionpack (= 4.0.2)
Expand Down Expand Up @@ -396,6 +396,8 @@ GEM
tins (~> 0.8)
terminal-notifier-guard (1.5.3)
text (1.2.3)
textacular (3.1.0)
activerecord (>= 3.0, < 4.1)
thin (1.6.1)
daemons (>= 1.0.9)
eventmachine (>= 1.0.0)
Expand Down Expand Up @@ -511,6 +513,7 @@ DEPENDENCIES
state_machine
taps
terminal-notifier-guard
textacular (~> 3.0)
thin
timecop
turbolinks
Expand Down
10 changes: 10 additions & 0 deletions app/assets/stylesheets/bootstrap_ext/_forms.css.sass
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ select,
&:focus
border-color: $focus_color
@include box-shadow(inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px $focus_color)

.form-search
margin-top: 5px
margin-bottom: 0

input[type=text]
height: 30px

&:focus
@extend .input-large
10 changes: 10 additions & 0 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# encoding: UTF-8
class SearchController < ApplicationController
include Traits::RequiresLogin

before_filter :require_account!

def index
@search = Search.new(params[:search].fetch(:query, nil))
end
end
14 changes: 14 additions & 0 deletions app/models/search.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Search
include ActiveModel::Conversion
extend ActiveModel::Naming

attr_accessor :query

def initialize(query = nil)
@query = query
end

def ideas
Idea.basic_search(query)
end
end
1 change: 1 addition & 0 deletions app/views/application/_header.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
%a{href: path, title: s_('Tooltip|Show stories you are following'), :'data-placement' => 'bottom'}
%i.fa.fa-bookmark-o
%span= _('Bookmarks')
%li= render 'search'

%ul.nav.pull-right#current_user
- if current_account
Expand Down
4 changes: 4 additions & 0 deletions app/views/application/_search.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
= form_for(@search || Search.new, method: :get, html: { class: 'form-search' }) do |f|
.input-append
= f.text_field :query, class: 'input-medium search-query', placeholder: 'Search'
= f.submit 'Go', class: 'btn'
6 changes: 3 additions & 3 deletions app/views/ideas/_idea_maxi.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
.idea.idea-maxi.af-drop-hilite{ class:classes }

.meta.top.af-mutable
= render 'idea_rating', idea:idea
= render 'ideas/idea_rating', idea:idea
.category.muted.pull-left.pull-left-spaced
= idea.category || _('No category')
.state.muted.pull-right.pull-right-spaced{ title: s_('Tooltip|The current progress on this idea'), :'data-container' => '.container' }<
Expand Down Expand Up @@ -48,7 +48,7 @@
!= pipeline_render idea.metrics

.meta.bottom.af-mutable
= render 'idea_people', idea:idea
= render 'ideas/idea_people', idea:idea

.actions.pull-right
%ul
Expand All @@ -65,4 +65,4 @@
= can_link_to idea, data: { confirm: _('Are you sure?') }, method: :delete, auth:[:destroy,idea], title: s_('Tooltip|Delete Idea') do
%i.fa.fa-trash-o<>
%li
= render 'bookmark_link', idea:idea
= render 'ideas/bookmark_link', idea:idea
5 changes: 5 additions & 0 deletions app/views/search/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- @search.ideas.each do |idea|
= render partial: 'ideas/idea_maxi', locals: { :idea => idea }

- if @search.ideas.empty?
%h3.text-center No ideas matches #{@search.query.inspect}
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
resources :attachments, only: [:create, :destroy, :show]
end

get '/search', controller: :search, action: :index

resources :comments do
resources :votes, only: [:create, :destroy]
resources :attachments, only: [:create, :destroy, :show]
Expand Down
15 changes: 15 additions & 0 deletions features/ideas/search.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: Idea search
As a user
In order to find existing ideas
I want to be able to search all ideas

Background:
Given a submitted idea "A good idea for the future"
Given a submitted idea "Idea about something else"
Given a user named "Ursula"
And I sign in as "Ursula"

Scenario: Query contains one result
When I search for "future"
Then I should see "A good idea for the future"
And I should not see "Idea about something else"
13 changes: 13 additions & 0 deletions features/step_definitions/search_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
When(/^I search for "(.*?)"$/) do |query|
visit root_url
fill_in 'search_query', with: query
click_button 'Go'
end

Then(/^I should see "(.*?)"$/) do |text|
page.should have_text(text)
end

Then(/^I should not see "(.*?)"$/) do |text|
page.should_not have_text(text)
end