Commit f71c2edbffe26ad50268305b773b846164653d10

Authored by Rodrigo Souto
1 parent 269bdeca

[purchase-order] Adding test for reports

plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb
... ... @@ -83,6 +83,26 @@ class ShoppingCartPluginMyprofileControllerTest < Test::Unit::TestCase
83 83 assert_not_includes assigns(:orders), po4
84 84 end
85 85  
  86 + should 'group filtered orders products and quantities' do
  87 + p1 = fast_create(Product, :enterprise_id => enterprise.id, :price => 1)
  88 + p2 = fast_create(Product, :enterprise_id => enterprise.id, :price => 2)
  89 + p3 = fast_create(Product, :enterprise_id => enterprise.id, :price => 3)
  90 + po1_products = {p1.id => {:quantity => 1, :price => p1.price}, p2.id => {:quantity => 2, :price => p2.price }}
  91 + po2_products = {p2.id => {:quantity => 1, :price => p2.price}, p3.id => {:quantity => 2, :price => p3.price }}
  92 + po1 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :products_list => po1_products, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED)
  93 + po2 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :products_list => po2_products, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED)
  94 +
  95 + post :reports,
  96 + :profile => enterprise.identifier,
  97 + :from => (Time.now - 1.day).strftime(TIME_FORMAT),
  98 + :to => (Time.now + 1.day).strftime(TIME_FORMAT),
  99 + :filter_status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED
  100 +
  101 + hash = {p1.id => 1, p2.id => 3, p3.id => 2}
  102 +
  103 + assert_equal hash, assigns(:products)
  104 + end
  105 +
86 106 should 'be able to update the order status' do
87 107 po = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED)
88 108  
... ...
plugins/shopping_cart/views/shopping_cart_plugin_myprofile/_orders_list.html.erb
... ... @@ -34,7 +34,7 @@
34 34 <div style="display:none">
35 35 <ul class="customer-details">
36 36 <% { 'name' =>_('Name'), 'email' => _('E-mail'), 'contact_phone' => _('Contact phone'), 'address' => _('Address'), 'city' => _('City'), 'zip_code' => _('Zip code')}.each do |attribute, name| %>
37   - <%= content_tag('li', content_tag('strong', name+': ') + order.send('customer_'+attribute)) if order.send('customer_'+attribute) %>
  37 + <%= content_tag('li', content_tag('strong', name+': ') + order.send('customer_'+attribute)) if !order.send('customer_'+attribute).blank? %>
38 38 <% end %>
39 39 </ul>
40 40 <ul class="order-products">
... ...
plugins/shopping_cart/views/shopping_cart_plugin_myprofile/_products_list.html.erb
... ... @@ -8,7 +8,7 @@
8 8 </tr>
9 9 <% @products.each do |id, quantity|%>
10 10 <tr>
11   - <td><%= Product.find(id).name %></td>
  11 + <td><%= link_to(Product.find(id).name, Product.find(id).url) %></td>
12 12 <td style="text-align: center"><%= quantity %></td>
13 13 </tr>
14 14 <% end %>
... ...