Skip to content

Commit

Permalink
Removes the tag selector from debate#index view & refactors i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
kikito committed Sep 3, 2015
1 parent c7b4448 commit 002d868
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 60 deletions.
40 changes: 17 additions & 23 deletions app/views/debates/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,24 @@
<div class="filters row">
<div class="small-9 column">

<div class="inline-block" >
<% if @tag_filter %>
<h2>
<%= t("debates.index.filter_topic",
number: @debates.size,
topic: @tag_filter) %>
</h2>
<% else %>
<h2><%= t("debates.index.select_topic") %></h2>
<form class="inline-block">
<select class="js-location-changer" name="tag-filter">
<option value="/" selected="selected"><%= t("debates.index.all") %></option>
<% @tags.each do |tag| %>
<option value='<%= current_path_with_query_params(tag: tag.name) %>'>
<%= tag.name %>
</option>
<% end %>
</select>
</form>
<% end %>
</div>
<% if @tag_filter %>
<div class="inline-block small-8" >
<h2>
<%= t("debates.index.filter_topic",
count: @debates.size,
topic: @tag_filter) %>
</h2>
</div>
<% end %>

<div class="inline-block right">
<h6 class="inline-block"><%= t("debates.index.select_order") %></h6>
<div class="inline-block <%= 'right' if @tag_filter %>">
<h6 class="inline-block">
<% if @tag_filter %>
<%= t("debates.index.select_order") %>
<% else %>
<%= t("debates.index.select_order_long") %>
<% end %>
</h6>
<form class="inline-block">
<select class="js-location-changer" name="order-selector">
<% @valid_orders.each do |order| %>
Expand Down
7 changes: 4 additions & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ en:
index:
create_debate: Create a debate
select_order: Order by
select_order_long: Order debates 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
filter_topic:
one: "You are seeing one debate with the topic '%{topic}'"
other: "You are seeing %{count} debates with the topic '%{topic}'"
debate:
debate: Debate
comments:
Expand Down
9 changes: 5 additions & 4 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ es:
index:
create_debate: Crea un debate
select_order: Ordenar por
select_order_long: Estás viendo los debates
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
likes: "mejor valorados"
filter_topic:
one: "Estás viendo un debate con el tema ''%{topic}''"
other: "Estás viendo %{count} debates con el tema '%{topic}'"
debate:
debate: Debate
comments:
Expand Down
30 changes: 0 additions & 30 deletions spec/features/debates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,34 +407,4 @@
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

0 comments on commit 002d868

Please sign in to comment.