diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 672f41d20..df98fdb72 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -1,15 +1,16 @@ class DebatesController < ApplicationController - include RecaptchaHelper + include RecaptchaHelper before_action :set_debate, only: [:show, :edit, :update] before_action :authenticate_user!, except: [:show, :index] before_action :validate_ownership, only: [:edit, :update] def index if params[:tag] - @debates = Debate.tagged_with(params[:tag]) + @debates = Debate.tagged_with(params[:tag]).order("created_at DESC") else - @debates = Debate.all + @debates = Debate.all.order("created_at DESC") end + @featured_debates = [] end def show @@ -53,7 +54,7 @@ class DebatesController < ApplicationController def verify_captcha? return true unless recaptcha_keys? - verify_recaptcha(model: @debate) + verify_recaptcha(model: @debate) end end diff --git a/app/views/debates/_featured_debates.html.erb b/app/views/debates/_featured_debates.html.erb new file mode 100644 index 000000000..6de9472e3 --- /dev/null +++ b/app/views/debates/_featured_debates.html.erb @@ -0,0 +1,42 @@ +
+
+ +
+
+ diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb index b88d5e9bd..7c6f80042 100644 --- a/app/views/debates/index.html.erb +++ b/app/views/debates/index.html.erb @@ -1,52 +1,9 @@ -
-
- - <% debate = @debates.first %> -
-
- -
-
+
+
- -
+
<%= render @debates %>
diff --git a/spec/factories.rb b/spec/factories.rb index 65315a112..8e1a2ea6c 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -9,7 +9,7 @@ FactoryGirl.define do end factory :debate do - title 'Debate title' + sequence(:title) {|n| "Debate #{n} title"} description 'Debate description' terms_of_service '1' association :author, factory: :user diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 034b1d504..637c7ed3e 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -3,16 +3,16 @@ require 'rails_helper' feature 'Debates' do scenario 'Index' do - 3.times { create(:debate) } + debates = [create(:debate), create(:debate), create(:debate)] visit debates_path expect(page).to have_selector('.debate', count: 3) - within first('.debate') do - expect(page).to have_content "Debate title" - expect(page).to have_content "Debate description" - expect(page).to have_content Debate.first.author.name - expect(page).to have_content I18n.l(Date.today) + debates.each do |debate| + within('#debates') do + expect(page).to have_content debate.title + expect(page).to have_content debate.description + end end end @@ -21,7 +21,7 @@ feature 'Debates' do visit debate_path(debate) - expect(page).to have_content "Debate title" + expect(page).to have_content debate.title expect(page).to have_content "Debate description" expect(page).to have_content debate.author.name expect(page).to have_content I18n.l(Date.today) diff --git a/spec/features/tags_spec.rb b/spec/features/tags_spec.rb index 6b5889ea7..2e62a1ef4 100644 --- a/spec/features/tags_spec.rb +++ b/spec/features/tags_spec.rb @@ -18,16 +18,20 @@ feature 'Tags' do end scenario 'Filtered' do - 2.times { create(:debate, tag_list: 'Salud') } - 2.times { create(:debate, tag_list: 'Hacienda') } + debate1 = create(:debate, tag_list: 'Salud') + debate2 = create(:debate, tag_list: 'Salud') + debate3 = create(:debate, tag_list: 'Hacienda') + debate4 = create(:debate, tag_list: 'Hacienda') visit debates_path first(:link, "Salud").click within('#debates') do expect(page).to have_css('.debate', count: 2) - expect(page).to have_content('Salud') - expect(page).to_not have_content('Hacienda') + expect(page).to have_content(debate1.title) + expect(page).to have_content(debate2.title) + expect(page).to_not have_content(debate3.title) + expect(page).to_not have_content(debate4.title) end end