Combine debates topic and order filters

This commit is contained in:
Marko Lovic
2015-08-28 17:03:15 +02:00
parent d7c2dd3aac
commit c11b611b1a
2 changed files with 31 additions and 38 deletions

View File

@@ -1,41 +1,37 @@
<section role="main">
<!-- Filters -->
<div class="filters row">
<div class="small-12 column">
<h2><%= t("debates.index.showing") %></h2>
<form class="inline-block">
<select class="js-order-selector" name="order-selector">
<%= available_options_for_order_selector(@valid_orders, @order) %>
</select>
</form>
</div>
</div>
<!-- /. Filters -->
<div class="small-9 column">
<!-- Filter topic results -->
<div class="filters row">
<div class="small-12 column">
<% if @tag_filter %>
<h2>
<%= t("debates.index.filter_topic",
number: @debates.size,
# TODO translation
topic: @tag_filter).html_safe %>
</h2>
<% else %>
<h2>Filtrar por tema: </h2>
<div class="inline-block" >
<% if @tag_filter %>
<h2>
<%= t("debates.index.filter_topic",
number: @debates.size,
topic: @tag_filter).html_safe %>
</h2>
<% else %>
<h2><%= t("debates.index.select_topic") %></h2>
<form class="inline-block">
<select class="js-tag-filter" name="tag-filter">
<option value="all" selected="selected"><%= t("debates.index.all") %></option>
<%= options_from_collection_for_select(ActsAsTaggableOn::Tag.all, :name, :name) %>
</select>
</form>
<% end %>
</div>
<div class="inline-block right">
<h6 class="inline-block"><%= t("debates.index.select_order") %></h6>
<form class="inline-block">
<select class="js-tag-filter" name="tag-filter">
<%# select_tag 'tag-filter', nil, {prompt: 'Temas --', class: 'js-tag-filter'} do %>
<option value="default" disabled="disabled" selected="selected">Temas --</option>
<%= options_from_collection_for_select(ActsAsTaggableOn::Tag.all, :name, :name, prompt: 'Temas...') %>
<select class="js-order-selector" name="order-selector">
<%= available_options_for_order_selector(@valid_orders, @order) %>
</select>
</form>
<% end %>
</div>
</div>
</div>
<!-- /. Filter topic results -->
<div class="row">
<div id="debates" class="debates-list small-12 medium-9 column">

View File

@@ -410,16 +410,15 @@ feature 'Debates' do
feature 'Debates can be filtered by tags', :js do
let!(:debate1) { create(:debate, tag_list: ["Deporte", "Corrupción"]) }
let!(:debate2) { create(:debate, tag_list: ["Deporte", "Corrupción", "Fiestas populares"]) }
let!(:debate2) { create(:debate, tag_list: ["Deporte", "Fiestas populares"]) }
let!(:debate3) { create(:debate, tag_list: ["Corrupción", "Fiestas populares"]) }
scenario 'By default no tag filter is applied' do
visit debates_path
expect(page).to have_content('Filtrar por tema')
expect(page).not_to have_content('con el tema')
expect(page).to have_content('Filter by topic')
expect(page).not_to have_content('with the topic')
expect(page).to have_selector('#debates .debate', count: 3)
expect(current_url).to_not include('tag=')
end
scenario 'Debates are filtered by single tag' do
@@ -427,17 +426,15 @@ feature 'Debates' do
select('Deporte', from: 'tag-filter')
expect(page).not_to have_content('Filtrar por tema')
expect(page).to have_content('with the topic')
expect(page).not_to have_content('Filter by topic')
expect(page).not_to have_select('tag-filter')
expect(page).to have_content('with the topic')
expect(current_url).to include('tag=Deporte')
expect(page).to have_selector('#debates .debate', count: 2)
expect(page).to have_selector('#debates .debate', count: 2)
expect(page).to_not have_content(debate3.title)
expect(page).to have_content(debate1.title)
expect(page).to have_content(debate2.title)
end
end
end