-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Use ActiveModel::Attributes instead of custom implementation #137
Comments
I've discovered a bug in this PR that isn't covered by a spec: when you are using an organizer, the context values in the organizer's steps don't get initialized properly. Basic case: class TestInteractor < ApplicationInteractor
def perform
p context
p context['user']
p context.user
end
end
class TestInteractorContext < ApplicationContext
attributes :user
end
class TestOrganizer < ApplicationInteractorOrganizer
organize :test_interactor
end
TestOrganizer.perform(user: 'foo') Output before change:
Output after change:
As we see here, accessing the
This issue presumably affects any time that a context is being copied, because it now relies upon attributes being specified rather than all values in an enumerable structure being copied by iteration via The question here becomes then: should attributes need to be explicit, rather than allowing basically any value to enter the context via I played around with a couple of ideas, and pushed a branch with a test case that works in both the original code and with the adjustments I've made, but I don't particularly like the code I've written (https://github.com/dark-panda/activeinteractor/tree/attribute-merging-fixes):
This might sort of boil down to philosophy though -- are explicit contexts with implicit key-pair values going to work together in this structure? |
@dark-panda the on the fly context is not new functionality and is the intended behavior. See the first paragraph in https://github.com/aaronmallen/activeinteractor/wiki/Context however this is a bug and I think it is because of the private method Could you do me a favor and open a bug with your use case. I look at it tomorrow. |
I see that it's the intended behaviour, my point is more wondering aloud if the context should inherit all of the values in the incoming context or if it should only handle named attributes when initializing the context. The context should be modifiable once it has been received by an interactor since that is the intent of the interactor pattern, but should the initial context itself receive all values during initialization? In the patch I provided (which I'm not particularly fond of) I only copy over explicitly named attributes when they are set, rather than all attributes in the context. Anyways, we can continue the discussion in the bug report. I'll post the example code from here. |
@dark-panda the feature has been released and is now available in v1.0.1 |
Elevator pitch, describe and sell us your feature request
As a rails developer,
I want to be able to expect a similar api as
ActiveModel::Attributes
forContext::Base
so that I can utilize common testing libraries like
shoulda-matchers
Is your feature request related to a problem
This was originally requested by @dark-panda on reddit: https://www.reddit.com/r/rails/comments/eu4z1b/activeinteractor_v100_release/ffnzmy3?utm_source=share&utm_medium=web2x
Have you considered any alternatives
Additional Comments
This should be done in a backwards compatible manor. I don't want to have to bump the major version for this functionality at this time.
The reason for the custom functionality is that
Context::Base
inherits fromOpenStruct
and the overall goal of theContext::Attributes
was to provide a mechanism for explicitly returning the desired attributes on the context object instead of all the actual attributes defined on the object.The text was updated successfully, but these errors were encountered: