[PATCH conductor] Deploaybles and catalog_entries cleanups

jprovazn at redhat.com jprovazn at redhat.com
Fri Dec 2 13:26:41 UTC 2011


From: Jan Provaznik <jprovazn at redhat.com>

This is first try to cleanup deploayble/catalog_entries rename.
TODO: rename locale messages (will be probably separate patch).
---
 src/app/controllers/catalog_entries_controller.rb  |   13 +--
 src/app/controllers/catalogs_controller.rb         |    2 +-
 src/app/controllers/deployables_controller.rb      |  117 ++++++++++----------
 src/app/controllers/images_controller.rb           |    2 +-
 src/app/models/catalog_entry.rb                    |   15 ---
 src/app/models/deployable.rb                       |   20 +++-
 src/app/views/catalogs/show.html.haml              |   28 +++---
 src/app/views/deployables/_form.html.haml          |   35 +++---
 src/app/views/deployables/_from_url.html.haml      |   21 ++--
 src/app/views/deployables/_list.html.haml          |   14 +-
 .../views/deployables/_new_from_image.html.haml    |   14 +-
 src/app/views/deployables/_upload.html.haml        |   29 +++---
 src/app/views/deployables/edit.html.haml           |    8 +-
 src/app/views/deployables/show.html.haml           |   14 +-
 src/config/locales/en.yml                          |    3 +
 src/features/deployables.feature                   |   18 ++--
 src/features/step_definitions/deployable_steps.rb  |   12 +--
 .../controllers/deployables_controller_spec.rb     |    2 +-
 18 files changed, 179 insertions(+), 188 deletions(-)

diff --git a/src/app/controllers/catalog_entries_controller.rb b/src/app/controllers/catalog_entries_controller.rb
index 1d454eb..8f8d9ea 100644
--- a/src/app/controllers/catalog_entries_controller.rb
+++ b/src/app/controllers/catalog_entries_controller.rb
@@ -24,10 +24,10 @@ class CatalogEntriesController < ApplicationController
     require_privilege(Privilege::MODIFY, @catalog_entry.deployable)
 
     if @catalog_entry.save
-      redirect_to catalog_deployable_path(@catalog_entry.catalog, @catalog_entry), :notice => t('catalog_entries.flash.notice.added')
+      redirect_to catalog_deployable_path(@catalog_entry.catalog, @catalog_entry.deployable), :notice => t('catalog_entries.flash.notice.added')
     else
       flash[:warning] = t('catalog_entries.flash.warning.failed')
-      redirect_to catalog_deployable_path(@catalog_entry.catalog, @catalog_entry.deployable.catalog_entries.first)
+      redirect_to catalog_deployable_path(@catalog_entry.catalog, @catalog_entry.deployable)
     end
   end
 
@@ -39,14 +39,7 @@ class CatalogEntriesController < ApplicationController
     require_privilege(Privilege::MODIFY, @catalog_entry.catalog)
     require_privilege(Privilege::MODIFY, @catalog_entry.deployable)
     @catalog_entry.destroy
-
-    if deployable.catalog_entries.empty?
-      redirect_to catalog_path(catalog), :notice => t('catalog_entries.flash.notice.deleted')
-    else
-      catalog_entry_to_nagigate = deployable.catalog_entries.first
-      redirect_to catalog_deployable_path(catalog_entry_to_nagigate.catalog, catalog_entry_to_nagigate), :notice => t('catalog_entries.flash.notice.deleted')
-    end
-
+    redirect_to catalog_deployable_path(catalog, deployable), :notice => t('catalog_entries.flash.notice.deleted')
   end
 
 end
diff --git a/src/app/controllers/catalogs_controller.rb b/src/app/controllers/catalogs_controller.rb
index 6957d1c..8a3d6cd 100644
--- a/src/app/controllers/catalogs_controller.rb
+++ b/src/app/controllers/catalogs_controller.rb
@@ -39,7 +39,7 @@ class CatalogsController < ApplicationController
 
   def show
     @catalog = Catalog.find(params[:id])
-    @catalog_entries = @catalog.catalog_entries.apply_filters(:preset_filter_id => params[:catalog_entries_preset_filter], :search_filter => params[:catalog_entries_search])
+    @deployables = @catalog.deployables.apply_filters(:preset_filter_id => params[:catalog_entries_preset_filter], :search_filter => params[:catalog_entries_search])
     require_privilege(Privilege::VIEW, @catalog)
     save_breadcrumb(catalogs_path(@catalog), @catalog.name)
     @header = [
diff --git a/src/app/controllers/deployables_controller.rb b/src/app/controllers/deployables_controller.rb
index c5e7a4e..a1d7f9b 100644
--- a/src/app/controllers/deployables_controller.rb
+++ b/src/app/controllers/deployables_controller.rb
@@ -23,21 +23,21 @@ class DeployablesController < ApplicationController
   def index
     clear_breadcrumbs
     save_breadcrumb(catalog_deployables_path(:viewstate => @viewstate ? @viewstate.id : nil))
-    @deployables = Deployable.list_for_user(current_user, Privilege::VIEW)
+    @catalog = Catalog.find(params[:catalog_id])
+    @deployables = @catalog.deployables
     @catalog_entries = @deployables.collect { |d| d.catalog_entries.first }
     #@catalog_entries = CatalogEntry.list_for_user(current_user, Privilege::VIEW).apply_filters(:preset_filter_id => params[:catalog_entries_preset_filter], :search_filter => params[:catalog_entries_search])
-    @catalog = @catalog_entries.first.catalog unless @catalog_entries.empty?
     set_header
   end
 
   def new
-    @catalog_entry = params[:catalog_entry].nil? ? CatalogEntry.new() : CatalogEntry.new(params[:catalog_entry])
-    @catalog_entry.deployable = Deployable.new unless @catalog_entry.deployable
+    @deployable = Deployable.new(params[:deployable])
     require_privilege(Privilege::CREATE, Deployable)
     if params[:create_from_image]
       @image = Aeolus::Image::Warehouse::Image.find(params[:create_from_image])
       @hw_profiles = HardwareProfile.frontend.list_for_user(current_user, Privilege::VIEW)
-      @catalog_entry.deployable.name = @image.name
+      @deployable.name = @image.name
+      @selected_catalogs = params[:catalog_id].to_a
       load_catalogs
     else
       @catalog = Catalog.find(params[:catalog_id])
@@ -51,13 +51,14 @@ class DeployablesController < ApplicationController
   end
 
   def show
-    @catalog_entry = CatalogEntry.find(params[:id])
-    require_privilege(Privilege::VIEW, @catalog_entry.deployable)
-    save_breadcrumb(catalog_deployable_path(@catalog_entry.catalog, @catalog_entry), @catalog_entry.deployable.name)
+    @deployable = Deployable.find(params[:id])
+    @catalog = Catalog.find(params[:catalog_id])
+    require_privilege(Privilege::VIEW, @deployable)
+    save_breadcrumb(catalog_deployable_path(@catalog, @deployable), @deployable.name)
     @providers = Provider.all
-    @catalogs_options = Catalog.all.map {|c| [c.name, c.id] unless c == @catalog_entry.catalog}.compact
-    add_permissions_inline(@catalog_entry.deployable)
-    @image_details = @catalog_entry.deployable.get_image_details
+    @catalogs_options = Catalog.all.map {|c| [c.name, c.id] unless c == @catalog}.compact
+    add_permissions_inline(@deployable)
+    @image_details = @deployable.get_image_details
     @image_details.each do |assembly|
       assembly.keys.each do |key|
         flash[:error] = assembly[key] if key.to_s =~ /^error\w+/
@@ -71,69 +72,70 @@ class DeployablesController < ApplicationController
       return
     end
 
-
-    @catalog_entry = CatalogEntry.new(params[:catalog_entry])
-    if params[:create_from_image].present?
-      @catalog = @catalog_entry.catalog
-      @catalog_entry.deployable = Deployable.new unless @catalog_entry.deployable
-    else
-      @catalog = Catalog.find(params[:catalog_id])
-      @catalog_entry.catalog = @catalog
-    end
-    require_privilege(Privilege::MODIFY, @catalog)
     require_privilege(Privilege::CREATE, Deployable)
-    @catalog_entry.deployable.owner = current_user
+    @deployable = Deployable.new(params[:deployable])
+    @selected_catalogs = Catalog.find(params[:catalog_id]).to_a
+    @deployable.owner = current_user
 
     if params.has_key? :url
         xml = import_xml_from_url(params[:url])
         unless xml.nil?
           #store xml_filename for url (i.e. url ends to: foo || foo.xml)
-          @catalog_entry.deployable.xml_filename =  File.basename(URI.parse(params[:url]).path)
-          @catalog_entry.deployable.xml = xml
+          @deployable.xml_filename =  File.basename(URI.parse(params[:url]).path)
+          @deployable.xml = xml
         end
     elsif params[:create_from_image].present?
       hw_profile = HardwareProfile.frontend.find(params[:hardware_profile])
       require_privilege(Privilege::VIEW, hw_profile)
-      @catalog_entry.deployable.set_from_image(params[:create_from_image], hw_profile)
+      @deployable.set_from_image(params[:create_from_image], hw_profile)
     end
 
-    if @catalog_entry.save
-      flash[:notice] = t "catalog_entries.flash.notice.added"
-      if params[:edit_xml]
-        redirect_to edit_catalog_deployable_path @catalog_entry.catalog.id, @catalog_entry.id, :edit_xml =>true
-      else
-        redirect_to catalog_deployables_path(@catalog)
+    begin
+      raise t("deployables.flash.error.no_catalog") if @selected_catalogs.empty?
+      @deployable.transaction do
+        @deployable.save!
+        @selected_catalogs.each do |catalog|
+          require_privilege(Privilege::MODIFY, catalog)
+          CatalogEntry.create!(:catalog_id => catalog.id, :deployable_id => @deployable.id)
+        end
+        flash[:notice] = t "catalog_entries.flash.notice.added"
+        if params[:edit_xml]
+          redirect_to edit_catalog_deployable_path @selected_catalogs.first, @deployable.id, :edit_xml =>true
+        else
+          redirect_to catalog_deployables_path(@selected_catalogs.first)
+        end
       end
-    else
-      flash[:warning]= t('catalog_entries.flash.warning.not_valid') if @catalog_entry.errors.has_key?(:xml)
+    rescue => e
+      flash[:warning]= t('deployables.flash.warning.failed', :message => e.message)
+      flash[:warning]= t('catalog_entries.flash.warning.not_valid') if @deployable.errors.has_key?(:xml)
       if params[:create_from_image].present?
         load_catalogs
         @image = Aeolus::Image::Warehouse::Image.find(params[:create_from_image])
         @hw_profiles = HardwareProfile.frontend.list_for_user(current_user, Privilege::VIEW)
-        @catalog_entry.deployable.name = @image.name
+        @deployable.name = @image.name
       else
+        @catalog = @selected_catalogs.first
         params.delete(:edit_xml) if params[:edit_xml]
-        @form_option = params[:catalog_entry].has_key?(:xml) ? 'upload' : 'from_url'
-        @form_option = params[:catalog_entry][:deployable].has_key?(:xml) ? 'upload' : 'from_url'
+        @form_option = params[:deployable].has_key?(:xml) ? 'upload' : 'from_url'
       end
       render :new
     end
   end
 
   def edit
-    @catalog_entry = CatalogEntry.find(params[:id])
-    require_privilege(Privilege::MODIFY, @catalog_entry.deployable)
-    @catalog = @catalog_entry.catalog
+    @deployable = Deployable.find(params[:id])
+    require_privilege(Privilege::MODIFY, @deployable)
+    @catalog = Catalog.find(params[:catalog_id])
   end
 
   def update
-    @catalog_entry = CatalogEntry.find(params[:id])
-    require_privilege(Privilege::MODIFY, @catalog_entry.deployable)
-    params[:catalog_entry][:deployable].delete(:owner_id) if params[:catalog_entry] and params[:catalog_entry][:deployable]
+    @deployable = Deployable.find(params[:id])
+    require_privilege(Privilege::MODIFY, @deployable)
+    params[:deployable].delete(:owner_id) if params[:deployable]
 
-    if @catalog_entry.update_attributes(params[:catalog_entry])
+    if @deployable.update_attributes(params[:deployable])
       flash[:notice] = t"catalog_entries.flash.notice.updated"
-      redirect_to catalog_deployable_path(@catalog_entry.catalog, @catalog_entry)
+      redirect_to catalog_deployable_path(params[:catalog_id], @deployable)
     else
       render :action => 'edit'
     end
@@ -141,28 +143,25 @@ class DeployablesController < ApplicationController
 
   def multi_destroy
     @catalog = nil
-    CatalogEntry.find(params[:catalog_entries_selected]).to_a.each do |d|
-      require_privilege(Privilege::MODIFY, d.catalog)
-      require_privilege(Privilege::MODIFY, d.deployable)
-      @catalog = d.catalog
-      # Don't do this when we're managing deployables independently
-      d.deployable.destroy
+    Deployable.find(params[:deployables_selected]).to_a.each do |d|
+      # TODO: delete only in catalogs where I have permission to
+      #require_privilege(Privilege::MODIFY, d.catalog)
+      require_privilege(Privilege::MODIFY, d)
+      #@catalog = d.catalog
       d.destroy
     end
-    redirect_to catalog_path(@catalog)
+    redirect_to catalog_path(params[:catalog_id])
   end
 
   def destroy
-    catalog_entry = CatalogEntry.find(params[:id])
-    require_privilege(Privilege::MODIFY, catalog_entry.catalog)
-    require_privilege(Privilege::MODIFY, catalog_entry.deployable)
-    @catalog = catalog_entry.catalog
-    # Don't do this when we're managing deployables independently
-    catalog_entry.deployable.destroy
-    catalog_entry.destroy
+    deployable = Deployable.find(params[:id])
+    # TODO: delete only in catalogs where I have permission to
+    #require_privilege(Privilege::MODIFY, catalog_entry.catalog)
+    require_privilege(Privilege::MODIFY, deployable)
+    deployable.destroy
 
     respond_to do |format|
-      format.html { redirect_to catalog_path(@catalog) }
+      format.html { redirect_to catalog_path(params[:catalog_id]) }
     end
   end
 
diff --git a/src/app/controllers/images_controller.rb b/src/app/controllers/images_controller.rb
index 3560640..e951059 100644
--- a/src/app/controllers/images_controller.rb
+++ b/src/app/controllers/images_controller.rb
@@ -172,7 +172,7 @@ class ImagesController < ApplicationController
     })
     flash.now[:error] = t('images.flash.notice.created')
     if params[:make_deployable]
-      redirect_to new_catalog_entry_path(:create_from_image => @image.id)
+      redirect_to new_deployable_path(:create_from_image => @image.id)
     else
       redirect_to image_path(@image.id)
     end
diff --git a/src/app/models/catalog_entry.rb b/src/app/models/catalog_entry.rb
index 21a8b9b..2ea3a3c 100644
--- a/src/app/models/catalog_entry.rb
+++ b/src/app/models/catalog_entry.rb
@@ -29,10 +29,6 @@
 #
 
 class CatalogEntry < ActiveRecord::Base
-  class << self
-    include CommonFilterMethods
-  end
-
   belongs_to :catalog
   belongs_to :deployable
 
@@ -43,15 +39,4 @@ class CatalogEntry < ActiveRecord::Base
 
   # This probably goes away once we separate catalog entry creation from deployables
   accepts_nested_attributes_for :deployable
-  PRESET_FILTERS_OPTIONS = []
-
-  private
-
-  def self.apply_search_filter(search)
-    if search
-      where("name ILIKE :search", :search => "%#{search}%")
-    else
-      scoped
-    end
-  end
 end
diff --git a/src/app/models/deployable.rb b/src/app/models/deployable.rb
index be553e7..2a568ac 100644
--- a/src/app/models/deployable.rb
+++ b/src/app/models/deployable.rb
@@ -17,6 +17,11 @@
 # also available at http://www.gnu.org/copyleft/gpl.html.
 
 class Deployable < ActiveRecord::Base
+  class << self
+    include CommonFilterMethods
+  end
+
+
   include PermissionedObject
 
   validates_presence_of :name
@@ -29,12 +34,14 @@ class Deployable < ActiveRecord::Base
   has_many :permissions, :as => :permission_object, :dependent => :destroy,
            :include => [:role],
            :order => "permissions.id ASC"
-  has_many :catalog_entries
+  has_many :catalog_entries, :dependent => :destroy
   has_many :catalogs, :through => :catalog_entries
 
   belongs_to :owner, :class_name => "User", :foreign_key => "owner_id"
   after_create "assign_owner_roles(owner)"
 
+  PRESET_FILTERS_OPTIONS = []
+
   def valid_deployable_xml?
     deployable_xml = DeployableXML.new(xml)
     unless deployable_xml.validate!
@@ -135,4 +142,15 @@ class Deployable < ActiveRecord::Base
     #returned value [{:name => 'assembly1',{:hwp => {...}}, {:error => "msg"}, {assembly3} ..]
     result_array
   end
+
+  private
+
+  def self.apply_search_filter(search)
+    if search
+      where("name ILIKE :search", :search => "%#{search}%")
+    else
+      scoped
+    end
+  end
+
 end
diff --git a/src/app/views/catalogs/show.html.haml b/src/app/views/catalogs/show.html.haml
index 1dd4259..b4433f8 100644
--- a/src/app/views/catalogs/show.html.haml
+++ b/src/app/views/catalogs/show.html.haml
@@ -21,33 +21,33 @@
   .content
     - content_for :form_header do
       %li= restful_submit_tag t("delete"), "destroy", multi_destroy_catalog_deployables_path(@catalog), 'DELETE', :id => 'delete_button', :class => 'button danger'
-      %li= link_to t("catalog_entries.new_catalog_entry"), new_catalog_deployable_path(@catalog), :class => 'button', :id => 'new_catalog_entry_button'
+      %li= link_to t("catalog_entries.new_catalog_entry"), new_catalog_deployable_path(@catalog), :class => 'button', :id => 'new_deployablesutton'
 
     - content_for :filter_controls do
       %li
-        = label_tag :catalog_entries_preset_filter, t('filter_table.viewing')
+        = label_tag :deployables_preset_filter, t('filter_table.viewing')
         = hidden_field_tag :current_path, request.fullpath
-        = select_tag(:catalog_entries_preset_filter, preset_filters_options_for_select(CatalogEntry::PRESET_FILTERS_OPTIONS, params[:catalog_entries_preset_filter]), :include_blank => t("catalog_entries.preset_filters.all_catalog_entries"), :disabled => true)
-        = restful_submit_tag t("filter_table.apply_filters"), "filter", filter_catalog_deployables_path(@catalog), 'POST', :class => 'button', :id => 'apply_catalog_entries_preset_filter'
-        %span.label.badge.dark= @catalog_entries.count
+        = select_tag(:deployables_preset_filter, preset_filters_options_for_select(Deployable::PRESET_FILTERS_OPTIONS, params[:deployables_preset_filter]), :include_blank => t("catalog_entries.preset_filters.all_catalog_entries"), :disabled => true)
+        = restful_submit_tag t("filter_table.apply_filters"), "filter", filter_catalog_deployables_path(@catalog), 'POST', :class => 'button', :id => 'apply_deployables_preset_filter'
+        %span.label.badge.dark= @deployables.count
       %li.table-search-filter
-        = text_field_tag :catalog_entries_search, params[:catalog_entries_search], :placeholder => t("filter_table.search")
-        = restful_submit_tag "", "search", filter_catalog_deployables_path(@catalog), 'POST', :class => 'button', :id => 'apply_catalog_entries_search'
+        = text_field_tag :deployables_search, params[:deployables_search], :placeholder => t("filter_table.search")
+        = restful_submit_tag "", "search", filter_catalog_deployables_path(@catalog), 'POST', :class => 'button', :id => 'apply_deployables_search'
 
       :javascript
         $(document).ready(function(){
-          $("#apply_catalog_entries_preset_filter").hide();
-          $("#catalog_entries_preset_filter").change(function() {
-            $("#apply_catalog_entries_preset_filter").click();
+          $("#apply_deployables_preset_filter").hide();
+          $("#deployables_preset_filter").change(function() {
+            $("#apply_deployables_preset_filter").click();
           });
         });
 
-    = filter_table(@header, @catalog_entries) do |catalog_entry|
+    = filter_table(@header, @deployables) do |deployable|
       %tr{:class => cycle('nostripe','stripe')}
         %td{:class => 'checkbox'}
           - selected = params[:select] == 'all'
-          = check_box_tag "catalog_entries_selected[]", catalog_entry.id, selected, :id => "catalog_entry_checkbox_#{catalog_entry.id}"
+          = check_box_tag "deployables_selected[]", deployable.id, selected, :id => "deployable_checkbox_#{deployable.id}"
         %td
-          = link_to catalog_entry.deployable.name, catalog_deployable_path(@catalog, catalog_entry)
+          = link_to deployable.name, catalog_deployable_path(@catalog, deployable)
         %td
-          = link_to catalog_entry.deployable.xml_filename, catalog_deployable_path(@catalog, catalog_entry, :deployable_xml => true)
+          = link_to deployable.xml_filename, catalog_deployable_path(@catalog, deployable, :deployable_xml => true)
diff --git a/src/app/views/deployables/_form.html.haml b/src/app/views/deployables/_form.html.haml
index d638684..fa6ec32 100644
--- a/src/app/views/deployables/_form.html.haml
+++ b/src/app/views/deployables/_form.html.haml
@@ -1,26 +1,25 @@
-- if @catalog_entry.errors.any?
-  = render 'layouts/error_messages', :object => @catalog_entry
+- if @deployable.errors.any?
+  = render 'layouts/error_messages', :object => @deployable
 %fieldset
-  - if params[:edit_xml]
-    = form.fields_for :deployable, @catalog_entry.deployable do |deployable_fields|
+  = form_for @deployable do |form|
+    - if params[:edit_xml]
       %p
-        = deployable_fields.label :xml, t('.deployable_xml')
-        = deployable_fields.text_area :xml, :class => 'long'
-  - else
-    %p
-      = form.label :catalog_id, t('catalog_entries.form.catalog')
-      = @catalog ? @catalog.name : @catalog_entry.catalog.name
-      .clear
-    = form.fields_for :deployable, @catalog_entry.deployable do |deployable_fields|
+        = form.label :xml, t('.deployable_xml')
+        = form.text_area :xml, :class => 'long'
+    - else
       %p
-        = deployable_fields.label :name, t('catalog_entries.index.name')
-        = deployable_fields.text_field :name, :class => 'em long'
+        = label_tag :catalog_id, t('catalog_entries.form.catalog')
+        = @catalog.name
+        .clear
       %p
-        = deployable_fields.label :description, t('.description')
-        = deployable_fields.text_area :description, :class => 'long'
+        = form.label :name, t('catalog_entries.index.name')
+        = form.text_field :name, :class => 'em long'
       %p
-        = deployable_fields.label :xml, t('.deployable_xml')
-        = link_to t("catalog_entries.properties.edit_deployable_xml"), edit_catalog_deployable_path(@catalog_entry.catalog.id, @catalog_entry.id, :edit_xml=>true)
+        = form.label :description, t('.description')
+        = form.text_area :description, :class => 'long'
+      %p
+        = form.label :xml, t('.deployable_xml')
+        = link_to t("catalog_entries.properties.edit_deployable_xml"), edit_catalog_deployable_path(@catalog.id, @deployable.id, :edit_xml=>true)
 
 %fieldset.options
   = link_to t('cancel'), catalog_path(@catalog), :class => 'button danger'
diff --git a/src/app/views/deployables/_from_url.html.haml b/src/app/views/deployables/_from_url.html.haml
index 22b0099..d351ecb 100644
--- a/src/app/views/deployables/_from_url.html.haml
+++ b/src/app/views/deployables/_from_url.html.haml
@@ -1,19 +1,18 @@
-= form_for @catalog_entry, :url => catalog_deployables_path(@catalog), :html => {:class => 'generic', :multipart => true } do |form|
-  - if @catalog_entry.errors.any?
-    = render 'layouts/error_messages', :object => @catalog_entry
+= form_for @deployable, :url => catalog_deployables_path(@catalog), :html => {:class => 'generic', :multipart => true } do |form|
+  - if @deployable.errors.any?
+    = render 'layouts/error_messages', :object => @deployable
   %fieldset
     %p
       = form.label :catalog_id, t('catalog_entries.form.catalog')
       %span.text_instead_input= @catalog.name
       .clear
-  =form.fields_for :deployable, @catalog_entry.deployable do |deployable_fields|
-    %fieldset
-      %p
-        = deployable_fields.label :name, t('catalog_entries.index.name')
-        = deployable_fields.text_field :name, :class => 'em long'
-      %p
-        = deployable_fields.label :description, t('catalog_entries.form.description')
-        = deployable_fields.text_area :description, :class => 'long'
+  %fieldset
+    %p
+      = form.label :name, t('catalog_entries.index.name')
+      = form.text_field :name, :class => 'em long'
+    %p
+      = form.label :description, t('catalog_entries.form.description')
+      = form.text_area :description, :class => 'long'
   %fieldset
     %p
       = label_tag :url, t('catalog_entries.form.deployable_xml_url')
diff --git a/src/app/views/deployables/_list.html.haml b/src/app/views/deployables/_list.html.haml
index 117e636..55bf664 100644
--- a/src/app/views/deployables/_list.html.haml
+++ b/src/app/views/deployables/_list.html.haml
@@ -10,9 +10,9 @@
       %li
         = label_tag :catalog_entries_preset_filter, t('filter_table.viewing')
         = hidden_field_tag :current_path, request.fullpath
-        = select_tag(:catalog_entries_preset_filter, preset_filters_options_for_select(CatalogEntry::PRESET_FILTERS_OPTIONS, params[:catalog_entries_preset_filter]), :include_blank => t("catalog_entries.preset_filters.all_catalog_entries"), :disabled => true)
+        = select_tag(:catalog_entries_preset_filter, preset_filters_options_for_select(Deployable::PRESET_FILTERS_OPTIONS, params[:catalog_entries_preset_filter]), :include_blank => t("catalog_entries.preset_filters.all_catalog_entries"), :disabled => true)
         = restful_submit_tag t("filter_table.apply_filters"), "filter", filter_catalog_deployables_path(@catalog), 'POST', :class => 'button', :id => 'apply_catalog_entries_preset_filter'
-        %span.label.badge.dark= @catalog_entries.count
+        %span.label.badge.dark= @deployables.count
       %li.table-search-filter
         = text_field_tag :catalog_entries_search, params[:catalog_entries_search], :placeholder => t("filter_table.search")
         = restful_submit_tag "", "search", filter_catalog_deployables_path(@catalog), 'POST', :class => 'button', :id => 'apply_catalog_entries_search'
@@ -25,14 +25,14 @@
           });
         });
 
-    = filter_table(@header, @catalog_entries) do |catalog_entry|
+    = filter_table(@header, @deployables) do |deployable|
       %tr{:class => cycle('nostripe','stripe')}
         %td{:class => 'checkbox'}
           - selected = params[:select] == 'all'
-          = check_box_tag "catalog_entries_selected[]", catalog_entry.id, selected, :id => "catalog_entry_checkbox_#{catalog_entry.id}"
+          = check_box_tag "deployables_selected[]", deployable.id, selected, :id => "deployable_checkbox_#{deployable.id}"
         %td
-          = link_to catalog_entry.deployable.name, catalog_deployable_path(@catalog, catalog_entry.id)
+          = link_to deployable.name, catalog_deployable_path(@catalog, deployable.id)
         %td
-          = link_to catalog_entry.catalog.name, catalog_entry.catalog
+          = link_to @catalog.name, @catalog
         %td
-          = link_to catalog_entry.deployable.xml_filename, catalog_deployable_path(@catalog, catalog_entry.id)
+          = link_to deployable.xml_filename, catalog_deployable_path(@catalog, deployable.id)
diff --git a/src/app/views/deployables/_new_from_image.html.haml b/src/app/views/deployables/_new_from_image.html.haml
index f546698..2e1b285 100644
--- a/src/app/views/deployables/_new_from_image.html.haml
+++ b/src/app/views/deployables/_new_from_image.html.haml
@@ -1,12 +1,12 @@
 %header.admin-page-header
-  %h1.deployables= t('.catalog_entry_name', :name => @catalog_entry.deployable.name)
+  %h1.deployables= t('.catalog_entry_name', :name => @deployable.name)
 
 %section.admin-content-section
   .content.buildpush
-    = form_for @catalog_entry, :html => {:class => 'generic'} do |form|
+    = form_for @deployable, :html => {:class => 'generic'} do |form|
       = hidden_field_tag :create_from_image, params[:create_from_image]
-      - if @catalog_entry.errors.any?
-        = render 'layouts/error_messages', :object => @catalog_entry
+      - if @deployable.errors.any?
+        = render 'layouts/error_messages', :object => @deployable
       .lefted.new-catalog-entry-from-image
         %h2= t('.title')
         %p= t('.description', :name => @image.name)
@@ -17,8 +17,8 @@
             .clear
           %div
             = form.label :catalog_id, t('catalog_entries.form.catalog')
-            = form.select :catalog_id, @catalogs.collect{|c| [c.name, c.id]}
-            %span.text_instead_input= "Catalog1"
+            /= form.select :catalog_id, @catalogs.collect{|c| [c.name, c.id]}
+            %span.text_instead_input= @selected_catalogs.empty? ? t('deployables.form.none') : @selected_catalogs.count > 1 ? t('deployables.form.multiple') : @selected_catalogs.first.name
             %span.catalog_link
               &nbsp
               %div.catalog_list
@@ -26,7 +26,7 @@
                   - @catalogs.each do |catalog|
                     %li.catalog
                       .catalog_with_checkbox
-                        = check_box_tag :catalog_ids
+                        = check_box_tag 'catalog_id[]', catalog.id, @selected_catalogs.any?{|c| c.id == catalog.id}
                         = catalog.name
                         .clear
             .clear
diff --git a/src/app/views/deployables/_upload.html.haml b/src/app/views/deployables/_upload.html.haml
index 475d492..6afaa8f 100644
--- a/src/app/views/deployables/_upload.html.haml
+++ b/src/app/views/deployables/_upload.html.haml
@@ -1,22 +1,21 @@
-= form_for @catalog_entry, :url => catalog_deployables_path(@catalog), :html => {:class => 'generic', :multipart => true } do |form|
-  - if @catalog_entry.errors.any?
-    = render 'layouts/error_messages', :object => @catalog_entry
+= form_for @deployable, :url => catalog_deployables_path(@catalog), :html => {:class => 'generic', :multipart => true } do |form|
+  - if @deployable.errors.any?
+    = render 'layouts/error_messages', :object => @deployable
   %fieldset
     %p
-      = form.label :catalog_id, t('catalog_entries.form.catalog')
+      = label_tag :catalog_id, t('catalog_entries.form.catalog')
       %span.text_instead_input= @catalog.name
       .clear
-  = form.fields_for :deployable, @catalog_entry.deployable do |deployable_fields|
-    %fieldset
-      %p
-        = deployable_fields.label :name, t('catalog_entries.index.name')
-        = deployable_fields.text_field :name, :class => 'em long'
-      %p
-        = deployable_fields.label :description, t('catalog_entries.form.description')
-        = deployable_fields.text_area :description, :class => 'long'
-      %p
-        = deployable_fields.label :xml, t('catalog_entries.form.choose_xml')
-        = deployable_fields.file_field :xml
+  %fieldset
+    %p
+      = form.label :name, t('catalog_entries.index.name')
+      = form.text_field :name, :class => 'em long'
+    %p
+      = form.label :description, t('catalog_entries.form.description')
+      = form.text_area :description, :class => 'long'
+    %p
+      = form.label :xml, t('catalog_entries.form.choose_xml')
+      = form.file_field :xml
   %fieldset
     %p
       = check_box_tag(:edit_xml, true, false)
diff --git a/src/app/views/deployables/edit.html.haml b/src/app/views/deployables/edit.html.haml
index e76b3e2..942f422 100644
--- a/src/app/views/deployables/edit.html.haml
+++ b/src/app/views/deployables/edit.html.haml
@@ -1,15 +1,15 @@
 = render :partial => 'layouts/admin_nav'
 %header.admin-page-header
-  %h1{:class => controller.controller_name}= @catalog_entry.deployable.name
+  %h1{:class => controller.controller_name}= @deployable.name
   #obj_actions.button-container
-    = link_to 'New Deployable', new_catalog_deployable_path(@catalog_entry.catalog, @catalog_entry), :class => 'button primary', :id => 'new_deployable_button'
+    = link_to 'New Deployable', new_catalog_deployable_path(@catalog, @deployable), :class => 'button primary', :id => 'new_deployable_button'
     .button-group
-      = link_to 'Cancel Editing', catalog_deployables_path(@catalog_entry.catalog), :class => 'button pill danger', :id => 'new_deployable_button'
+      = link_to 'Cancel Editing', catalog_deployables_path(@catalog), :class => 'button pill danger', :id => 'new_deployable_button'
 
 %section.admin-content-section.user
   %header
     %h2=t'catalog_entries.edit.editing_catalog_entry'
 
   .content
-    = form_for @catalog_entry, :url => catalog_deployable_path(@catalog_entry.catalog, @catalog_entry), :html => { :method => :put, :class => 'generic' } do |f|
+    = form_for @deployable, :url => catalog_deployable_path(@catalog, @deployable), :html => { :method => :put, :class => 'generic' } do |f|
       = render :partial => "form", :locals => { :form => f }
diff --git a/src/app/views/deployables/show.html.haml b/src/app/views/deployables/show.html.haml
index 1eab46e..e09f4bf 100644
--- a/src/app/views/deployables/show.html.haml
+++ b/src/app/views/deployables/show.html.haml
@@ -1,12 +1,12 @@
 = render :partial => 'layouts/admin_nav'
 %header.admin-page-header
-  %h1{:class => controller.controller_name}= @catalog_entry.deployable.name
+  %h1{:class => controller.controller_name}= @deployable.name
   #obj_actions.button-container
     .button-group
-      = button_to t('catalog_entries.show.delete'), catalog_deployable_path(@catalog_entry.catalog, @catalog_entry), :method => 'delete', :confirm => "#{t'catalog_entries.show.confirm_delete'}", :class => 'button danger', :id => 'delete'
-      = link_to t('catalog_entries.show.edit'), edit_catalog_deployable_path(@catalog_entry.catalog, @catalog_entry), :class => 'button', :id => 'edit_button'
+      = button_to t('catalog_entries.show.delete'), catalog_deployable_path(@catalog, @deployable), :method => 'delete', :confirm => "#{t'catalog_entries.show.confirm_delete'}", :class => 'button danger', :id => 'delete'
+      = link_to t('catalog_entries.show.edit'), edit_catalog_deployable_path(@catalog, @deployable), :class => 'button', :id => 'edit_button'
 
-    = link_to t('deployments.overview.launch'), launch_new_deployments_path(:deployable_id => @catalog_entry.deployable.id, :pool_id => @catalog_entry.catalog.pool), :id => :launch_deployment
+    = link_to t('deployments.overview.launch'), launch_new_deployments_path(:deployable_id => @deployable.id, :pool_id => @catalog.pool), :id => :launch_deployment
 
 %section.admin-content-section.deployable
   %section.image
@@ -61,7 +61,7 @@
       %p= t('.choose_catalog')
       = form_for(:catalog_entry, :url => catalog_entries_path) do |f|
         = f.select :catalog_id, options_for_select(@catalogs_options)
-        = f.hidden_field(:deployable_id, :value => @catalog_entry.deployable.id)
+        = f.hidden_field(:deployable_id, :value => @deployable.id)
         = f.submit t('catalog_entries.show.add_catalog'), :id => :add_catalog
 
       %table
@@ -70,10 +70,10 @@
             %label= t('.catalog_name')
           %th
             %label= t('.environment')
-        - @catalog_entry.deployable.catalog_entries.each do |catalog_entry|
+        - @deployable.catalog_entries.each do |catalog_entry|
           %tr
             %td
-              = button_to t('catalog_entries.show.delete'), catalog_entry_path(@catalog_entry), :method => 'delete', :confirm => "#{t'catalog_entries.show.confirm_delete'}", :id => 'delete'
+              = button_to t('catalog_entries.show.delete'), catalog_entry_path(catalog_entry), :method => 'delete', :confirm => "#{t'catalog_entries.show.confirm_delete'}", :id => 'delete'
               = catalog_entry.catalog.name
             %td= catalog_entry.catalog.pool.pool_family.name
 
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
index 64512ec..e45d743 100644
--- a/src/config/locales/en.yml
+++ b/src/config/locales/en.yml
@@ -786,6 +786,9 @@ en:
     flash:
       error:
         attribute_not_exist: "Some attribute(s) is missing in XML, please check the file!"
+        no_catalog: "No catalogs selected"
+      warning:
+        failed: "Deployable was not created: %{message}"
     error:
       attribute_not_exists: invalid
       hwp_not_exists: "Hardware profile %{name} doesn't exist in DB"
diff --git a/src/features/deployables.feature b/src/features/deployables.feature
index d950c50..f551a14 100644
--- a/src/features/deployables.feature
+++ b/src/features/deployables.feature
@@ -13,27 +13,27 @@ Feature: Manage Catalog Entries
     Then I should see "Catalog Entries"
     When I follow "new_catalog_entry_button"
     Then I should see "Add New Catalog Entry"
-    When I fill in "catalog_entry[deployable_attributes][name]" with "test1"
-    And I fill in "catalog_entry[deployable_attributes][description]" with "description"
-    When I attach the file "features/upload_files/deployable.xml" to "catalog_entry[deployable_attributes][xml]"
+    When I fill in "deployable[name]" with "test1"
+    And I fill in "deployable[description]" with "description"
+    When I attach the file "features/upload_files/deployable.xml" to "deployable[xml]"
     And I press "save_button"
     Then I should see "Catalog entry added"
 
   Scenario: Change the name
     Given there is a "default" catalog
-    And a catalog entry "testdepl" exists
+    And a catalog entry "testdepl" exists for "default" catalog
     When I am on the "default" catalog catalog entries page
     When I follow "testdepl"
     And I follow "edit_button"
     Then I should see "Editing Catalog Entry"
-    When I fill in "catalog_entry[deployable_attributes][name]" with "testdepl-renamed"
+    When I fill in "deployable[name]" with "testdepl-renamed"
     And I press "save_button"
     Then I should see "Catalog entry updated successfully!"
     And I should see "testdepl-renamed"
 
   Scenario: Show catalog entry details
     Given there is a "default" catalog
-    And a catalog entry "testdepl" exists
+    And a catalog entry "testdepl" exists for "default" catalog
     And I am on the "default" catalog catalog entries page
     When I follow "testdepl"
     Then I should see "testdepl"
@@ -44,7 +44,7 @@ Feature: Manage Catalog Entries
 
   Scenario: Launch  a deployment
     Given there is a "default" catalog
-    And a catalog entry "testdepl" exists
+    And a catalog entry "testdepl" exists for "default" catalog
     And I am on testdepl's catalog entry page
     When I follow "launch_deployment"
     Then I should be on the launch new deployments page
@@ -57,7 +57,7 @@ Feature: Manage Catalog Entries
     When I check "testdepl1" catalog entry
     And I check "testdepl2" catalog entry
     And I press "delete_button"
-    Then there should be only 0 catalog entries
+    Then there should be only 0 catalog entries for "default" catalog
     And I should be on the "default" catalog page
     And I should not see "testdepl1"
     And I should not see "testdepl2"
@@ -68,7 +68,7 @@ Feature: Manage Catalog Entries
     And I am on the "default" catalog page
     When I follow "testdepl1"
     And I press "delete"
-    Then there should be only 0 catalog entries
+    Then there should be only 0 catalog entries for "default" catalog
     And I should be on the "default" catalog page
     And I should not see "testdepl1"
 
diff --git a/src/features/step_definitions/deployable_steps.rb b/src/features/step_definitions/deployable_steps.rb
index 73bf7be..62e45ee 100644
--- a/src/features/step_definitions/deployable_steps.rb
+++ b/src/features/step_definitions/deployable_steps.rb
@@ -1,15 +1,11 @@
-Given /^a catalog entry "([^"]*)" exists$/ do |arg1|
-  deployable = FactoryGirl.create :deployable, :name => arg1
-  entry = FactoryGirl.create :catalog_entry, :deployable => deployable
-end
-
 When /^I check "([^"]*)" catalog entry$/ do |arg1|
   dep = CatalogEntry.find_by_deployable_id(Deployable.find_by_name(arg1))
-  check("catalog_entry_checkbox_#{dep.id}")
+  check("deployable_checkbox_#{dep.id}")
 end
 
-Then /^there should be only (\d+) catalog entries$/ do |arg1|
-  CatalogEntry.count.should == arg1.to_i
+Then /^there should be only (\d+) catalog entries for "([^"]*)" catalog$/ do |arg1, catalog_name|
+  catalog = Catalog.find_by_name(catalog_name) || FactoryGirl.create(:catalog, :name => catalog_name)
+  catalog.catalog_entries.count.should == arg1.to_i
 end
 
 Given /^a catalog entry "([^"]*)" exists for "([^"]*)" catalog$/ do |arg1, catalog_name|
diff --git a/src/spec/controllers/deployables_controller_spec.rb b/src/spec/controllers/deployables_controller_spec.rb
index eb0a6f8..09d1917 100644
--- a/src/spec/controllers/deployables_controller_spec.rb
+++ b/src/spec/controllers/deployables_controller_spec.rb
@@ -39,7 +39,7 @@ describe DeployablesController do
     hw_profile = FactoryGirl.create(:front_hwp1)
     catalog = FactoryGirl.create(:catalog)
     mock_warden(@admin)
-    post(:create, :create_from_image => @image.id, :hardware_profile => hw_profile.id, :catalog_entry => {:catalog_id => catalog.id})
+    post(:create, :create_from_image => @image.id, :hardware_profile => hw_profile.id, :catalog_id => catalog.id)
     response.should redirect_to(catalog_deployables_url(catalog.id))
   end
 
-- 
1.7.6




More information about the aeolus-devel mailing list