Uses the new field, erased_at, for erased users

This commit is contained in:
kikito
2015-10-21 14:28:21 +02:00
parent 3d4e82f94f
commit 6c5d1faa90
14 changed files with 123 additions and 10 deletions

View File

@@ -147,8 +147,8 @@ class User < ActiveRecord::Base
end
def erase(erase_reason = nil)
self.hide
self.update(
erased_at: Time.now,
erase_reason: erase_reason,
username: nil,
email: nil,
@@ -162,6 +162,10 @@ class User < ActiveRecord::Base
)
end
def erased?
erased_at.present?
end
def email_provided?
!!(email && email !~ OMNIAUTH_EMAIL_REGEX) ||
!!(unconfirmed_email && unconfirmed_email !~ OMNIAUTH_EMAIL_REGEX)
@@ -189,11 +193,11 @@ class User < ActiveRecord::Base
end
def username_required?
!organization? && !hidden?
!organization? && !erased?
end
def email_required?
!hidden?
!erased?
end
private

View File

@@ -19,7 +19,7 @@
<% else %>
<%= avatar_image(comment.user, seed: comment.user_id, size: 32, class: "left") %>
<% end %>
<% if comment.user.hidden? %>
<% if comment.user.hidden? || comment.user.erased? %>
<i class="icon-deleted user-deleted"></i>
<% end %>
<% end %>
@@ -33,7 +33,7 @@
<span class="user-name"><%= t("comments.comment.moderator") %> #<%= comment.moderator_id%></span>
<% else %>
<% if comment.user.hidden? %>
<% if comment.user.hidden? || comment.user.erased? %>
<span class="user-name"><%= t("comments.comment.user_deleted") %></span>
<% else %>
<span class="user-name"><%= comment.user.name %></span>

View File

@@ -14,7 +14,7 @@
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= l debate.created_at.to_date %>
<% if debate.author.hidden? %>
<% if debate.author.hidden? || debate.author.erased? %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<span class="author">
<%= t("debates.show.author_deleted") %>

View File

@@ -23,7 +23,7 @@
<div class="debate-info">
<%= avatar_image(@debate.author, seed: @debate.author_id, size: 32, class: 'author-photo') %>
<% if @debate.author.hidden? %>
<% if @debate.author.hidden? || @debate.author.erased? %>
<i class="icon-deleted author-deleted"></i>
<span class="author">
<%= t("debates.show.author_deleted") %>

View File

@@ -13,7 +13,7 @@
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= l proposal.created_at.to_date %>
<% if proposal.author.hidden? %>
<% if proposal.author.hidden? || proposal.author.erased? %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<span class="author">
<%= t("proposals.show.author_deleted") %>

View File

@@ -29,7 +29,7 @@
<div class="proposal-info">
<%= avatar_image(@proposal.author, seed: @proposal.author_id, size: 32, class: 'author-photo') %>
<% if @proposal.author.hidden? %>
<% if @proposal.author.hidden? || @proposal.author.erased? %>
<i class="icon-deleted author-deleted"></i>
<span class="author">
<%= t("proposals.show.author_deleted") %>

View File

@@ -193,6 +193,18 @@ feature 'Commenting debates' do
end
end
scenario "Erasing a comment's author" do
debate = create(:debate)
comment = create(:comment, commentable: debate, body: 'this should be visible')
comment.user.erase
visit debate_path(debate)
within "#comment_#{comment.id}" do
expect(page).to have_content('Deleted user')
expect(page).to have_content('this should be visible')
end
end
feature "Moderators" do
scenario "can create comment as a moderator", :js do
moderator = create(:moderator)

View File

@@ -193,6 +193,18 @@ feature 'Commenting proposals' do
end
end
scenario "Erasing a comment's author" do
proposal = create(:proposal)
comment = create(:comment, commentable: proposal, body: "this should be visible")
comment.user.erase
visit proposal_path(proposal)
within "#comment_#{comment.id}" do
expect(page).to have_content('Deleted user')
expect(page).to have_content('this should be visible')
end
end
feature "Moderators" do
scenario "can create comment as a moderator", :js do
moderator = create(:moderator)

View File

@@ -523,4 +523,16 @@ feature 'Debates' do
visit debate_path(good_debate)
expect(page).to_not have_content "This debate has been flag as innapropiate for some users."
end
scenario 'Erased author' do
user = create(:user)
debate = create(:debate, author: user)
user.erase
visit debates_path
expect(page).to have_content('Deleted user')
visit debate_path(debate)
expect(page).to have_content('Deleted user')
end
end

View File

@@ -605,4 +605,16 @@ feature 'Proposals' do
expect(Flag.flagged?(user, proposal)).to_not be
end
scenario 'Erased author' do
user = create(:user)
proposal = create(:proposal, author: user)
user.erase
visit proposals_path
expect(page).to have_content('Deleted user')
visit proposal_path(proposal)
expect(page).to have_content('Deleted user')
end
end

View File

@@ -57,6 +57,11 @@ describe Comment do
.to change { [comment.reload.updated_at, comment.author.updated_at] }
end
it "expires cache when the author is erased" do
expect { comment.user.erase }
.to change { [comment.reload.updated_at, comment.author.updated_at] }
end
it "expires cache when the author changes" do
expect { comment.user.update(username: "Isabel") }
.to change { [comment.reload.updated_at, comment.author.updated_at] }

View File

@@ -380,6 +380,11 @@ describe Debate do
.to change { [debate.reload.updated_at, debate.author.updated_at] }
end
it "should expire cache when the author is erased" do
expect { debate.author.erase }
.to change { [debate.reload.updated_at, debate.author.updated_at] }
end
it "should expire cache when its author changes" do
expect { debate.author.update(username: "Eva") }
.to change { [debate.reload.updated_at, debate.author.updated_at] }

View File

@@ -304,4 +304,55 @@ describe Proposal do
end
end
describe "cache" do
let(:proposal) { create(:proposal) }
it "should expire cache when it has a new comment" do
expect { create(:comment, commentable: proposal) }
.to change { proposal.updated_at }
end
it "should expire cache when it has a new vote" do
expect { create(:vote, votable: proposal) }
.to change { proposal.updated_at }
end
it "should expire cache when it has a new flag" do
expect { create(:flag, flaggable: proposal) }
.to change { proposal.reload.updated_at }
end
it "should expire cache when it has a new tag" do
expect { proposal.update(tag_list: "new tag") }
.to change { proposal.updated_at }
end
it "should expire cache when hidden" do
expect { proposal.hide }
.to change { proposal.updated_at }
end
it "should expire cache when the author is hidden" do
expect { proposal.author.hide }
.to change { [proposal.reload.updated_at, proposal.author.updated_at] }
end
it "should expire cache when the author is erased" do
expect { proposal.author.erase }
.to change { [proposal.reload.updated_at, proposal.author.updated_at] }
end
it "should expire cache when its author changes" do
expect { proposal.author.update(username: "Eva") }
.to change { [proposal.reload.updated_at, proposal.author.updated_at] }
end
it "should expire cache when the author's organization get verified" do
create(:organization, user: proposal.author)
expect { proposal.author.organization.verify }
.to change { [proposal.reload.updated_at, proposal.author.updated_at] }
end
end
end

View File

@@ -317,7 +317,7 @@ describe User do
user.reload
expect(user.erase_reason).to eq('a test')
expect(user.hidden_at).to be
expect(user.erased_at).to be
expect(user.username).to be_nil