From 68f9a76cea41d201f739ce23d6b4ba7ae395ce88 Mon Sep 17 00:00:00 2001 From: MaiteHdezRivas Date: Sun, 20 Mar 2016 13:55:04 +0100 Subject: [PATCH 1/8] Mark debates as featured --- app/controllers/debates_controller.rb | 10 +++++ app/helpers/debates_helper.rb | 6 +++ app/models/abilities/administrator.rb | 4 ++ app/models/debate.rb | 7 +++- app/views/admin/_menu.html.erb | 2 +- app/views/debates/_actions.html.erb | 11 ++++++ app/views/debates/_featured_debates.html.erb | 13 +++++++ .../debates/_featured_debates_static.html.erb | 17 -------- app/views/debates/index.html.erb | 4 +- config/locales/admin.en.yml | 3 ++ config/locales/admin.es.yml | 3 ++ config/routes.rb | 2 + ...160315084335_add_featured_at_to_debates.rb | 5 +++ db/schema.rb | 3 +- spec/features/debates_spec.rb | 39 +++++++++++++++++++ 15 files changed, 107 insertions(+), 22 deletions(-) create mode 100644 app/helpers/debates_helper.rb create mode 100644 app/views/debates/_featured_debates.html.erb delete mode 100644 app/views/debates/_featured_debates_static.html.erb create mode 100644 db/migrate/20160315084335_add_featured_at_to_debates.rb diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index b5a0ae25a..4a22d2e3e 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -28,6 +28,16 @@ class DebatesController < ApplicationController set_debate_votes(@debate) end + def remove_feature + @debate.update_attribute(:featured_at, nil) + redirect_to request.query_parameters.merge(action: :index) + end + + def feature + @debate.update_attribute(:featured_at, Time.now) + redirect_to request.query_parameters.merge(action: :index) + end + private def debate_params diff --git a/app/helpers/debates_helper.rb b/app/helpers/debates_helper.rb new file mode 100644 index 000000000..d12db7f78 --- /dev/null +++ b/app/helpers/debates_helper.rb @@ -0,0 +1,6 @@ +module DebatesHelper + + def has_featured + Debate.all.featured.count > 0 + end +end \ No newline at end of file diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 78cb60806..fa15bacb3 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -30,6 +30,10 @@ module Abilities can :confirm_hide, User cannot :confirm_hide, User, hidden_at: nil + can :feature, Debate + + can :remove_feature, Debate + can :comment_as_administrator, [Debate, Comment, Proposal] can [:search, :create, :index, :destroy], ::Moderator diff --git a/app/models/debate.rb b/app/models/debate.rb index ceec9946b..249ae0c44 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -36,7 +36,8 @@ class Debate < ActiveRecord::Base scope :sort_by_random, -> { reorder("RANDOM()") } scope :sort_by_relevance, -> { all } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } - scope :last_week, -> { where("created_at >= ?", 7.days.ago)} + scope :last_week, -> { where("created_at >= ?", 7.days.ago)} + scope :featured, -> { where("featured_at is not null")} # Ahoy setup visitable # Ahoy will automatically assign visit_id on create @@ -132,4 +133,8 @@ class Debate < ActiveRecord::Base self.tags.each{ |t| t.increment_custom_counter_for('Debate') } end + def featured? + ! self.featured_at.nil? + end + end diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index f435c5511..313c34042 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -25,7 +25,7 @@ <%= t("admin.menu.hidden_debates") %> <% end %> - <% end %> + <% end %>
  • > <%= link_to admin_comments_path do %> diff --git a/app/views/debates/_actions.html.erb b/app/views/debates/_actions.html.erb index db9821ad0..b88d4830c 100644 --- a/app/views/debates/_actions.html.erb +++ b/app/views/debates/_actions.html.erb @@ -8,3 +8,14 @@ <%= link_to t("admin.actions.hide_author").capitalize, hide_moderation_user_path(debate.author_id), method: :put, data: { confirm: t('admin.actions.confirm') } %> <% end %> + +<% if can? :feature, debate %> +  |  + <% if debate.featured? %> + <%= link_to t("admin.actions.remove_feature").capitalize, remove_feature_debate_path(debate), + method: :put, data: { confirm: t('admin.actions.confirm') } %> + <% else %> + <%= link_to t("admin.actions.feature").capitalize, feature_debate_path(debate), + method: :put, data: { confirm: t('admin.actions.confirm') } %> + <% 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..8b0450e16 --- /dev/null +++ b/app/views/debates/_featured_debates.html.erb @@ -0,0 +1,13 @@ + diff --git a/app/views/debates/_featured_debates_static.html.erb b/app/views/debates/_featured_debates_static.html.erb deleted file mode 100644 index 8f7d0b68d..000000000 --- a/app/views/debates/_featured_debates_static.html.erb +++ /dev/null @@ -1,17 +0,0 @@ - diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb index 6488b5844..7ee9d12d4 100644 --- a/app/views/debates/index.html.erb +++ b/app/views/debates/index.html.erb @@ -25,8 +25,8 @@ <% end %> - <% unless @tag_filter || @search_terms %> - <%= render "featured_debates_static" %> + <% unless @tag_filter || @search_terms || !has_featured %> + <%= render "featured_debates", debate: @debates.featured %> <% end %> <%= render "shared/advanced_search", search_path: debates_path(page: 1) %> diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 4ecf9cbda..4c09952ef 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -7,6 +7,8 @@ en: hide: Hide hide_author: Hide author restore: Restore + feature: Feature + remove_feature: Remove feature activity: show: action: Action @@ -50,6 +52,7 @@ en: debate_topics: Debate topics hidden_comments: Hidden comments hidden_debates: Hidden debates + featured_debates: Featured debates hidden_proposals: Hidden proposals hidden_users: Hidden users incomplete_verifications: Incomplete verifications diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index bc882fab2..922191d49 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -7,6 +7,8 @@ es: hide: Ocultar hide_author: Bloquear al autor restore: Volver a mostrar + feature: Destacar + remove_feature: Quitar destacado activity: show: action: Acción @@ -50,6 +52,7 @@ es: debate_topics: Temas de debate hidden_comments: Comentarios ocultos hidden_debates: Debates ocultos + featured_debates: Debates destacados hidden_proposals: Propuestas ocultas hidden_users: Usuarios bloqueados incomplete_verifications: Verificaciones incompletas diff --git a/config/routes.rb b/config/routes.rb index 680f657ab..2406e40fb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -36,6 +36,8 @@ Rails.application.routes.draw do post :vote put :flag put :unflag + put :remove_feature + put :feature end collection do get :map diff --git a/db/migrate/20160315084335_add_featured_at_to_debates.rb b/db/migrate/20160315084335_add_featured_at_to_debates.rb new file mode 100644 index 000000000..81093aed3 --- /dev/null +++ b/db/migrate/20160315084335_add_featured_at_to_debates.rb @@ -0,0 +1,5 @@ +class AddFeaturedAtToDebates < ActiveRecord::Migration + def change + add_column :debates, :featured_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 8d3a3caa9..79034e405 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: 20160308184050) do +ActiveRecord::Schema.define(version: 20160315084335) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -120,6 +120,7 @@ ActiveRecord::Schema.define(version: 20160308184050) do t.integer "confidence_score", default: 0 t.integer "geozone_id" t.tsvector "tsv" + t.datetime "featured_at" end add_index "debates", ["author_id", "hidden_at"], name: "index_debates_on_author_id_and_hidden_at", using: :btree diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index d9ab8c8eb..b7cc3ea3a 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -1008,4 +1008,43 @@ feature 'Debates' do end end end + + scenario 'Mark debate as featured' do + admin = create(:administrator) + login_as(admin.user) + + debate1 = create(:debate) + debate2 = create(:debate, featured_at: Time.now) + + visit debate_path(debate1) + expect(page).to have_content("Feature") + + visit debate_path(debate2) + expect(page).to have_content("Remove feature") + + end + + + scenario 'Show featured debates' do + admin = create(:administrator) + login_as(admin.user) + + debate1 = create(:debate, featured_at: Time.now) + debate2 = create(:debate) + + visit debates_path + expect(page).to have_content("Featured") + end + + + scenario 'Dont show featured debates' do + admin = create(:administrator) + login_as(admin.user) + + debate1 = create(:debate) + debate2 = create(:debate) + + visit debates_path + expect(page).to_not have_content("Featured") + end end From e9bc6ff75f1eba7808953f20e4dfadc655aace38 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 5 Apr 2016 14:14:04 +0200 Subject: [PATCH 2/8] Improves layout for featured debates --- app/views/admin/_menu.html.erb | 2 +- app/views/debates/_featured_debates.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 313c34042..f435c5511 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -25,7 +25,7 @@ <%= t("admin.menu.hidden_debates") %> <% end %>
  • - <% end %> + <% end %>
  • > <%= link_to admin_comments_path do %> diff --git a/app/views/debates/_featured_debates.html.erb b/app/views/debates/_featured_debates.html.erb index 8b0450e16..e678e2da8 100644 --- a/app/views/debates/_featured_debates.html.erb +++ b/app/views/debates/_featured_debates.html.erb @@ -5,7 +5,7 @@ <% @debates.featured.each do |debate| %> -
    +

    <%= link_to debate.title, debate %>

    <%= link_to debate.author.name, user_path(debate.author)%>
    From b4c6e2f1606745932e954ee9e6859d79a769fac0 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 6 Apr 2016 11:09:24 +0200 Subject: [PATCH 3/8] Removes unused keys --- config/locales/admin.en.yml | 1 - config/locales/admin.es.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 16d0a72a3..024c0140d 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -52,7 +52,6 @@ en: debate_topics: Debate topics hidden_comments: Hidden comments hidden_debates: Hidden debates - featured_debates: Featured debates hidden_proposals: Hidden proposals hidden_users: Hidden users incomplete_verifications: Incomplete verifications diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index ca1255560..0493cedeb 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -52,7 +52,6 @@ es: debate_topics: Temas de debate hidden_comments: Comentarios ocultos hidden_debates: Debates ocultos - featured_debates: Debates destacados hidden_proposals: Propuestas ocultas hidden_users: Usuarios bloqueados incomplete_verifications: Verificaciones incompletas From 3e7db9d1b5f57c94179b0128c9aea8996b3070fa Mon Sep 17 00:00:00 2001 From: MaiteHdezRivas Date: Wed, 20 Apr 2016 16:40:58 +0200 Subject: [PATCH 4/8] Best practices code changes --- app/controllers/debates_controller.rb | 9 +++++++-- app/helpers/debates_helper.rb | 2 +- app/models/abilities/administrator.rb | 5 ++--- app/models/debate.rb | 2 +- app/views/debates/_actions.html.erb | 8 ++++---- app/views/debates/_featured_debates.html.erb | 2 +- app/views/debates/index.html.erb | 4 ++-- config/locales/admin.en.yml | 4 ++-- config/locales/admin.es.yml | 4 ++-- config/routes.rb | 4 ++-- 10 files changed, 24 insertions(+), 20 deletions(-) diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 4a22d2e3e..cd213bd94 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -18,6 +18,11 @@ class DebatesController < ApplicationController helper_method :resource_model, :resource_name respond_to :html, :js + def index + super + @featured_debates = @debates.featured + end + def show super redirect_to debate_path(@debate), status: :moved_permanently if request.path != debate_path(@debate) @@ -28,12 +33,12 @@ class DebatesController < ApplicationController set_debate_votes(@debate) end - def remove_feature + def unmark_featured @debate.update_attribute(:featured_at, nil) redirect_to request.query_parameters.merge(action: :index) end - def feature + def mark_featured @debate.update_attribute(:featured_at, Time.now) redirect_to request.query_parameters.merge(action: :index) end diff --git a/app/helpers/debates_helper.rb b/app/helpers/debates_helper.rb index d12db7f78..3c1aa02a7 100644 --- a/app/helpers/debates_helper.rb +++ b/app/helpers/debates_helper.rb @@ -1,6 +1,6 @@ module DebatesHelper - def has_featured + def has_featured? Debate.all.featured.count > 0 end end \ No newline at end of file diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 9727e8e35..55759959e 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -30,9 +30,8 @@ module Abilities can :confirm_hide, User cannot :confirm_hide, User, hidden_at: nil - can :feature, Debate - - can :remove_feature, Debate + can :mark_featured, Debate + can :unmark_featured, Debate can :comment_as_administrator, [Debate, Comment, Proposal] diff --git a/app/models/debate.rb b/app/models/debate.rb index 249ae0c44..cdae527f7 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -134,7 +134,7 @@ class Debate < ActiveRecord::Base end def featured? - ! self.featured_at.nil? + self.featured_at.present? end end diff --git a/app/views/debates/_actions.html.erb b/app/views/debates/_actions.html.erb index b88d4830c..1b61e045b 100644 --- a/app/views/debates/_actions.html.erb +++ b/app/views/debates/_actions.html.erb @@ -9,13 +9,13 @@ method: :put, data: { confirm: t('admin.actions.confirm') } %> <% end %> -<% if can? :feature, debate %> -  |  +<% if can? :mark_featured, debate %> +  |  <% if debate.featured? %> - <%= link_to t("admin.actions.remove_feature").capitalize, remove_feature_debate_path(debate), + <%= link_to t("admin.actions.unmark_featured").capitalize, unmark_featured_debate_path(debate), method: :put, data: { confirm: t('admin.actions.confirm') } %> <% else %> - <%= link_to t("admin.actions.feature").capitalize, feature_debate_path(debate), + <%= link_to t("admin.actions.mark_featured").capitalize, mark_featured_debate_path(debate), method: :put, data: { confirm: t('admin.actions.confirm') } %> <% end %> <% end %> diff --git a/app/views/debates/_featured_debates.html.erb b/app/views/debates/_featured_debates.html.erb index e678e2da8..577a6da77 100644 --- a/app/views/debates/_featured_debates.html.erb +++ b/app/views/debates/_featured_debates.html.erb @@ -4,7 +4,7 @@

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

    - <% @debates.featured.each do |debate| %> + <% @featured_debates.each do |debate| %>

    <%= link_to debate.title, debate %>

    <%= link_to debate.author.name, user_path(debate.author)%> diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb index 7ee9d12d4..ab0a137c7 100644 --- a/app/views/debates/index.html.erb +++ b/app/views/debates/index.html.erb @@ -25,8 +25,8 @@ <% end %>
    - <% unless @tag_filter || @search_terms || !has_featured %> - <%= render "featured_debates", debate: @debates.featured %> + <% unless @tag_filter || @search_terms || !has_featured? %> + <%= render "featured_debates" %> <% end %> <%= render "shared/advanced_search", search_path: debates_path(page: 1) %> diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 024c0140d..60b615562 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -7,8 +7,8 @@ en: hide: Hide hide_author: Hide author restore: Restore - feature: Feature - remove_feature: Remove feature + mark_featured: Featured + unmark_featured: Unmark featured activity: show: action: Action diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 0493cedeb..c2a3669d5 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -7,8 +7,8 @@ es: hide: Ocultar hide_author: Bloquear al autor restore: Volver a mostrar - feature: Destacar - remove_feature: Quitar destacado + mark_featured: Destacar + unmark_featured: Quitar destacado activity: show: action: Acción diff --git a/config/routes.rb b/config/routes.rb index 79aa167e5..b9cdbdd3a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -36,8 +36,8 @@ Rails.application.routes.draw do post :vote put :flag put :unflag - put :remove_feature - put :feature + put :mark_featured + put :unmark_featured end collection do get :map From f771a61a50b1c92e387bfd0c6eaeddee1a8b6bc0 Mon Sep 17 00:00:00 2001 From: MaiteHdezRivas Date: Thu, 21 Apr 2016 11:13:58 +0200 Subject: [PATCH 5/8] Refactoring method on debates controller --- .../concerns/commentable_actions.rb | 6 ++++ app/controllers/debate_links_controller.rb | 31 ------------------- app/controllers/debates_controller.rb | 9 +++--- 3 files changed, 10 insertions(+), 36 deletions(-) delete mode 100644 app/controllers/debate_links_controller.rb diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 01066c8ad..a948948a2 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -9,6 +9,7 @@ module CommentableActions @resources = @resources.tagged_with(@tag_filter) if @tag_filter @resources = @resources.page(params[:page]).for_render.send("sort_by_#{@current_order}") index_customization if index_customization.present? + featured_debates if featured_debates.present? @tag_cloud = tag_cloud set_resource_votes(@resources) @@ -152,4 +153,9 @@ module CommentableActions def index_customization nil end + + def featured_debates + nil + end + end diff --git a/app/controllers/debate_links_controller.rb b/app/controllers/debate_links_controller.rb deleted file mode 100644 index f6f7c3af8..000000000 --- a/app/controllers/debate_links_controller.rb +++ /dev/null @@ -1,31 +0,0 @@ -class DebateLinksController < ApplicationController - include FeatureFlags - include CommentableActions - - before_action :authenticate_user!, except: [:show] - - load_and_authorize_resource class: "Debate" - - feature_flag :debates - - respond_to :html, :js - - private - - def create_params - params.require(:debate).permit(:title, :external_link, :tag_list, :terms_of_service, :captcha, :captcha_key).merge(link_required: true) - end - - def debate_params - params.require(:debate).permit(:title, :external_link, :tag_list, :terms_of_service, :captcha, :captcha_key).merge(link_required: true) - end - - def after_create_path - debate_path(@resource) - end - - def resource_model - Debate - end - -end diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index cd213bd94..c743d58a7 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -18,11 +18,6 @@ class DebatesController < ApplicationController helper_method :resource_model, :resource_name respond_to :html, :js - def index - super - @featured_debates = @debates.featured - end - def show super redirect_to debate_path(@debate), status: :moved_permanently if request.path != debate_path(@debate) @@ -43,6 +38,10 @@ class DebatesController < ApplicationController redirect_to request.query_parameters.merge(action: :index) end + def featured_debates + @featured_debates = @debates.featured + end + private def debate_params From c86f3516db59028e008864e5006646d4c79b630c Mon Sep 17 00:00:00 2001 From: MaiteHdezRivas Date: Thu, 21 Apr 2016 11:30:45 +0200 Subject: [PATCH 6/8] correct text in the test --- spec/features/debates_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index b7cc3ea3a..9db200f11 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -1017,10 +1017,10 @@ feature 'Debates' do debate2 = create(:debate, featured_at: Time.now) visit debate_path(debate1) - expect(page).to have_content("Feature") + expect(page).to have_content("Featured") visit debate_path(debate2) - expect(page).to have_content("Remove feature") + expect(page).to have_content("Unmark featured") end From 54c1c581f9088b9046027aa88d8014c91d85c8be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Thu, 21 Apr 2016 12:00:48 +0200 Subject: [PATCH 7/8] uses index_customization in debates_controller --- app/controllers/concerns/commentable_actions.rb | 5 ----- app/controllers/debates_controller.rb | 8 ++++---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index a948948a2..332d031a5 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -9,7 +9,6 @@ module CommentableActions @resources = @resources.tagged_with(@tag_filter) if @tag_filter @resources = @resources.page(params[:page]).for_render.send("sort_by_#{@current_order}") index_customization if index_customization.present? - featured_debates if featured_debates.present? @tag_cloud = tag_cloud set_resource_votes(@resources) @@ -154,8 +153,4 @@ module CommentableActions nil end - def featured_debates - nil - end - end diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index c743d58a7..b747cd903 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -18,6 +18,10 @@ class DebatesController < ApplicationController helper_method :resource_model, :resource_name respond_to :html, :js + def index_customization + @featured_debates = @debates.featured + end + def show super redirect_to debate_path(@debate), status: :moved_permanently if request.path != debate_path(@debate) @@ -38,10 +42,6 @@ class DebatesController < ApplicationController redirect_to request.query_parameters.merge(action: :index) end - def featured_debates - @featured_debates = @debates.featured - end - private def debate_params From 198f6c96bdbff1e8256a1a0f53d6d63c7d4960cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 25 Apr 2016 17:59:42 +0200 Subject: [PATCH 8/8] adds & refactors specs for featured debates --- spec/features/debates_spec.rb | 46 +++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 9db200f11..0db455401 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -1009,42 +1009,52 @@ feature 'Debates' do end end - scenario 'Mark debate as featured' do + scenario 'Matk/Unmark a debate as featured' do admin = create(:administrator) login_as(admin.user) - - debate1 = create(:debate) - debate2 = create(:debate, featured_at: Time.now) - - visit debate_path(debate1) - expect(page).to have_content("Featured") - visit debate_path(debate2) - expect(page).to have_content("Unmark featured") + debate = create(:debate) - end + visit debates_path + expect(page).to_not have_content 'Featured' + + click_link debate.title + + click_link 'Featured' + + visit debates_path + expect(page).to have_content 'Featured' + within('#featured-debates') do + expect(page).to have_content debate.title + end + + visit debate_path(debate) + click_link 'Unmark featured' + + expect(page).to_not have_content 'Featured' + end - scenario 'Show featured debates' do + scenario 'Index include featured debates' do admin = create(:administrator) login_as(admin.user) - + debate1 = create(:debate, featured_at: Time.now) debate2 = create(:debate) - + visit debates_path expect(page).to have_content("Featured") - end + end - scenario 'Dont show featured debates' do + scenario 'Index do not show featured debates if none is marked as featured' do admin = create(:administrator) login_as(admin.user) - + debate1 = create(:debate) debate2 = create(:debate) - + visit debates_path expect(page).to_not have_content("Featured") - end + end end