moves featured debates to home page

This commit is contained in:
rgarcia
2015-08-10 21:25:04 +02:00
parent 2c88c6e07d
commit 4dd7e14ac4
14 changed files with 129 additions and 58 deletions

View File

@@ -37,4 +37,7 @@ class ApplicationController < ActionController::Base
end end
end end
def set_voted_values(debates_ids)
@voted_values = current_user ? current_user.votes_on_debates(debates_ids) : {}
end
end end

View File

@@ -9,7 +9,6 @@ class DebatesController < ApplicationController
else else
@debates = Debate.all.order("created_at DESC") @debates = Debate.all.order("created_at DESC")
set_voted_values @debates.map(&:id) set_voted_values @debates.map(&:id)
@featured_debates = @debates.to_a.shift(3)
end end
end end
@@ -54,7 +53,4 @@ class DebatesController < ApplicationController
params.require(:debate).permit(:title, :description, :tag_list, :terms_of_service, :captcha, :captcha_key) params.require(:debate).permit(:title, :description, :tag_list, :terms_of_service, :captcha, :captcha_key)
end end
def set_voted_values(debates_ids)
@voted_values = current_user ? current_user.votes_on_debates(debates_ids) : {}
end
end end

View File

@@ -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

View File

@@ -1,4 +1,4 @@
<div id="debate-<%= debate.id %>" class="debate"> <div id="<%= dom_id(debate) %>" class="debate">
<div class="panel"> <div class="panel">
<div class="row"> <div class="row">

View File

@@ -1,7 +1,4 @@
<section role="main"> <section role="main">
<div id="featured-debates" class="row">
<%= render partial: "featured_debate", collection: @featured_debates %>
</div>
<div class="row"> <div class="row">
<div id="debates" class="small-12 medium-9 column debates-list"> <div id="debates" class="small-12 medium-9 column debates-list">
<%= render @debates %> <%= render @debates %>

View File

@@ -41,7 +41,7 @@
<div class="small-12 column text-center"> <div class="small-12 column text-center">
<h1><%= t("layouts.header.open_city") %></h1> <h1><%= t("layouts.header.open_city") %></h1>
<h2><%= t("layouts.header.open_city_slogan") %></h2> <h2><%= t("layouts.header.open_city_slogan") %></h2>
<%= 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' %>
</div> </div>
</div> </div>
<% end %> <% end %>

View File

@@ -0,0 +1,13 @@
<section role="main">
<div id="featured-debates" class="row">
<%= render partial: "featured_debate", collection: @featured_debates %>
</div>
<div class="row">
<div class="small-12 medium-3 column">
<aside role="complementary">
<%= link_to t("layouts.header.see_all_debates"), debates_path, class: 'button radius expand' %>
<%= render "shared/tag_cloud" %>
</aside>
</div>
</div>
</section>

View File

@@ -9,7 +9,7 @@ en:
menu: Menu menu: Menu
open_city: We are opening Madrid open_city: We are opening Madrid
open_city_slogan: So the citizens can decide what kind of city they want. 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 my_account_link: My account
language: Site language language: Site language
footer: footer:

View File

@@ -9,7 +9,7 @@ es:
menu: Menú menu: Menú
open_city: Estamos abriendo Madrid open_city: Estamos abriendo Madrid
open_city_slogan: Para que todos los madrileños decidamos que ciudad queremos tener. 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 my_account_link: Mi cuenta
language: Idioma de la página language: Idioma de la página
footer: footer:

View File

@@ -5,7 +5,7 @@ Rails.application.routes.draw do
# See how all your routes lay out with "rake routes". # See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root" # You can have the root of your site routed with "root"
root 'debates#index' root 'welcome#index'
resources :debates do resources :debates do
member do member do

View File

@@ -4,18 +4,9 @@ feature 'Debates' do
scenario 'Index' do scenario 'Index' do
debates = [create(:debate), create(:debate), create(:debate)] debates = [create(:debate), create(:debate), create(:debate)]
featured_debates = [create(:debate), create(:debate), create(:debate)]
visit debates_path 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) expect(page).to have_selector('#debates .debate', count: 3)
debates.each do |debate| debates.each do |debate|
within('#debates') do within('#debates') do

View File

@@ -2,4 +2,19 @@ require 'rails_helper'
feature "Home" do 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 end

View File

@@ -13,15 +13,16 @@ feature 'Votes' do
visit debate_path(@debate) visit debate_path(@debate)
end end
scenario "Index show user votes on debates" do scenario "Home shows user votes on featured debates" do
debate1 = create(:debate) debate1 = create(:debate)
debate2 = create(:debate) debate2 = create(:debate)
debate3 = create(:debate) debate3 = create(:debate)
vote = create(:vote, voter: @manuela, votable: debate1, vote_flag: true) vote = create(:vote, voter: @manuela, votable: debate1, vote_flag: true)
vote = create(:vote, voter: @manuela, votable: debate3, vote_flag: false) vote = create(:vote, voter: @manuela, votable: debate3, vote_flag: false)
visit debates_path visit root_path
within("#featured-debates") do
within("#debate_#{debate1.id}_votes") do within("#debate_#{debate1.id}_votes") do
within(".in-favor") do within(".in-favor") do
expect(page).to have_css("a.voted") expect(page).to have_css("a.voted")
@@ -57,7 +58,55 @@ feature 'Votes' do
expect(page).to_not have_css("a.no-voted") expect(page).to_not have_css("a.no-voted")
end end
end end
end
end
scenario "Index shows user votes on 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 debates_path
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("#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 end
scenario 'Show no votes' do scenario 'Show no votes' do
@@ -114,7 +163,7 @@ feature 'Votes' do
end end
scenario 'Create from debate featured', :js do scenario 'Create from debate featured', :js do
visit debates_path visit root_path
within("#featured-debates") do within("#featured-debates") do
find('.in-favor a').click find('.in-favor a').click
@@ -131,15 +180,13 @@ feature 'Votes' do
expect(page).to have_content "1 vote" expect(page).to have_content "1 vote"
end end
expect(URI.parse(current_url).path).to eq(debates_path) expect(URI.parse(current_url).path).to eq(root_path)
end end
scenario 'Create from debate index', :js do scenario 'Create from debate index', :js do
3.times { create(:debate) }
visit debates_path visit debates_path
within("#debates") do within("#debates") do
expect(page).to have_css(".debate", count: 1)
find('.in-favor a').click find('.in-favor a').click