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

Confirmable API #3412

Closed
nviennot opened this issue Jan 10, 2015 · 12 comments · Fixed by #3570
Closed

Confirmable API #3412

nviennot opened this issue Jan 10, 2015 · 12 comments · Fixed by #3570

Comments

@nviennot
Copy link
Contributor

Hi @josevalim,

As I was looking at the confirm! method in confirmable: https://github.com/plataformatec/devise/blob/85238014593443fb66cd0b1387f7ec8103f0fb91/lib/devise/models/confirmable.rb#L59-L84

And find the API a bit odd.

confirm! expects users to check for its return value, true or false, to detect possible errors.
This might not be a reasonable assumption. The name of the method implies that it would raise, similarly to the save vs save! behavior.

Here's some data to backup my claims:

So I'd say that confirm! should use save! instead of returning true/false. Or be renamed to just confirm?, or try_confirm, to make it explicit to the user should check for the return value.

What do you think?

Side note: I have personal interest to go with the save! route, because NoBrainer's save! method has the same semantics as other ORMs, unlike save which behaves like save!.

@josevalim
Copy link
Contributor

Thanks. I don't think we use save! anywhere though, do we? The issue is that using save! would extend Devise's API... So we should either not use save! and then raise ourselves or rename the method to confirm (keep confirm! with a deprecation warning).

@nviennot
Copy link
Contributor Author

save! is not used in the codebase, only save and save(validate: false).

There is only one other method where validations are run and the method is a bang: https://github.com/plataformatec/devise/blob/master/lib/devise/models/recoverable.rb#L42

so we might rename reset_password! to reset_password as well.

@josevalim
Copy link
Contributor

Agreed, that would be best!​ Thanks for looking into this!

@josevalim
Copy link
Contributor

Btw, can you please submit a pull request? :)

@nviennot
Copy link
Contributor Author

I've submitted a PR (#3570).


Also I have a bit of a problem with compatiblity with NoBrainer and the adapter devise-nobrainer

The AR equivalent in NoBrainer of save is save? (and save! is save).
Everywhere save(validate: false) is used, it doesn't matter. But when validations are performed it matters as NoBrainer raises an exception while devise expect no exception.

There are two places save is called and performs validations:

Side node: there are 13 places where save is called without performing validations (that seems a bit odd, but whatever).

So to make NoBrainer compatible with devise, I make these two save calls to call NoBrainer's save?.
A few solutions:

  1. Since it's only two call to change, it's simple enough to do a defined(:save?) ? save? : save.
  2. We could modify orm_adapter to provide a layer of indirection for save
  3. But the orm_adapter project doesn't seem to be much maintained. Further, orm_adapter is not really used by any other project besides devise. Popular libraries seem to provide in-library adapters, which is easier to maintain. (e.g. https://github.com/amatsuda/kaminari/tree/master/lib/kaminari/models). So we could remove the dependency on orm_adapter, and roll in-library adapters.

What do you think we should do?

nviennot added a commit to nviennot/devise that referenced this issue Apr 19, 2015
nviennot added a commit to nviennot/devise that referenced this issue Apr 19, 2015
@nviennot
Copy link
Contributor Author

Before closing, can you address my latest comment?
Should I do a PR to go with 1) ?

@josevalim
Copy link
Contributor

I could swear I had written a reply, sorry.

I don't think we should change Devise due to an ORM. The only short-term option I have in mind right now is to pass :validate option to all save calls, then you can monkey-patch no brainer and do the proper thing based on the :validate option.

The long-term option is to improve orm_adapter (I am a maintainer) to have a save function so we could do model.to_adapter.save(model) or something similar.

@nviennot
Copy link
Contributor Author

going with the save(:validates => false) route will not work due to the uniqueness validations. (e.g. NoBrainer acquires locks to avoid races with uniqueness validations and persistence).

So let's do the orm_adapter solution :)
Should you do it, or should I make a PR (which I will do it next week though)?

@josevalim
Copy link
Contributor

Please do send a PR!

José Valimwww.plataformatec.com.br
http://www.plataformatec.com.br/Founder and Lead Developer

@nviennot
Copy link
Contributor Author

nviennot commented May 2, 2015

Done:

ianwhite/orm_adapter#45
#3587

@josevalim josevalim reopened this May 2, 2015
@nviennot
Copy link
Contributor Author

ping :)

@nviennot
Copy link
Contributor Author

Nevermind, I no longer need the save abstraction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants