Commit 8838cfb0864458dc7efd834d026a63ff12a17f32
1 parent
5348ee30
Exists in
master
and in
29 other branches
ActionItem328: move consumed_products actions to manage_products
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1888 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
10 changed files
with
130 additions
and
137 deletions
Show diff stats
app/controllers/my_profile/consumed_products_controller.rb
... | ... | @@ -1,33 +0,0 @@ |
1 | -class ConsumedProductsController < ApplicationController | |
2 | - needs_profile | |
3 | - | |
4 | - protect 'manage_products', :profile | |
5 | - | |
6 | - def index | |
7 | - @consumptions = @profile.consumptions | |
8 | - @product_categories = @profile.consumed_product_categories | |
9 | - end | |
10 | - | |
11 | - def new | |
12 | - @consumption = @profile.consumptions.build(params[:consumption]) | |
13 | - if request.post? | |
14 | - if @consumption.save | |
15 | - flash[:notice] = _('Product succesfully created') | |
16 | - redirect_to :action => 'index' | |
17 | - else | |
18 | - flash[:notice] = _('Could not create the product') | |
19 | - end | |
20 | - end | |
21 | - end | |
22 | - | |
23 | - def destroy | |
24 | - @consumption = @profile.consumptions.find(params[:id]) | |
25 | - if @consumption.destroy | |
26 | - flash[:notice] = _('Product succesfully removed') | |
27 | - else | |
28 | - flash[:notice] = _('Could not remove the product') | |
29 | - end | |
30 | - redirect_back_or_default :action => 'index' | |
31 | - end | |
32 | - | |
33 | -end |
app/controllers/my_profile/manage_products_controller.rb
... | ... | @@ -5,6 +5,7 @@ class ManageProductsController < ApplicationController |
5 | 5 | |
6 | 6 | def index |
7 | 7 | @products = @profile.products |
8 | + @consumptions = @profile.consumptions | |
8 | 9 | end |
9 | 10 | |
10 | 11 | def show |
... | ... | @@ -56,5 +57,39 @@ class ManageProductsController < ApplicationController |
56 | 57 | @categories = @current_category.children |
57 | 58 | render :partial => 'subcategories' |
58 | 59 | end |
60 | + | |
61 | + def new_consumption | |
62 | + @consumption = @profile.consumptions.build(params[:consumption]) | |
63 | + if request.post? | |
64 | + if @consumption.save | |
65 | + flash[:notice] = _('Product succesfully created') | |
66 | + redirect_to :action => 'index' | |
67 | + else | |
68 | + flash[:notice] = _('Could not create the product') | |
69 | + end | |
70 | + end | |
71 | + end | |
72 | + | |
73 | + def destroy_consumption | |
74 | + @consumption = @profile.consumptions.find(params[:id]) | |
75 | + if @consumption.destroy | |
76 | + flash[:notice] = _('Product succesfully removed') | |
77 | + else | |
78 | + flash[:notice] = _('Could not remove the product') | |
79 | + end | |
80 | + redirect_back_or_default :action => 'index' | |
81 | + end | |
59 | 82 | |
83 | + def edit_consumption | |
84 | + @consumption = @profile.consumptions.find(params[:id]) | |
85 | + if request.post? | |
86 | + if @consumption.update_attributes(params[:consumption]) | |
87 | + flash[:notice] = _('Consumed product succesfully updated') | |
88 | + redirect_back_or_default :action => 'index' | |
89 | + else | |
90 | + flash[:notice] = _('Could not update the consumed product') | |
91 | + end | |
92 | + end | |
93 | + end | |
94 | + | |
60 | 95 | end | ... | ... |
app/views/consumed_products/index.rhtml
... | ... | @@ -1,12 +0,0 @@ |
1 | -<h2> <%=_('Listing consumed products') %> </h2> | |
2 | - | |
3 | -<p> <%= link_to _('Add product'), :action => 'new' %> </p> | |
4 | - | |
5 | -<% @consumptions.each do |consumption| %> | |
6 | - <p> <b> <%= link_to_category(consumption.product_category) %> </b> | |
7 | - <%= link_to _('remove'), { :action => 'destroy', :id => consumption }, | |
8 | - :confirm => _('Are you sure, you want to remove this product from your list') %> | |
9 | - <pre><%= consumption.aditional_specifications %></pre> </p> | |
10 | -<% end %> | |
11 | - | |
12 | -<%= link_to_myprofile(_('Back'), {}, @profile.identifier)%> |
app/views/consumed_products/new.rhtml
... | ... | @@ -1,17 +0,0 @@ |
1 | -<h2><%= _('Add product') %></h2> | |
2 | - | |
3 | -<%= error_messages_for :consumption %> | |
4 | - | |
5 | -<% form_for :consumption, @consumption do |f| %> | |
6 | - <p> | |
7 | - <%= _('Product:') %> | |
8 | - <span class="formfield"> <%= f.select "product_category_id", ProductCategory.find(:all).map{|pc| [pc.name, pc.id]} %> </span> | |
9 | - </p> | |
10 | - <p> | |
11 | - <%= _('Aditional specifications:') %> <br /> | |
12 | - <span class="formfield"> <%= f.text_area "aditional_specifications", :rows => 5 %> </span> | |
13 | - </p> | |
14 | - <% button_bar do %> | |
15 | - <%= submit_button('add', _('Add product'), :cancel => {:action => 'index'}) %> | |
16 | - <% end %> | |
17 | -<% end %> |
app/views/manage_products/index.rhtml
1 | 1 | <h2> <%=_('Listing products and services') %> </h2> |
2 | 2 | |
3 | +<table> | |
4 | + <tr> | |
5 | + <th><%= _('Product') %></th> | |
6 | + <th><%= _('Price') %></th> | |
7 | + <th><%= _('Actions') %></th> | |
8 | + </tr> | |
9 | + <% @products.each do |product| %> | |
10 | + <tr> | |
11 | + <td><strong><%= link_to product.name, :action => 'show', :id => product %></strong></td> | |
12 | + <td><%= product.price %></td> | |
13 | + <td> | |
14 | + <%= button :edit, _('Edit'), :action => 'edit', :id => product %> | |
15 | + <%= button :delete, _('Destroy'), :action => 'destroy', :id => product %> | |
16 | + </td> | |
17 | + </tr> | |
18 | + <% end %> | |
19 | +</table> | |
20 | + | |
3 | 21 | <p> <%= link_to _('New product or service'), :action => 'new' %> </p> |
4 | 22 | |
5 | -<% @products.each do |product| %> | |
6 | - <p> <b> <%= link_to product.name, :action => 'show', :id => product %> </b> | |
7 | - <%= _('Price:') %> <%= product.price %> | |
8 | - <%= link_to _('edit'), :action => 'edit', :id => product %> | |
9 | - <%= link_to _('destroy'), :action => 'destroy', :id => product %> </p> | |
10 | -<% end %> | |
23 | +<h3> <%=_('Listing consumed products') %> </h3> | |
24 | + | |
25 | +<table> | |
26 | + <tr> | |
27 | + <th><%= _('Consumed product') %></th> | |
28 | + <th><%= _('Actions') %></th> | |
29 | + </tr> | |
30 | + <% @consumptions.each do |consumption| %> | |
31 | + <tr> | |
32 | + <td> | |
33 | + <strong><%= link_to_category(consumption.product_category) %></strong> | |
34 | + <br/> | |
35 | + <em><%= consumption.aditional_specifications %></em> | |
36 | + </td> | |
37 | + <td> | |
38 | + <%= button :edit, _('Edit'), :action => 'edit_consumption', :id => consumption %> | |
39 | + <%= button :delete, _('Remove'), { :action => 'destroy_consumption', :id => consumption }, :confirm => _('Are you sure, you want to remove this product from your list') %> | |
40 | + </td> | |
41 | + </tr> | |
42 | + <% end %> | |
43 | +</table> | |
44 | + | |
45 | +<p> <%= link_to _('Add cunsumed product'), :action => 'new_consumption' %> </p> | |
11 | 46 | |
12 | 47 | <%= link_to_myprofile(_('Back'), {}, @profile.identifier) %> | ... | ... |
app/views/profile_editor/index.rhtml
... | ... | @@ -20,8 +20,6 @@ |
20 | 20 | |
21 | 21 | <%= file_manager_button(_('Manage Members'), 'icons-app/members.png', :controller => 'profile_members') if profile.organization? && user.has_permission?(:manage_memberships, profile) %> |
22 | 22 | |
23 | - <%= file_manager_button(_('Consumed Products'), 'icons-app/consumed_product.png', :controller => 'consumed_products') if profile.enterprise? %> | |
24 | - | |
25 | 23 | <%= file_manager_button(_('Manage Products and Services'), 'icons-app/products.png', :controller => 'manage_products') if profile.enterprise? %> |
26 | 24 | |
27 | 25 | <%= file_manager_button(_('Enterprise Validation'), 'icons-app/validation.png', :controller => 'enterprise_validation') if profile.is_validation_entity? %> | ... | ... |
test/functional/consumed_products_controller_test.rb
... | ... | @@ -1,67 +0,0 @@ |
1 | -require File.dirname(__FILE__) + '/../test_helper' | |
2 | -require 'consumed_products_controller' | |
3 | - | |
4 | -# Re-raise errors caught by the controller. | |
5 | -class ConsumedProductsController; def rescue_action(e) raise e end; end | |
6 | - | |
7 | -class ConsumedProductsControllerTest < Test::Unit::TestCase | |
8 | - | |
9 | - all_fixtures | |
10 | - | |
11 | - def setup | |
12 | - @controller = ConsumedProductsController.new | |
13 | - @request = ActionController::TestRequest.new | |
14 | - @response = ActionController::TestResponse.new | |
15 | - | |
16 | - @profile = create_user('testinguser').person | |
17 | - end | |
18 | - attr_reader :profile | |
19 | - | |
20 | - def test_local_files_reference | |
21 | - assert_local_files_reference :get, :index, :profile => profile.identifier | |
22 | - end | |
23 | - | |
24 | - def test_valid_xhtml | |
25 | - assert_valid_xhtml | |
26 | - end | |
27 | - | |
28 | - should 'display new form' do | |
29 | - login_as(profile.identifier) | |
30 | - get :new, :profile => profile.identifier | |
31 | - assert_tag :tag => 'h2', :content => 'Add product' | |
32 | - end | |
33 | - | |
34 | - should 'create product' do | |
35 | - login_as(profile.identifier) | |
36 | - product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
37 | - assert_difference Consumption, :count do | |
38 | - post :new, :profile => profile.identifier, :consumption => { :product_category_id => product_category.id } | |
39 | - end | |
40 | - end | |
41 | - | |
42 | - should 'display list of products' do | |
43 | - login_as(profile.identifier) | |
44 | - product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
45 | - profile.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info') | |
46 | - get :index, :profile => profile.identifier | |
47 | - assert_tag :tag => 'pre', :content => 'extra info' | |
48 | - end | |
49 | - | |
50 | - should 'filter html from specifications' do | |
51 | - login_as(profile.identifier) | |
52 | - product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
53 | - post :new, :profile => profile.identifier, | |
54 | - :consumption => { :product_category_id => product_category.id, :aditional_specifications => 'extra <b>info</b>' } | |
55 | - assert_sanitized assigns(:consumption).aditional_specifications | |
56 | - end | |
57 | - | |
58 | - should 'destroy product' do | |
59 | - login_as(profile.identifier) | |
60 | - product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
61 | - product = profile.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info') | |
62 | - assert_difference Consumption, :count, -1 do | |
63 | - post :destroy, :profile => profile.identifier, :id => product.id | |
64 | - end | |
65 | - end | |
66 | - | |
67 | -end |
test/functional/manage_products_controller_test.rb
... | ... | @@ -198,4 +198,52 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
198 | 198 | assert_sanitized assigns(:product).description |
199 | 199 | end |
200 | 200 | |
201 | + should 'display new consumption form' do | |
202 | + get :new_consumption, :profile => @enterprise.identifier | |
203 | + assert_tag :tag => 'h2', :content => 'Add consumed product' | |
204 | + end | |
205 | + | |
206 | + should 'create consumption product' do | |
207 | + product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
208 | + assert_difference Consumption, :count do | |
209 | + post :new_consumption, :profile => @enterprise.identifier, :consumption => { :product_category_id => product_category.id } | |
210 | + end | |
211 | + end | |
212 | + | |
213 | + should 'display list of consumption products' do | |
214 | + product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
215 | + @enterprise.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info') | |
216 | + get :index, :profile => @enterprise.identifier | |
217 | + assert_tag :tag => 'em', :content => 'extra info' | |
218 | + end | |
219 | + | |
220 | + should 'filter html from consumption specifications' do | |
221 | + product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
222 | + post :new_consumption, :profile => @enterprise.identifier, | |
223 | + :consumption => { :product_category_id => product_category.id, :aditional_specifications => 'extra <b>info</b>' } | |
224 | + assert_sanitized assigns(:consumption).aditional_specifications | |
225 | + end | |
226 | + | |
227 | + should 'destroy consumption product' do | |
228 | + product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
229 | + product = @enterprise.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info') | |
230 | + assert_difference Consumption, :count, -1 do | |
231 | + post :destroy_consumption, :profile => @enterprise.identifier, :id => product.id | |
232 | + end | |
233 | + end | |
234 | + | |
235 | + should 'display edit consumption form' do | |
236 | + product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
237 | + product = @enterprise.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info') | |
238 | + get :edit_consumption, :profile => @enterprise.identifier, :id => product | |
239 | + assert_tag :tag => 'h2', :content => 'Editing Food' | |
240 | + end | |
241 | + | |
242 | + should 'update consumption product' do | |
243 | + product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
244 | + product = @enterprise.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info') | |
245 | + post :edit_consumption, :profile => @enterprise.identifier, :id => product, :consumption => { :aditional_specifications => 'new extra info' } | |
246 | + assert_equal 'new extra info', @enterprise.consumptions.find(product.reload.id).aditional_specifications | |
247 | + end | |
248 | + | |
201 | 249 | end | ... | ... |