Skip to content

Commit c4deeca

Browse files
authored
Merge pull request #140 from emmvs/fix/cannot-delete-account-lol
Fix/cannot delete account lol
2 parents 8780af2 + 5d195d0 commit c4deeca

32 files changed

+163
-278
lines changed

Gemfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ gem 'sassc-rails' # Use SCSS for stylesheets
3333
# Devise for authentication
3434
gem 'devise', '~> 4.8'
3535

36-
#OAauth Providers
36+
# OAauth Providers
3737
gem 'omniauth-google-oauth2'
3838
gem 'omniauth-rails_csrf_protection'
3939

@@ -71,16 +71,15 @@ group :development, :test do
7171
end
7272

7373
group :development do
74-
gem 'web-console' # Rails console for the browser
7574
gem 'annotate' # Annotate models with schema
75+
gem 'web-console' # Rails console for the browser
7676
# gem 'spring' # Speeds up development by keeping app running in the background
7777
# gem 'rack-mini-profiler' # Displays speed badge for performance profiling
7878
end
7979

8080
group :test do
8181
gem 'capybara' # Capybara for integration testing
8282
gem 'selenium-webdriver' # WebDriver for browsers
83-
gem 'webdrivers' # Auto-updates webdrivers
8483
end
8584

8685
# Optional gems for specific features

Gemfile.lock

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ GEM
332332
http-cookie (>= 1.0.2, < 2.0)
333333
mime-types (>= 1.16, < 4.0)
334334
netrc (~> 0.8)
335-
rexml (3.2.6)
335+
rexml (3.4.1)
336336
rspec-core (3.12.2)
337337
rspec-support (~> 3.12.0)
338338
rspec-expectations (3.12.3)
@@ -369,7 +369,7 @@ GEM
369369
faraday-multipart (>= 1)
370370
ruby-progressbar (1.13.0)
371371
ruby2_keywords (0.0.5)
372-
rubyzip (2.3.2)
372+
rubyzip (2.4.1)
373373
sassc (2.4.0)
374374
ffi (~> 1.9)
375375
sassc-rails (2.1.2)
@@ -378,7 +378,9 @@ GEM
378378
sprockets (> 3.0)
379379
sprockets-rails
380380
tilt
381-
selenium-webdriver (4.16.0)
381+
selenium-webdriver (4.32.0)
382+
base64 (~> 0.2)
383+
logger (~> 1.4)
382384
rexml (~> 3.2, >= 3.2.5)
383385
rubyzip (>= 1.2.2, < 3.0)
384386
websocket (~> 1.0)
@@ -420,11 +422,7 @@ GEM
420422
activemodel (>= 6.0.0)
421423
bindex (>= 0.4.0)
422424
railties (>= 6.0.0)
423-
webdrivers (5.2.0)
424-
nokogiri (~> 1.6)
425-
rubyzip (>= 1.3.0)
426-
selenium-webdriver (~> 4.0)
427-
websocket (1.2.10)
425+
websocket (1.2.11)
428426
websocket-driver (0.7.6)
429427
websocket-extensions (>= 0.1.0)
430428
websocket-extensions (0.1.5)
@@ -479,7 +477,6 @@ DEPENDENCIES
479477
stimulus-rails
480478
turbo-rails
481479
web-console
482-
webdrivers
483480

484481
RUBY VERSION
485482
ruby 3.1.2p20

app/assets/stylesheets/components/_navbar.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@
7070
border-bottom-right-radius: 50px;
7171
}
7272

73-
/* Mobile */
73+
/* Desktop */
7474
@media screen and (min-width: 768px) {
7575
.bottom-navbar {
7676
display: none !important;
7777
}
7878
}
7979

80-
/* Desktop */
80+
/* Mobile */
8181
@media screen and (max-width: 767px) {
8282
.bottom-navbar {
8383
display: flex;

app/models/happy_thing.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ class HappyThing < ApplicationRecord
2323

2424
belongs_to :user
2525
belongs_to :category
26-
has_many :likes
27-
has_many :comments
26+
has_many :comments, dependent: :destroy
2827
has_many :happy_thing_user_shares, dependent: :destroy
2928
has_many :shared_users, through: :happy_thing_user_shares, source: :friend
3029
has_many :happy_thing_group_shares, dependent: :destroy

app/models/like.rb

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/models/user.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,17 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength
5454
validates :provider, presence: true, on: :oauth_linking
5555
validates :uid, presence: true, on: :oauth_linking
5656

57-
has_many :happy_things
58-
has_many :comments
59-
has_many :likes
57+
has_many :happy_things, dependent: :destroy
58+
has_many :comments, dependent: :destroy
6059
has_many :groups, dependent: :destroy
6160
has_many :happy_thing_user_shares, foreign_key: :friend_id, dependent: :destroy
6261
has_many :received_happy_things, through: :happy_thing_user_shares, source: :happy_thing
63-
has_many :group_memberships, foreign_key: :friend_id
62+
has_many :group_memberships, foreign_key: :friend_id, dependent: :destroy
6463
has_many :groups_as_member, through: :group_memberships, source: :group
6564

6665
# Friendships
67-
has_many :friendships
68-
has_many :received_friend_requests, class_name: 'Friendship', foreign_key: 'friend_id'
66+
has_many :friendships, dependent: :destroy
67+
has_many :received_friend_requests, class_name: 'Friendship', foreign_key: 'friend_id', dependent: :destroy
6968
has_many :friends, -> { where(friendships: { accepted: true }) }, through: :friendships, source: :friend
7069
has_many :friends_who_added_me, lambda {
7170
where(friendships: { accepted: true })

app/views/devise/registrations/edit.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
<h4>Cancel my account</h4>
4949

50-
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
50+
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), data: { turbo_confirm: "Are you sure?", turbo_method: :delete } %></p>
5151

5252
<%= link_to "Back", :back %>
5353
</div>

spec/fixtures/test_image.jpg

88.7 KB
Loading

spec/rails_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,16 @@
7575

7676
config.include Devise::Test::IntegrationHelpers, type: :request
7777
config.include ActiveJob::TestHelper
78+
79+
config.before(:each, type: :system) do
80+
Capybara.register_driver :custom_selenium_chrome_headless do |app|
81+
options = Selenium::WebDriver::Chrome::Options.new
82+
options.add_argument('--headless')
83+
options.add_argument('--window-size=767,1024')
84+
85+
Capybara::Selenium::Driver.new(app, browser: :chrome, options:)
86+
end
87+
88+
driven_by :custom_selenium_chrome_headless
89+
end
7890
end

spec/requests/users_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,13 @@
8282
expect(response.body).to include(I18n.t('errors.models.user.password.invalid'))
8383
end
8484
end
85+
86+
describe 'DELETE /destroy' do
87+
it 'allows users to delete their account' do
88+
delete user_registration_path
89+
expect(response).to have_http_status(:found)
90+
expect(response).to redirect_to(root_path)
91+
expect(User.find_by(id: @user.id)).to be_nil
92+
end
93+
end
8594
end

0 commit comments

Comments
 (0)