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

Encapsulate dependencies on Devise (refactoring) #112

Merged
merged 30 commits into from
Sep 30, 2014

Conversation

gonzalo-bulnes
Copy link
Owner

As a developer
In order to make dependencies transparent
And to make the code testable in spite of them (see #104)
I want all dependencies to be properly encapsulated
And I want them to be injected in the methods that use them

Let's start with the (numerous) dependencies on Devise methods.

While doing that:
In order to make the code mode readable
And to make modifications easier
I want methods to be short
And their names to be descriptive

Define and use the method in `ActsAsTokenAuthenticationHandlerMethods`.
Adds a little bit of duplication, yet I believe the change is worth it.
Define and use the method in `ActsAsTokenAuthenticationHandlerMethods`.
Adds a little bit of duplication, yet I believe the change is worth
it.
Both methods follow now the pattern: entity_{attribute}_{some_name}.
Add TokenComparator public interface specs
Add TokenComparator private specs

The dependency to the Devise secure comparison method is now encapsulated
in the `ActsAsTokenAuthenticationHandler#token_comparator` method.

If necessary, the `#token_correct?` specs could be written using
a DummyTokenComparator instead of the Devise-dependent TokenComparator.
Add SignInHandler private specs (there is no public interface for now)

The dependency to the Devise secure comparison method is now
encapsulated in the `ActsAsTokenAuthenticationHandler#sign_in_handler`
method.

If necessary, the `#perform_sign_in!` specs could be written using
a DummySignInHandler instead of the Devise-dependent SignInHandler.
Add FallbackAuthenticationHandler private specs (there is no public
interface for now)

The dependency on the Devise authentication helpers is now encapsulated in
the `ActsAsTokenAuthenticationHandler#fallback_authentication_handler`
method.

If necessary, the `#authenticate_entity_from_fallback!` specs could
be written using a DummyAuthenticationHandler instead of
the Devise-dependent FallbackAuthenticationHandler.
And remove redundant `entity_name_underscore`
The `get_entity(name)` method allows to pass an Entity instance reference
as argument of the methods defined through metaprogramming.
The token authenticatable model is no longer passed as argument of the
authentication methods; its corresponding Entity is passed instead.
And remove redundant `entity_token_header_name`
And remove redundant `entity_identifier_header_name`
And remove redundant methods `entity_identifier/token_header_name`
@gonzalo-bulnes gonzalo-bulnes force-pushed the refactor-encapsulate-dependencies-on-devise branch from c69e6c5 to fc4c5cc Compare September 30, 2014 00:29
And remove redundant `get_token_from_params_or_headers`
And remove redundant `get_identifier_from_params_or_headers`
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.

None yet

1 participant