diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 083165303..550fbcf2e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -37,4 +37,7 @@ class ApplicationController < ActionController::Base end end + def set_voted_values(debates_ids) + @voted_values = current_user ? current_user.votes_on_debates(debates_ids) : {} + end end diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 84f7d11a4..cca1e89a2 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -9,7 +9,6 @@ class DebatesController < ApplicationController else @debates = Debate.all.order("created_at DESC") set_voted_values @debates.map(&:id) - @featured_debates = @debates.to_a.shift(3) end end @@ -54,7 +53,4 @@ class DebatesController < ApplicationController params.require(:debate).permit(:title, :description, :tag_list, :terms_of_service, :captcha, :captcha_key) end - def set_voted_values(debates_ids) - @voted_values = current_user ? current_user.votes_on_debates(debates_ids) : {} - end end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb new file mode 100644 index 000000000..70498a70c --- /dev/null +++ b/app/controllers/welcome_controller.rb @@ -0,0 +1,9 @@ +class WelcomeController < ApplicationController + skip_authorization_check + + def index + @featured_debates = Debate.order("created_at DESC").limit(3) + set_voted_values @featured_debates.map(&:id) + end + +end \ No newline at end of file diff --git a/app/views/debates/_debate.html.erb b/app/views/debates/_debate.html.erb index 207584fcb..0bcc2e708 100644 --- a/app/views/debates/_debate.html.erb +++ b/app/views/debates/_debate.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb index 9f5217270..f459b6564 100644 --- a/app/views/debates/index.html.erb +++ b/app/views/debates/index.html.erb @@ -1,7 +1,4 @@
-
<%= render @debates %> diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 48ffa41d5..5d9cdb665 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -41,7 +41,7 @@

<%= t("layouts.header.open_city") %>

<%= t("layouts.header.open_city_slogan") %>

- <%= link_to t("layouts.header.create_debate"), new_debate_path, class: 'button radius' %> + <%= link_to t("layouts.header.see_all_debates"), debates_path, class: 'button radius' %>
<% end %> diff --git a/app/views/debates/_featured_debate.html.erb b/app/views/welcome/_featured_debate.html.erb similarity index 100% rename from app/views/debates/_featured_debate.html.erb rename to app/views/welcome/_featured_debate.html.erb diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb new file mode 100644 index 000000000..b73276091 --- /dev/null +++ b/app/views/welcome/index.html.erb @@ -0,0 +1,13 @@ +
+ +
+
+ +
+
+
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index d552ec75e..d5bf38506 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -9,7 +9,7 @@ en: menu: Menu open_city: We are opening Madrid open_city_slogan: So the citizens can decide what kind of city they want. - create_debate: Create a debate + see_all_debates: See all debates my_account_link: My account language: Site language footer: diff --git a/config/locales/es.yml b/config/locales/es.yml index 46c426310..f11259370 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -9,7 +9,7 @@ es: menu: Menú open_city: Estamos abriendo Madrid open_city_slogan: Para que todos los madrileños decidamos que ciudad queremos tener. - create_debate: Crea un debate + see_all_debates: Ver todos los debates my_account_link: Mi cuenta language: Idioma de la página footer: diff --git a/config/routes.rb b/config/routes.rb index 74179ba2a..fc7c040b2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,7 @@ Rails.application.routes.draw do # See how all your routes lay out with "rake routes". # You can have the root of your site routed with "root" - root 'debates#index' + root 'welcome#index' resources :debates do member do diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index d164f113b..6265b17d7 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -4,18 +4,9 @@ feature 'Debates' do scenario 'Index' do debates = [create(:debate), create(:debate), create(:debate)] - featured_debates = [create(:debate), create(:debate), create(:debate)] visit debates_path - expect(page).to have_selector('#featured-debates .debate-featured', count: 3) - featured_debates.each do |debate| - within('#featured-debates') do - expect(page).to have_content debate.title - expect(page).to have_css("a[href='#{debate_path(debate)}']", text: debate.description) - end - end - expect(page).to have_selector('#debates .debate', count: 3) debates.each do |debate| within('#debates') do diff --git a/spec/features/home_spec.rb b/spec/features/home_spec.rb index 2efa307cc..fcad1ca24 100644 --- a/spec/features/home_spec.rb +++ b/spec/features/home_spec.rb @@ -2,4 +2,19 @@ require 'rails_helper' feature "Home" do + scenario 'featured debates' do + featured_debates = [create(:debate), create(:debate), create(:debate)] + + visit root_path + + expect(page).to have_selector('#featured-debates .debate-featured', count: 3) + featured_debates.each do |debate| + within('#featured-debates') do + expect(page).to have_content debate.title + expect(page).to have_css("a[href='#{debate_path(debate)}']", text: debate.description) + end + end + + end + end diff --git a/spec/features/votes_spec.rb b/spec/features/votes_spec.rb index ecb8a8b8f..8deb20c20 100644 --- a/spec/features/votes_spec.rb +++ b/spec/features/votes_spec.rb @@ -13,7 +13,55 @@ feature 'Votes' do visit debate_path(@debate) end - scenario "Index show user votes on debates" do + scenario "Home shows user votes on featured debates" do + debate1 = create(:debate) + debate2 = create(:debate) + debate3 = create(:debate) + vote = create(:vote, voter: @manuela, votable: debate1, vote_flag: true) + vote = create(:vote, voter: @manuela, votable: debate3, vote_flag: false) + + visit root_path + + within("#featured-debates") do + within("#debate_#{debate1.id}_votes") do + within(".in-favor") do + expect(page).to have_css("a.voted") + expect(page).to_not have_css("a.no-voted") + end + + within(".against") do + expect(page).to have_css("a.no-voted") + expect(page).to_not have_css("a.voted") + end + end + + within("#debate_#{debate2.id}_votes") do + within(".in-favor") do + expect(page).to_not have_css("a.voted") + expect(page).to_not have_css("a.no-voted") + end + + within(".against") do + expect(page).to_not have_css("a.no-voted") + expect(page).to_not have_css("a.voted") + end + end + + within("#debate_#{debate3.id}_votes") do + within(".in-favor") do + expect(page).to have_css("a.no-voted") + expect(page).to_not have_css("a.voted") + end + + within(".against") do + expect(page).to have_css("a.voted") + expect(page).to_not have_css("a.no-voted") + end + end + end + end + + scenario "Index shows user votes on debates" do debate1 = create(:debate) debate2 = create(:debate) debate3 = create(:debate) @@ -22,42 +70,43 @@ feature 'Votes' do visit debates_path - within("#debate_#{debate1.id}_votes") do - within(".in-favor") do - expect(page).to have_css("a.voted") - expect(page).to_not have_css("a.no-voted") + within("#debates") do + within("#debate_#{debate1.id}_votes") do + within(".in-favor") do + expect(page).to have_css("a.voted") + expect(page).to_not have_css("a.no-voted") + end + + within(".against") do + expect(page).to have_css("a.no-voted") + expect(page).to_not have_css("a.voted") + end end - within(".against") do - expect(page).to have_css("a.no-voted") - expect(page).to_not have_css("a.voted") + within("#debate_#{debate2.id}_votes") do + within(".in-favor") do + expect(page).to_not have_css("a.voted") + expect(page).to_not have_css("a.no-voted") + end + + within(".against") do + expect(page).to_not have_css("a.no-voted") + expect(page).to_not have_css("a.voted") + end + end + + within("#debate_#{debate3.id}_votes") do + within(".in-favor") do + expect(page).to have_css("a.no-voted") + expect(page).to_not have_css("a.voted") + end + + within(".against") do + expect(page).to have_css("a.voted") + expect(page).to_not have_css("a.no-voted") + end end end - - within("#debate_#{debate2.id}_votes") do - within(".in-favor") do - expect(page).to_not have_css("a.voted") - expect(page).to_not have_css("a.no-voted") - end - - within(".against") do - expect(page).to_not have_css("a.no-voted") - expect(page).to_not have_css("a.voted") - end - end - - within("#debate_#{debate3.id}_votes") do - within(".in-favor") do - expect(page).to have_css("a.no-voted") - expect(page).to_not have_css("a.voted") - end - - within(".against") do - expect(page).to have_css("a.voted") - expect(page).to_not have_css("a.no-voted") - end - end - end scenario 'Show no votes' do @@ -114,7 +163,7 @@ feature 'Votes' do end scenario 'Create from debate featured', :js do - visit debates_path + visit root_path within("#featured-debates") do find('.in-favor a').click @@ -131,15 +180,13 @@ feature 'Votes' do expect(page).to have_content "1 vote" end - expect(URI.parse(current_url).path).to eq(debates_path) + expect(URI.parse(current_url).path).to eq(root_path) end scenario 'Create from debate index', :js do - 3.times { create(:debate) } visit debates_path within("#debates") do - expect(page).to have_css(".debate", count: 1) find('.in-favor a').click