-
-
-

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

-
- -
-
-
- +
- -
-
-

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

+
+ <% if @tag_filter %> +

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

+ <% else %> +

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

+
+ +
+ <% end %> +
+ +
+
<%= t("debates.index.select_order") %>
+
+ +
+
-
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/lib/user_api.rb b/lib/census_api.rb similarity index 95% rename from lib/user_api.rb rename to lib/census_api.rb index a5553e279..ac5a88d08 100644 --- a/lib/user_api.rb +++ b/lib/census_api.rb @@ -1,4 +1,4 @@ -class UserApi +class CensusApi attr_accessor :client, :citizen, :response def initialize(citizen) @@ -42,6 +42,8 @@ class UserApi end def valid? + return false unless data[:datos_habitante][:item].present? + citizen.date_of_birth == date_of_birth && citizen.postal_code == postal_code end diff --git a/spec/features/comments_spec.rb b/spec/features/comments_spec.rb index 0986412bc..9814a4b33 100644 --- a/spec/features/comments_spec.rb +++ b/spec/features/comments_spec.rb @@ -59,7 +59,7 @@ feature 'Comments' do login_as(user) visit debate_path(debate) - fill_in 'comment_body', with: 'Have you thought about...?' + fill_in "comment-body-debate_#{debate.id}", with: 'Have you thought about...?' click_button 'Publish comment' within "#comments" do @@ -91,7 +91,7 @@ feature 'Comments' do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in 'comment_body', with: 'It will be done next week.' + fill_in "comment-body-comment_#{comment.id}", with: 'It will be done next week.' click_button 'Publish reply' end @@ -178,8 +178,8 @@ feature 'Comments' do login_as(moderator.user) visit debate_path(debate) - fill_in "comment_body", with: "I am moderating!" - check "comment_as_moderator" + fill_in "comment-body-debate_#{debate.id}", with: "I am moderating!" + check "comment-as-moderator-debate_#{debate.id}" click_button "Publish comment" within "#comments" do @@ -203,8 +203,8 @@ feature 'Comments' do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment_body", with: "I am moderating!" - check "comment_as_moderator" + fill_in "comment-body-comment_#{comment.id}", with: "I am moderating!" + check "comment-as-moderator-comment_#{comment.id}" click_button 'Publish reply' end @@ -237,8 +237,8 @@ feature 'Comments' do login_as(admin.user) visit debate_path(debate) - fill_in "comment_body", with: "I am your Admin!" - check "comment_as_administrator" + fill_in "comment-body-debate_#{debate.id}", with: "I am your Admin!" + check "comment-as-administrator-debate_#{debate.id}" click_button "Publish comment" within "#comments" do @@ -262,8 +262,8 @@ feature 'Comments' do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment_body", with: "Top of the world!" - check "comment_as_administrator" + fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!" + check "comment-as-administrator-comment_#{comment.id}" click_button 'Publish reply' end 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 diff --git a/spec/features/moderation/comments_spec.rb b/spec/features/moderation/comments_spec.rb index 6c2689f0e..4fdef5c10 100644 --- a/spec/features/moderation/comments_spec.rb +++ b/spec/features/moderation/comments_spec.rb @@ -4,7 +4,7 @@ feature 'Moderate Comments' do feature 'Hiding Comments' do - scenario 'Hide', :js do + scenario 'Hide without children hides the comment completely', :js do citizen = create(:user) moderator = create(:moderator) @@ -23,7 +23,7 @@ feature 'Moderate Comments' do visit debate_path(debate) expect(page).to have_css('.comment', count: 1) - expect(page).to have_content('This comment has been deleted') + expect(page).to_not have_content('This comment has been deleted') expect(page).to_not have_content('SPAM') end diff --git a/spec/features/verification/letter_spec.rb b/spec/features/verification/letter_spec.rb index 4816bd9b1..fa4a451db 100644 --- a/spec/features/verification/letter_spec.rb +++ b/spec/features/verification/letter_spec.rb @@ -13,13 +13,13 @@ feature 'Verify Letter' do expect(page).to have_content "You will receive a letter to your home address" end - scenario "Error accessing address from UserApi" do + scenario "Error accessing address from CensusApi" do user = create(:user, residence_verified_at: Time.now, confirmed_phone: "611111111") login_as(user) visit new_letter_path - allow_any_instance_of(UserApi).to receive(:address).and_return(nil) + allow_any_instance_of(CensusApi).to receive(:address).and_return(nil) click_button "Send me a letter" @@ -57,4 +57,4 @@ feature 'Verify Letter' do expect(URI.parse(current_url).path).to eq(new_sms_path) end -end \ No newline at end of file +end diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 591e0cebd..5773293cd 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -30,7 +30,7 @@ module CommonActions login_as(user2) visit debate_path(debate) - fill_in 'comment_body', with: 'Have you thought about...?' + fill_in "comment-body-debate_#{debate.id}", with: 'Have you thought about...?' click_button 'Publish comment' expect(page).to have_content 'Have you thought about...?' end @@ -45,7 +45,7 @@ module CommonActions click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in 'comment_body', with: 'It will be done next week.' + fill_in "comment-body-comment_#{comment.id}", with: 'It will be done next week.' click_button 'Publish reply' end expect(page).to have_content 'It will be done next week.'