Skip to content
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

Add valid_email & confirmed_at to /me-only attributes #4272

Merged
merged 6 commits into from
Jan 8, 2024

Conversation

zwolf
Copy link
Member

@zwolf zwolf commented Dec 20, 2023

Include User model attributes valid_email and confirmed_at in serialized user objects via the /me route. These attributes can then be used to indicate an invalid email or that an email address needs confirmation on the user's profile/settings page.

Review checklist

  • First, the most important one: is this PR small enough that you can actually review it? Feel free to just reject a branch if the changes are hard to review due to the length of the diff.
  • If there are any migrations, will they the previous version of the app work correctly after they've been run (e.g. the don't remove columns still known about by ActiveRecord).
  • If anything changed with regards to the public API, are those changes also documented in the apiary.apib file?
  • Are all the changes covered by tests? Think about any possible edge cases that might be left untested.

@zwolf zwolf requested a review from yuenmichelle1 January 5, 2024 20:35
Copy link
Collaborator

@yuenmichelle1 yuenmichelle1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Do we want to add a test on users_controller spec for #me method tests?

@zwolf
Copy link
Member Author

zwolf commented Jan 5, 2024

Private attrs are specced out already here:

describe "private user attributes" do
let(:result) do
UserSerializer.single({}, User.where(id: user.id), context)
end
let(:private_attrs) do
UserSerializer::ME_ONLY_ATTRS - ["login_prompt"]
end
context "when i am the permitted requester" do
let(:context) do
{ requester: ApiUser.new(user) }
end
it 'should include the private user data', :aggregate_failures do
private_attrs.each do |me_only_attr|
private_user_data = user.send(me_only_attr)
serialized_result = result[me_only_attr.to_sym]
expect(serialized_result).to eq(private_user_data)
end
end
end

The date comparison failed with a nanosecond-scale difference between the database & object values, hence the explicit setting of the confirmation attrs here.

edit: ope misread controller as serializer, yeah I'll add one for the controller spec!

@@ -392,6 +392,12 @@
expect(result).to eq(user.upload_whitelist)
end

it "should have the confirmed_at for the user" do
result = user_response["confirmed_at"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

@@ -392,6 +392,12 @@
expect(result).to eq(user.upload_whitelist)
end

it "should have the confirmed_at for the user" do
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
RSpec/ExampleWording: Do not use should when describing your tests.

@zwolf zwolf merged commit 226e5cb into master Jan 8, 2024
8 checks passed
@zwolf zwolf deleted the user-serializer-me-attrs branch January 8, 2024 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants