From: Martyn Taylor <mtaylor(a)redhat.com>
---
src/features/step_definitions/template_steps.rb | 12 ++++++
src/features/template.feature | 43 +++++++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/src/features/step_definitions/template_steps.rb
b/src/features/step_definitions/template_steps.rb
index 24dea3b..79a6739 100644
--- a/src/features/step_definitions/template_steps.rb
+++ b/src/features/step_definitions/template_steps.rb
@@ -42,6 +42,18 @@ Given /^I jump on the "([^"]*)" template software page$/
do |name|
visit url_for(:action => 'software', :controller => 'templates',
:id => @template)
end
+Given /^there are these templates:$/ do |table|
+ table.hashes.each do |hash|
+ @template = Factory.build (:template, :name => hash['name'],
+ :platform => hash['platform'])
+ @template.save!
+ @template.platform_version = hash['platform_version']
+ @template.architecture = hash['architecture']
+ @template.summary = hash['summary']
+ @template.save!
+ end
+end
+
Then /^I should have a template named "([^"]*)"$/ do |name|
Template.first(:order => 'created_at DESC').xml.name.should eql(name)
end
diff --git a/src/features/template.feature b/src/features/template.feature
index 272573a..b7d75a8 100644
--- a/src/features/template.feature
+++ b/src/features/template.feature
@@ -124,3 +124,46 @@ Feature: Manage Templates
And I press "Build"
Then I should be on the templates page
And I should see "Build imported template is not supported"
+
+ Scenario: Search for templates
+ Given there are these templates:
+ | name | platform | platform_version | architecture | summary
|
+ | Test1 | fedora | 13 | x86_64 | Test Template Fedora
13 64 bit Description |
+ | Mock | fedora | 14 | i386 | Test Template Fedora
14 Description |
+ | Other | fedora | 10.04 | i386 | Test Template Ubuntu
10.04 32 bit Description |
+ And I am on the image factory templates page
+ Then I should see the following:
+ | NAME | OS | VERSION | ARCH |
+ | Test1 | fedora | 13 | x86_64 |
+ | Mock | fedora | 14 | i386 |
+ | Other | fedora | 10.04 | i386 |
+ When I fill in "q" with "test"
+ And I press "Search"
+ Then I should see "Test1"
+ And I should see "Mock"
+ And I should see "Other"
+ When I fill in "q" with "Mock"
+ And I press "Search"
+ Then I should see "Mock"
+ And I should not see "Test1"
+ And I should not see "Other"
+ When I fill in "q" with "13"
+ And I press "Search"
+ Then I should see "Test1"
+ And I should not see "Other"
+ And I should not see "Mock"
+ When I fill in "q" with "x86_64"
+ And I press "Search"
+ Then I should see "Test1"
+ And I should not see "Other"
+ And I should not see "Mock"
+ When I fill in "q" with "fedora"
+ And I press "Search"
+ Then I should see "Test1"
+ And I should see "Other"
+ And I should see "Mock"
+ When I fill in "q" with "32 bit Description"
+ And I press "Search"
+ Then I should not see "Test1"
+ And I should see "Other"
+ And I should not see "Mock"
\ No newline at end of file
--
1.7.2.3
Show replies by date
From: Martyn Taylor <mtaylor(a)redhat.com>
---
.../image_factory/templates_controller.rb | 11 +++++++++++
src/app/models/template.rb | 8 ++++++++
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/src/app/controllers/image_factory/templates_controller.rb
b/src/app/controllers/image_factory/templates_controller.rb
index fbba625..1015efa 100644
--- a/src/app/controllers/image_factory/templates_controller.rb
+++ b/src/app/controllers/image_factory/templates_controller.rb
@@ -6,6 +6,17 @@ class ImageFactory::TemplatesController < ApplicationController
before_filter :load_templates, :only => [:index, :show]
def index
+ @params = params
+ @search_term = params[:q]
+ if @search_term.blank?
+ load_templates
+ return
+ end
+
+ search = Template.search do
+ keywords(params[:q])
+ end
+ @templates = search.results
end
def show
diff --git a/src/app/models/template.rb b/src/app/models/template.rb
index d545f9b..2b05e1b 100644
--- a/src/app/models/template.rb
+++ b/src/app/models/template.rb
@@ -2,6 +2,14 @@ require 'util/image_descriptor_xml'
require 'typhoeus'
class Template < ActiveRecord::Base
+ searchable do
+ text :name, :as => :code_substring
+ text :platform, :as => :code_substring
+ text :platform_version, :as => :code_substring
+ text :architecture, :as => :code_substring
+ text :summary, :as => :code_substring
+ end
+
has_many :images, :dependent => :destroy
has_many :instances
before_validation :generate_uuid
--
1.7.2.3