From: Jan Provaznik jprovazn@redhat.com
https://bugzilla.redhat.com/show_bug.cgi?id=649843 --- src/app/controllers/templates_controller.rb | 17 +++++++++++------ src/app/views/templates/builds.haml | 8 ++++---- 2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/src/app/controllers/templates_controller.rb b/src/app/controllers/templates_controller.rb index 8261eab..55e41c9 100644 --- a/src/app/controllers/templates_controller.rb +++ b/src/app/controllers/templates_controller.rb @@ -11,12 +11,10 @@ class TemplatesController < ApplicationController def index # TODO: add template permission check require_privilege(Privilege::IMAGE_VIEW) - @order_dir = params[:order_dir] == 'desc' ? 'desc' : 'asc' - @order_field = params[:order_field] || 'name' @templates = Template.find( :all, :include => :images, - :order => @order_field + ' ' + @order_dir + :order => get_order('name') ) end
@@ -222,9 +220,10 @@ add account on <a href="#{url_for :controller => 'provider', \ end
def builds - @running_images = Image.all(:include => :template, :conditions => ['status IN (?)', Image::ACTIVE_STATES]) - @completed_images = Image.all(:include => :template, :conditions => {:status => Image::STATE_COMPLETE}) - @failed_images = Image.all(:include => :template, :conditions => {:status => Image::STATE_FAILED}) + order = get_order('templates.name') + @running_images = Image.all(:include => :template, :conditions => ['status IN (?)', Image::ACTIVE_STATES], :order => order) + @completed_images = Image.all(:include => :template, :conditions => {:status => Image::STATE_COMPLETE}, :order => order) + @failed_images = Image.all(:include => :template, :conditions => {:status => Image::STATE_FAILED}, :order => order) require_privilege(Privilege::IMAGE_VIEW) end
@@ -260,6 +259,12 @@ add account on <a href="#{url_for :controller => 'provider', \
private
+ def get_order(default) + @order_dir = params[:order_dir] == 'desc' ? 'desc' : 'asc' + @order_field = params[:order_field] || default + "#{@order_field} #{@order_dir}" + end + def flash_error(msg) flash.now[:error] ||= {} flash.now[:error][:summary] = 'Error while trying to build image' diff --git a/src/app/views/templates/builds.haml b/src/app/views/templates/builds.haml index e265634..0d2d5ce 100644 --- a/src/app/views/templates/builds.haml +++ b/src/app/views/templates/builds.haml @@ -1,8 +1,8 @@ - columns = [ | - {:name => 'NAME', :sort_attr => 'template.name'}, | - {:name => 'OS', :sort_attr => 'template.platform'}, | - {:name => 'VERSION', :sort_attr => 'template.platform_version'}, | - {:name => 'ARCH', :sort_attr => 'template.architecture'}, | + {:name => 'NAME', :sort_attr => 'templates.name'}, | + {:name => 'OS', :sort_attr => 'templates.platform'}, | + {:name => 'VERSION', :sort_attr => 'templates.platform_version'}, | + {:name => 'ARCH', :sort_attr => 'templates.architecture'}, | {:name => 'STATUS', :sort_attr => 'status'}, | ] |
From: Jan Provaznik jprovazn@redhat.com
--- src/features/step_definitions/template_steps.rb | 19 +++++++++++++++---- src/features/support/paths.rb | 3 +++ src/features/template.feature | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/src/features/step_definitions/template_steps.rb b/src/features/step_definitions/template_steps.rb index c793e01..9d3bd96 100644 --- a/src/features/step_definitions/template_steps.rb +++ b/src/features/step_definitions/template_steps.rb @@ -16,10 +16,10 @@ Given /^There is a mock pulp repository$/ do
end
-Given /^There is a "([^"]*)" template$/ do |name| - @template = Template.new +Given /^there is a "([^"]*)" template$/ do |name| + @template = Factory.build :template @template.xml.name = name - @template.save_xml! + @template.save! end
Given /^there is a package group$/ do @@ -41,7 +41,7 @@ end # web_steps.rb and in this case I have to use @template as parameter which "I # am" doesn't support Given /^I jump on the "([^"]*)" template software page$/ do |name| - visit url_for :action => 'software', :controller => 'templates', :id => @template + visit url_for(:action => 'software', :controller => 'templates', :id => @template) end
Then /^I should have a template named "([^"]*)"$/ do |name| @@ -64,3 +64,14 @@ end Then /^the page should not contain "([^"]*)" selector$/ do |selector| response.should_not have_selector(selector) end + +Then /^I should see "([^"]*)" followed by "([^"]*)"$/ do |arg1, arg2| + # webrat doesn't support checking order of elements on a page, so + # this seems to be siplest check + response.body =~ /#{Regexp.escape(arg1)}.*#{Regexp.escape(arg1)}/ +end + +# FIXME: move this into image_steps when it exists +Given /^there is a "([^"]*)" image$/ do |arg1| + @image = Factory.build :image +end diff --git a/src/features/support/paths.rb b/src/features/support/paths.rb index fdc63f5..198099b 100644 --- a/src/features/support/paths.rb +++ b/src/features/support/paths.rb @@ -68,6 +68,9 @@ module NavigationHelpers when /the new template page/ url_for :action => 'new', :controller => 'templates', :only_path => true
+ when /the template builds page/ + url_for :action => 'builds', :controller => 'templates', :only_path => true + when /the templates page/ templates_path
diff --git a/src/features/template.feature b/src/features/template.feature index 73de5ca..26776ac 100644 --- a/src/features/template.feature +++ b/src/features/template.feature @@ -42,3 +42,21 @@ Feature: Manage Templates Then I should be on the templates page And I should see "Template saved" And I should see "mocktemplate" + + Scenario: Sorting templates + Given there is a "mock1" template + And there is a "mock2" template + And I am on the templates page + When I follow "Name" within ".templates" + Then I should see "mock1" followed by "mock2" + When I follow "Name" within ".templates" + Then I should see "mock2" followed by "mock1" + + Scenario: Sorting template builds + Given there is a "mock1" image + And there is a "mock2" image + And I am on the template builds page + When I follow "Name" + Then I should see "mock1" followed by "mock2" + When I follow "Name" + Then I should see "mock2" followed by "mock1"
deltacloud-devel@lists.fedorahosted.org