Comments (9)
Ah, I see now -- it is passing with the update. I hadn't updated the code, I just cherry picked the spec into what I had pulled down before. Yes this is working now, and the code in my app is working as expected, along with the shoulda-matchers. Good stuff.
from activeinteractor.
caused by #138
from activeinteractor.
The original behavior was the context was intended to be a catch all. You should be able to assign any variable to the context and then return attributes explicitly defined on the context with the #attributes
instance method:
class MyContext < ActiveInteractor::Context::Base
attributes :foo
end
context = MyContext.new(foo: 'foo', bar: 'bar')
context.attributes
#=> { foo: 'foo' }
context.bar
#=> 'bar'
Acceptance criteria for this bug is to restore the intended functionality while also supporting an api friendly to libraries that expect the ActiveModel::Attributes
api.
from activeinteractor.
@dark-panda maybe I'm miss understanding the underlying issue. I'm actually unable to reproduce the bug. See this spec: https://github.com/aaronmallen/activeinteractor/pull/152/files#diff-3021fc89a3bdd3d6956d17e354ce08b3R98
from activeinteractor.
Here's another spec then that shows the issue. The following spec succeeds in v1.0.0 but fails in the current master at 64e12ec.
context 'with attributes in the contexts' do
before do
build_interactor('TestInteractor') do
def perform
context.has_foo_as_method = context.foo.present?
context.has_foo_as_element = context['foo'].present?
context.has_bar_as_method = context.bar.present?
context.has_bar_as_element = context['bar'].present?
end
end
build_context('TestInteractorContext') do
attributes :foo
end
build_organizer('TestOrganizer') do
organize :test_interactor
end
end
it 'copies over all attributes in the contexts to each interactor' do
result = TestOrganizer.perform(foo: 'hello', bar: 'world')
expect(result.has_foo_as_method).to be true
expect(result.has_foo_as_element).to be true
expect(result.has_bar_as_method).to be true
expect(result.has_bar_as_element).to be true
end
end
So, this spec works in v1.0.0 but fails in master, and it's due to #merge_attribute_values
, because that method will only copy over named attributes when context
responds to #attributes
, which in this case is what the organizer is passing along to the interactor. In v1.0.0, all attributes were copied over because they were just properties of an OpenStruct effectively, but in master they must be explicitly named in a context under certain situations, and using an organizer is one such situation.
from activeinteractor.
@dark-panda can you try it out with the following in your gemfile:
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'activeinteractor', require: 'active_interactor', github: 'aaronmallen/activeinteractor', branch: 'bugfix/#151'
from activeinteractor.
The spec mentioned above still fails when applied to the bugfix/#151 branch.
from activeinteractor.
@dark-panda did you try it after I updated the branch? bundle update
from activeinteractor.
#152 is passing with your spec?
from activeinteractor.
Related Issues (20)
- Add a State Object
- Add the Result Object
- Ensure interactors return the result object
- Deprecate ActiveInteractor::Context::Status
- 2.0.0 Cleanup
- Remove ActiveInteractor::Context::Status
- Deprecate ActiveInteractor::Context::Errors
- Remove ActiveInteractor::Context::Errors
- [Bug Report] Allow default attributes to propagate to sibling/child interactors
- Add 2.0 Deprecator
- RFC Interactor#perform Cycle HOT 5
- Clean up ActiveInteractor::Context::Attributes
- Exclude Specs from Rubocop
- Address Lint/NoReturnInBeginEndBlocks cop in version.rb
- [Question] What is the expected Rollback behavior with complex skip_rollback ? HOT 6
- Rails 6.1 changes how ActiveModels are deep_dup'ed HOT 2
- Fix the 1-1-stable build
- Rollback unreleased code
- [Question]
- [Bug Report] before_perform invoked before context is validated
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from activeinteractor.