Skip to content

refactor/provider_key_change_use_case#16

Merged
bors[bot] merged 2 commits intomasterfrom
refactor/ProviderKeyChangeUseCase
Apr 12, 2018
Merged

refactor/provider_key_change_use_case#16
bors[bot] merged 2 commits intomasterfrom
refactor/ProviderKeyChangeUseCase

Conversation

@miguelsorianod
Copy link
Copy Markdown
Contributor

The ProviderKeyChangeUseCase has been refactored to use the
Service class methods to clear the cache, removing duplication

The ProviderKeyChangeUseCase has been refactored to use the
Service class methods to clear the cache, removing duplication
@miguelsorianod miguelsorianod changed the title refactor/provider_key_change_ refactor/provider_key_change_use_case Apr 12, 2018
def exercise_provider_service_memoizer(provider_key, service_id)
# Call the Service class methods just
# to force the memoization of them with
# specific values
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

comment lines can be longer here

end

it 'clears the Service cache keys of the old provider key' do
service_ids_with_old_key.each do |service_id|
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this can be described in a new context or describe block if you split these examples in one part for the "general" specs and another one for the memoization stuff, and this way you would not need to insert use_case.process in all the other examples as a consequence of removing it from the before block (you would have two describe/context blocks, and each with independent before blocks if you do not nest them).

Copy link
Copy Markdown
Contributor

@unleashed unleashed left a comment

Choose a reason for hiding this comment

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

LGTM. I am not a fan of having to spec memoization effects, but it is true that we are already caring about clearing some entries and some other places also test this. Not made my mind yet on whether we should be generally doing that and if so whether it should be here, but it's ok atm.

end

def build_provider_service_memoizer_keys(provider_key, service_id)
memoizer_keys = Memoizer.build_keys_for_class(Service,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no need to define memoizer_keys. It's not used anywhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's true. I'll remove it

exercise_provider_service_memoizer(new_key, service_id)
memoizer_keys = build_provider_service_memoizer_keys(new_key, service_id)

memoizer_keys.each do |memoized_key|
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To test a change in the state of an object you can use the Rspec change matcher: https://relishapp.com/rspec/rspec-expectations/v/3-7/docs/built-in-matchers/change-matcher

In this case, we want to check how all the elements of an array changed, so using the change matcher becomes a bit more complex:

            expect { use_case.process }
                .to change { memoizer_keys.count { |k| Memoizer.memoized?(k) } }
                .from(memoizer_keys.size)
                .to(0)

I'm not proposing to make the change, just wanted to let you know that the matcher exists.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not proposing it? Seems sensible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good to know. Thank you for the information 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@unleashed I like it and it's what I would use, but it's just a matter of preference. I'm OK with both solutions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not only a matter of preference: it vastly simplifies the code, leaving less room for error, and it reads way better.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have changed it and now uses the change matcher

@miguelsorianod miguelsorianod force-pushed the refactor/ProviderKeyChangeUseCase branch from d237d6a to a14d5b3 Compare April 12, 2018 16:18
Add tests to check if the memoizer cache entries are cleared when
performing a provider key change
@miguelsorianod miguelsorianod force-pushed the refactor/ProviderKeyChangeUseCase branch from a14d5b3 to a380570 Compare April 12, 2018 16:42
@unleashed
Copy link
Copy Markdown
Contributor

bors r=@davidor,@unleashed

bors Bot added a commit that referenced this pull request Apr 12, 2018
16: refactor/provider_key_change_use_case r=davidor,unleashed a=miguelsorianod

The ProviderKeyChangeUseCase has been refactored to use the
Service class methods to clear the cache, removing duplication


Co-authored-by: Miguel Soriano <msoriano@redhat.com>
@bors
Copy link
Copy Markdown
Contributor

bors Bot commented Apr 12, 2018

Build succeeded

@bors bors Bot merged commit a380570 into master Apr 12, 2018
@bors bors Bot deleted the refactor/ProviderKeyChangeUseCase branch April 12, 2018 17:04
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.

3 participants