From 8838cfb0864458dc7efd834d026a63ff12a17f32 Mon Sep 17 00:00:00 2001
From: JoenioCosta
Date: Fri, 6 Jun 2008 17:52:34 +0000
Subject: [PATCH] ActionItem328: move consumed_products actions to manage_products
---
app/controllers/my_profile/consumed_products_controller.rb | 33 ---------------------------------
app/controllers/my_profile/manage_products_controller.rb | 35 +++++++++++++++++++++++++++++++++++
app/views/consumed_products/index.rhtml | 12 ------------
app/views/consumed_products/new.rhtml | 17 -----------------
app/views/manage_products/edit_consumption.rhtml | 3 +++
app/views/manage_products/index.rhtml | 47 +++++++++++++++++++++++++++++++++++++++++------
app/views/manage_products/new_consumption.rhtml | 3 +++
app/views/profile_editor/index.rhtml | 2 --
test/functional/consumed_products_controller_test.rb | 67 -------------------------------------------------------------------
test/functional/manage_products_controller_test.rb | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
10 files changed, 130 insertions(+), 137 deletions(-)
delete mode 100644 app/controllers/my_profile/consumed_products_controller.rb
delete mode 100644 app/views/consumed_products/index.rhtml
delete mode 100644 app/views/consumed_products/new.rhtml
create mode 100644 app/views/manage_products/edit_consumption.rhtml
create mode 100644 app/views/manage_products/new_consumption.rhtml
delete mode 100644 test/functional/consumed_products_controller_test.rb
diff --git a/app/controllers/my_profile/consumed_products_controller.rb b/app/controllers/my_profile/consumed_products_controller.rb
deleted file mode 100644
index 8f3e8cc..0000000
--- a/app/controllers/my_profile/consumed_products_controller.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-class ConsumedProductsController < ApplicationController
- needs_profile
-
- protect 'manage_products', :profile
-
- def index
- @consumptions = @profile.consumptions
- @product_categories = @profile.consumed_product_categories
- end
-
- def new
- @consumption = @profile.consumptions.build(params[:consumption])
- if request.post?
- if @consumption.save
- flash[:notice] = _('Product succesfully created')
- redirect_to :action => 'index'
- else
- flash[:notice] = _('Could not create the product')
- end
- end
- end
-
- def destroy
- @consumption = @profile.consumptions.find(params[:id])
- if @consumption.destroy
- flash[:notice] = _('Product succesfully removed')
- else
- flash[:notice] = _('Could not remove the product')
- end
- redirect_back_or_default :action => 'index'
- end
-
-end
diff --git a/app/controllers/my_profile/manage_products_controller.rb b/app/controllers/my_profile/manage_products_controller.rb
index 99cdaa6..993ccda 100644
--- a/app/controllers/my_profile/manage_products_controller.rb
+++ b/app/controllers/my_profile/manage_products_controller.rb
@@ -5,6 +5,7 @@ class ManageProductsController < ApplicationController
def index
@products = @profile.products
+ @consumptions = @profile.consumptions
end
def show
@@ -56,5 +57,39 @@ class ManageProductsController < ApplicationController
@categories = @current_category.children
render :partial => 'subcategories'
end
+
+ def new_consumption
+ @consumption = @profile.consumptions.build(params[:consumption])
+ if request.post?
+ if @consumption.save
+ flash[:notice] = _('Product succesfully created')
+ redirect_to :action => 'index'
+ else
+ flash[:notice] = _('Could not create the product')
+ end
+ end
+ end
+
+ def destroy_consumption
+ @consumption = @profile.consumptions.find(params[:id])
+ if @consumption.destroy
+ flash[:notice] = _('Product succesfully removed')
+ else
+ flash[:notice] = _('Could not remove the product')
+ end
+ redirect_back_or_default :action => 'index'
+ end
+ def edit_consumption
+ @consumption = @profile.consumptions.find(params[:id])
+ if request.post?
+ if @consumption.update_attributes(params[:consumption])
+ flash[:notice] = _('Consumed product succesfully updated')
+ redirect_back_or_default :action => 'index'
+ else
+ flash[:notice] = _('Could not update the consumed product')
+ end
+ end
+ end
+
end
diff --git a/app/views/consumed_products/index.rhtml b/app/views/consumed_products/index.rhtml
deleted file mode 100644
index 9c7c03f..0000000
--- a/app/views/consumed_products/index.rhtml
+++ /dev/null
@@ -1,12 +0,0 @@
- <%=_('Listing consumed products') %>
-
- <%= link_to _('Add product'), :action => 'new' %>
-
-<% @consumptions.each do |consumption| %>
- <%= link_to_category(consumption.product_category) %>
- <%= link_to _('remove'), { :action => 'destroy', :id => consumption },
- :confirm => _('Are you sure, you want to remove this product from your list') %>
-
<%= consumption.aditional_specifications %>
-<% end %>
-
-<%= link_to_myprofile(_('Back'), {}, @profile.identifier)%>
diff --git a/app/views/consumed_products/new.rhtml b/app/views/consumed_products/new.rhtml
deleted file mode 100644
index b2eb615..0000000
--- a/app/views/consumed_products/new.rhtml
+++ /dev/null
@@ -1,17 +0,0 @@
-<%= _('Add product') %>
-
-<%= error_messages_for :consumption %>
-
-<% form_for :consumption, @consumption do |f| %>
-
- <%= _('Product:') %>
- <%= f.select "product_category_id", ProductCategory.find(:all).map{|pc| [pc.name, pc.id]} %>
-
-
- <%= _('Aditional specifications:') %>
- <%= f.text_area "aditional_specifications", :rows => 5 %>
-
- <% button_bar do %>
- <%= submit_button('add', _('Add product'), :cancel => {:action => 'index'}) %>
- <% end %>
-<% end %>
diff --git a/app/views/manage_products/edit_consumption.rhtml b/app/views/manage_products/edit_consumption.rhtml
new file mode 100644
index 0000000..b57b95a
--- /dev/null
+++ b/app/views/manage_products/edit_consumption.rhtml
@@ -0,0 +1,3 @@
+<%= _("Editing %s") % @consumption.product_category.name %>
+
+<%= render :partial => 'form_consumption', :locals => {:action => 'edit_consumption'} %>
diff --git a/app/views/manage_products/index.rhtml b/app/views/manage_products/index.rhtml
index 37ecccc..e82333e 100644
--- a/app/views/manage_products/index.rhtml
+++ b/app/views/manage_products/index.rhtml
@@ -1,12 +1,47 @@
<%=_('Listing products and services') %>
+
+
+ <%= _('Product') %> |
+ <%= _('Price') %> |
+ <%= _('Actions') %> |
+
+ <% @products.each do |product| %>
+
+ <%= link_to product.name, :action => 'show', :id => product %> |
+ <%= product.price %> |
+
+ <%= button :edit, _('Edit'), :action => 'edit', :id => product %>
+ <%= button :delete, _('Destroy'), :action => 'destroy', :id => product %>
+ |
+
+ <% end %>
+
+
<%= link_to _('New product or service'), :action => 'new' %>
-<% @products.each do |product| %>
- <%= link_to product.name, :action => 'show', :id => product %>
- <%= _('Price:') %> <%= product.price %>
- <%= link_to _('edit'), :action => 'edit', :id => product %>
- <%= link_to _('destroy'), :action => 'destroy', :id => product %>
-<% end %>
+ <%=_('Listing consumed products') %>
+
+
+
+ <%= _('Consumed product') %> |
+ <%= _('Actions') %> |
+
+ <% @consumptions.each do |consumption| %>
+
+
+ <%= link_to_category(consumption.product_category) %>
+
+ <%= consumption.aditional_specifications %>
+ |
+
+ <%= button :edit, _('Edit'), :action => 'edit_consumption', :id => consumption %>
+ <%= button :delete, _('Remove'), { :action => 'destroy_consumption', :id => consumption }, :confirm => _('Are you sure, you want to remove this product from your list') %>
+ |
+
+ <% end %>
+
+
+ <%= link_to _('Add cunsumed product'), :action => 'new_consumption' %>
<%= link_to_myprofile(_('Back'), {}, @profile.identifier) %>
diff --git a/app/views/manage_products/new_consumption.rhtml b/app/views/manage_products/new_consumption.rhtml
new file mode 100644
index 0000000..38bd6ad
--- /dev/null
+++ b/app/views/manage_products/new_consumption.rhtml
@@ -0,0 +1,3 @@
+<%= _('Add consumed product') %>
+
+<%= render :partial => 'form_consumption', :locals => {:action => 'new_consumption'} %>
diff --git a/app/views/profile_editor/index.rhtml b/app/views/profile_editor/index.rhtml
index 1b61637..39189c7 100644
--- a/app/views/profile_editor/index.rhtml
+++ b/app/views/profile_editor/index.rhtml
@@ -20,8 +20,6 @@
<%= file_manager_button(_('Manage Members'), 'icons-app/members.png', :controller => 'profile_members') if profile.organization? && user.has_permission?(:manage_memberships, profile) %>
- <%= file_manager_button(_('Consumed Products'), 'icons-app/consumed_product.png', :controller => 'consumed_products') if profile.enterprise? %>
-
<%= file_manager_button(_('Manage Products and Services'), 'icons-app/products.png', :controller => 'manage_products') if profile.enterprise? %>
<%= file_manager_button(_('Enterprise Validation'), 'icons-app/validation.png', :controller => 'enterprise_validation') if profile.is_validation_entity? %>
diff --git a/test/functional/consumed_products_controller_test.rb b/test/functional/consumed_products_controller_test.rb
deleted file mode 100644
index 2007eff..0000000
--- a/test/functional/consumed_products_controller_test.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper'
-require 'consumed_products_controller'
-
-# Re-raise errors caught by the controller.
-class ConsumedProductsController; def rescue_action(e) raise e end; end
-
-class ConsumedProductsControllerTest < Test::Unit::TestCase
-
- all_fixtures
-
- def setup
- @controller = ConsumedProductsController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
-
- @profile = create_user('testinguser').person
- end
- attr_reader :profile
-
- def test_local_files_reference
- assert_local_files_reference :get, :index, :profile => profile.identifier
- end
-
- def test_valid_xhtml
- assert_valid_xhtml
- end
-
- should 'display new form' do
- login_as(profile.identifier)
- get :new, :profile => profile.identifier
- assert_tag :tag => 'h2', :content => 'Add product'
- end
-
- should 'create product' do
- login_as(profile.identifier)
- product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default)
- assert_difference Consumption, :count do
- post :new, :profile => profile.identifier, :consumption => { :product_category_id => product_category.id }
- end
- end
-
- should 'display list of products' do
- login_as(profile.identifier)
- product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default)
- profile.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info')
- get :index, :profile => profile.identifier
- assert_tag :tag => 'pre', :content => 'extra info'
- end
-
- should 'filter html from specifications' do
- login_as(profile.identifier)
- product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default)
- post :new, :profile => profile.identifier,
- :consumption => { :product_category_id => product_category.id, :aditional_specifications => 'extra info' }
- assert_sanitized assigns(:consumption).aditional_specifications
- end
-
- should 'destroy product' do
- login_as(profile.identifier)
- product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default)
- product = profile.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info')
- assert_difference Consumption, :count, -1 do
- post :destroy, :profile => profile.identifier, :id => product.id
- end
- end
-
-end
diff --git a/test/functional/manage_products_controller_test.rb b/test/functional/manage_products_controller_test.rb
index b1e4f8b..fe2931f 100644
--- a/test/functional/manage_products_controller_test.rb
+++ b/test/functional/manage_products_controller_test.rb
@@ -198,4 +198,52 @@ class ManageProductsControllerTest < Test::Unit::TestCase
assert_sanitized assigns(:product).description
end
+ should 'display new consumption form' do
+ get :new_consumption, :profile => @enterprise.identifier
+ assert_tag :tag => 'h2', :content => 'Add consumed product'
+ end
+
+ should 'create consumption product' do
+ product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default)
+ assert_difference Consumption, :count do
+ post :new_consumption, :profile => @enterprise.identifier, :consumption => { :product_category_id => product_category.id }
+ end
+ end
+
+ should 'display list of consumption products' do
+ product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default)
+ @enterprise.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info')
+ get :index, :profile => @enterprise.identifier
+ assert_tag :tag => 'em', :content => 'extra info'
+ end
+
+ should 'filter html from consumption specifications' do
+ product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default)
+ post :new_consumption, :profile => @enterprise.identifier,
+ :consumption => { :product_category_id => product_category.id, :aditional_specifications => 'extra info' }
+ assert_sanitized assigns(:consumption).aditional_specifications
+ end
+
+ should 'destroy consumption product' do
+ product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default)
+ product = @enterprise.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info')
+ assert_difference Consumption, :count, -1 do
+ post :destroy_consumption, :profile => @enterprise.identifier, :id => product.id
+ end
+ end
+
+ should 'display edit consumption form' do
+ product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default)
+ product = @enterprise.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info')
+ get :edit_consumption, :profile => @enterprise.identifier, :id => product
+ assert_tag :tag => 'h2', :content => 'Editing Food'
+ end
+
+ should 'update consumption product' do
+ product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default)
+ product = @enterprise.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info')
+ post :edit_consumption, :profile => @enterprise.identifier, :id => product, :consumption => { :aditional_specifications => 'new extra info' }
+ assert_equal 'new extra info', @enterprise.consumptions.find(product.reload.id).aditional_specifications
+ end
+
end
--
libgit2 0.21.2