Commit e8e1083e2ec08176dc4413cc0c90495bbde027f9
1 parent
2f11e284
Exists in
master
and in
22 other branches
test fixes and refactorings for search
Showing
18 changed files
with
196 additions
and
360 deletions
Show diff stats
app/controllers/public/search_controller.rb
... | ... | @@ -123,6 +123,8 @@ class SearchController < PublicController |
123 | 123 | @results_only = true |
124 | 124 | |
125 | 125 | @enabled_searchs.select { |key,description| @searching[key] }.each do |key, description| |
126 | + load_query | |
127 | + @asset = key | |
126 | 128 | send(key) |
127 | 129 | @order << key |
128 | 130 | @names[key] = getterm(description) |
... | ... | @@ -204,8 +206,9 @@ class SearchController < PublicController |
204 | 206 | @category = environment.categories.find_by_path(path) |
205 | 207 | if @category.nil? |
206 | 208 | render_not_found(path) |
209 | + else | |
210 | + @category_id = @category.id | |
207 | 211 | end |
208 | - @category_id = @category.id | |
209 | 212 | end |
210 | 213 | end |
211 | 214 | |
... | ... | @@ -301,12 +304,4 @@ class SearchController < PublicController |
301 | 304 | result |
302 | 305 | end |
303 | 306 | |
304 | - def asset_class(asset) | |
305 | - asset.to_s.singularize.camelize.constantize | |
306 | - end | |
307 | - | |
308 | - def asset_table(asset) | |
309 | - asset_class(asset).table_name | |
310 | - end | |
311 | - | |
312 | 307 | end | ... | ... |
app/helpers/application_helper.rb
... | ... | @@ -884,19 +884,6 @@ module ApplicationHelper |
884 | 884 | result |
885 | 885 | end |
886 | 886 | |
887 | - def search_page_title(title, category = nil) | |
888 | - title = "<h1>" + title | |
889 | - title += '<small>' + category.name + '</small>' if category | |
890 | - title + "</h1>" | |
891 | - end | |
892 | - | |
893 | - def search_page_link_to_all(options={}) | |
894 | - if options[:category] | |
895 | - title = "<div align='center'>" + _('In all categories') + "</div>" | |
896 | - link_to title, :action => 'assets', :asset => options[:asset], :category_path => [] | |
897 | - end | |
898 | - end | |
899 | - | |
900 | 887 | def template_stylesheet_path |
901 | 888 | if profile.nil? |
902 | 889 | "/designs/templates/#{environment.layout_template}/stylesheets/style.css" | ... | ... |
app/helpers/search_helper.rb
... | ... | @@ -3,10 +3,17 @@ module SearchHelper |
3 | 3 | # FIXME remove it after search_controler refactored |
4 | 4 | include EventsHelper |
5 | 5 | |
6 | - def relevance_for(hit) | |
7 | - n = (hit.ferret_score if hit.respond_to?(:ferret_score)) | |
8 | - n ||= 1.0 | |
9 | - (n * 100.0).round | |
6 | + def search_page_title(title, category = nil) | |
7 | + title = "<h1>" + title | |
8 | + title += '<small>' + category.name + '</small>' if category | |
9 | + title + "</h1>" | |
10 | + end | |
11 | + | |
12 | + def category_context(category, url) | |
13 | + content_tag('div', category.full_name + _(', ') + | |
14 | + link_to(_('search in all categories'), | |
15 | + url.merge(:category_path => [], :action => (params[:action] == 'category_index' ? 'index' : params[:action]) )), | |
16 | + :align => 'center', :class => 'search-category-context') if category | |
10 | 17 | end |
11 | 18 | |
12 | 19 | def display_results(use_map = false) |
... | ... | @@ -24,7 +31,7 @@ module SearchHelper |
24 | 31 | def display_map_list_button |
25 | 32 | button(:search, params[:display] == 'map' ? _('Display in list') : _('Display in map'), |
26 | 33 | params.merge(:display => (params[:display] == 'map' ? 'list' : 'map')), |
27 | - :class => "map-toggle-button" ) | |
34 | + :class => "map-toggle-button" ) if GoogleMaps.enabled?(environment.default_hostname) | |
28 | 35 | end |
29 | 36 | |
30 | 37 | def city_with_state(city) |
... | ... | @@ -115,14 +122,6 @@ module SearchHelper |
115 | 122 | end.join |
116 | 123 | end |
117 | 124 | |
118 | - def asset_class(asset) | |
119 | - asset.to_s.singularize.camelize.constantize | |
120 | - end | |
121 | - | |
122 | - def asset_table(asset) | |
123 | - asset_class(asset).table_name | |
124 | - end | |
125 | - | |
126 | 125 | def order_by(asset) |
127 | 126 | options = { |
128 | 127 | :products => [[_('Relevance'), ''], [_('Name'), 'name_or_category_sort asc'], [_('Lower price'), 'price_sort asc'], [_('Higher price'), 'price_sort desc']], |
... | ... | @@ -134,9 +133,9 @@ module SearchHelper |
134 | 133 | } |
135 | 134 | |
136 | 135 | content_tag('div', _('Sort results by ') + |
137 | - select_tag(asset.to_s + '[order]', options_for_select(options[asset], params[:order_by]), | |
138 | - {:onchange => "window.location=jQuery.param.querystring(window.location.href, { 'order_by' : this.options[this.selectedIndex].value})"}), | |
139 | - :class => "search-ordering") | |
136 | + select_tag(asset.to_s + '[order]', options_for_select(options[asset], params[:order_by]), | |
137 | + {:onchange => "window.location=jQuery.param.querystring(window.location.href, { 'order_by' : this.options[this.selectedIndex].value})"}), | |
138 | + :class => "search-ordering") | |
140 | 139 | end |
141 | 140 | |
142 | 141 | def label_total_found(asset, total_found) |
... | ... | @@ -148,12 +147,16 @@ module SearchHelper |
148 | 147 | :enterprises => _("%s enterprises found"), |
149 | 148 | :communities => _("%s communities found"), |
150 | 149 | } |
151 | - if labels[asset] | |
152 | - content_tag('span', labels[asset] % total_found, | |
153 | - :class => "total-pages-found") | |
154 | - else | |
155 | - '' | |
156 | - end | |
150 | + content_tag('span', labels[asset] % total_found, | |
151 | + :class => "total-pages-found") if labels[asset] | |
152 | + end | |
153 | + | |
154 | + def asset_class(asset) | |
155 | + asset.to_s.singularize.camelize.constantize | |
156 | + end | |
157 | + | |
158 | + def asset_table(asset) | |
159 | + asset_class(asset).table_name | |
157 | 160 | end |
158 | 161 | |
159 | 162 | end | ... | ... |
app/models/article.rb
... | ... | @@ -152,7 +152,7 @@ class Article < ActiveRecord::Base |
152 | 152 | # Only includes articles where advertise == true |
153 | 153 | def self.recent(limit = nil, extra_conditions = {}) |
154 | 154 | # FIXME this method is a horrible hack |
155 | - options = { :limit => limit, | |
155 | + options = { :page => 1, :per_page => limit, | |
156 | 156 | :conditions => [ |
157 | 157 | "advertise = ? AND |
158 | 158 | published = ? AND |
... | ... | @@ -170,10 +170,10 @@ class Article < ActiveRecord::Base |
170 | 170 | options.delete(:include) |
171 | 171 | end |
172 | 172 | if extra_conditions == {} |
173 | - self.find(:all, options) | |
173 | + self.paginate(options) | |
174 | 174 | else |
175 | 175 | with_scope :find => {:conditions => extra_conditions} do |
176 | - self.find(:all, options) | |
176 | + self.paginate(options) | |
177 | 177 | end |
178 | 178 | end |
179 | 179 | end |
... | ... | @@ -181,7 +181,7 @@ class Article < ActiveRecord::Base |
181 | 181 | # retrives the most commented articles, sorted by the comment count (largest |
182 | 182 | # first) |
183 | 183 | def self.most_commented(limit) |
184 | - find(:all, :order => 'comments_count DESC', :limit => limit) | |
184 | + paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit) | |
185 | 185 | end |
186 | 186 | |
187 | 187 | # produces the HTML code that is to be displayed as this article's contents. | ... | ... |
app/views/search/_event.rhtml
... | ... | @@ -4,12 +4,6 @@ |
4 | 4 | <%= render :partial => 'image', :object => event %> |
5 | 5 | </div> |
6 | 6 | <div class="search-content-second-column"> |
7 | - <% if event.body %> | |
8 | - <% body_stripped = strip_tags(event.body.to_s) %> | |
9 | - <div class="searc-article-event-date"> | |
10 | - <span class="article-item-body"><%= excerpt(body_stripped, body_stripped.first(3), 200) %></span> | |
11 | - </div> | |
12 | - <% end %> | |
13 | 7 | <% if event.start_date %> |
14 | 8 | <div class="searc-article-event-date"> |
15 | 9 | <span class="search-field-label"><%= _('Start date') %></span> | ... | ... |
app/views/search/_results_header.rhtml
1 | 1 | <div class="search-results-header <%= "search-no-results" if @results[@asset].nil? or @results[@asset].length == 0 %>"> |
2 | 2 | <% if !@empty_query %> |
3 | 3 | <div class="search-results-header-information"> |
4 | - <%= label_total_found(asset, results.total_entries) %> | |
4 | + <%= label_total_found(@asset, @results[@asset].total_entries) %> | |
5 | 5 | <% if params[:display] != 'map' %> |
6 | - <span class="current-page"><%= _("Showing page %s of %s") % [results.current_page, results.total_pages] %></span> | |
6 | + <span class="current-page"><%= _("Showing page %s of %s") % [@results[@asset].current_page, @results[@asset].total_pages] %></span> | |
7 | 7 | <% end %> |
8 | 8 | </div> |
9 | 9 | |
10 | 10 | <div class="search-results-header-facets-order-by"> |
11 | - <%= facets_unselect_menu(asset) %> | |
12 | - <%= order_by(asset) if params[:display] != 'map' %> | |
11 | + <%= facets_unselect_menu(@asset) %> | |
12 | + <%= order_by(@asset) if params[:display] != 'map' %> | |
13 | 13 | </div> |
14 | 14 | <% else %> |
15 | 15 | <div id='search-filter-title'><%= @filter_title if @filter_title %></div> | ... | ... |
app/views/search/_search_form.rhtml
1 | 1 | <div class='search-form'> |
2 | -<% simple_search = false unless defined? simple_search %> | |
3 | 2 | |
4 | 3 | <% form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) }, |
5 | 4 | :method => 'get', :class => 'search_form' ) do %> | ... | ... |
app/views/search/articles.rhtml
... | ... | @@ -7,9 +7,8 @@ |
7 | 7 | </div> |
8 | 8 | |
9 | 9 | <div id="search-column-right"> |
10 | - <%= render :partial => 'search_form', :locals => { :form_title => _('Search'), :simple_search => true, | |
11 | - :hint => _('Type the title, author or content desired') } %> | |
12 | - <%= render :partial => 'results_header', :locals => { :asset => :articles, :results => @results[:articles] } %> | |
10 | + <%= render :partial => 'search_form', :locals => { :hint => _('Type the title, author or content desired') } %> | |
11 | + <%= render :partial => 'results_header' %> | |
13 | 12 | |
14 | 13 | <% if !@empty_query or @filter %> |
15 | 14 | <%= display_results %> | ... | ... |
app/views/search/category_index.rhtml
... | ... | @@ -1,23 +0,0 @@ |
1 | -<div id="view-category"> | |
2 | - | |
3 | - <div id="category-image"><%= image_tag(@category.image.public_filename(:thumb), :id => 'category-image') if @category.image %></div> | |
4 | - <h1 id="category-name"><%= @category.name %></h1> | |
5 | - | |
6 | - <%= display_results %> | |
7 | - | |
8 | - <div id="category-childs"> | |
9 | - <h2> <%= _('Sub-categories') %> </h2> | |
10 | - <% if @category.children.empty? %> | |
11 | - <strong id="cat-no-child"><%= _('No sub-categories') %></strong> | |
12 | - <% else %> | |
13 | - <ul> | |
14 | - <% @category.children.each do |c| %> | |
15 | - <li> <%= link_to_category c, false %> </li> | |
16 | - <% end %> | |
17 | - </ul> | |
18 | - <% end %> | |
19 | - </div><!-- end id="child-categories" --> | |
20 | - | |
21 | -<br style="clear:both" /> | |
22 | -</div><!-- end id="view-category" --> | |
23 | - |
app/views/search/communities.rhtml
... | ... | @@ -14,9 +14,8 @@ |
14 | 14 | </div> |
15 | 15 | |
16 | 16 | <div id='search-column-right'> |
17 | - <%= render :partial => 'search_form', :locals => { :form_title => _('Search'), :simple_search => true, | |
18 | - :hint => _("Type words about the community you're looking for") } %> | |
19 | - <%= render :partial => 'results_header', :locals => { :asset => :communities, :results => @results[:communities] } %> | |
17 | + <%= render :partial => 'search_form', :locals => { :hint => _("Type words about the community you're looking for") } %> | |
18 | + <%= render :partial => 'results_header' %> | |
20 | 19 | |
21 | 20 | <%= display_results %> |
22 | 21 | <%= pagination_links @results.values.first %> | ... | ... |
app/views/search/enterprises.rhtml
... | ... | @@ -16,9 +16,8 @@ |
16 | 16 | </div> |
17 | 17 | |
18 | 18 | <div id="search-column-right"> |
19 | - <%= render :partial => 'search_form', :locals => { :form_title => _('Search'), :simple_search => true, | |
20 | - :hint => _("Type words about the enterprise you're looking for") } %> | |
21 | - <%= render :partial => 'results_header', :locals => { :asset => :enterprises, :results => @results[:enterprises] } %> | |
19 | + <%= render :partial => 'search_form', :locals => { :hint => _("Type words about the enterprise you're looking for") } %> | |
20 | + <%= render :partial => 'results_header' %> | |
22 | 21 | |
23 | 22 | <%= display_results(true) %> |
24 | 23 | <% if params[:display] != 'map' %> | ... | ... |
app/views/search/index.rhtml
1 | -<div id="search-page"> | |
1 | +<div id="search-page" class="<%= "view-category" if @category %>"> | |
2 | 2 | |
3 | -<%= search_page_title(_('Search Results'), @category) %> | |
3 | + <% if @category %> | |
4 | + <div id="category-image"><%= image_tag(@category.image.public_filename(:thumb), :id => 'category-image') if @category.image %></div> | |
5 | + <% end %> | |
4 | 6 | |
5 | -<%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %> | |
7 | + <%= search_page_title(_('Search Results'), @category) %> | |
8 | + <%= render :partial => 'search_form', :locals => { :hint => '' } %> | |
9 | + <%= category_context(@category, params) %> | |
10 | + <%= display_results %> | |
11 | + | |
12 | + <div id="category-childs"> | |
13 | + <% if @category %> | |
14 | + <h2> <%= _('Sub-categories') %> </h2> | |
15 | + <% if @category.children.empty? %> | |
16 | + <strong id="cat-no-child"><%= _('No sub-categories') %></strong> | |
17 | + <% else %> | |
18 | + <ul> | |
19 | + <% @category.children.each do |c| %> | |
20 | + <li> <%= link_to_category c, false %> </li> | |
21 | + <% end %> | |
22 | + </ul> | |
23 | + <% end %> | |
24 | + <% end %> | |
25 | + </div> | |
6 | 26 | |
7 | -<%= render :partial => 'display_results' %> | |
8 | - | |
9 | -</div><!-- end id="search-page" --> | |
27 | +</div> | |
10 | 28 | <br style="clear:both" /> | ... | ... |
app/views/search/people.rhtml
... | ... | @@ -7,9 +7,8 @@ |
7 | 7 | </div> |
8 | 8 | |
9 | 9 | <div id='search-column-right'> |
10 | - <%= render :partial => 'search_form', :locals => { :form_title => _('Search'), :simple_search => true, | |
11 | - :hint => _("Type words about the person you're looking for") } %> | |
12 | - <%= render :partial => 'results_header', :locals => { :asset => :people, :results => @results[:people] } %> | |
10 | + <%= render :partial => 'search_form', :locals => { :hint => _("Type words about the person you're looking for") } %> | |
11 | + <%= render :partial => 'results_header' %> | |
13 | 12 | |
14 | 13 | <%= display_results %> |
15 | 14 | <% if params[:display] != 'map' %> | ... | ... |
app/views/search/products.rhtml
... | ... | @@ -10,9 +10,8 @@ |
10 | 10 | </div> |
11 | 11 | |
12 | 12 | <div id="search-column-right"> |
13 | - <%= render :partial => 'search_form', :locals => { :form_title => _("Search"), :simple_search => true, | |
14 | - :hint => _('Type the product, service, city or qualifier desired') } %> | |
15 | - <%= render :partial => 'results_header', :locals => { :asset => :products, :results => @results[:products] } %> | |
13 | + <%= render :partial => 'search_form', :locals => { :hint => _('Type the product, service, city or qualifier desired') } %> | |
14 | + <%= render :partial => 'results_header' %> | |
16 | 15 | |
17 | 16 | <% if !@empty_query %> |
18 | 17 | <%= display_results(true) %> | ... | ... |
public/stylesheets/search.css
1 | +.search-category-context { | |
2 | + margin: 30px 0px; | |
3 | +} | |
1 | 4 | .controller-search #search-page { |
2 | 5 | position: relative; /* to the text appear on MSIE 6 */ |
3 | 6 | width: 100%; |
... | ... | @@ -726,4 +729,4 @@ li.search-product-item hr { |
726 | 729 | } |
727 | 730 | .facet-menu a.facet-options-toggle.facet-less-options { |
728 | 731 | background-position: 0 -32px; |
729 | -} | |
730 | 732 | \ No newline at end of file |
733 | +} | ... | ... |
test/functional/search_controller_test.rb
... | ... | @@ -51,15 +51,10 @@ class SearchControllerTest < Test::Unit::TestCase |
51 | 51 | end |
52 | 52 | |
53 | 53 | should 'search only in specified types of content' do |
54 | - get :index, :query => 'something not important', :find_in => [ 'articles' ] | |
54 | + get :articles, :query => 'something not important' | |
55 | 55 | assert_equal [:articles], assigns(:results).keys |
56 | 56 | end |
57 | 57 | |
58 | - should 'search in more than one specified types of content' do | |
59 | - get :index, :query => 'something not important', :find_in => [ 'articles', 'people' ] | |
60 | - assert_equivalent [:articles, :people ], assigns(:results).keys | |
61 | - end | |
62 | - | |
63 | 58 | should 'render success in search' do |
64 | 59 | get :index, :query => 'something not important' |
65 | 60 | assert_response :success |
... | ... | @@ -94,7 +89,7 @@ class SearchControllerTest < Test::Unit::TestCase |
94 | 89 | art1 = create_article_with_optional_category('one article', person, @category) |
95 | 90 | art2 = create_article_with_optional_category('two article', person, @category) |
96 | 91 | |
97 | - get :assets, :asset => 'articles' | |
92 | + get :articles | |
98 | 93 | |
99 | 94 | assert_includes assigns(:results)[:articles], art1 |
100 | 95 | assert_includes assigns(:results)[:articles], art2 |
... | ... | @@ -110,7 +105,7 @@ class SearchControllerTest < Test::Unit::TestCase |
110 | 105 | # not in category |
111 | 106 | art3 = create_article_with_optional_category('another article', person) |
112 | 107 | |
113 | - get :assets, :asset => 'articles', :category_path => ['my-category'] | |
108 | + get :articles, :category_path => ['my-category'] | |
114 | 109 | |
115 | 110 | assert_includes assigns(:results)[:articles], art1 |
116 | 111 | assert_includes assigns(:results)[:articles], art2 |
... | ... | @@ -140,7 +135,7 @@ class SearchControllerTest < Test::Unit::TestCase |
140 | 135 | ent1 = create_profile_with_optional_category(Enterprise, 'teste 1') |
141 | 136 | ent2 = create_profile_with_optional_category(Enterprise, 'teste 2') |
142 | 137 | |
143 | - get :assets, :asset => 'enterprises' | |
138 | + get :enterprises | |
144 | 139 | assert_includes assigns(:results)[:enterprises], ent1 |
145 | 140 | assert_includes assigns(:results)[:enterprises], ent2 |
146 | 141 | end |
... | ... | @@ -152,7 +147,7 @@ class SearchControllerTest < Test::Unit::TestCase |
152 | 147 | # not in category |
153 | 148 | ent2 = create_profile_with_optional_category(Enterprise, 'teste 2') |
154 | 149 | |
155 | - get :assets, :asset => 'enterprises', :category_path => [ 'my-category' ] | |
150 | + get :enterprises, :category_path => [ 'my-category' ] | |
156 | 151 | assert_includes assigns(:results)[:enterprises], ent1 |
157 | 152 | assert_not_includes assigns(:results)[:enterprises], ent2 |
158 | 153 | end |
... | ... | @@ -178,7 +173,7 @@ class SearchControllerTest < Test::Unit::TestCase |
178 | 173 | p1 = create_user('test1').person |
179 | 174 | p2 = create_user('test2').person |
180 | 175 | |
181 | - get :assets, :asset => 'people' | |
176 | + get :people | |
182 | 177 | |
183 | 178 | assert_equivalent [p2,p1], assigns(:results)[:people] |
184 | 179 | end |
... | ... | @@ -193,7 +188,7 @@ class SearchControllerTest < Test::Unit::TestCase |
193 | 188 | # not in category |
194 | 189 | p2 = create_user('test2').person |
195 | 190 | |
196 | - get :assets, :asset => 'people', :category_path => [ 'my-category' ] | |
191 | + get :people, :category_path => [ 'my-category' ] | |
197 | 192 | assert_equal [p1], assigns(:results)[:people] |
198 | 193 | end |
199 | 194 | |
... | ... | @@ -216,7 +211,7 @@ class SearchControllerTest < Test::Unit::TestCase |
216 | 211 | c1 = create_profile_with_optional_category(Community, 'a beautiful community') |
217 | 212 | c2 = create_profile_with_optional_category(Community, 'another beautiful community') |
218 | 213 | |
219 | - get :assets, :asset => 'communities' | |
214 | + get :communities | |
220 | 215 | assert_equivalent [c2, c1], assigns(:results)[:communities] |
221 | 216 | end |
222 | 217 | |
... | ... | @@ -232,7 +227,7 @@ class SearchControllerTest < Test::Unit::TestCase |
232 | 227 | # in category |
233 | 228 | c3 = create_profile_with_optional_category(Community, 'yet another beautiful community', @category) |
234 | 229 | |
235 | - get :assets, :asset => 'communities', :category_path => [ 'my-category' ] | |
230 | + get :communities, :category_path => [ 'my-category' ] | |
236 | 231 | |
237 | 232 | assert_equivalent [c3, c1], assigns(:results)[:communities] |
238 | 233 | end |
... | ... | @@ -263,7 +258,7 @@ class SearchControllerTest < Test::Unit::TestCase |
263 | 258 | prod1 = ent1.products.create!(:name => 'a beautiful product', :product_category => @product_category) |
264 | 259 | prod2 = ent2.products.create!(:name => 'another beautiful product', :product_category => @product_category) |
265 | 260 | |
266 | - get :assets, :asset => 'products' | |
261 | + get :products | |
267 | 262 | assert_equivalent [prod2, prod1], assigns(:results)[:products] |
268 | 263 | end |
269 | 264 | |
... | ... | @@ -279,7 +274,7 @@ class SearchControllerTest < Test::Unit::TestCase |
279 | 274 | ent2 = create_profile_with_optional_category(Enterprise, 'teste2') |
280 | 275 | prod2 = ent2.products.create!(:name => 'another beautiful product', :product_category => @product_category) |
281 | 276 | |
282 | - get :assets, :asset => 'products', :category_path => [ 'my-category' ] | |
277 | + get :products, :category_path => [ 'my-category' ] | |
283 | 278 | |
284 | 279 | assert_equal [prod1], assigns(:results)[:products] |
285 | 280 | end |
... | ... | @@ -328,7 +323,7 @@ class SearchControllerTest < Test::Unit::TestCase |
328 | 323 | environment.enable_plugin(Plugin1.name) |
329 | 324 | environment.enable_plugin(Plugin2.name) |
330 | 325 | |
331 | - get :assets, :asset => 'products' | |
326 | + get :products | |
332 | 327 | |
333 | 328 | assert_tag :tag => 'li', :content => /Property1/, :child => {:tag => 'a', :attributes => {:href => '/plugin1'}, :content => product.name} |
334 | 329 | assert_tag :tag => 'li', :content => /Property2/, :child => {:tag => 'a', :attributes => {:href => '/plugin2'}, :content => product.name} |
... | ... | @@ -339,7 +334,7 @@ class SearchControllerTest < Test::Unit::TestCase |
339 | 334 | ent1 = create_profile_with_optional_category(Enterprise, 'teste 1') |
340 | 335 | ent2 = create_profile_with_optional_category(Enterprise, 'teste 2') |
341 | 336 | |
342 | - get :assets, :asset => 'enterprises', :page => '2' | |
337 | + get :enterprises, :page => '2' | |
343 | 338 | |
344 | 339 | assert_equal 1, assigns(:results)[:enterprises].size |
345 | 340 | end |
... | ... | @@ -372,16 +367,6 @@ class SearchControllerTest < Test::Unit::TestCase |
372 | 367 | assert_tag :tag => 'div', :attributes => { :class => /search-results-people/ }, :descendant => { :tag => 'h3', :content => /People/ } |
373 | 368 | end |
374 | 369 | |
375 | - should 'search in whole site when told so' do | |
376 | - parent = Category.create!(:name => 'randomcat', :environment => Environment.default) | |
377 | - Category.create!(:name => 'randomchild', :environment => Environment.default, :parent => parent) | |
378 | - | |
379 | - get :index, :category_path => [ 'randomcat', 'randomchild' ], :query => 'some random query', :search_whole_site => 'yes' | |
380 | - | |
381 | - # search_whole_site must be removed to precent a infinite redirect loop | |
382 | - assert_redirected_to :action => 'index', :category_path => [], :query => 'some random query', :search_whole_site => nil | |
383 | - end | |
384 | - | |
385 | 370 | should 'display a given category' do |
386 | 371 | get :category_index, :category_path => [ 'my-category' ] |
387 | 372 | assert_equal @category, assigns(:category) |
... | ... | @@ -392,68 +377,9 @@ class SearchControllerTest < Test::Unit::TestCase |
392 | 377 | assert_same assigns(:category), @controller.category |
393 | 378 | end |
394 | 379 | |
395 | - should 'list recent articles in the category' do | |
396 | - recent = [] | |
397 | - finger = CategoryFinder.new(@category) | |
398 | - finger.expects(:recent).with(any_parameters).at_least_once | |
399 | - finger.expects(:recent).with('text_articles', anything).returns(recent) | |
400 | - CategoryFinder.expects(:new).with(@category).returns(finger) | |
401 | - | |
402 | - get :category_index, :category_path => [ 'my-category' ] | |
403 | - assert_same recent, assigns(:results)[:articles] | |
404 | - end | |
405 | - | |
406 | - should 'list most commented articles in the category' do | |
407 | - most_commented = [] | |
408 | - finger = CategoryFinder.new(@category) | |
409 | - finger.expects(:most_commented_articles).returns(most_commented) | |
410 | - CategoryFinder.expects(:new).with(@category).returns(finger) | |
411 | - | |
412 | - get :category_index, :category_path => [ 'my-category' ] | |
413 | - assert_same most_commented, assigns(:results)[:most_commented_articles] | |
414 | - end | |
415 | - | |
416 | - should 'list recently registered people in the category' do | |
417 | - recent_people = [] | |
418 | - finger = CategoryFinder.new(@category) | |
419 | - finger.expects(:recent).with(any_parameters).at_least_once | |
420 | - finger.expects(:recent).with('people', kind_of(Integer)).returns(recent_people) | |
421 | - CategoryFinder.expects(:new).with(@category).returns(finger) | |
422 | - | |
423 | - get :category_index, :category_path => [ 'my-category' ] | |
424 | - assert_same recent_people, assigns(:results)[:people] | |
425 | - end | |
426 | - | |
427 | - should 'list recently registered communities in the category' do | |
428 | - recent_communities = [] | |
429 | - finger = CategoryFinder.new(@category) | |
430 | - finger.expects(:recent).with(any_parameters).at_least_once | |
431 | - finger.expects(:recent).with('communities', anything).returns(recent_communities) | |
432 | - CategoryFinder.expects(:new).with(@category).returns(finger) | |
433 | - | |
434 | - get :category_index, :category_path => [ 'my-category' ] | |
435 | - assert_same recent_communities, assigns(:results)[:communities] | |
436 | - end | |
437 | - | |
438 | - should 'list recently registered enterprises in the category' do | |
439 | - recent_enterptises = [] | |
440 | - finger = CategoryFinder.new(@category) | |
441 | - finger.expects(:recent).with(any_parameters).at_least_once | |
442 | - finger.expects(:recent).with('enterprises', anything).returns(recent_enterptises) | |
443 | - CategoryFinder.expects(:new).with(@category).returns(finger) | |
444 | - | |
445 | - get :category_index, :category_path => [ 'my-category' ] | |
446 | - assert_same recent_enterptises, assigns(:results)[:enterprises] | |
447 | - end | |
448 | - | |
449 | - should 'not list "Search for ..." in category_index' do | |
450 | - get :category_index, :category_path => [ 'my-category' ] | |
451 | - assert_no_tag :content => /Search for ".*" in the whole site/ | |
452 | - end | |
453 | - | |
454 | 380 | # SECURITY |
455 | 381 | should 'not allow unrecognized assets' do |
456 | - get :assets, :asset => 'unexisting_asset' | |
382 | + get :unexisting_asset | |
457 | 383 | assert_response 403 |
458 | 384 | end |
459 | 385 | |
... | ... | @@ -478,11 +404,6 @@ class SearchControllerTest < Test::Unit::TestCase |
478 | 404 | } |
479 | 405 | end |
480 | 406 | |
481 | - should 'offer button search in the whole site' do | |
482 | - get :index, :category_path => [ 'my-category' ], :query => 'a sample search' | |
483 | - assert_tag :tag => 'input', :attributes => { :type => 'submit', :name => 'search_whole_site_yes' } | |
484 | - end | |
485 | - | |
486 | 407 | should 'display only category name in "search results for ..." title' do |
487 | 408 | parent = Category.create!(:name => 'Parent Category', :environment => Environment.default) |
488 | 409 | child = Category.create!(:name => "Child Category", :environment => Environment.default, :parent => parent) |
... | ... | @@ -498,7 +419,7 @@ class SearchControllerTest < Test::Unit::TestCase |
498 | 419 | |
499 | 420 | p = create_profile_with_optional_category(Person, 'test_profile', child) |
500 | 421 | |
501 | - get :index, :category_path => ['parent-category'], :query => 'test_profile', :find_in => ['people'] | |
422 | + get :category_index, :category_path => ['parent-category'], :query => 'test_profile', :find_in => ['people'] | |
502 | 423 | |
503 | 424 | assert_includes assigns(:results)[:people], p |
504 | 425 | end |
... | ... | @@ -525,22 +446,6 @@ class SearchControllerTest < Test::Unit::TestCase |
525 | 446 | assert_not_includes assigns('results')[:enterprises], ent2 |
526 | 447 | end |
527 | 448 | |
528 | - should 'find profiles by radius and region' do | |
529 | - city = City.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0) | |
530 | - ent1 = create_profile_with_optional_category(Enterprise, 'test 1', nil, :lat => 45.0, :lng => 45.0) | |
531 | - p1 = create_profile_with_optional_category(Person, 'test 2', nil, :lat => 45.0, :lng => 45.0) | |
532 | - | |
533 | - ent2 = create_profile_with_optional_category(Enterprise, 'test 1', nil, :lat => 30.0, :lng => 30.0) | |
534 | - p2 = create_profile_with_optional_category(Person, 'test 2', nil, :lat => 30.0, :lng => 30.0) | |
535 | - | |
536 | - get :index, :city => city.id, :radius => 10, :query => 'test' | |
537 | - | |
538 | - assert_includes assigns('results')[:enterprises], ent1 | |
539 | - assert_not_includes assigns('results')[:enterprises], ent2 | |
540 | - assert_includes assigns('results')[:people], p1 | |
541 | - assert_not_includes assigns('results')[:people], p2 | |
542 | - end | |
543 | - | |
544 | 449 | should 'display category image while in directory' do |
545 | 450 | parent = Category.create!(:name => 'category1', :environment => Environment.default) |
546 | 451 | cat = Category.create!(:name => 'category2', :environment => Environment.default, :parent => parent, |
... | ... | @@ -552,60 +457,6 @@ class SearchControllerTest < Test::Unit::TestCase |
552 | 457 | assert_tag :tag => 'img', :attributes => { :src => /rails_thumb\.png/ } |
553 | 458 | end |
554 | 459 | |
555 | - should 'complete region name' do | |
556 | - r1 = Region.create!(:name => 'One region', :environment => Environment.default, :lat => 111.07, :lng => '88.9') | |
557 | - r2 = Region.create!(:name => 'Another region', :environment => Environment.default, :lat => 111.07, :lng => '88.9') | |
558 | - | |
559 | - get :complete_region, :region => { :name => 'one' } | |
560 | - assert_includes assigns(:regions), r1 | |
561 | - assert_tag :tag => 'ul', :descendant => { :tag => 'li', :content => 'One region' } | |
562 | - end | |
563 | - | |
564 | - should 'render completion results without layout' do | |
565 | - get :complete_region, :region => { :name => 'test' } | |
566 | - assert_no_tag :tag => 'body' | |
567 | - end | |
568 | - | |
569 | - should 'complete only georeferenced regions' do | |
570 | - r1 = Region.create!(:name => 'One region', :environment => Environment.default, :lat => 111.07, :lng => '88.9') | |
571 | - r2 = Region.create!(:name => 'Another region', :environment => Environment.default) | |
572 | - | |
573 | - get :complete_region, :region => { :name => 'region' } | |
574 | - assert_includes assigns(:regions), r1 | |
575 | - assert_tag :tag => 'ul', :descendant => { :tag => 'li', :content => r1.name } | |
576 | - assert_not_includes assigns(:regions), r2 | |
577 | - assert_no_tag :tag => 'ul', :descendant => { :tag => 'li', :content => r2.name } | |
578 | - end | |
579 | - | |
580 | - should 'return options of cities by its state' do | |
581 | - state1 = State.create!(:name => 'State One', :environment => Environment.default) | |
582 | - state2 = State.create!(:name => 'State Two', :environment => Environment.default) | |
583 | - city1 = City.create!(:name => 'City One', :environment => Environment.default, :lat => 111.07, :lng => '88.9', :parent => state1) | |
584 | - city2 = City.create!(:name => 'City Two', :environment => Environment.default, :lat => 111.07, :lng => '88.9', :parent => state2) | |
585 | - | |
586 | - get :cities, :state_id => state1.id | |
587 | - assert_includes assigns(:cities), city1 | |
588 | - assert_tag :tag => 'option', :content => city1.name, :attributes => {:value => city1.id} | |
589 | - assert_not_includes assigns(:cities), city2 | |
590 | - assert_no_tag :tag => 'option', :content => city2.name, :attributes => {:value => city2.id} | |
591 | - end | |
592 | - | |
593 | - should 'render cities results without layout' do | |
594 | - get :cities, :state_id => 1 | |
595 | - assert_no_tag :tag => 'body' | |
596 | - end | |
597 | - | |
598 | - should 'list only georeferenced cities' do | |
599 | - state = State.create!(:name => 'State One', :environment => Environment.default) | |
600 | - city1 = City.create!(:name => 'City One', :environment => Environment.default, :lat => 111.07, :lng => '88.9', :parent => state) | |
601 | - city2 = City.create!(:name => 'City Two', :environment => Environment.default, :parent => state) | |
602 | - | |
603 | - get :cities, :state_id => state.id | |
604 | - | |
605 | - assert_includes assigns(:cities), city1 | |
606 | - assert_not_includes assigns(:cities), city2 | |
607 | - end | |
608 | - | |
609 | 460 | should 'search for events' do |
610 | 461 | person = create_user('teste').person |
611 | 462 | ev = create_event(person, :name => 'an event to be found') |
... | ... | @@ -642,7 +493,7 @@ class SearchControllerTest < Test::Unit::TestCase |
642 | 493 | |
643 | 494 | ev2 = create_event(person2, :name => 'two event', :category_ids => [@category.id]) |
644 | 495 | |
645 | - get :assets, :asset => 'events' | |
496 | + get :events | |
646 | 497 | |
647 | 498 | assert_includes assigns(:results)[:events], ev1 |
648 | 499 | assert_includes assigns(:results)[:events], ev2 |
... | ... | @@ -659,7 +510,7 @@ class SearchControllerTest < Test::Unit::TestCase |
659 | 510 | # not in category |
660 | 511 | ev3 = create_event(person, :name => 'another event') |
661 | 512 | |
662 | - get :assets, :asset => 'events', :category_path => ['my-category'] | |
513 | + get :events, :category_path => ['my-category'] | |
663 | 514 | |
664 | 515 | assert_includes assigns(:results)[:events], ev1 |
665 | 516 | assert_includes assigns(:results)[:events], ev2 |
... | ... | @@ -672,7 +523,7 @@ class SearchControllerTest < Test::Unit::TestCase |
672 | 523 | create_event(person, :name => 'upcoming event 1', :category_ids => [@category.id], :start_date => Date.new(2008, 1, 25)) |
673 | 524 | create_event(person, :name => 'upcoming event 2', :category_ids => [@category.id], :start_date => Date.new(2008, 4, 27)) |
674 | 525 | |
675 | - get :assets, :asset => 'events', :year => '2008', :month => '1' | |
526 | + get :events, :year => '2008', :month => '1' | |
676 | 527 | |
677 | 528 | assert_equal [ 'upcoming event 1' ], assigns(:results)[:events].map(&:name) |
678 | 529 | end |
... | ... | @@ -683,7 +534,7 @@ class SearchControllerTest < Test::Unit::TestCase |
683 | 534 | create_event(person, :name => 'upcoming event 1', :category_ids => [@category.id], :start_date => Date.new(2008, 1, 25)) |
684 | 535 | create_event(person, :name => 'upcoming event 2', :category_ids => [@category.id], :start_date => Date.new(2008, 4, 27)) |
685 | 536 | |
686 | - get :assets, :asset => 'events', :category_path => [ 'my-category' ], :year => '2008', :month => '1' | |
537 | + get :events, :category_path => [ 'my-category' ], :year => '2008', :month => '1' | |
687 | 538 | |
688 | 539 | assert_equal [ 'upcoming event 1' ], assigns(:results)[:events].map(&:name) |
689 | 540 | end |
... | ... | @@ -866,27 +717,15 @@ class SearchControllerTest < Test::Unit::TestCase |
866 | 717 | should 'display current year/month by default as caption of current month' do |
867 | 718 | Date.expects(:today).returns(Date.new(2008, 8, 1)).at_least_once |
868 | 719 | |
869 | - get :assets, :asset => 'events' | |
720 | + get :events | |
870 | 721 | assert_tag :tag => 'table', :attributes => {:class => /current-month/}, :descendant => {:tag => 'caption', :content => /August 2008/} |
871 | 722 | end |
872 | 723 | |
873 | 724 | should 'submit search form to /search when viewing asset' do |
874 | - get :index, :asset => 'people' | |
725 | + get :people | |
875 | 726 | assert_tag :tag => "form", :attributes => { :class => 'search_form', :action => '/search' } |
876 | 727 | end |
877 | - | |
878 | - should 'treat blank input for the city id' do | |
879 | - get :index, :city => '' | |
880 | - | |
881 | - assert_equal nil, assigns(:region) | |
882 | - end | |
883 | 728 | |
884 | - should 'treat non-numeric input for the city id' do | |
885 | - get :index, :city => 'bla' | |
886 | - | |
887 | - assert_equal nil, assigns(:region) | |
888 | - end | |
889 | - | |
890 | 729 | should 'found TextileArticle in articles' do |
891 | 730 | person = create_user('teste').person |
892 | 731 | art = TextileArticle.create!(:name => 'an text_article article to be found', :profile => person) |
... | ... | @@ -910,32 +749,16 @@ class SearchControllerTest < Test::Unit::TestCase |
910 | 749 | assert_not_includes @controller.where_to_search.map(&:first), :products |
911 | 750 | end |
912 | 751 | |
913 | - should 'search for products by origin and radius correctly' do | |
914 | - s = City.create!(:name => 'Salvador', :lat => -12.97, :lng => -38.51, :environment => Environment.default) | |
915 | - e1 = create_profile_with_optional_category(Enterprise, 'test ent 1', nil, :lat => -12.97, :lng => -38.51) | |
916 | - p1 = e1.products.create!(:name => 'test_product1', :product_category => @product_category) | |
917 | - e2 = create_profile_with_optional_category(Enterprise, 'test ent 2', nil, :lat => -14.97, :lng => -40.51) | |
918 | - p2 = e2.products.create!(:name => 'test_product2', :product_category => @product_category) | |
919 | - | |
920 | - get :assets, :asset => 'products', :city => s.id, :radius => 15 | |
921 | - | |
922 | - assert_includes assigns(:results)[:products], p1 | |
923 | - assert_not_includes assigns(:results)[:products], p2 | |
924 | - end | |
925 | - | |
926 | - should 'show link to article asset in the see all foot link of the most_commented_articles block in the category page' do | |
927 | - art = create_user('teste').person.articles.create!(:name => 'an article to be found') | |
928 | - most_commented = [art] | |
929 | - finder = CategoryFinder.new(@category) | |
930 | - finder.expects(:most_commented_articles).returns(most_commented) | |
931 | - CategoryFinder.expects(:new).with(@category).returns(finder) | |
752 | + should 'show link to article asset in the see all foot link of the articles block in the category page' do | |
753 | + a = create_user('test1').person.articles.create!(:name => 'an article to be found') | |
754 | + a.add_category @category | |
932 | 755 | |
933 | 756 | get :category_index, :category_path => [ 'my-category' ] |
934 | - assert_tag :tag => 'div', :attributes => {:class => /search-results-most_commented_articles/} , :descendant => {:tag => 'a', :attributes => { :href => '/search/index/my-category?asset=articles'}} | |
757 | + assert_tag :tag => 'div', :attributes => {:class => /search-results-articles/} , :descendant => {:tag => 'a', :attributes => { :href => '/search/articles/my-category'}} | |
935 | 758 | end |
936 | 759 | |
937 | 760 | should 'display correct title on list communities' do |
938 | - get :assets, :asset => 'communities' | |
761 | + get :communities | |
939 | 762 | assert_tag :tag => 'h1', :content => 'Communities' |
940 | 763 | end |
941 | 764 | |
... | ... | @@ -952,14 +775,14 @@ class SearchControllerTest < Test::Unit::TestCase |
952 | 775 | |
953 | 776 | should 'add link to list in all categories when in a category' do |
954 | 777 | ['people', 'enterprises', 'products', 'communities', 'articles'].each do |asset| |
955 | - get :index, :asset => asset, :category_path => [ 'my-category' ] | |
778 | + get asset, :category_path => [ 'my-category' ] | |
956 | 779 | assert_tag :tag => 'div', :content => 'In all categories' |
957 | 780 | end |
958 | 781 | end |
959 | 782 | |
960 | 783 | should 'not add link to list in all categories when not in a category' do |
961 | 784 | ['people', 'enterprises', 'products', 'communities', 'articles'].each do |asset| |
962 | - get :index, :asset => asset | |
785 | + get asset | |
963 | 786 | assert_no_tag :tag => 'div', :content => 'In all categories' |
964 | 787 | end |
965 | 788 | end |
... | ... | @@ -1019,7 +842,7 @@ class SearchControllerTest < Test::Unit::TestCase |
1019 | 842 | event_in_searched_category = create_event(person, :name => 'Maria Birthday', :start_date => Date.today, :category_ids => [searched_category.id]) |
1020 | 843 | event_in_non_searched_category = create_event(person, :name => 'Joao Birthday', :start_date => Date.today, :category_ids => [@category.id]) |
1021 | 844 | |
1022 | - get :assets, :asset => 'events', :category_path => ['category-with-events'] | |
845 | + get :events, :category_path => ['category-with-events'] | |
1023 | 846 | |
1024 | 847 | assert_includes assigns(:events_of_the_day), event_in_searched_category |
1025 | 848 | assert_not_includes assigns(:events_of_the_day), event_in_non_searched_category |
... | ... | @@ -1112,7 +935,7 @@ class SearchControllerTest < Test::Unit::TestCase |
1112 | 935 | |
1113 | 936 | get :people, :filter => 'more_active' |
1114 | 937 | |
1115 | - assert_equal Person.count/per_page, assigns(:results).total_pages | |
938 | + assert_equal Person.count/per_page, assigns(:results).total_entries | |
1116 | 939 | end |
1117 | 940 | |
1118 | 941 | should 'list all people filter by more active' do |
... | ... | @@ -1141,36 +964,52 @@ class SearchControllerTest < Test::Unit::TestCase |
1141 | 964 | assert_equal [p2,p1,p3] , assigns(:results) |
1142 | 965 | end |
1143 | 966 | |
1144 | - should 'the people filter be only the hardcoded one' do | |
967 | + should 'set filter be only the hardcoded one' do | |
1145 | 968 | get :people, :filter => 'more_recent' |
1146 | 969 | assert_equal 'more_recent' , assigns(:filter) |
1147 | - | |
1148 | 970 | get :people, :filter => 'more_active' |
1149 | 971 | assert_equal 'more_active' , assigns(:filter) |
1150 | - | |
1151 | 972 | get :people, :filter => 'more_popular' |
1152 | 973 | assert_equal 'more_popular' , assigns(:filter) |
1153 | - | |
1154 | 974 | get :people, :filter => 'more_anything' |
1155 | 975 | assert_equal 'more_recent' , assigns(:filter) |
976 | + | |
977 | + get :communities, :filter => 'more_recent' | |
978 | + assert_equal 'more_recent' , assigns(:filter) | |
979 | + get :communities, :filter => 'more_active' | |
980 | + assert_equal 'more_active' , assigns(:filter) | |
981 | + get :communities, :filter => 'more_popular' | |
982 | + assert_equal 'more_popular' , assigns(:filter) | |
983 | + get :communities, :filter => 'more_anything' | |
984 | + assert_equal 'more_recent' , assigns(:filter) | |
1156 | 985 | end |
1157 | 986 | |
1158 | 987 | should 'the people filter define the title' do |
1159 | 988 | get :people, :filter => 'more_recent' |
1160 | - assert_equal 'More recent people' , assigns(:title) | |
1161 | - assert_tag :h1, :content => 'More recent people' | |
1162 | - | |
989 | + assert_equal 'More recent people from network' , assigns(:filter_title) | |
990 | + assert_tag :h1, :content => 'More recent people from network' | |
1163 | 991 | get :people, :filter => 'more_active' |
1164 | - assert_equal 'More active people' , assigns(:title) | |
1165 | - assert_tag :h1, :content => 'More active people' | |
1166 | - | |
992 | + assert_equal 'More active people from network' , assigns(:filter_title) | |
993 | + assert_tag :h1, :content => 'More active people from network' | |
1167 | 994 | get :people, :filter => 'more_popular' |
1168 | - assert_equal 'More popular people' , assigns(:title) | |
1169 | - assert_tag :h1, :content => 'More popular people' | |
1170 | - | |
995 | + assert_equal 'More popular people from network' , assigns(:filter_title) | |
996 | + assert_tag :h1, :content => 'More popular people from network' | |
1171 | 997 | get :people, :filter => 'more_anything' |
1172 | - assert_equal 'More recent people' , assigns(:title) | |
1173 | - assert_tag :h1, :content => 'More recent people' | |
998 | + assert_equal 'More recent people from network' , assigns(:filter_title) | |
999 | + assert_tag :h1, :content => 'More recent people from network' | |
1000 | + get :communities, :filter => 'more_recent' | |
1001 | + | |
1002 | + assert_equal 'More recent communities from network' , assigns(:filter_title) | |
1003 | + assert_tag :h1, :content => 'More recent communities from network' | |
1004 | + get :communities, :filter => 'more_active' | |
1005 | + assert_equal 'More active communities from network' , assigns(:filter_title) | |
1006 | + assert_tag :h1, :content => 'More active communities from network' | |
1007 | + get :communities, :filter => 'more_popular' | |
1008 | + assert_equal 'More popular communities from network' , assigns(:filter_title) | |
1009 | + assert_tag :h1, :content => 'More popular communities from network' | |
1010 | + get :communities, :filter => 'more_anything' | |
1011 | + assert_equal 'More recent communities from network' , assigns(:filter_title) | |
1012 | + assert_tag :h1, :content => 'More recent communities from network' | |
1174 | 1013 | end |
1175 | 1014 | |
1176 | 1015 | should 'search for community' do |
... | ... | @@ -1259,38 +1098,6 @@ class SearchControllerTest < Test::Unit::TestCase |
1259 | 1098 | assert_equal [c2,c1] , assigns(:results) |
1260 | 1099 | end |
1261 | 1100 | |
1262 | - should 'the communities filter be only the hardcoded one' do | |
1263 | - get :communities, :filter => 'more_recent' | |
1264 | - assert_equal 'more_recent' , assigns(:filter) | |
1265 | - | |
1266 | - get :communities, :filter => 'more_active' | |
1267 | - assert_equal 'more_active' , assigns(:filter) | |
1268 | - | |
1269 | - get :communities, :filter => 'more_popular' | |
1270 | - assert_equal 'more_popular' , assigns(:filter) | |
1271 | - | |
1272 | - get :communities, :filter => 'more_anything' | |
1273 | - assert_equal 'more_recent' , assigns(:filter) | |
1274 | - end | |
1275 | - | |
1276 | - should 'the communities filter define the title' do | |
1277 | - get :communities, :filter => 'more_recent' | |
1278 | - assert_equal 'More recent communities' , assigns(:title) | |
1279 | - assert_tag :h1, :content => 'More recent communities' | |
1280 | - | |
1281 | - get :communities, :filter => 'more_active' | |
1282 | - assert_equal 'More active communities' , assigns(:title) | |
1283 | - assert_tag :h1, :content => 'More active communities' | |
1284 | - | |
1285 | - get :communities, :filter => 'more_popular' | |
1286 | - assert_equal 'More popular communities' , assigns(:title) | |
1287 | - assert_tag :h1, :content => 'More popular communities' | |
1288 | - | |
1289 | - get :communities, :filter => 'more_anything' | |
1290 | - assert_equal 'More recent communities' , assigns(:title) | |
1291 | - assert_tag :h1, :content => 'More recent communities' | |
1292 | - end | |
1293 | - | |
1294 | 1101 | should "only include visible people in more_recent filter" do |
1295 | 1102 | # assuming that all filters behave the same! |
1296 | 1103 | p1 = fast_create(Person, :visible => false) | ... | ... |
test/unit/category_test.rb
... | ... | @@ -219,6 +219,62 @@ class CategoryTest < Test::Unit::TestCase |
219 | 219 | ################################################################ |
220 | 220 | # category filter stuff |
221 | 221 | ################################################################ |
222 | + | |
223 | + should 'should paginate recent-like methods' do | |
224 | + c = @env.categories.build(:name => 'my category'); c.save! | |
225 | + assert c.recent_people.respond_to? 'total_entries' | |
226 | + assert c.recent_enterprises.respond_to? 'total_entries' | |
227 | + assert c.recent_communities.respond_to? 'total_entries' | |
228 | + assert c.recent_products.respond_to? 'total_entries' | |
229 | + assert c.recent_articles.respond_to? 'total_entries' | |
230 | + assert c.recent_comments.respond_to? 'total_entries' | |
231 | + assert c.most_commented_articles.respond_to? 'total_entries' | |
232 | + end | |
233 | + | |
234 | + should 'list recent people' do | |
235 | + c = @env.categories.build(:name => 'my category'); c.save! | |
236 | + p1 = create_user('testuser').person | |
237 | + p1.add_category c | |
238 | + p1.save! | |
239 | + | |
240 | + p2 = create_user('testuser2').person | |
241 | + p2.add_category c | |
242 | + p2.save! | |
243 | + | |
244 | + assert_equal [p2, p1], c.recent_people | |
245 | + end | |
246 | + | |
247 | + should 'list recent enterprises' do | |
248 | + c = @env.categories.build(:name => 'my category'); c.save! | |
249 | + ent1 = fast_create(Enterprise, :identifier => 'enterprise_1', :name => 'Enterprise one') | |
250 | + ent1.add_category c | |
251 | + ent2 = fast_create(Enterprise, :identifier => 'enterprise_2', :name => 'Enterprise one') | |
252 | + ent2.add_category c | |
253 | + | |
254 | + assert_equal [ent2, ent1], c.recent_enterprises | |
255 | + end | |
256 | + | |
257 | + should 'list recent communities' do | |
258 | + c = @env.categories.build(:name => 'my category'); c.save! | |
259 | + c1 = fast_create(Community, :name => 'testcommunity_1') | |
260 | + c1.add_category c | |
261 | + c2 = fast_create(Community, :name => 'testcommunity_2') | |
262 | + c2.add_category c | |
263 | + | |
264 | + assert_equal [c2, c1], c.recent_communities | |
265 | + end | |
266 | + | |
267 | + should 'list recent products' do | |
268 | + product_category = fast_create(ProductCategory, :name => 'Products', :environment_id => Environment.default.id) | |
269 | + c = @env.categories.build(:name => 'my category'); c.save! | |
270 | + ent1 = fast_create(Enterprise, :identifier => 'enterprise_1', :name => 'Enterprise one') | |
271 | + ent1.add_category c | |
272 | + ent2 = fast_create(Enterprise, :identifier => 'enterprise_2', :name => 'Enterprise one') | |
273 | + ent2.add_category c | |
274 | + prod1 = ent1.products.create!(:name => 'test_prod1', :product_category => product_category) | |
275 | + prod2 = ent2.products.create!(:name => 'test_prod2', :product_category => product_category) | |
276 | + assert_equal [prod2, prod1], c.recent_products | |
277 | + end | |
222 | 278 | |
223 | 279 | should 'list recent articles' do |
224 | 280 | c = @env.categories.build(:name => 'my category'); c.save! |
... | ... | @@ -232,7 +288,7 @@ class CategoryTest < Test::Unit::TestCase |
232 | 288 | a2.add_category c |
233 | 289 | a2.save! |
234 | 290 | |
235 | - assert_equivalent [a1, a2], c.recent_articles | |
291 | + assert_equal [a2, a1], c.recent_articles | |
236 | 292 | end |
237 | 293 | |
238 | 294 | should 'list recent comments' do |
... | ... | @@ -249,7 +305,7 @@ class CategoryTest < Test::Unit::TestCase |
249 | 305 | a2.save! |
250 | 306 | c2 = a2.comments.build(:title => 'comm1', :body => 'khdkashd ', :author => person); c2.save! |
251 | 307 | |
252 | - assert_equivalent [c1, c2], c.recent_comments | |
308 | + assert_equal [c2, c1], c.recent_comments | |
253 | 309 | end |
254 | 310 | |
255 | 311 | should 'list most commented articles' do |
... | ... | @@ -267,6 +323,7 @@ class CategoryTest < Test::Unit::TestCase |
267 | 323 | |
268 | 324 | assert_equal [a3, a2], c.most_commented_articles(2) |
269 | 325 | end |
326 | + | |
270 | 327 | should 'have comments' do |
271 | 328 | c = @env.categories.build(:name => 'my category'); c.save! |
272 | 329 | person = create_user('testuser').person | ... | ... |