Commit 2cad0a738b3342b291031197ff1756a2dfe09cbf

Authored by Larissa Reis
1 parent 4032bfa4

[search-improvements] Fixes cucumber tests in Noosfero 1.0

app/helpers/search_helper.rb
@@ -90,12 +90,12 @@ module SearchHelper @@ -90,12 +90,12 @@ module SearchHelper
90 end 90 end
91 end 91 end
92 92
93 - def select_filter(name, options) 93 + def select_filter(name, options, default = nil)
94 if options.size <= 1 94 if options.size <= 1
95 return 95 return
96 else 96 else
97 options = options.map {|option| [FILTERS_OPTIONS_TRANSLATION[name][option], option]} 97 options = options.map {|option| [FILTERS_OPTIONS_TRANSLATION[name][option], option]}
98 - options = options_for_select(options, :selected => params[name]) 98 + options = options_for_select(options, :selected => (params[name] || default))
99 select_tag(name, options) 99 select_tag(name, options)
100 end 100 end
101 end 101 end
@@ -104,7 +104,8 @@ module SearchHelper @@ -104,7 +104,8 @@ module SearchHelper
104 return if !asset 104 return if !asset
105 klass = asset_class(asset) 105 klass = asset_class(asset)
106 content_tag('div', klass::SEARCH_FILTERS.map do |name, options| 106 content_tag('div', klass::SEARCH_FILTERS.map do |name, options|
107 - select_filter(name, options) 107 + default = klass.respond_to?("default_search_#{name}") ? klass.send("default_search_#{name}".to_s) : nil
  108 + select_filter(name, options, default)
108 end.join("\n"), :id => 'search-filters') 109 end.join("\n"), :id => 'search-filters')
109 end 110 end
110 111
app/models/product.rb
@@ -7,7 +7,7 @@ class Product &lt; ActiveRecord::Base @@ -7,7 +7,7 @@ class Product &lt; ActiveRecord::Base
7 7
8 SEARCH_FILTERS = { 8 SEARCH_FILTERS = {
9 :order => %w[more_recent], 9 :order => %w[more_recent],
10 - :display => %w[map full] 10 + :display => %w[full map]
11 } 11 }
12 12
13 attr_accessible :name, :product_category, :highlighted, :price, :enterprise, :image_builder, :description, :available, :qualifiers, :unit_id, :discount, :inputs 13 attr_accessible :name, :product_category, :highlighted, :price, :enterprise, :image_builder, :description, :available, :qualifiers, :unit_id, :discount, :inputs
features/search_enterprises.feature
@@ -47,6 +47,7 @@ Feature: search enterprises @@ -47,6 +47,7 @@ Feature: search enterprises
47 When I follow "Shoes shop" 47 When I follow "Shoes shop"
48 Then I should be on shop1's homepage 48 Then I should be on shop1's homepage
49 49
  50 + @selenium
50 Scenario: show clean enterprise homepage on search results 51 Scenario: show clean enterprise homepage on search results
51 Given the following enterprises 52 Given the following enterprises
52 | identifier | name | 53 | identifier | name |
@@ -59,12 +60,13 @@ Feature: search enterprises @@ -59,12 +60,13 @@ Feature: search enterprises
59 Then I should see "This is the homepage of" within ".search-enterprise-description" 60 Then I should see "This is the homepage of" within ".search-enterprise-description"
60 And I should see "about sho..." within ".search-enterprise-description" 61 And I should see "about sho..." within ".search-enterprise-description"
61 62
  63 + @selenium
62 Scenario: show clean enterprise description on search results 64 Scenario: show clean enterprise description on search results
63 Given the following enterprises 65 Given the following enterprises
64 | identifier | name | description | 66 | identifier | name | description |
65 | shop4 | Clothes shop | This <b>clothes</b> shop also sells shoes! This too has a very long and pretty vague description, just so we can test wether the system will correctly create an excerpt of this text. Clothes are a really important part of our lives. | 67 | shop4 | Clothes shop | This <b>clothes</b> shop also sells shoes! This too has a very long and pretty vague description, just so we can test wether the system will correctly create an excerpt of this text. Clothes are a really important part of our lives. |
66 When I search enterprises for "clothes" 68 When I search enterprises for "clothes"
67 - And I follow "Full" 69 + And I choose the search filter "Full"
68 And I should see "This clothes shop" within ".search-enterprise-description" 70 And I should see "This clothes shop" within ".search-enterprise-description"
69 And I should see "really import..." within ".search-enterprise-description" 71 And I should see "really import..." within ".search-enterprise-description"
70 72