Commit 070dfc0914c8b397fb27d9de0b0b854856a12bc8

Authored by Leandro Santos
Committed by Joenio Costa
1 parent 50a4e204

The FeaturedProductsBlock doesn't works with noosfero 0.25.0 version.

This code fix this bug and make some cucumber test to the FeaturedProductsBlock.

(ActionItem1591)
app/helpers/application_helper.rb
@@ -973,4 +973,8 @@ module ApplicationHelper @@ -973,4 +973,8 @@ module ApplicationHelper
973 link_to_remote(label, options, html_options.merge(:class => 'ui_button fg-button')) 973 link_to_remote(label, options, html_options.merge(:class => 'ui_button fg-button'))
974 end 974 end
975 975
  976 + def float_to_currency(value)
  977 + number_to_currency(value, :unit => environment.currency_unit, :separator => environment.currency_separator, :delimiter => environment.currency_delimiter, :format => "%u %n")
  978 + end
  979 +
976 end 980 end
app/helpers/display_helper.rb
@@ -2,12 +2,16 @@ module DisplayHelper @@ -2,12 +2,16 @@ module DisplayHelper
2 2
3 def link_to_product(product, opts={}) 3 def link_to_product(product, opts={})
4 return _('No product') unless product 4 return _('No product') unless product
5 - target = product.enterprise.enabled? ? product.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => product) : product.enterprise.url 5 + target = product_path(product)
6 link_to content_tag( 'span', product.name ), 6 link_to content_tag( 'span', product.name ),
7 target, 7 target,
8 opts 8 opts
9 end 9 end
10 10
  11 + def product_path(product)
  12 + product.enterprise.enabled? ? product.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => product) : product.enterprise.url
  13 + end
  14 +
11 def link_to_category(category, full = true) 15 def link_to_category(category, full = true)
12 return _('Uncategorized product') unless category 16 return _('Uncategorized product') unless category
13 name = full ? category.full_name(' → ') : category.name 17 name = full ? category.full_name(' → ') : category.name
app/helpers/manage_products_helper.rb
@@ -152,10 +152,6 @@ module ManageProductsHelper @@ -152,10 +152,6 @@ module ManageProductsHelper
152 link_to(_('Change category'), { :action => 'edit_category', :id => product.id}, options) 152 link_to(_('Change category'), { :action => 'edit_category', :id => product.id}, options)
153 end 153 end
154 154
155 - def float_to_currency(value)  
156 - number_to_currency(value, :unit => environment.currency_unit, :separator => environment.currency_separator, :delimiter => environment.currency_delimiter, :format => "%u %n")  
157 - end  
158 -  
159 def display_value(product) 155 def display_value(product)
160 price = product.price 156 price = product.price
161 unless price.blank? || price.zero? 157 unless price.blank? || price.zero?
app/views/blocks/featured_products.rhtml
@@ -9,13 +9,13 @@ @@ -9,13 +9,13 @@
9 <ul> 9 <ul>
10 <% group.reject{ |x| x.nil? }.each_with_index do |p, i| %> 10 <% group.reject{ |x| x.nil? }.each_with_index do |p, i| %>
11 <li class="featured-product-item"> 11 <li class="featured-product-item">
12 - <%= link_to content_tag(:img, nil, :src => p.image.public_filename(:thumb), :alt => p.name, :class => ('reflect' if block.reflect)), product_path(p.enterprise.identifier, p), :class => 'featured-product-image' %> 12 + <%= link_to content_tag(:img, nil, :src => p.image.public_filename(:thumb), :alt => p.name, :class => ('reflect' if block.reflect)), product_path(p), :class => 'featured-product-image' %>
13 <div class="featured-product-info position-<%= i + 1 %>" style="display: none"> 13 <div class="featured-product-info position-<%= i + 1 %>" style="display: none">
14 <div class="featured-product-text"> 14 <div class="featured-product-text">
15 <h3><%= p.name %></h3> 15 <h3><%= p.name %></h3>
16 <p class="featured-product-price"><%= float_to_currency(p.price) %></p> 16 <p class="featured-product-price"><%= float_to_currency(p.price) %></p>
17 <p class="featured-product-desc"><%= p.description.chars[0...50].to_s + '...' %></p> 17 <p class="featured-product-desc"><%= p.description.chars[0...50].to_s + '...' %></p>
18 - <p><%= link_to _('See More'), product_path(p.enterprise.identifier, p), :class => 'featured-product-link' %></p> 18 + <p><%= link_to _('See More'), product_path(p), :class => 'featured-product-link' %></p>
19 </div> 19 </div>
20 </div> 20 </div>
21 </li> 21 </li>
features/featured_products_block.feature 0 → 100644
@@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
  1 +Feature: featured_products_block
  2 + As a profile owner
  3 + I want to edit the featured block
  4 +
  5 + Background:
  6 + Given I am on the homepage
  7 + And the following users
  8 + | login | name |
  9 + | eddievedder | Eddie Vedder |
  10 + And the following enterprises
  11 + | identifier | owner | name | enabled |
  12 + | redemoinho | eddievedder | Rede Moinho | true |
  13 + And the following blocks
  14 + | owner | type |
  15 + | redemoinho | FeaturedProductsBlock |
  16 + And the following product_category
  17 + | name |
  18 + | automobile |
  19 + And the following products
  20 + | owner | category | name | description | highlighted |
  21 + | redemoinho | automobile | Car | Red Car | true |
  22 + | redemoinho | automobile | Truck | Blue Truck | true |
  23 + And I am logged in as "eddievedder"
  24 +
  25 + @selenium
  26 + Scenario: select a product to be featured
  27 + And I follow "Manage my groups"
  28 + And I follow "Control panel of this group"
  29 + And I follow "Edit sideboxes"
  30 + Given I follow "Edit" within ".featured-products-block"
  31 + And I select "Car"
  32 + When I press "Save"
  33 + Then I should see "Car"
  34 + And I should not see "float_to_currency"
  35 + And I should not see "product_path"
features/step_definitions/noosfero_steps.rb
@@ -62,7 +62,8 @@ Given /^the following products$/ do |table| @@ -62,7 +62,8 @@ Given /^the following products$/ do |table|
62 data = item.dup 62 data = item.dup
63 owner = Enterprise[data.delete("owner")] 63 owner = Enterprise[data.delete("owner")]
64 category = Category.find_by_slug(data.delete("category")) 64 category = Category.find_by_slug(data.delete("category"))
65 - Product.create!(data.merge(:enterprise => owner, :product_category => category)) 65 + product = Product.create!(data.merge(:enterprise => owner, :product_category => category))
  66 + image = Image.create!(:owner => product, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
66 end 67 end
67 end 68 end
68 69