-
Notifications
You must be signed in to change notification settings - Fork 112
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 view model for ForgotPassword#show #1354
Conversation
**WHY**: Now we can have 1 ivar in the view instead of 3. Also no conditionals.
this security warning seems like a false positive to me -- anyone else? |
+1 I think "render path contains a parameter value" is definitely a false positive |
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.
LGTM, small style stuff but not blockers
session[:email] = 'test@example.com' | ||
|
||
get :show | ||
|
||
expect(session[:email]).to be_nil |
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.
I think this is still a valid assertion? Since the .delete
was moved into the view model?
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.
yes, but now that the logic was re-shuffled it will only happen if we render the view (view.model.email
is called).
Since rendering the views makes the test slower, I added a spec around session deletion in the unit test for the view model.
@@ -0,0 +1,26 @@ | |||
class ForgotPasswordShow | |||
def initialize(params:, session:) |
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.
params
and session
only use one key each...what do you think of making those the params?
ForgotPasswordShow.new(resend: params[:resend], email: session.delete(:email))
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.
I find it just as easy / easier to access those within the model itself. What do you see as the benefits or passing the parsed vals instead?
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.
I like that the view model "knows less", it's just dealing with the direct values. For example, why does the view model mutate the session currently? Seems weird to me.
However I don't think we have an established pattern here so I'm also fine leaving it as is.
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.
Updated at 5c73e6c
I am now passing the param[:resend]
value instead of all params. I kept the session
stuff as-is, because I liked having the deletion part happen in a method rather than in the controller. Easier to test that way. 🍇
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.
LGTM! thanks
**WHY**: It is OK to render a partial based on a param's presence
WHY: Now we can have 1 ivar in the view instead of 3. Also no
conditionals.