Merge pull request #6125 from consuldemocracy/remove-obsolete-scopes
Add missing investments filter on admin activity page
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
class Admin::ActivityController < Admin::BaseController
|
class Admin::ActivityController < Admin::BaseController
|
||||||
has_filters %w[all on_users on_proposals on_debates on_comments on_system_emails]
|
has_filters %w[all on_users on_proposals on_debates on_comments on_budget_investments on_system_emails]
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@activity = Activity.for_render.send(@current_filter)
|
@activity = Activity.for_render.send(@current_filter)
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ class Community < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def users_who_topics_author
|
def users_who_topics_author
|
||||||
author_ids = topics.pluck(:author_id)
|
ids = topics.pluck(:author_id)
|
||||||
User.by_authors(author_ids)
|
User.with_ids(ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
def author_from_community
|
def author_from_community
|
||||||
|
|||||||
@@ -2,10 +2,7 @@ module Filterable
|
|||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
scope :by_date_range, ->(date_range) { where(created_at: date_range) }
|
scope :by_date_range, ->(date_range) { where(created_at: date_range) }
|
||||||
scope :by_official_level, ->(official_level) do
|
|
||||||
where(users: { official_level: official_level }).joins(:author)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class_methods do
|
class_methods do
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ class Debate < ApplicationRecord
|
|||||||
scope :sort_by_hot_score, -> { reorder(hot_score: :desc) }
|
scope :sort_by_hot_score, -> { reorder(hot_score: :desc) }
|
||||||
scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc) }
|
scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc) }
|
||||||
scope :sort_by_created_at, -> { reorder(created_at: :desc) }
|
scope :sort_by_created_at, -> { reorder(created_at: :desc) }
|
||||||
scope :sort_by_most_commented, -> { reorder(comments_count: :desc) }
|
|
||||||
scope :sort_by_relevance, -> { all }
|
scope :sort_by_relevance, -> { all }
|
||||||
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
|
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
|
||||||
scope :sort_by_recommendations, -> { order(cached_votes_total: :desc) }
|
scope :sort_by_recommendations, -> { order(cached_votes_total: :desc) }
|
||||||
|
|||||||
@@ -40,11 +40,8 @@ class Legislation::Proposal < ApplicationRecord
|
|||||||
|
|
||||||
before_save :calculate_hot_score, :calculate_confidence_score
|
before_save :calculate_hot_score, :calculate_confidence_score
|
||||||
|
|
||||||
scope :for_render, -> { includes(:tags) }
|
|
||||||
scope :sort_by_hot_score, -> { reorder(hot_score: :desc) }
|
|
||||||
scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc) }
|
scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc) }
|
||||||
scope :sort_by_created_at, -> { reorder(created_at: :desc) }
|
scope :sort_by_created_at, -> { reorder(created_at: :desc) }
|
||||||
scope :sort_by_most_commented, -> { reorder(comments_count: :desc) }
|
|
||||||
scope :sort_by_title, -> { reorder(title: :asc) }
|
scope :sort_by_title, -> { reorder(title: :asc) }
|
||||||
scope :sort_by_id, -> { reorder(id: :asc) }
|
scope :sort_by_id, -> { reorder(id: :asc) }
|
||||||
scope :sort_by_supports, -> { reorder(cached_votes_score: :desc) }
|
scope :sort_by_supports, -> { reorder(cached_votes_score: :desc) }
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ class Poll < ApplicationRecord
|
|||||||
scope :expired, -> { where(ends_at: ...Time.current) }
|
scope :expired, -> { where(ends_at: ...Time.current) }
|
||||||
scope :recounting, -> { where(ends_at: (RECOUNT_DURATION.ago)...Time.current) }
|
scope :recounting, -> { where(ends_at: (RECOUNT_DURATION.ago)...Time.current) }
|
||||||
scope :published, -> { where(published: true) }
|
scope :published, -> { where(published: true) }
|
||||||
scope :by_geozone_id, ->(geozone_id) { where(geozones: { id: geozone_id }.joins(:geozones)) }
|
|
||||||
scope :public_for_api, -> { all }
|
scope :public_for_api, -> { all }
|
||||||
scope :not_budget, -> { where(budget_id: nil) }
|
scope :not_budget, -> { where(budget_id: nil) }
|
||||||
scope :created_by_admin, -> { where(related_type: nil) }
|
scope :created_by_admin, -> { where(related_type: nil) }
|
||||||
|
|||||||
@@ -12,6 +12,5 @@ class Poll::Answer < ApplicationRecord
|
|||||||
validates :answer, inclusion: { in: ->(poll_answer) { poll_answer.option.possible_answers }},
|
validates :answer, inclusion: { in: ->(poll_answer) { poll_answer.option.possible_answers }},
|
||||||
if: ->(poll_answer) { poll_answer.option.present? }
|
if: ->(poll_answer) { poll_answer.option.present? }
|
||||||
|
|
||||||
scope :by_author, ->(author_id) { where(author_id: author_id) }
|
|
||||||
scope :by_question, ->(question_id) { where(question_id: question_id) }
|
scope :by_question, ->(question_id) { where(question_id: question_id) }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class Poll::PartialResult < ApplicationRecord
|
|||||||
validates :origin, inclusion: { in: ->(*) { VALID_ORIGINS }}
|
validates :origin, inclusion: { in: ->(*) { VALID_ORIGINS }}
|
||||||
validates :option, uniqueness: { scope: [:booth_assignment_id, :date] }, allow_nil: true
|
validates :option, uniqueness: { scope: [:booth_assignment_id, :date] }, allow_nil: true
|
||||||
|
|
||||||
scope :by_author, ->(author_id) { where(author_id: author_id) }
|
|
||||||
scope :by_question, ->(question_id) { where(question_id: question_id) }
|
scope :by_question, ->(question_id) { where(question_id: question_id) }
|
||||||
|
|
||||||
before_save :update_logs
|
before_save :update_logs
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ class Poll::Recount < ApplicationRecord
|
|||||||
scope :booth, -> { where(origin: "booth") }
|
scope :booth, -> { where(origin: "booth") }
|
||||||
scope :letter, -> { where(origin: "letter") }
|
scope :letter, -> { where(origin: "letter") }
|
||||||
|
|
||||||
scope :by_author, ->(author_id) { where(author_id: author_id) }
|
|
||||||
|
|
||||||
before_save :update_logs
|
before_save :update_logs
|
||||||
|
|
||||||
def update_logs
|
def update_logs
|
||||||
|
|||||||
@@ -90,7 +90,6 @@ class Proposal < ApplicationRecord
|
|||||||
scope :draft, -> { excluding(published) }
|
scope :draft, -> { excluding(published) }
|
||||||
|
|
||||||
scope :not_supported_by_user, ->(user) { where.not(id: user.find_voted_items(votable_type: "Proposal")) }
|
scope :not_supported_by_user, ->(user) { where.not(id: user.find_voted_items(votable_type: "Proposal")) }
|
||||||
scope :created_by, ->(author) { where(author: author) }
|
|
||||||
|
|
||||||
def publish
|
def publish
|
||||||
update!(published_at: Time.current)
|
update!(published_at: Time.current)
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ class User < ApplicationRecord
|
|||||||
scope :erased, -> { where.not(erased_at: nil) }
|
scope :erased, -> { where.not(erased_at: nil) }
|
||||||
scope :active, -> { excluding(erased) }
|
scope :active, -> { excluding(erased) }
|
||||||
scope :public_for_api, -> { all }
|
scope :public_for_api, -> { all }
|
||||||
scope :by_authors, ->(author_ids) { where(id: author_ids) }
|
scope :with_ids, ->(ids) { where(id: ids) }
|
||||||
scope :by_comments, ->(commentables) do
|
scope :by_comments, ->(commentables) do
|
||||||
joins(:comments).where("comments.commentable": commentables).distinct
|
joins(:comments).where("comments.commentable": commentables).distinct
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
class VerifiedUser < ApplicationRecord
|
class VerifiedUser < ApplicationRecord
|
||||||
scope :by_user, ->(user) { where(document_number: user.document_number) }
|
scope :by_user, ->(user) { where(document_number: user.document_number) }
|
||||||
|
|
||||||
scope :by_email, ->(email) { where(email: email) }
|
|
||||||
scope :by_phone, ->(phone) { where(phone: phone) }
|
scope :by_phone, ->(phone) { where(phone: phone) }
|
||||||
|
|
||||||
def self.phone?(user)
|
def self.phone?(user)
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ en:
|
|||||||
filter: Show
|
filter: Show
|
||||||
filters:
|
filters:
|
||||||
all: All
|
all: All
|
||||||
|
on_budget_investments: Investment projects
|
||||||
on_comments: Comments
|
on_comments: Comments
|
||||||
on_debates: Debates
|
on_debates: Debates
|
||||||
on_proposals: Proposals
|
on_proposals: Proposals
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ en:
|
|||||||
confidence_score: highest rated
|
confidence_score: highest rated
|
||||||
created_at: newest
|
created_at: newest
|
||||||
hot_score: most active
|
hot_score: most active
|
||||||
most_commented: most commented
|
|
||||||
relevance: relevance
|
relevance: relevance
|
||||||
recommendations: recommendations
|
recommendations: recommendations
|
||||||
recommendations:
|
recommendations:
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ es:
|
|||||||
filter: Mostrar
|
filter: Mostrar
|
||||||
filters:
|
filters:
|
||||||
all: Todos
|
all: Todos
|
||||||
|
on_budget_investments: Proyectos de gasto
|
||||||
on_comments: Comentarios
|
on_comments: Comentarios
|
||||||
on_debates: Debates
|
on_debates: Debates
|
||||||
on_proposals: Propuestas
|
on_proposals: Propuestas
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ es:
|
|||||||
confidence_score: Mejor valorados
|
confidence_score: Mejor valorados
|
||||||
created_at: Nuevos
|
created_at: Nuevos
|
||||||
hot_score: Más activos
|
hot_score: Más activos
|
||||||
most_commented: Más comentados
|
|
||||||
relevance: Más relevantes
|
relevance: Más relevantes
|
||||||
recommendations: Recomendaciones
|
recommendations: Recomendaciones
|
||||||
recommendations:
|
recommendations:
|
||||||
|
|||||||
@@ -650,20 +650,6 @@ describe Debate do
|
|||||||
|
|
||||||
expect(results).to eq [newest, recent, oldest]
|
expect(results).to eq [newest, recent, oldest]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is able to reorder by most commented after searching" do
|
|
||||||
least_commented = create(:debate, title: "stop corruption", cached_votes_up: 1, comments_count: 1)
|
|
||||||
most_commented = create(:debate, title: "stop corruption", cached_votes_up: 2, comments_count: 100)
|
|
||||||
some_comments = create(:debate, title: "stop corruption", cached_votes_up: 3, comments_count: 10)
|
|
||||||
|
|
||||||
results = Debate.search("stop corruption")
|
|
||||||
|
|
||||||
expect(results).to eq [some_comments, most_commented, least_commented]
|
|
||||||
|
|
||||||
results = results.sort_by_most_commented
|
|
||||||
|
|
||||||
expect(results).to eq [most_commented, some_comments, least_commented]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "no results" do
|
context "no results" do
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe "Admin activity" do
|
describe "Admin activity" do
|
||||||
let(:admin) { create(:administrator) }
|
let(:admin) { create(:administrator, user: create(:user, username: "Admin Smith")) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
login_as(admin.user)
|
login_as(admin.user)
|
||||||
@@ -9,135 +9,117 @@ describe "Admin activity" do
|
|||||||
|
|
||||||
context "Proposals" do
|
context "Proposals" do
|
||||||
scenario "Shows moderation activity on proposals" do
|
scenario "Shows moderation activity on proposals" do
|
||||||
proposal = create(:proposal, description: "<p>Description with html tag</p>")
|
proposal = create(:proposal, description: "<p>Description with html tag</p>", title: "Sample proposal")
|
||||||
|
|
||||||
visit proposal_path(proposal)
|
visit proposal_path(proposal)
|
||||||
|
|
||||||
within("#proposal_#{proposal.id}") do
|
accept_confirm('Are you sure? Hide "Sample proposal"') { click_button "Hide" }
|
||||||
accept_confirm("Are you sure? Hide \"#{proposal.title}\"") { click_button "Hide" }
|
|
||||||
end
|
|
||||||
expect(page).to have_css("#proposal_#{proposal.id}.faded")
|
|
||||||
|
|
||||||
visit admin_activity_path
|
expect(page).to have_css "#proposal_#{proposal.id}.faded"
|
||||||
|
|
||||||
within first("tbody tr") do
|
visit admin_activity_path(filter: "on_proposals")
|
||||||
expect(page).to have_content(proposal.title)
|
|
||||||
expect(page).to have_content("Hidden")
|
within "tbody tr" do
|
||||||
expect(page).to have_content(admin.user.username)
|
expect(page).to have_content "Sample proposal"
|
||||||
expect(page).to have_css("p", exact_text: "Description with html tag")
|
expect(page).to have_content "Hidden"
|
||||||
|
expect(page).to have_content "Admin Smith"
|
||||||
|
expect(page).to have_css "p", exact_text: "Description with html tag"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Shows moderation activity from moderation screen" do
|
scenario "Shows moderation activity from moderation screen" do
|
||||||
proposal1 = create(:proposal)
|
create(:proposal, title: "Sample proposal 1")
|
||||||
proposal2 = create(:proposal)
|
create(:proposal, title: "Sample proposal 2")
|
||||||
proposal3 = create(:proposal)
|
create(:proposal, title: "Sample proposal 3")
|
||||||
|
|
||||||
visit moderation_proposals_path(filter: "all")
|
visit moderation_proposals_path(filter: "all")
|
||||||
|
|
||||||
within("#proposal_#{proposal1.id}") do
|
check "Sample proposal 1"
|
||||||
check "proposal_#{proposal1.id}_check"
|
check "Sample proposal 3"
|
||||||
end
|
|
||||||
|
|
||||||
within("#proposal_#{proposal3.id}") do
|
|
||||||
check "proposal_#{proposal3.id}_check"
|
|
||||||
end
|
|
||||||
|
|
||||||
accept_confirm("Are you sure? Hide proposals") { click_button "Hide proposals" }
|
accept_confirm("Are you sure? Hide proposals") { click_button "Hide proposals" }
|
||||||
|
|
||||||
expect(page).not_to have_content(proposal1.title)
|
expect(page).not_to have_content "Sample proposal 1"
|
||||||
|
|
||||||
visit admin_activity_path
|
visit admin_activity_path(filter: "on_proposals")
|
||||||
|
|
||||||
expect(page).to have_content(proposal1.title)
|
expect(page).to have_content "Sample proposal 1"
|
||||||
expect(page).not_to have_content(proposal2.title)
|
expect(page).not_to have_content "Sample proposal 2"
|
||||||
expect(page).to have_content(proposal3.title)
|
expect(page).to have_content "Sample proposal 3"
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Shows admin restores" do
|
scenario "Shows admin restores" do
|
||||||
proposal = create(:proposal, :hidden)
|
create(:proposal, :hidden, title: "Sample proposal")
|
||||||
|
|
||||||
visit admin_hidden_proposals_path
|
visit admin_hidden_proposals_path
|
||||||
|
|
||||||
within("#proposal_#{proposal.id}") do
|
accept_confirm("Are you sure? Restore") { click_button "Restore" }
|
||||||
accept_confirm("Are you sure? Restore") { click_button "Restore" }
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "There are no hidden proposals"
|
expect(page).to have_content "There are no hidden proposals"
|
||||||
|
|
||||||
visit admin_activity_path
|
visit admin_activity_path(filter: "on_proposals")
|
||||||
|
|
||||||
within first("tbody tr") do
|
within "tbody tr" do
|
||||||
expect(page).to have_content(proposal.title)
|
expect(page).to have_content "Sample proposal"
|
||||||
expect(page).to have_content("Restored")
|
expect(page).to have_content "Restored"
|
||||||
expect(page).to have_content(admin.user.username)
|
expect(page).to have_content "Admin Smith"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Debates" do
|
context "Debates" do
|
||||||
scenario "Shows moderation activity on debates" do
|
scenario "Shows moderation activity on debates" do
|
||||||
debate = create(:debate)
|
debate = create(:debate, title: "Sample debate")
|
||||||
|
|
||||||
visit debate_path(debate)
|
visit debate_path(debate)
|
||||||
|
|
||||||
within("#debate_#{debate.id}") do
|
accept_confirm('Are you sure? Hide "Sample debate"') { click_button "Hide" }
|
||||||
accept_confirm("Are you sure? Hide \"#{debate.title}\"") { click_button "Hide" }
|
|
||||||
end
|
|
||||||
expect(page).to have_css("#debate_#{debate.id}.faded")
|
|
||||||
|
|
||||||
visit admin_activity_path
|
expect(page).to have_css "#debate_#{debate.id}.faded"
|
||||||
|
|
||||||
within first("tbody tr") do
|
visit admin_activity_path(filter: "on_debates")
|
||||||
expect(page).to have_content(debate.title)
|
|
||||||
expect(page).to have_content("Hidden")
|
within "tbody tr" do
|
||||||
expect(page).to have_content(admin.user.username)
|
expect(page).to have_content "Sample debate"
|
||||||
|
expect(page).to have_content "Hidden"
|
||||||
|
expect(page).to have_content "Admin Smith"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Shows moderation activity from moderation screen" do
|
scenario "Shows moderation activity from moderation screen" do
|
||||||
debate1 = create(:debate)
|
create(:debate, title: "Sample debate 1")
|
||||||
debate2 = create(:debate)
|
create(:debate, title: "Sample debate 2")
|
||||||
debate3 = create(:debate)
|
create(:debate, title: "Sample debate 3")
|
||||||
|
|
||||||
visit moderation_debates_path(filter: "all")
|
visit moderation_debates_path(filter: "all")
|
||||||
|
|
||||||
within("#debate_#{debate1.id}") do
|
check "Sample debate 1"
|
||||||
check "debate_#{debate1.id}_check"
|
check "Sample debate 3"
|
||||||
end
|
|
||||||
|
|
||||||
within("#debate_#{debate3.id}") do
|
|
||||||
check "debate_#{debate3.id}_check"
|
|
||||||
end
|
|
||||||
|
|
||||||
accept_confirm("Are you sure? Hide debates") { click_button "Hide debates" }
|
accept_confirm("Are you sure? Hide debates") { click_button "Hide debates" }
|
||||||
|
|
||||||
expect(page).not_to have_content(debate1.title)
|
expect(page).not_to have_content "Sample debate 1"
|
||||||
|
|
||||||
visit admin_activity_path
|
visit admin_activity_path(filter: "on_debates")
|
||||||
|
|
||||||
expect(page).to have_content(debate1.title)
|
expect(page).to have_content "Sample debate 1"
|
||||||
expect(page).not_to have_content(debate2.title)
|
expect(page).not_to have_content "Sample debate 2"
|
||||||
expect(page).to have_content(debate3.title)
|
expect(page).to have_content "Sample debate 3"
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Shows admin restores" do
|
scenario "Shows admin restores" do
|
||||||
debate = create(:debate, :hidden)
|
create(:debate, :hidden, title: "Sample debate")
|
||||||
|
|
||||||
visit admin_hidden_debates_path
|
visit admin_hidden_debates_path
|
||||||
|
|
||||||
within("#debate_#{debate.id}") do
|
accept_confirm("Are you sure? Restore") { click_button "Restore" }
|
||||||
accept_confirm("Are you sure? Restore") { click_button "Restore" }
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "There are no hidden debates"
|
expect(page).to have_content "There are no hidden debates"
|
||||||
|
|
||||||
visit admin_activity_path
|
visit admin_activity_path(filter: "on_debates")
|
||||||
|
|
||||||
within first("tbody tr") do
|
within "tbody tr" do
|
||||||
expect(page).to have_content(debate.title)
|
expect(page).to have_content "Sample debate"
|
||||||
expect(page).to have_content("Restored")
|
expect(page).to have_content "Restored"
|
||||||
expect(page).to have_content(admin.user.username)
|
expect(page).to have_content "Admin Smith"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -145,186 +127,159 @@ describe "Admin activity" do
|
|||||||
context "Comments" do
|
context "Comments" do
|
||||||
scenario "Shows moderation activity on comments" do
|
scenario "Shows moderation activity on comments" do
|
||||||
debate = create(:debate)
|
debate = create(:debate)
|
||||||
comment = create(:comment, commentable: debate)
|
comment = create(:comment, commentable: debate, body: "Sample comment")
|
||||||
|
|
||||||
visit debate_path(debate)
|
visit debate_path(debate)
|
||||||
|
|
||||||
within("#comment_#{comment.id}") do
|
within "#comment_#{comment.id}" do
|
||||||
accept_confirm("Are you sure? Hide \"#{comment.body}\"") { click_button "Hide" }
|
accept_confirm('Are you sure? Hide "Sample comment"') { click_button "Hide" }
|
||||||
expect(page).to have_css(".faded")
|
expect(page).to have_css ".faded"
|
||||||
end
|
end
|
||||||
|
|
||||||
visit admin_activity_path
|
visit admin_activity_path(filter: "on_comments")
|
||||||
|
|
||||||
within first("tbody tr") do
|
within "tbody tr" do
|
||||||
expect(page).to have_content(comment.body)
|
expect(page).to have_content "Sample comment"
|
||||||
expect(page).to have_content("Hidden")
|
expect(page).to have_content "Hidden"
|
||||||
expect(page).to have_content(admin.user.username)
|
expect(page).to have_content "Admin Smith"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Shows moderation activity from moderation screen" do
|
scenario "Shows moderation activity from moderation screen" do
|
||||||
comment1 = create(:comment, body: "SPAM")
|
comment1 = create(:comment, body: "SPAM")
|
||||||
comment2 = create(:comment)
|
create(:comment, body: "Not Spam")
|
||||||
comment3 = create(:comment, body: "Offensive!")
|
comment3 = create(:comment, body: "Offensive!")
|
||||||
|
|
||||||
visit moderation_comments_path(filter: "all")
|
visit moderation_comments_path(filter: "all")
|
||||||
|
|
||||||
within("#comment_#{comment1.id}") do
|
check "comment_#{comment1.id}_check"
|
||||||
check "comment_#{comment1.id}_check"
|
check "comment_#{comment3.id}_check"
|
||||||
end
|
|
||||||
|
|
||||||
within("#comment_#{comment3.id}") do
|
|
||||||
check "comment_#{comment3.id}_check"
|
|
||||||
end
|
|
||||||
|
|
||||||
accept_confirm("Are you sure? Hide comments") { click_button "Hide comments" }
|
accept_confirm("Are you sure? Hide comments") { click_button "Hide comments" }
|
||||||
|
|
||||||
expect(page).not_to have_content(comment1.body)
|
expect(page).not_to have_content "SPAM"
|
||||||
|
|
||||||
visit admin_activity_path
|
visit admin_activity_path(filter: "on_comments")
|
||||||
|
|
||||||
expect(page).to have_content(comment1.body)
|
expect(page).to have_content "SPAM"
|
||||||
expect(page).not_to have_content(comment2.body)
|
expect(page).not_to have_content "Not Spam"
|
||||||
expect(page).to have_content(comment3.body)
|
expect(page).to have_content "Offensive!"
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Shows admin restores" do
|
scenario "Shows admin restores" do
|
||||||
comment = create(:comment, :hidden)
|
create(:comment, :hidden, body: "Sample comment")
|
||||||
|
|
||||||
visit admin_hidden_comments_path
|
visit admin_hidden_comments_path
|
||||||
|
|
||||||
within("#comment_#{comment.id}") do
|
accept_confirm("Are you sure? Restore") { click_button "Restore" }
|
||||||
accept_confirm("Are you sure? Restore") { click_button "Restore" }
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "There are no hidden comments"
|
expect(page).to have_content "There are no hidden comments"
|
||||||
|
|
||||||
visit admin_activity_path
|
visit admin_activity_path(filter: "on_comments")
|
||||||
|
|
||||||
within first("tbody tr") do
|
within "tbody tr" do
|
||||||
expect(page).to have_content(comment.body)
|
expect(page).to have_content "Sample comment"
|
||||||
expect(page).to have_content("Restored")
|
expect(page).to have_content "Restored"
|
||||||
expect(page).to have_content(admin.user.username)
|
expect(page).to have_content "Admin Smith"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "User" do
|
context "User" do
|
||||||
scenario "Shows moderation activity on users" do
|
scenario "Shows moderation activity on users" do
|
||||||
proposal = create(:proposal, author: create(:user, username: "Sam"))
|
proposal = create(:proposal, author: create(:user, username: "Sam", email: "sam@example.com"))
|
||||||
|
|
||||||
visit proposal_path(proposal)
|
visit proposal_path(proposal)
|
||||||
|
|
||||||
within("#proposal_#{proposal.id}") do
|
accept_confirm('Are you sure? This will hide the user "Sam" and all their contents.') do
|
||||||
accept_confirm("Are you sure? This will hide the user \"Sam\" and all their contents.") do
|
click_button "Block author"
|
||||||
click_button "Block author"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_current_path(proposals_path)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
visit admin_activity_path
|
expect(page).to have_current_path proposals_path
|
||||||
|
|
||||||
within first("tbody tr") do
|
visit admin_activity_path(filter: "on_users")
|
||||||
|
|
||||||
|
within "tbody tr" do
|
||||||
expect(page).to have_content("Blocked")
|
expect(page).to have_content("Blocked")
|
||||||
expect(page).to have_content(proposal.author.username)
|
expect(page).to have_content "Sam"
|
||||||
expect(page).to have_content(proposal.author.email)
|
expect(page).to have_content "sam@example.com"
|
||||||
expect(page).to have_content(admin.user.username)
|
expect(page).to have_content "Admin Smith"
|
||||||
expect(page).not_to have_content(proposal.title)
|
expect(page).not_to have_content proposal.title
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Shows moderation activity from moderation screen" do
|
scenario "Shows moderation activity from moderation screen" do
|
||||||
user = create(:user)
|
create(:user, username: "Sam", email: "sam@example.com")
|
||||||
|
|
||||||
visit moderation_users_path(search: user.username)
|
visit moderation_users_path(search: "Sam")
|
||||||
|
|
||||||
within("#moderation_users") do
|
accept_confirm { click_button "Block" }
|
||||||
accept_confirm { click_button "Block" }
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "The user has been blocked"
|
expect(page).to have_content "The user has been blocked"
|
||||||
|
|
||||||
visit admin_activity_path
|
visit admin_activity_path(filter: "on_users")
|
||||||
|
|
||||||
within first("tbody tr") do
|
within "tbody tr" do
|
||||||
expect(page).to have_content(user.username)
|
expect(page).to have_content "Sam"
|
||||||
expect(page).to have_content(user.email)
|
expect(page).to have_content "sam@example.com"
|
||||||
expect(page).to have_content(admin.user.username)
|
expect(page).to have_content "Admin Smith"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Shows moderation activity from proposals moderation screen" do
|
scenario "Shows moderation activity from proposals moderation screen" do
|
||||||
proposal1 = create(:proposal)
|
proposal1 = create(:proposal, title: "Sample proposal 1")
|
||||||
proposal2 = create(:proposal)
|
proposal2 = create(:proposal, title: "Sample proposal 2")
|
||||||
proposal3 = create(:proposal)
|
proposal3 = create(:proposal, title: "Sample proposal 3")
|
||||||
|
|
||||||
visit moderation_proposals_path(filter: "all")
|
visit moderation_proposals_path(filter: "all")
|
||||||
|
|
||||||
within("#proposal_#{proposal1.id}") do
|
check "Sample proposal 1"
|
||||||
check "proposal_#{proposal1.id}_check"
|
check "Sample proposal 3"
|
||||||
end
|
|
||||||
|
|
||||||
within("#proposal_#{proposal3.id}") do
|
|
||||||
check "proposal_#{proposal3.id}_check"
|
|
||||||
end
|
|
||||||
|
|
||||||
accept_confirm("Are you sure? Block authors") { click_button "Block authors" }
|
accept_confirm("Are you sure? Block authors") { click_button "Block authors" }
|
||||||
|
|
||||||
expect(page).not_to have_content(proposal1.author.username)
|
expect(page).not_to have_content "Sample proposal 1"
|
||||||
|
|
||||||
visit admin_activity_path
|
visit admin_activity_path(filter: "on_users")
|
||||||
|
|
||||||
expect(page).to have_content(proposal1.author.username)
|
expect(page).to have_content proposal1.author.username
|
||||||
expect(page).to have_content(proposal1.author.email)
|
expect(page).to have_content proposal1.author.email
|
||||||
expect(page).to have_content(proposal3.author.username)
|
expect(page).to have_content proposal3.author.username
|
||||||
expect(page).to have_content(proposal3.author.email)
|
expect(page).to have_content proposal3.author.email
|
||||||
expect(page).not_to have_content(proposal2.author.username)
|
expect(page).not_to have_content proposal2.author.username
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Shows moderation activity from debates moderation screen" do
|
scenario "Shows moderation activity from debates moderation screen" do
|
||||||
debate1 = create(:debate)
|
debate1 = create(:debate, title: "Sample debate 1")
|
||||||
debate2 = create(:debate)
|
debate2 = create(:debate, title: "Sample debate 2")
|
||||||
debate3 = create(:debate)
|
debate3 = create(:debate, title: "Sample debate 3")
|
||||||
|
|
||||||
visit moderation_debates_path(filter: "all")
|
visit moderation_debates_path(filter: "all")
|
||||||
|
|
||||||
within("#debate_#{debate1.id}") do
|
check "Sample debate 1"
|
||||||
check "debate_#{debate1.id}_check"
|
check "Sample debate 3"
|
||||||
end
|
|
||||||
|
|
||||||
within("#debate_#{debate3.id}") do
|
|
||||||
check "debate_#{debate3.id}_check"
|
|
||||||
end
|
|
||||||
|
|
||||||
accept_confirm("Are you sure? Block authors") { click_button "Block authors" }
|
accept_confirm("Are you sure? Block authors") { click_button "Block authors" }
|
||||||
|
|
||||||
expect(page).not_to have_content(debate1.author.username)
|
expect(page).not_to have_content debate1.author.username
|
||||||
|
|
||||||
visit admin_activity_path
|
visit admin_activity_path
|
||||||
|
|
||||||
expect(page).to have_content(debate1.author.username)
|
expect(page).to have_content debate1.author.username
|
||||||
expect(page).to have_content(debate1.author.email)
|
expect(page).to have_content debate1.author.email
|
||||||
expect(page).to have_content(debate3.author.username)
|
expect(page).to have_content debate3.author.username
|
||||||
expect(page).to have_content(debate3.author.email)
|
expect(page).to have_content debate3.author.email
|
||||||
expect(page).not_to have_content(debate2.author.username)
|
expect(page).not_to have_content debate2.author.username
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Shows moderation activity from comments moderation screen" do
|
scenario "Shows moderation activity from comments moderation screen" do
|
||||||
comment1 = create(:comment, body: "SPAM")
|
comment1 = create(:comment)
|
||||||
comment2 = create(:comment)
|
comment2 = create(:comment)
|
||||||
comment3 = create(:comment, body: "Offensive!")
|
comment3 = create(:comment)
|
||||||
|
|
||||||
visit moderation_comments_path(filter: "all")
|
visit moderation_comments_path(filter: "all")
|
||||||
|
|
||||||
within("#comment_#{comment1.id}") do
|
check "comment_#{comment1.id}_check"
|
||||||
check "comment_#{comment1.id}_check"
|
check "comment_#{comment3.id}_check"
|
||||||
end
|
|
||||||
|
|
||||||
within("#comment_#{comment3.id}") do
|
|
||||||
check "comment_#{comment3.id}_check"
|
|
||||||
end
|
|
||||||
|
|
||||||
accept_confirm("Are you sure? Block authors") { click_button "Block authors" }
|
accept_confirm("Are you sure? Block authors") { click_button "Block authors" }
|
||||||
|
|
||||||
@@ -332,31 +287,29 @@ describe "Admin activity" do
|
|||||||
|
|
||||||
visit admin_activity_path
|
visit admin_activity_path
|
||||||
|
|
||||||
expect(page).to have_content(comment1.author.username)
|
expect(page).to have_content comment1.author.username
|
||||||
expect(page).to have_content(comment1.author.email)
|
expect(page).to have_content comment1.author.email
|
||||||
expect(page).to have_content(comment3.author.username)
|
expect(page).to have_content comment3.author.username
|
||||||
expect(page).to have_content(comment3.author.email)
|
expect(page).to have_content comment3.author.email
|
||||||
expect(page).not_to have_content(comment2.author.username)
|
expect(page).not_to have_content comment2.author.username
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Shows admin restores" do
|
scenario "Shows admin restores" do
|
||||||
user = create(:user, :hidden)
|
create(:user, :hidden, username: "Sam", email: "sam@example.com")
|
||||||
|
|
||||||
visit admin_hidden_users_path
|
visit admin_hidden_users_path
|
||||||
|
|
||||||
within("#user_#{user.id}") do
|
accept_confirm("Are you sure? Restore") { click_button "Restore" }
|
||||||
accept_confirm("Are you sure? Restore") { click_button "Restore" }
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "There are no hidden users"
|
expect(page).to have_content "There are no hidden users"
|
||||||
|
|
||||||
visit admin_activity_path
|
visit admin_activity_path(filter: "on_users")
|
||||||
|
|
||||||
within first("tbody tr") do
|
within "tbody tr" do
|
||||||
expect(page).to have_content(user.username)
|
expect(page).to have_content "Sam"
|
||||||
expect(page).to have_content(user.email)
|
expect(page).to have_content "sam@example.com"
|
||||||
expect(page).to have_content("Restored")
|
expect(page).to have_content "Restored"
|
||||||
expect(page).to have_content(admin.user.username)
|
expect(page).to have_content "Admin Smith"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -369,12 +322,70 @@ describe "Admin activity" do
|
|||||||
body: "Proposal A Notification Body")
|
body: "Proposal A Notification Body")
|
||||||
proposal_notification.moderate_system_email(admin.user)
|
proposal_notification.moderate_system_email(admin.user)
|
||||||
|
|
||||||
visit admin_activity_path
|
visit admin_activity_path(filter: "on_system_emails")
|
||||||
|
|
||||||
within first("tbody tr") do
|
within "tbody tr" do
|
||||||
expect(page).to have_content(proposal_notification.title)
|
expect(page).to have_content "Proposal A Title"
|
||||||
expect(page).to have_content("Hidden")
|
expect(page).to have_content "Hidden"
|
||||||
expect(page).to have_content(admin.user.username)
|
expect(page).to have_content "Admin Smith"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Budget investments" do
|
||||||
|
scenario "Shows moderation activity on budget investments" do
|
||||||
|
investment = create(:budget_investment, title: "Sample investment")
|
||||||
|
|
||||||
|
visit budget_investment_path(investment.budget, investment)
|
||||||
|
|
||||||
|
accept_confirm('Are you sure? Hide "Sample investment"') { click_button "Hide" }
|
||||||
|
|
||||||
|
expect(page).to have_css "#budget_investment_#{investment.id}.faded"
|
||||||
|
|
||||||
|
visit admin_activity_path(filter: "on_budget_investments")
|
||||||
|
|
||||||
|
within "tbody tr" do
|
||||||
|
expect(page).to have_content "Sample investment"
|
||||||
|
expect(page).to have_content "Hidden"
|
||||||
|
expect(page).to have_content "Admin Smith"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Shows moderation activity from moderation screen" do
|
||||||
|
create(:budget_investment, title: "Sample investment 1")
|
||||||
|
create(:budget_investment, title: "Sample investment 2")
|
||||||
|
create(:budget_investment, title: "Sample investment 3")
|
||||||
|
|
||||||
|
visit moderation_budget_investments_path(filter: "all")
|
||||||
|
|
||||||
|
check "Sample investment 1"
|
||||||
|
check "Sample investment 3"
|
||||||
|
accept_confirm("Are you sure? Hide budget investments") { click_button "Hide budget investments" }
|
||||||
|
|
||||||
|
expect(page).not_to have_content "Sample investment 1"
|
||||||
|
|
||||||
|
visit admin_activity_path(filter: "on_budget_investments")
|
||||||
|
|
||||||
|
expect(page).to have_content "Sample investment 1"
|
||||||
|
expect(page).not_to have_content "Sample investment 2"
|
||||||
|
expect(page).to have_content "Sample investment 3"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Shows admin restores" do
|
||||||
|
create(:budget_investment, :hidden, title: "Sample investment")
|
||||||
|
|
||||||
|
visit admin_hidden_budget_investments_path
|
||||||
|
|
||||||
|
accept_confirm("Are you sure? Restore") { click_button "Restore" }
|
||||||
|
|
||||||
|
expect(page).to have_content "There are no hidden budget investments"
|
||||||
|
|
||||||
|
visit admin_activity_path(filter: "on_budget_investments")
|
||||||
|
|
||||||
|
within "tbody tr" do
|
||||||
|
expect(page).to have_content "Sample investment"
|
||||||
|
expect(page).to have_content "Restored"
|
||||||
|
expect(page).to have_content "Admin Smith"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user