Skip to content

Commit

Permalink
search box also queries attachment titles and descriptions as well as…
Browse files Browse the repository at this point in the history
… page bodies.
  • Loading branch information
fiedl committed Jul 23, 2014
1 parent 05950b4 commit be7b84c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def index
q = "%" + query_string.gsub( ' ', '%' ) + "%"
@users = User.where("CONCAT(first_name, ' ', last_name) LIKE ?", q)
.order( :last_name, :first_name )
@pages = Page.where( "title like ?", q )
@pages = Page.where("title like ? OR content like ?", q, q)
.order( :title )
@groups = Group.where( "name like ?", q )

Expand All @@ -33,6 +33,11 @@ def index
end
end

# browse attachments
#
attachments = Attachment.where("title like ? or description like ?", q, q).where(parent_type: 'Page')
@pages += attachments.collect { |attachment| attachment.parent }

# eleminiate duplicate results
#
@users.uniq!
Expand Down
29 changes: 26 additions & 3 deletions vendor/engines/your_platform/spec/features/search_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,35 @@

describe "finding pages" do
before do
@page = create( :page, title: "foo" )
@page = create(:page, title: "foo", content: "some page content")
end
specify "searching for page titles should list the pages" do
fill_in 'query', with: "foo"
press_enter in: 'query'
page.should have_content @page.title
end
specify "searching for page contents (bodies) should list the pages" do
fill_in 'query', with: "some page content"
press_enter in: 'query'
page.should have_content @page.title
end
end

describe "finding attachments" do
before do
@page = create(:page, title: "foo page")
@attachment = @page.attachments.create(title: "bar attachment", description: "some attachment description")
end
specify "searching for attachment titles should list their parent pages" do
fill_in 'query', with: 'bar attachment'
press_enter in: 'query'
page.should have_content @page.title
end
specify "searching for attachment descriptions should list their parent pages" do
fill_in 'query', with: 'some attachment description'
press_enter in: 'query'
page.should have_content @page.title
end
subject { page }
it { should have_content( @page.title ) }
end

describe "finding groups" do
Expand Down

0 comments on commit be7b84c

Please sign in to comment.