Skip to content

Commit

Permalink
AO3-4250 Made gift recipients update on blurbs on pseud / username ch…
Browse files Browse the repository at this point in the history
…anges
  • Loading branch information
melinath committed Feb 13, 2025
1 parent ec6c90f commit c8cb063
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 20 deletions.
14 changes: 11 additions & 3 deletions app/models/pseud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Pseud < ApplicationRecord
after_update :check_default_pseud
after_update :expire_caches
after_commit :reindex_creations, :touch_comments
after_destroy :expire_caches

scope :alphabetical, -> { order(:name) }
scope :default_alphabetical, -> { order(is_default: :desc).alphabetical }
Expand Down Expand Up @@ -390,9 +391,16 @@ def check_default_pseud
end

def expire_caches
if saved_change_to_name?
works.touch_all
series.each(&:expire_byline_cache)
return unless saved_change_to_name? || (destroyed? && user != nil && user.default_pseud != nil)

Check warning on line 394 in app/models/pseud.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Add empty line after guard clause. Raw Output: app/models/pseud.rb:394:5: C: Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.

Check warning on line 394 in app/models/pseud.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Prefer `!user.nil?` over `user != nil`. Raw Output: app/models/pseud.rb:394:59: C: Style/NonNilCheck: Prefer `!user.nil?` over `user != nil`.

Check warning on line 394 in app/models/pseud.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Prefer `!user.default_pseud.nil?` over `user.default_pseud != nil`. Raw Output: app/models/pseud.rb:394:74: C: Style/NonNilCheck: Prefer `!user.default_pseud.nil?` over `user.default_pseud != nil`.
pseud = if destroyed? then user.default_pseud else self end

Check warning on line 395 in app/models/pseud.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Favor the ternary operator (`?:`) or multi-line constructs over single-line `if/then/else/end` constructs. Raw Output: app/models/pseud.rb:395:13: C: Style/OneLineConditional: Favor the ternary operator (`?:`) or multi-line constructs over single-line `if/then/else/end` constructs.
pseud.series.each(&:expire_byline_cache)
pseud.works.each do |work|
work.touch
work.expire_caches
end
pseud.gift_works.each do |work|
work.touch
work.expire_caches
end
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ def expire_caches
work.touch
work.expire_caches
end
self.gift_works.each do |work|
work.touch
work.expire_caches
end
end

def remove_user_from_kudos
Expand Down
31 changes: 31 additions & 0 deletions features/other_a/pseud_delete.feature
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,34 @@ Feature: Delete pseud.
Then I should see "My Collection Thing"
And I should not see "other_pseud (myself)" within "#main"
And I should see "myself" within "#main"

Scenario: Deleting a pseud updates series blurbs

Given I am logged in as "Myself"
And I add the work "Great Work" to series "Best Series" as "Me2"
When I go to the dashboard page for user "Myself" with pseud "Me2"
And I follow "Series"
Then I should see "Best Series by Me2 (Myself)"

When I delete the pseud "Me2"
And I follow "Series"
Then I should see "Best Series by Myself"

Scenario: Deleting a pseud updates gift blurbs
Given I have no users
And the following activated users exist
| login | password | email | id |
| gifter | something | gifter@example.com | 1 |
| giftee1 | something | giftee1@example.com | 2 |
And a pseud exists with name: "Me2", user_id: 2
And the user "giftee1" allows gifts
And I am logged in as "gifter" with password "something"
And I set up the draft "GiftStory1"
And I give the work to "Me2 (giftee1)"
And I press "Post"
And I am logged in as "giftee1" with password "something"
When I go to my gifts page
Then I should see "GiftStory1 by gifter for Me2 (giftee1)"
When I delete the pseud "Me2"
And I go to my gifts page
Then I should see "GiftStory1 by gifter for giftee1"
24 changes: 24 additions & 0 deletions features/other_a/pseuds.feature
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,30 @@ Scenario: Edit pseud updates series blurbs
When I follow "Series"
Then I should see "Best Series by Me3 (Myself)"

Scenario: Edit pseud updates gift blurbs
Given I have no users
And the following activated users exist
| login | password | email | id |
| gifter | something | gifter@example.com | 1 |
| giftee1 | something | giftee1@example.com | 2 |
And a pseud exists with name: "Me2", user_id: 2
And the user "giftee1" allows gifts
And I am logged in as "gifter" with password "something"
And I set up the draft "GiftStory1"
And I give the work to "Me2 (giftee1)"
And I press "Post"
And I am logged in as "giftee1" with password "something"
When I go to my gifts page
Then I should see "GiftStory1 by gifter for Me2 (giftee1)"
When I go to my profile page
And I follow "Manage My Pseuds"
And I follow "Edit Me2"
And I fill in "Name" with "Me3"
And I press "Update"
Then I should see "Pseud was successfully updated."
When I go to my gifts page
Then I should see "GiftStory1 by gifter for Me3 (giftee1)"

Scenario: Change details as an admin

Given "someone" has the pseud "alt"
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/pseud_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

When(/^I delete the pseud "([^\"]*)"$/) do |pseud|
visit user_pseuds_path(User.current_user)
click_link("delete_#{pseud}")
click_link("delete_#{pseud.downcase}")
end

When /^"([^\"]*)" creates the default pseud "([^"]*)"$/ do |username, newpseud|
Expand Down
23 changes: 23 additions & 0 deletions features/users/user_delete.feature
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,26 @@ Scenario: Delete a user who has coauthored a work
And a user account should not exist for "testuser"
When I go to orphan_account's series page
Then I should see "Epic"

Scenario: Deleting a user updates gift blurbs
Given I have no users
And I have no works or comments
And the following activated users exist
| login | password | email | id |
| gifter | something | gifter@example.com | 1 |
| giftee1 | something | giftee1@example.com | 2 |
And the user "giftee1" allows gifts
And I am logged in as "gifter" with password "something"
And I set up the draft "GiftStory1"
And I give the work to "giftee1"
And I press "Post"
And I am logged in as "giftee1" with password "something"
When I am on gifter's works page
Then I should see "GiftStory1 by gifter for giftee1"
When I try to delete my account as giftee1
Then I should see "You have successfully deleted your account."
And a user account should not exist for "giftee1"
And I should be logged out
When I am on gifter's works page
Then I should see "GiftStory1 by gifter"
And I should not see "GiftStory1 by gifter for giftee1"
101 changes: 85 additions & 16 deletions features/users/user_rename.feature
Original file line number Diff line number Diff line change
Expand Up @@ -182,35 +182,104 @@ Feature:
And I should see "after" within "#main"
And I should not see "before" within "#main"

Scenario: Changing username updates series blurbs
Scenario: Changing only username updates series blurbs
Given I have no users
And I am logged in as "oldusername" with password "password"
And the following activated user exists
| login | password | id |
| oldusername | secret | 1 |
And a pseud exists with name: "newusername", user_id: 1
And I am logged in as "oldusername" with password "secret"
And I add the work "Great Work" to series "Best Series"
When I go to the dashboard page for user "oldusername" with pseud "oldusername"
And I follow "Series"
Then I should see "Best Series by oldusername"
When I visit the change username page for oldusername
And I fill in "New user name" with "newusername"
And I fill in "Password" with "password"
And I fill in "Password" with "secret"
And I press "Change User Name"
Then I should get confirmation that I changed my username
And I should see "Hi, newusername"
When I follow "Series"
Then I should see "Best Series by oldusername (newusername)"

Scenario: Changing username and pseud updates series blurbs
Given I have no users
And I am logged in as "oldusername" with password "secret"
And I add the work "Great Work" to series "Best Series"
When I go to the dashboard page for user "oldusername" with pseud "oldusername"
And I follow "Series"
Then I should see "Best Series by oldusername"
When I visit the change username page for oldusername
And I fill in "New user name" with "newusername"
And I fill in "Password" with "secret"
And I press "Change User Name"
Then I should get confirmation that I changed my username
And I should see "Hi, newusername"
When I follow "Series"
Then I should see "Best Series by newusername"
And I should not see "Best Series by oldusername"

Scenario: Changing only username updates gift blurbs
Given I have no users
And the following activated users exist
| login | password | email | id |
| gifter | something | gifter@example.com | 1 |
| giftee1 | something | giftee1@example.com | 2 |
And a pseud exists with name: "newusername", user_id: 2
And the user "giftee1" allows gifts
And I am logged in as "gifter" with password "something"
And I set up the draft "GiftStory1"
And I give the work to "giftee1"
And I press "Post"
And I am logged in as "giftee1" with password "something"
When I go to my gifts page
Then I should see "GiftStory1 by gifter for giftee1"
When I visit the change username page for giftee1
And I fill in "New user name" with "newusername"
And I fill in "Password" with "something"
And I press "Change User Name"
Then I should get confirmation that I changed my username
And I should see "Hi, newusername"
When I go to my gifts page
Then I should see "GiftStory1 by gifter for giftee1 (newusername)"

Scenario: Changing the username from a forbidden name to non-forbidden
Given I have no users
And the following activated user exists
| login | password |
| forbidden | secret |
And the user name "forbidden" is on the forbidden list
When I am logged in as "forbidden" with password "secret"
And I visit the change username page for forbidden
And I fill in "New user name" with "notforbidden"
And I fill in "Password" with "secret"
And I press "Change User Name"
Then I should get confirmation that I changed my username
And I should see "Hi, notforbidden"
Scenario: Changing username and pseud updates gift blurbs
Given I have no users
And the following activated users exist
| login | password | email | id |
| gifter | something | gifter@example.com | 1 |
| giftee1 | something | giftee1@example.com | 2 |
And the user "giftee1" allows gifts
And I am logged in as "gifter" with password "something"
And I set up the draft "GiftStory1"
And I give the work to "giftee1"
And I press "Post"
And I am logged in as "giftee1" with password "something"
When I go to my gifts page
Then I should see "GiftStory1 by gifter for giftee1"
When I visit the change username page for giftee1
And I fill in "New user name" with "newusername"
And I fill in "Password" with "something"
And I press "Change User Name"
Then I should get confirmation that I changed my username
And I should see "Hi, newusername"
When I go to my gifts page
Then I should see "GiftStory1 by gifter for newusername"
And I should not see "GiftStory1 by gifter for giftee1"

Scenario: Changing the username from a forbidden name to non-forbidden
Given I have no users
And the following activated user exists
| login | password |
| forbidden | secret |
And the user name "forbidden" is on the forbidden list
When I am logged in as "forbidden" with password "secret"
And I visit the change username page for forbidden
And I fill in "New user name" with "notforbidden"
And I fill in "Password" with "secret"
And I press "Change User Name"
Then I should get confirmation that I changed my username
And I should see "Hi, notforbidden"

Scenario: Tag wrangling supervisors are emailed about tag wrangler username changes
Given the user "before" exists and is activated
Expand Down

0 comments on commit c8cb063

Please sign in to comment.