-
Notifications
You must be signed in to change notification settings - Fork 313
Bug delete user #398 #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Bug delete user #398 #236
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,10 +82,12 @@ class User < ActiveRecord::Base | |
has_one :github_profile , class_name: 'Users::Github::Profile', dependent: :destroy | ||
has_many :github_repositories, through: :github_profile , source: :repositories | ||
|
||
|
||
geocoded_by :location, latitude: :lat, longitude: :lng, country: :country, state_code: :state_name | ||
# FIXME: Move to background job | ||
after_validation :geocode_location, if: :location_changed? unless Rails.env.test? | ||
|
||
before_destroy ->{ protips.destroy_all }, prepend: true | ||
|
||
def near | ||
User.near([lat, lng]) | ||
end | ||
|
@@ -130,7 +132,6 @@ def self.with_username(username, provider = :username) | |
where(["UPPER(#{sql_injection_safe_where_clause}) = UPPER(?)", username]).first | ||
end | ||
|
||
|
||
# Todo State machine | ||
def banned? | ||
banned_at.present? | ||
|
@@ -923,7 +924,6 @@ def make_referral_token | |
end | ||
|
||
after_save :refresh_dependencies | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Triggering |
||
after_destroy :refresh_protips | ||
|
||
def refresh_dependencies | ||
if username_changed? or avatar_changed? or team_document_id_changed? | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require "rails_helper" | ||
|
||
feature "User management", js: true do | ||
describe 'deleting a user' do | ||
before do | ||
stub_request(:post, /api.mixpanel.com/) | ||
end | ||
|
||
let!(:user) { login_as(username: 'alice', bypass_ui_login: true) } | ||
|
||
scenario 'user is presented with confirmation dialog when deletes his account' do | ||
visit '/settings' | ||
find('.delete').click_link 'click here.' | ||
|
||
expect(page).to have_content 'Warning: clicking this link below will permenatly delete your Coderwall account and its data.' | ||
expect(page).to have_button 'Delete your account & sign out' | ||
end | ||
|
||
scenario 'user is redirected to /welcome after deleting hios account' do | ||
visit '/settings' | ||
find('.delete').click_link 'click here.' | ||
find('.save').click_button 'Delete your account & sign out' | ||
|
||
expect(current_path).to eq('/welcome') | ||
end | ||
|
||
scenario 'user cannot login after deleting his account' do | ||
visit '/settings' | ||
find('.delete').click_link 'click here.' | ||
find('.save').click_button 'Delete your account & sign out' | ||
|
||
visit "/auth/developer" | ||
fill_in 'name', with: user.username | ||
fill_in 'email', with: user.email | ||
click_button 'Sign In' | ||
|
||
expect(current_path).to eq(new_user_path) | ||
end | ||
|
||
scenario 'users protips are not displayed after he deletes his account' do | ||
Protip.rebuild_index | ||
protip_1, protip_2 = Fabricate.times(2, :protip, user: user) | ||
protip_3 = Fabricate(:protip) | ||
|
||
visit '/settings' | ||
find('.delete').click_link 'click here.' | ||
find('.save').click_button 'Delete your account & sign out' | ||
|
||
login_as(username: 'bob', bypass_ui_login: true) | ||
visit '/p/fresh' | ||
|
||
expect(page).not_to have_content(protip_1.title) | ||
expect(page).not_to have_content(protip_2.title) | ||
expect(page).to have_content(protip_3.title) | ||
end | ||
end | ||
|
||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
RSpec.describe "User management", :type => :request do | ||
|
||
describe 'deleting a user' do | ||
it 'deletes associated protips and reindex search index' do | ||
user = Fabricate(:user) | ||
|
||
Protip.rebuild_index | ||
protip_1, protip_2 = Fabricate.times(2, :protip, user: user) | ||
protip_3 = Fabricate(:protip) | ||
|
||
user.reload.destroy | ||
search = Protip.search('*').map(&:title) | ||
|
||
expect(search).not_to include(protip_1.title) | ||
expect(search).not_to include(protip_2.title) | ||
expect(search).to include(protip_3.title) | ||
end | ||
end | ||
|
||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my experience it can lead to a hard debuggable issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It fine he just moved it from below. we should however remove it.
@YaroSpace , could you add a comment on top of that line
# FIXME: Move to background job