From b46a3e5452711250ba72f355f884d7b51ad9d0fb Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 3 Sep 2015 19:16:08 +0200 Subject: [PATCH 01/22] migration for adding hot_score --- .../20150903171309_add_hot_score_to_debates.rb | 5 +++++ db/schema.rb | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20150903171309_add_hot_score_to_debates.rb diff --git a/db/migrate/20150903171309_add_hot_score_to_debates.rb b/db/migrate/20150903171309_add_hot_score_to_debates.rb new file mode 100644 index 000000000..7e82d4c13 --- /dev/null +++ b/db/migrate/20150903171309_add_hot_score_to_debates.rb @@ -0,0 +1,5 @@ +class AddHotScoreToDebates < ActiveRecord::Migration + def change + add_column :debates, :hot_score, :bigint, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index d561bcccd..c6c4baf2a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150903155146) do +ActiveRecord::Schema.define(version: 20150903171309) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -101,6 +101,7 @@ ActiveRecord::Schema.define(version: 20150903155146) do t.datetime "confirmed_hide_at" t.integer "cached_anonymous_votes_total", default: 0 t.integer "cached_votes_score", default: 0 + t.integer "hot_score", limit: 8, default: 0 end add_index "debates", ["cached_votes_down"], name: "index_debates_on_cached_votes_down", using: :btree @@ -131,6 +132,16 @@ ActiveRecord::Schema.define(version: 20150903155146) do add_index "identities", ["user_id"], name: "index_identities_on_user_id", using: :btree + create_table "inappropiate_flags", force: :cascade do |t| + t.integer "user_id" + t.string "flaggable_type" + t.integer "flaggable_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "inappropiate_flags", ["flaggable_type", "flaggable_id"], name: "index_inappropiate_flags_on_flaggable_type_and_flaggable_id", using: :btree + create_table "moderators", force: :cascade do |t| t.integer "user_id" end From 7c3ca55de1b9b4ab65680696dd0a9999c92173fa Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 11:50:07 +0200 Subject: [PATCH 02/22] Adds the default score selector/controller. Refactors debates specs --- app/controllers/debates_controller.rb | 4 +- app/models/debate.rb | 1 + config/locales/en.yml | 1 + config/locales/es.yml | 1 + spec/features/debates_spec.rb | 71 ++++++++++++-------------- spec/support/matchers/appear_before.rb | 3 +- 6 files changed, 40 insertions(+), 41 deletions(-) diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 5219c1308..68570dd70 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -82,8 +82,8 @@ class DebatesController < ApplicationController end def parse_order - @valid_orders = ['created_at', 'score', 'most_commented', 'random'] - @order = @valid_orders.include?(params[:order]) ? params[:order] : 'created_at' + @valid_orders = ['hot_score', 'created_at', 'score', 'most_commented', 'random'] + @order = @valid_orders.include?(params[:order]) ? params[:order] : @valid_orders.first end def parse_tag_filter diff --git a/app/models/debate.rb b/app/models/debate.rb index 25ba8aca8..0ce52a168 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -32,6 +32,7 @@ class Debate < ActiveRecord::Base scope :sort_by_created_at, -> { reorder(created_at: :desc) } scope :sort_by_most_commented, -> { reorder(comments_count: :desc) } scope :sort_by_random, -> { reorder("RANDOM()") } + scope :sort_by_hot_score , -> { order(hot_score: :desc) } # Ahoy setup visitable # Ahoy will automatically assign visit_id on create diff --git a/config/locales/en.yml b/config/locales/en.yml index c4583ffd8..58b576c89 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -69,6 +69,7 @@ en: select_order: Order by select_order_long: Order debates by orders: + hot_score: most active created_at: newest score: best rated most_commented: most commented diff --git a/config/locales/es.yml b/config/locales/es.yml index 62ab28997..fe4b033d9 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -69,6 +69,7 @@ es: select_order: Ordenar por select_order_long: Estás viendo los debates orders: + hot_score: "más activos" created_at: "más nuevos" score: "mejor valorados" most_commented: "más comentados" diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index d45e1c46f..7ea8ad459 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -350,67 +350,63 @@ feature 'Debates' do expect(Flag.flagged?(user, debate)).to_not be end - feature 'Debate index order filters', :js do + feature 'Debate index order filters' do - before do - @most_commented_debate = create(:debate) - @most_score_debate = create(:debate) - @most_recent_debate = create(:debate) - create_list(:comment, 2, commentable: @most_commented_debate) - create_list(:vote, 2, votable: @most_score_debate) - create_list(:vote, 2, votable: @most_recent_debate, vote_flag: false) - create(:vote, votable: @most_recent_debate) - create(:comment, commentable: @most_recent_debate) - end + scenario 'Default order is hot_score', :js do + create(:debate, title: 'best', hot_score: 10) + create(:debate, title: 'medium', hot_score: 5) + create(:debate, title: 'worst', hot_score: 2) - scenario 'Default order is created_at' do visit debates_path - expect(page).to have_select('order-selector', selected: 'newest') - expect(@most_recent_debate.title).to appear_before(@most_score_debate.title) - expect(@most_score_debate.title).to appear_before(@most_commented_debate.title) + expect(page).to have_select('order-selector', selected: 'most active') + expect('best').to appear_before('medium') + expect('medium').to appear_before('worst') end - scenario 'Debates are ordered by best rated' do - visit debates_path + scenario 'Debates are ordered by best rated', :js do + create(:debate, title: 'best', cached_votes_score: 10) + create(:debate, title: 'medium', cached_votes_score: 5) + create(:debate, title: 'worst', cached_votes_score: 2) + visit debates_path select 'best rated', from: 'order-selector' + expect(page).to have_select('order-selector', selected: 'best rated') - expect(find("#debates .debate", match: :first)).to have_content(@most_score_debate.title) - + expect('best').to appear_before('medium') + expect('medium').to appear_before('worst') expect(current_url).to include('order=score') - expect(@most_score_debate.title).to appear_before(@most_commented_debate.title) - expect(@most_commented_debate.title).to appear_before(@most_recent_debate.title) end - scenario 'Debates are ordered by most commented' do - visit debates_path + scenario 'Debates are ordered by most commented', :js do + create(:debate, title: 'best', comments_count: 10) + create(:debate, title: 'medium', comments_count: 5) + create(:debate, title: 'worst', comments_count: 2) + visit debates_path select 'most commented', from: 'order-selector' + expect(page).to have_select('order-selector', selected: 'most commented') - expect(find("#debates .debate", match: :first)).to have_content(@most_commented_debate.title) - + expect('best').to appear_before('medium') + expect('medium').to appear_before('worst') expect(current_url).to include('order=most_commented') - expect(@most_commented_debate.title).to appear_before(@most_recent_debate.title) - expect(@most_recent_debate.title).to appear_before(@most_score_debate.title) end - scenario 'Debates are ordered by newest' do + scenario 'Debates are ordered by newest', :js do + create(:debate, title: 'best', created_at: Time.now) + create(:debate, title: 'medium', created_at: Time.now - 1.hour) + create(:debate, title: 'worst', created_at: Time.now - 1.day) + visit debates_path - - select 'best rated', from: 'order-selector' - expect(find("#debates .debate", match: :first)).to have_content(@most_score_debate.title) - select 'newest', from: 'order-selector' - expect(page).to have_select('order-selector', selected: 'newest') - expect(find("#debates .debate", match: :first)).to have_content(@most_recent_debate.title) + expect(page).to have_select('order-selector', selected: 'newest') + expect('best').to appear_before('medium') + expect('medium').to appear_before('worst') expect(current_url).to include('order=created_at') - expect(@most_recent_debate.title).to appear_before(@most_score_debate.title) - expect(@most_score_debate.title).to appear_before(@most_commented_debate.title) end - scenario 'Debates are ordered randomly' do + scenario 'Debates are ordered randomly', :js do create_list(:debate, 12) visit debates_path @@ -420,7 +416,6 @@ feature 'Debates' do select 'most commented', from: 'order-selector' expect(page).to have_select('order-selector', selected: 'most commented') - expect(find("#debates .debate", match: :first)).to have_content(@most_commented_debate.title) select 'random', from: 'order-selector' expect(page).to have_select('order-selector', selected: 'random') diff --git a/spec/support/matchers/appear_before.rb b/spec/support/matchers/appear_before.rb index bb1d65072..73df35139 100644 --- a/spec/support/matchers/appear_before.rb +++ b/spec/support/matchers/appear_before.rb @@ -1,6 +1,7 @@ RSpec::Matchers.define :appear_before do |later_content| match do |earlier_content| - page.body.index(earlier_content) < page.body.index(later_content) + text = page.text + text.index(earlier_content) < text.index(later_content) end end From 19e6740ee468aee2b2f2f8710173940c9e609529 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 11:50:29 +0200 Subject: [PATCH 03/22] Refactors has_filters.rb --- app/controllers/concerns/has_filters.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/concerns/has_filters.rb b/app/controllers/concerns/has_filters.rb index eeca1745f..ea5397183 100644 --- a/app/controllers/concerns/has_filters.rb +++ b/app/controllers/concerns/has_filters.rb @@ -5,8 +5,7 @@ module HasFilters def has_filters(valid_filters, *args) before_action(*args) do @valid_filters = valid_filters - @current_filter = params[:filter] - @current_filter = @valid_filters.first unless @valid_filters.include?(@current_filter) + @current_filter = @valid_filters.include?(params[:filter]) ? params[:filter] : @valid_filters.first end end end From 134f38a38f6734cdad3a668a58929ee3c008cb9c Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 11:51:21 +0200 Subject: [PATCH 04/22] Removes debates default order --- app/models/debate.rb | 2 -- spec/models/debate_spec.rb | 9 --------- 2 files changed, 11 deletions(-) diff --git a/app/models/debate.rb b/app/models/debate.rb index 0ce52a168..2f09b5eb7 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -1,7 +1,5 @@ require 'numeric' class Debate < ActiveRecord::Base - default_scope { order(created_at: :desc) } - apply_simple_captcha TITLE_LENGTH = Debate.columns.find { |c| c.name == 'title' }.limit diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index fc4130354..e5cbc4691 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -174,15 +174,6 @@ describe Debate do end end - describe '#default_order' do - let!(:economy) { create(:debate) } - let!(:health) { create(:debate) } - - it "returns debates ordered by last one first" do - expect(Debate.all).to eq([health, economy]) - end - end - describe '#anonymous_votes_ratio' do it "returns the percentage of anonymous votes of the total votes" do debate = create(:debate, cached_anonymous_votes_total: 25, cached_votes_total: 100) From de4706ffd432828cdb89e6e9017ac269858a9bfb Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 11:53:22 +0200 Subject: [PATCH 05/22] Refactors votes_spec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Some backgrounds created variables which were never used (@debates). This made the tests fail when the debate orders changed. * Some backgrounds visited pages when they didn’t need to * Pablo and Manuela are now created at the beginning --- spec/features/votes_spec.rb | 221 +++++++++++++++++++----------------- 1 file changed, 115 insertions(+), 106 deletions(-) diff --git a/spec/features/votes_spec.rb b/spec/features/votes_spec.rb index ea9761bde..1116d2985 100644 --- a/spec/features/votes_spec.rb +++ b/spec/features/votes_spec.rb @@ -2,17 +2,14 @@ require 'rails_helper' feature 'Votes' do + background do + @manuela = create(:user, verified_at: Time.now) + @pablo = create(:user) + + login_as(@manuela) + end + feature 'Debates' do - - background do - @manuela = create(:user, verified_at: Time.now) - @pablo = create(:user) - @debate = create(:debate) - - login_as(@manuela) - visit debate_path(@debate) - end - scenario "Home shows user votes on featured debates" do debate1 = create(:debate) debate2 = create(:debate) @@ -109,84 +106,86 @@ feature 'Votes' do end end - scenario 'Show no votes' do - visit debate_path(@debate) - - expect(page).to have_content "No votes" - - within('.in-favor') do - expect(page).to have_content "0%" - expect(page).to_not have_css("a.voted") - expect(page).to_not have_css("a.no-voted") + feature 'Single debate' do + background do + @debate = create(:debate) end - within('.against') do - expect(page).to have_content "0%" - expect(page).to_not have_css("a.voted") - expect(page).to_not have_css("a.no-voted") - end - end + scenario 'Show no votes' do + visit debate_path(@debate) - scenario 'Show' do - create(:vote, voter: @manuela, votable: @debate, vote_flag: true) - create(:vote, voter: @pablo, votable: @debate, vote_flag: false) - - visit debate_path(@debate) - - expect(page).to have_content "2 votes" - - within('.in-favor') do - expect(page).to have_content "50%" - expect(page).to have_css("a.voted") - end - - within('.against') do - expect(page).to have_content "50%" - expect(page).to have_css("a.no-voted") - end - end - - scenario 'Create from debate show', :js do - find('.in-favor a').click - - within('.in-favor') do - expect(page).to have_content "100%" - expect(page).to have_css("a.voted") - end - - within('.against') do - expect(page).to have_content "0%" - expect(page).to have_css("a.no-voted") - end - - expect(page).to have_content "1 vote" - end - - scenario 'Create from debate featured', :js do - visit root_path - - within("#featured-debates") do - find('.in-favor a').click + expect(page).to have_content "No votes" within('.in-favor') do - expect(page).to have_content "100%" - expect(page).to have_css("a.voted") + expect(page).to have_content "0%" + expect(page).to_not have_css("a.voted") + expect(page).to_not have_css("a.no-voted") end within('.against') do + expect(page).to have_content "0%" + expect(page).to_not have_css("a.voted") + expect(page).to_not have_css("a.no-voted") + end + end + + scenario 'Update', :js do + visit debate_path(@debate) + + find('.in-favor a').click + find('.against a').click + + within('.in-favor') do expect(page).to have_content "0%" expect(page).to have_css("a.no-voted") end + within('.against') do + expect(page).to have_content "100%" + expect(page).to have_css("a.voted") + end + expect(page).to have_content "1 vote" end - expect(URI.parse(current_url).path).to eq(root_path) - end - scenario 'Create from debate index', :js do - visit debates_path + scenario 'Trying to vote multiple times', :js do + visit debate_path(@debate) - within("#debates") do + find('.in-favor a').click + find('.in-favor a').click + + within('.in-favor') do + expect(page).to have_content "100%" + end + + within('.against') do + expect(page).to have_content "0%" + end + + expect(page).to have_content "1 vote" + end + + scenario 'Show' do + create(:vote, voter: @manuela, votable: @debate, vote_flag: true) + create(:vote, voter: @pablo, votable: @debate, vote_flag: false) + + visit debate_path(@debate) + + expect(page).to have_content "2 votes" + + within('.in-favor') do + expect(page).to have_content "50%" + expect(page).to have_css("a.voted") + end + + within('.against') do + expect(page).to have_content "50%" + expect(page).to have_css("a.no-voted") + end + end + + scenario 'Create from debate show', :js do + visit debate_path(@debate) find('.in-favor a').click @@ -202,51 +201,56 @@ feature 'Votes' do expect(page).to have_content "1 vote" end - expect(URI.parse(current_url).path).to eq(debates_path) - end - scenario 'Update', :js do - find('.in-favor a').click - find('.against a').click + scenario 'Create in featured', :js do + visit root_path - within('.in-favor') do - expect(page).to have_content "0%" - expect(page).to have_css("a.no-voted") + within("#featured-debates") do + find('.in-favor a').click + + within('.in-favor') do + expect(page).to have_content "100%" + expect(page).to have_css("a.voted") + end + + within('.against') do + expect(page).to have_content "0%" + expect(page).to have_css("a.no-voted") + end + + expect(page).to have_content "1 vote" + end + expect(URI.parse(current_url).path).to eq(root_path) end - within('.against') do - expect(page).to have_content "100%" - expect(page).to have_css("a.voted") + scenario 'Create in index', :js do + visit debates_path + + within("#debates") do + + find('.in-favor a').click + + within('.in-favor') do + expect(page).to have_content "100%" + expect(page).to have_css("a.voted") + end + + within('.against') do + expect(page).to have_content "0%" + expect(page).to have_css("a.no-voted") + end + + expect(page).to have_content "1 vote" + end + expect(URI.parse(current_url).path).to eq(debates_path) end - - expect(page).to have_content "1 vote" - end - - scenario 'Trying to vote multiple times', :js do - find('.in-favor a').click - find('.in-favor a').click - - within('.in-favor') do - expect(page).to have_content "100%" - end - - within('.against') do - expect(page).to have_content "0%" - end - - expect(page).to have_content "1 vote" end end feature 'Comments' do background do - @manuela = create(:user) - @pablo = create(:user) @debate = create(:debate) @comment = create(:comment, commentable: @debate) - - login_as(@manuela) - visit debate_path(@debate) end scenario 'Show' do @@ -269,6 +273,8 @@ feature 'Votes' do end scenario 'Create', :js do + visit debate_path(@debate) + within("#comment_#{@comment.id}_votes") do find(".in_favor a").click @@ -285,6 +291,8 @@ feature 'Votes' do end scenario 'Update', :js do + visit debate_path(@debate) + within("#comment_#{@comment.id}_votes") do find('.in_favor a').click find('.against a').click @@ -302,6 +310,8 @@ feature 'Votes' do end scenario 'Trying to vote multiple times', :js do + visit debate_path(@debate) + within("#comment_#{@comment.id}_votes") do find('.in_favor a').click find('.in_favor a').click @@ -317,6 +327,5 @@ feature 'Votes' do expect(page).to have_content "1 vote" end end - end end From 3012f2ffcdb879640435ce7647bdcdf691358b36 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 11:54:19 +0200 Subject: [PATCH 06/22] Removes reorder in debate (no default order) --- app/models/debate.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/debate.rb b/app/models/debate.rb index 2f09b5eb7..67c0c0206 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -26,11 +26,11 @@ class Debate < ActiveRecord::Base scope :with_ignored_flag, -> { where("ignored_flag_at IS NOT NULL AND hidden_at IS NULL") } scope :flagged, -> { where("flags_count > 0") } scope :for_render, -> { includes(:tags) } - scope :sort_by_score , -> { reorder(cached_votes_score: :desc) } - scope :sort_by_created_at, -> { reorder(created_at: :desc) } - scope :sort_by_most_commented, -> { reorder(comments_count: :desc) } - scope :sort_by_random, -> { reorder("RANDOM()") } scope :sort_by_hot_score , -> { order(hot_score: :desc) } + scope :sort_by_score , -> { order(cached_votes_score: :desc) } + scope :sort_by_created_at, -> { order(created_at: :desc) } + scope :sort_by_most_commented, -> { order(comments_count: :desc) } + scope :sort_by_random, -> { order("RANDOM()") } # Ahoy setup visitable # Ahoy will automatically assign visit_id on create From 9f970568acf7a5dd1201ca6e6263c2edefaf8673 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 12:16:11 +0200 Subject: [PATCH 07/22] Displays debate.created_at in debates#index --- app/views/debates/_debate.html.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/debates/_debate.html.erb b/app/views/debates/_debate.html.erb index 2d8ad2900..fd9304c3d 100644 --- a/app/views/debates/_debate.html.erb +++ b/app/views/debates/_debate.html.erb @@ -11,6 +11,8 @@

  <%= link_to t("debates.debate.comments", count: debate.comments_count), debate_path(debate, anchor: "comments") %> +  •  + <%= l debate.created_at.to_date %>

<%= link_to debate.description, debate %> From fba4f1fade795c9abe2a97d8024b8b1f0874a9d4 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 12:34:17 +0200 Subject: [PATCH 08/22] Adds initial hot score implementation for debates --- app/models/debate.rb | 21 ++++++++++++++++++++- spec/factories.rb | 4 ++++ spec/models/debate_spec.rb | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/app/models/debate.rb b/app/models/debate.rb index 67c0c0206..8017fba0e 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -21,6 +21,8 @@ class Debate < ActiveRecord::Base before_validation :sanitize_description before_validation :sanitize_tag_list + before_save :calculate_hot_score + scope :sorted_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) } scope :pending_flag_review, -> { where(ignored_flag_at: nil, hidden_at: nil) } scope :with_ignored_flag, -> { where("ignored_flag_at IS NOT NULL AND hidden_at IS NULL") } @@ -102,6 +104,24 @@ class Debate < ActiveRecord::Base update(ignored_flag_at: Time.now) end + def calculate_hot_score + z = 1.96 # Normal distribution with a confidence of 0.95 + time_unit = 12.hours + start = Time.new(2015, 6, 15) + + n = cached_votes_total + comments_count / 3 + pos = cached_votes_up + comments_count / 3 + + phat = 1.0 * pos / n + + weigted_score = n == 0 ? 0 : + (phat + z*z/(2*n) - z * Math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n) + + age_in_units = ((created_at || Time.now) - start) / time_unit + + self.hot_score = (age_in_units**3 + weigted_score * 1000).round + end + protected def sanitize_description @@ -111,5 +131,4 @@ class Debate < ActiveRecord::Base def sanitize_tag_list self.tag_list = TagSanitizer.new.sanitize_tag_list(self.tag_list) end - end diff --git a/spec/factories.rb b/spec/factories.rb index 9f4345d4d..e541c1b20 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -71,6 +71,10 @@ FactoryGirl.define do Flag.flag(FactoryGirl.create(:user), debate) end end + + trait :with_hot_score do + before(:save) { |d| d.calculate_hot_score } + end end factory :vote do diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index e5cbc4691..52d8c0740 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -181,4 +181,38 @@ describe Debate do end end + describe '#hot_score' do + let(:now) { Time.now } + + it "gets bigger for newer debates" do + old = create(:debate, :with_hot_score, created_at: now - 1.day) + new = create(:debate, :with_hot_score, created_at: now) + expect(new.hot_score).to be > old.hot_score + end + + it "gets bigger for debates with more comments" do + more_comments = create(:debate, :with_hot_score, created_at: now, comments_count: 10) + less_comments = create(:debate, :with_hot_score, created_at: now, comments_count: 1) + expect(more_comments.hot_score).to be > less_comments.hot_score + end + + it "gets bigger for debates with more positive votes" do + more_likes = create(:debate, :with_hot_score, created_at: now, cached_votes_total: 10, cached_votes_up: 5) + less_likes = create(:debate, :with_hot_score, created_at: now, cached_votes_total: 10, cached_votes_up: 1) + expect(more_likes.hot_score).to be > less_likes.hot_score + end + + it "gets bigger for debates with more confidence" do + more_confidence = create(:debate, :with_hot_score, created_at: now, cached_votes_total: 1000, cached_votes_up: 700) + less_confidence = create(:debate, :with_hot_score, created_at: now, cached_votes_total: 10, cached_votes_up: 9) + expect(more_confidence.hot_score).to be > less_confidence.hot_score + end + + it "decays older debates, even if they have more votes" do + older_more_voted = create(:debate, :with_hot_score, created_at: now - 2.days, cached_votes_total: 1000, cached_votes_up: 900) + new_less_voted = create(:debate, :with_hot_score, created_at: now, cached_votes_total: 10, cached_votes_up: 9) + expect(new_less_voted.hot_score).to be > older_more_voted.hot_score + end + end + end From 920ba48947ca39c6b7d9a6de0adb70b73c703500 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 12:45:10 +0200 Subject: [PATCH 09/22] Add random created_at on seeds --- db/dev_seeds.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 58a1da128..0fd7bbee1 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -59,6 +59,7 @@ tags = Faker::Lorem.words(25) description = "

#{Faker::Lorem.paragraphs.join('

')}

" debate = Debate.create!(author: author, title: Faker::Lorem.sentence(3), + created_at: rand((Time.now - 1.week) .. Time.now), description: description, tag_list: tags.sample(3).join(','), terms_of_service: "1") @@ -72,6 +73,7 @@ puts "Commenting Debates" author = User.reorder("RANDOM()").first debate = Debate.reorder("RANDOM()").first Comment.create!(user: author, + created_at: rand(debate.created_at .. Time.now), commentable: debate, body: Faker::Lorem.sentence) end @@ -82,7 +84,8 @@ puts "Commenting Comments" (1..100).each do |i| author = User.reorder("RANDOM()").first parent = Comment.reorder("RANDOM()").first - comment = Comment.create!(user: author, + Comment.create!(user: author, + created_at: rand(parent.created_at .. Time.now), commentable_id: parent.commentable_id, commentable_type: parent.commentable_type, body: Faker::Lorem.sentence, From 83ebbb14b168e555e14268ff292303eb18bfd200 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 13:59:30 +0200 Subject: [PATCH 10/22] Refactors hot_score calculations --- app/models/debate.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/models/debate.rb b/app/models/debate.rb index 8017fba0e..ef28f5132 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -106,20 +106,22 @@ class Debate < ActiveRecord::Base def calculate_hot_score z = 1.96 # Normal distribution with a confidence of 0.95 - time_unit = 12.hours + time_unit = 1.0 * 12.hours start = Time.new(2015, 6, 15) + comments_weight = 1.0/3 # 3 comments == 1 positive vote - n = cached_votes_total + comments_count / 3 - pos = cached_votes_up + comments_count / 3 + weighted_score = 0 - phat = 1.0 * pos / n + n = cached_votes_total + comments_weight * comments_count + if n > 0 then + pos = cached_votes_up + comments_weight * comments_count + phat = 1.0 * pos / n + weighted_score = (phat + z*z/(2*n) - z * Math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n) + end - weigted_score = n == 0 ? 0 : - (phat + z*z/(2*n) - z * Math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n) + age_in_units = 1.0 * ((created_at || Time.now) - start) / time_unit - age_in_units = ((created_at || Time.now) - start) / time_unit - - self.hot_score = (age_in_units**3 + weigted_score * 1000).round + self.hot_score = (age_in_units**3 + weighted_score * 1000).round end protected From 2975c6a38d765f2963361e0a0cb55d315cf83d7e Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 14:04:18 +0200 Subject: [PATCH 11/22] Makes votes increase/decrease hot score MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Debates already call update_attibutes in debates (to update cached counters), so there is no need to do an “after_voted”: the comment’s before_save call takes care of it. --- spec/models/debate_spec.rb | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index 52d8c0740..93403c591 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -184,35 +184,55 @@ describe Debate do describe '#hot_score' do let(:now) { Time.now } - it "gets bigger for newer debates" do + it "increases for newer debates" do old = create(:debate, :with_hot_score, created_at: now - 1.day) new = create(:debate, :with_hot_score, created_at: now) expect(new.hot_score).to be > old.hot_score end - it "gets bigger for debates with more comments" do + it "increases for debates with more comments" do more_comments = create(:debate, :with_hot_score, created_at: now, comments_count: 10) less_comments = create(:debate, :with_hot_score, created_at: now, comments_count: 1) expect(more_comments.hot_score).to be > less_comments.hot_score end - it "gets bigger for debates with more positive votes" do + it "increases for debates with more positive votes" do more_likes = create(:debate, :with_hot_score, created_at: now, cached_votes_total: 10, cached_votes_up: 5) less_likes = create(:debate, :with_hot_score, created_at: now, cached_votes_total: 10, cached_votes_up: 1) expect(more_likes.hot_score).to be > less_likes.hot_score end - it "gets bigger for debates with more confidence" do + it "increases for debates with more confidence" do more_confidence = create(:debate, :with_hot_score, created_at: now, cached_votes_total: 1000, cached_votes_up: 700) less_confidence = create(:debate, :with_hot_score, created_at: now, cached_votes_total: 10, cached_votes_up: 9) expect(more_confidence.hot_score).to be > less_confidence.hot_score end - it "decays older debates, even if they have more votes" do + it "decays in older debates, even if they have more votes" do older_more_voted = create(:debate, :with_hot_score, created_at: now - 2.days, cached_votes_total: 1000, cached_votes_up: 900) new_less_voted = create(:debate, :with_hot_score, created_at: now, cached_votes_total: 10, cached_votes_up: 9) expect(new_less_voted.hot_score).to be > older_more_voted.hot_score end + + describe 'actions which affect it' do + let(:debate) { create(:debate, :with_hot_score) } + + it "increases with likes" do + previous = debate.hot_score + 5.times { debate.register_vote(create(:user), true) } + expect(previous).to be < debate.hot_score + end + + it "decreases with dislikes" do + debate.register_vote(create(:user), true) + previous = debate.hot_score + 3.times { debate.register_vote(create(:user), false) } + expect(previous).to be > debate.hot_score + end + end + end + + end From 9bb63e9b32acb8586e89470abec1f2971d9d15ae Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 14:04:45 +0200 Subject: [PATCH 12/22] Makes comments increase the hot_score --- app/models/comment.rb | 6 ++++++ app/models/debate.rb | 4 ++++ spec/models/debate_spec.rb | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/app/models/comment.rb b/app/models/comment.rb index 422d39f8d..8190ff363 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -24,6 +24,8 @@ class Comment < ActiveRecord::Base scope :for_render, -> { with_hidden.includes(user: :organization) } + after_create :call_after_commented + def self.build(commentable, user, body, p_id=nil) new commentable: commentable, user_id: user.id, @@ -87,4 +89,8 @@ class Comment < ActiveRecord::Base !root? end + def call_after_commented + self.commentable.try(:after_commented) + end + end diff --git a/app/models/debate.rb b/app/models/debate.rb index ef28f5132..84181c26d 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -104,6 +104,10 @@ class Debate < ActiveRecord::Base update(ignored_flag_at: Time.now) end + def after_commented + save # updates teh hot_score because there is a before_save + end + def calculate_hot_score z = 1.96 # Normal distribution with a confidence of 0.95 time_unit = 1.0 * 12.hours diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index 93403c591..537cc303c 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -229,6 +229,12 @@ describe Debate do 3.times { debate.register_vote(create(:user), false) } expect(previous).to be > debate.hot_score end + + it "increases with comments" do + previous = debate.hot_score + Comment.create(user: create(:user), commentable: debate, body: 'foo') + expect(previous).to be < debate.hot_score + end end end From 50a8d4c854520992ccec7072a05f4905ecfd48ed Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 14:11:01 +0200 Subject: [PATCH 13/22] adds task for updating the hot_score in debates --- lib/tasks/debates.rake | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 lib/tasks/debates.rake diff --git a/lib/tasks/debates.rake b/lib/tasks/debates.rake new file mode 100644 index 000000000..ce37e2743 --- /dev/null +++ b/lib/tasks/debates.rake @@ -0,0 +1,9 @@ +namespace :debates do + desc "Updates all debates by recalculating their hot_score" + task hot_score: :environment do + Debate.find_in_batches do |debates| + debates.each(&:save) + end + end + +end From b6699932d1cd1e7b29f99de87f4791d584590fd9 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 14:16:05 +0200 Subject: [PATCH 14/22] uses the hot_score in the welcome screen --- app/controllers/welcome_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index dbb31863e..ca3d04d68 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -2,8 +2,8 @@ class WelcomeController < ApplicationController skip_authorization_check def index - @featured_debates = Debate.includes(:tags).limit(3) + @featured_debates = Debate.sort_by_hot_score.limit(3).for_render set_debate_votes(@featured_debates) end -end \ No newline at end of file +end From 08c31c5985beebca3d1f10b5ed235bd1e562bf62 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 14:17:59 +0200 Subject: [PATCH 15/22] calls all the sorting scopes the same way --- app/controllers/moderation/comments_controller.rb | 2 +- app/controllers/moderation/debates_controller.rb | 2 +- app/models/comment.rb | 2 +- app/models/debate.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/moderation/comments_controller.rb b/app/controllers/moderation/comments_controller.rb index b53785e81..3d8d960aa 100644 --- a/app/controllers/moderation/comments_controller.rb +++ b/app/controllers/moderation/comments_controller.rb @@ -27,7 +27,7 @@ class Moderation::CommentsController < Moderation::BaseController private def load_comments - @comments = Comment.accessible_by(current_ability, :hide).flagged.sorted_for_moderation.includes(:commentable) + @comments = Comment.accessible_by(current_ability, :hide).flagged.sort_for_moderation.includes(:commentable) end end diff --git a/app/controllers/moderation/debates_controller.rb b/app/controllers/moderation/debates_controller.rb index 85441d3f2..ce970b082 100644 --- a/app/controllers/moderation/debates_controller.rb +++ b/app/controllers/moderation/debates_controller.rb @@ -26,7 +26,7 @@ class Moderation::DebatesController < Moderation::BaseController private def load_debates - @debates = Debate.accessible_by(current_ability, :hide).flagged.sorted_for_moderation + @debates = Debate.accessible_by(current_ability, :hide).flagged.sort_for_moderation end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 8190ff363..8dd922714 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -17,7 +17,7 @@ class Comment < ActiveRecord::Base scope :recent, -> { order(id: :desc) } - scope :sorted_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) } + scope :sort_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) } scope :pending_flag_review, -> { where(ignored_flag_at: nil, hidden_at: nil) } scope :with_ignored_flag, -> { where("ignored_flag_at IS NOT NULL AND hidden_at IS NULL") } scope :flagged, -> { where("flags_count > 0") } diff --git a/app/models/debate.rb b/app/models/debate.rb index 84181c26d..f8f57fa97 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -23,7 +23,7 @@ class Debate < ActiveRecord::Base before_save :calculate_hot_score - scope :sorted_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) } + scope :sort_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) } scope :pending_flag_review, -> { where(ignored_flag_at: nil, hidden_at: nil) } scope :with_ignored_flag, -> { where("ignored_flag_at IS NOT NULL AND hidden_at IS NULL") } scope :flagged, -> { where("flags_count > 0") } From b6e635617241dccbd32ecc5483a3a00f538cfcb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 4 Sep 2015 15:00:18 +0200 Subject: [PATCH 16/22] fixes hot_score spec --- spec/features/debates_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 433ce1083..1f00e9c3a 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -367,9 +367,9 @@ feature 'Debates' do feature 'Debate index order filters' do scenario 'Default order is hot_score', :js do - create(:debate, title: 'best', hot_score: 10) - create(:debate, title: 'medium', hot_score: 5) - create(:debate, title: 'worst', hot_score: 2) + create(:debate, title: 'best').update_column(:hot_score, 10) + create(:debate, title: 'worst').update_column(:hot_score, 2) + create(:debate, title: 'medium').update_column(:hot_score, 5) visit debates_path From 44bab6f4b4a706ababbfeef669ef75f83d35edd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 4 Sep 2015 15:15:20 +0200 Subject: [PATCH 17/22] adds expect to wait for to capybara --- spec/features/debates_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 1f00e9c3a..808a128b5 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -430,6 +430,7 @@ feature 'Debates' do select 'most commented', from: 'order-selector' expect(page).to have_select('order-selector', selected: 'most commented') + expect(find("#debates .debate", match: :first)).to have_content(@most_commented_debate.title) select 'random', from: 'order-selector' expect(page).to have_select('order-selector', selected: 'random') From dd4a2d57cf0e5307469d11435517a89138ddb6b0 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 15:32:15 +0200 Subject: [PATCH 18/22] makes admin/organization specs more robust --- app/views/admin/organizations/index.html.erb | 2 +- spec/features/admin/organizations_spec.rb | 30 ++++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/views/admin/organizations/index.html.erb b/app/views/admin/organizations/index.html.erb index 464168746..7be6e7519 100644 --- a/app/views/admin/organizations/index.html.erb +++ b/app/views/admin/organizations/index.html.erb @@ -19,7 +19,7 @@ <% @organizations.each do |organization| %> - + diff --git a/spec/features/admin/organizations_spec.rb b/spec/features/admin/organizations_spec.rb index f43c5d4dc..576d26db3 100644 --- a/spec/features/admin/organizations_spec.rb +++ b/spec/features/admin/organizations_spec.rb @@ -13,7 +13,7 @@ feature 'Admin::Organizations' do background do @user = create(:user, email: "marley@humanrights.com", phone_number: "6764440002") - organization = create(:organization, user: @user, name: "Get up, Stand up") + create(:organization, user: @user, name: "Get up, Stand up") end scenario "returns no results if search term is empty" do @@ -70,11 +70,13 @@ feature 'Admin::Organizations' do organization = create(:organization) visit admin_organizations_path - expect(current_path).to eq(admin_organizations_path) - expect(page).to have_link('Verify') - expect(page).to have_link('Reject') + within("organization_#{organization.id}") do + expect(current_path).to eq(admin_organizations_path) + expect(page).to have_link('Verify') + expect(page).to have_link('Reject') - click_on 'Verify' + click_on 'Verify' + end expect(current_path).to eq(admin_organizations_path) expect(page).to have_content ('Verified') @@ -86,11 +88,13 @@ feature 'Admin::Organizations' do visit admin_organizations_path expect(current_path).to eq(admin_organizations_path) - expect(page).to have_content ('Verified') - expect(page).to_not have_link('Verify') - expect(page).to have_link('Reject') + within("organization_#{organization.id}") do + expect(page).to have_content ('Verified') + expect(page).to_not have_link('Verify') + expect(page).to have_link('Reject') - click_on 'Reject' + click_on 'Reject' + end expect(current_path).to eq(admin_organizations_path) expect(page).to have_content ('Rejected') @@ -102,10 +106,12 @@ feature 'Admin::Organizations' do visit admin_organizations_path expect(current_path).to eq(admin_organizations_path) - expect(page).to have_link('Verify') - expect(page).to_not have_link('Reject', exact: true) + within("organization_#{organization.id}") do + expect(page).to have_link('Verify') + expect(page).to_not have_link('Reject', exact: true) - click_on 'Verify' + click_on 'Verify' + end expect(current_path).to eq(admin_organizations_path) expect(page).to have_content ('Verified') From 8b16ecfcf9be4531111d8e4630f5bf6e9d309e1d Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 15:36:54 +0200 Subject: [PATCH 19/22] fixes typo and specs --- app/views/admin/organizations/index.html.erb | 2 +- spec/features/admin/organizations_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/admin/organizations/index.html.erb b/app/views/admin/organizations/index.html.erb index 7be6e7519..85f75cf34 100644 --- a/app/views/admin/organizations/index.html.erb +++ b/app/views/admin/organizations/index.html.erb @@ -19,7 +19,7 @@
<%= organization.name %> <%= organization.email %> <%= organization.phone_number %>
<% @organizations.each do |organization| %> - + diff --git a/spec/features/admin/organizations_spec.rb b/spec/features/admin/organizations_spec.rb index 576d26db3..289b5cd1c 100644 --- a/spec/features/admin/organizations_spec.rb +++ b/spec/features/admin/organizations_spec.rb @@ -70,7 +70,7 @@ feature 'Admin::Organizations' do organization = create(:organization) visit admin_organizations_path - within("organization_#{organization.id}") do + within("#organization_#{organization.id}") do expect(current_path).to eq(admin_organizations_path) expect(page).to have_link('Verify') expect(page).to have_link('Reject') @@ -88,7 +88,7 @@ feature 'Admin::Organizations' do visit admin_organizations_path expect(current_path).to eq(admin_organizations_path) - within("organization_#{organization.id}") do + within("#organization_#{organization.id}") do expect(page).to have_content ('Verified') expect(page).to_not have_link('Verify') expect(page).to have_link('Reject') @@ -106,7 +106,7 @@ feature 'Admin::Organizations' do visit admin_organizations_path expect(current_path).to eq(admin_organizations_path) - within("organization_#{organization.id}") do + within("#organization_#{organization.id}") do expect(page).to have_link('Verify') expect(page).to_not have_link('Reject', exact: true) From b9453a83bb7084063ade0ee169fa7eceb8a689fe Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 15:41:12 +0200 Subject: [PATCH 20/22] remove failing line (undefined var) --- spec/features/debates_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 808a128b5..1f00e9c3a 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -430,7 +430,6 @@ feature 'Debates' do select 'most commented', from: 'order-selector' expect(page).to have_select('order-selector', selected: 'most commented') - expect(find("#debates .debate", match: :first)).to have_content(@most_commented_debate.title) select 'random', from: 'order-selector' expect(page).to have_select('order-selector', selected: 'random') From 457b734ca4da07868cf9fb38b6aba9d47b01c643 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 15:55:30 +0200 Subject: [PATCH 21/22] adds within clauses to debates specs. This should wait for page refreshes if needed --- spec/features/debates_spec.rb | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 1f00e9c3a..1b1b72712 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -385,10 +385,13 @@ feature 'Debates' do visit debates_path select 'best rated', from: 'order-selector' - expect(page).to have_select('order-selector', selected: 'best rated') - expect('best').to appear_before('medium') - expect('medium').to appear_before('worst') + + within '#debates' do + expect('best').to appear_before('medium') + expect('medium').to appear_before('worst') + end + expect(current_url).to include('order=score') end @@ -399,10 +402,13 @@ feature 'Debates' do visit debates_path select 'most commented', from: 'order-selector' - expect(page).to have_select('order-selector', selected: 'most commented') - expect('best').to appear_before('medium') - expect('medium').to appear_before('worst') + + within '#debates' do + expect('best').to appear_before('medium') + expect('medium').to appear_before('worst') + end + expect(current_url).to include('order=most_commented') end @@ -413,10 +419,13 @@ feature 'Debates' do visit debates_path select 'newest', from: 'order-selector' - expect(page).to have_select('order-selector', selected: 'newest') - expect('best').to appear_before('medium') - expect('medium').to appear_before('worst') + + within '#debates' do + expect('best').to appear_before('medium') + expect('medium').to appear_before('worst') + end + expect(current_url).to include('order=created_at') end From 8e451dbf668153bd0e37184fdf4dcde2a52598af Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 4 Sep 2015 16:22:07 +0200 Subject: [PATCH 22/22] adds even more expects to random debate order spec to fix travis --- spec/features/debates_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 1b1b72712..5c808a5ef 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -435,13 +435,16 @@ feature 'Debates' do select 'random', from: 'order-selector' expect(page).to have_select('order-selector', selected: 'random') + expect(page).to have_selector('#debates') debates_first_time = find("#debates").text select 'most commented', from: 'order-selector' expect(page).to have_select('order-selector', selected: 'most commented') + expect(page).to have_selector('#debates') select 'random', from: 'order-selector' expect(page).to have_select('order-selector', selected: 'random') + expect(page).to have_selector('#debates') debates_second_time = find("#debates").text expect(debates_first_time).to_not eq(debates_second_time)
<%= organization.name %> <%= organization.email %> <%= organization.phone_number %>