-
-
-

<%= t("debates.index.showing") %>

- <%= render 'order_selector' %> -
-
- +
+ +
+ <% if @tag_filter %> +

+ <%= t("debates.index.filter_topic", + number: @debates.size, + topic: @tag_filter).html_safe %> +

+ <% else %> +

<%= t("debates.index.select_topic") %>

+
+ +
+ <% end %> +
+ +
+
<%= t("debates.index.select_order") %>
+
+ +
+
- -
-
-

- <%= t("debates.index.filter_topic", - number: "N", - topic: "topic").html_safe %> -

-
diff --git a/config/locales/en.yml b/config/locales/en.yml index afda0391b..148eaed88 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -56,12 +56,14 @@ en: debates: index: create_debate: Create a debate - showing: You are seeing debates + select_order: Order by orders: created_at: newest total_votes: most voted likes: best rated + select_topic: "Filter by topic:" filter_topic: "You are seeing %{number} debates with the topic '%{topic}'" + all: All debate: debate: Debate comments: diff --git a/config/locales/es.yml b/config/locales/es.yml index 5884f0cfc..4b4816047 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -56,12 +56,14 @@ es: debates: index: create_debate: Crea un debate - showing: "Estás viendo los debates" + select_order: Ordenar por orders: created_at: "más nuevos" total_votes: "más votados" likes: mejor valorados + select_topic: "Filtrar por tema:" filter_topic: "Estás viendo %{number} debates con el tema '%{topic}'" + all: Todos debate: debate: Debate comments: diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 3f01bd312..da966f7a3 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -407,4 +407,34 @@ feature 'Debates' do expect(@most_liked_debate.title).to appear_before(@most_voted_debate.title) end end + + 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", "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('Filter by topic') + expect(page).not_to have_content('with the topic') + expect(page).to have_selector('#debates .debate', count: 3) + end + + scenario 'Debates are filtered by single tag' do + visit debates_path + + select('Deporte', from: 'tag-filter') + + 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_not have_content(debate3.title) + expect(page).to have_content(debate1.title) + expect(page).to have_content(debate2.title) + end + end end