Indexed attributes are 'name' and 'username'.
---
.../admin/provider_accounts_controller.rb | 19 ++++++++++++++++---
src/app/models/cloud_account.rb | 7 +++++++
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/src/app/controllers/admin/provider_accounts_controller.rb
b/src/app/controllers/admin/provider_accounts_controller.rb
index 2c331f7..7a63d38 100644
--- a/src/app/controllers/admin/provider_accounts_controller.rb
+++ b/src/app/controllers/admin/provider_accounts_controller.rb
@@ -1,8 +1,18 @@
class Admin::ProviderAccountsController < ApplicationController
before_filter :require_user
- before_filter :load_accounts, :only => [:index, :show]
+ before_filter :load_accounts, :only => :show
+ before_filter :set_view_vars, :only => [:index,:show]
def index
+ @search_term = params[:q]
+ if @search_term.blank?
+ load_accounts
+ else
+ search = CloudAccount.search do
+ keywords(params[:q])
+ end
+ @accounts = search.results
+ end
end
def show
@@ -118,15 +128,18 @@ class Admin::ProviderAccountsController < ApplicationController
flash.now[:error] = "Test Connection Failed: Could not connect to
provider"
end
- def load_accounts
+ def set_view_vars
@header = [
{ :name => "Name", :sort_attr => :name },
{ :name => "Username", :sort_attr => :username},
]
+ @url_params = params
+ end
+
+ def load_accounts
@accounts = CloudAccount.paginate(:all,
:page => params[:page] || 1,
:order => (params[:order_field] || 'label') +' '+
(params[:order_dir] || 'asc')
)
- @url_params = params
end
end
diff --git a/src/app/models/cloud_account.rb b/src/app/models/cloud_account.rb
index 4371a1a..334b7cb 100644
--- a/src/app/models/cloud_account.rb
+++ b/src/app/models/cloud_account.rb
@@ -20,8 +20,15 @@
# Likewise, all the methods added will be available for all controllers.
require 'nokogiri'
+require 'sunspot_rails'
class CloudAccount < ActiveRecord::Base
+
+ searchable do
+ text :name, :as => :code_substring
+ text :username, :as => :code_substring
+ end
+
include PermissionedObject
# Relations
--
1.7.3.4
Show replies by date
---
src/features/provider_account.feature | 16 ++++++++++++++++
.../step_definitions/provider_account_steps.rb | 6 ++++++
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/src/features/provider_account.feature
b/src/features/provider_account.feature
index 9a73bb5..cb4c2ce 100644
--- a/src/features/provider_account.feature
+++ b/src/features/provider_account.feature
@@ -68,3 +68,19 @@ Feature: Manage Provider Accounts
And I press "Delete"
Then I should be on the admin provider accounts page
And there should be no provider accounts
+
+ Scenario: Search for Provider Accounts
+ Given there is a provider named "testprovider"
+ And there is a provider account named "testaccount"
+ And I am on the admin provider accounts page
+ When I fill in "q" with "test"
+ And I press "Search"
+ Then I should see the following:
+ | testaccount | mockuser |
+ When I fill in "q" with "mock"
+ And I press "Search"
+ Then I should see the following:
+ | testaccount | mockuser |
+ When I fill in "q" with "foo"
+ And I press "Search"
+ Then I should not see "testaccount"
diff --git a/src/features/step_definitions/provider_account_steps.rb
b/src/features/step_definitions/provider_account_steps.rb
index bf9991c..40d6d76 100644
--- a/src/features/step_definitions/provider_account_steps.rb
+++ b/src/features/step_definitions/provider_account_steps.rb
@@ -24,3 +24,9 @@ When /^I check the "([^"]*)" account$/ do |label|
account = CloudAccount.find_by_label(label)
check("account_checkbox_#{account.id}")
end
+
+Given /^that there are these provider accounts:$/ do |table|
+ table.hashes.each do |hash|
+ Factory.create(:cloud_account, :name => hash['name'], :username =>
hash['username'])
+ end
+end
--
1.7.3.4