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 view model for ForgotPassword#show #1354

Merged
merged 3 commits into from
Apr 11, 2017
Merged

Conversation

jessieay
Copy link
Contributor

WHY: Now we can have 1 ivar in the view instead of 3. Also no
conditionals.

**WHY**: Now we can have 1 ivar in the view instead of 3. Also no
conditionals.
@jessieay
Copy link
Contributor Author

this security warning seems like a false positive to me -- anyone else?

@zachmargolis
Copy link
Contributor

+1 I think "render path contains a parameter value" is definitely a false positive

Copy link
Contributor

@zachmargolis zachmargolis left a 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
Copy link
Contributor

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?

Copy link
Contributor Author

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:)
Copy link
Contributor

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))

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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. 🍇

Copy link
Contributor

@zachmargolis zachmargolis left a 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
@jessieay jessieay merged commit b5e91e3 into master Apr 11, 2017
@jessieay jessieay deleted the jy-forgot-password-view-model branch April 11, 2017 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants