Giter Club home page Giter Club logo

Comments (9)

dark-panda avatar dark-panda commented on July 23, 2024 1

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.

aaronmallen avatar aaronmallen commented on July 23, 2024

caused by #138

from activeinteractor.

aaronmallen avatar aaronmallen commented on July 23, 2024

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.

aaronmallen avatar aaronmallen commented on July 23, 2024

@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.

dark-panda avatar dark-panda commented on July 23, 2024

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.

aaronmallen avatar aaronmallen commented on July 23, 2024

@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.

dark-panda avatar dark-panda commented on July 23, 2024

The spec mentioned above still fails when applied to the bugfix/#151 branch.

from activeinteractor.

aaronmallen avatar aaronmallen commented on July 23, 2024

@dark-panda did you try it after I updated the branch? bundle update

from activeinteractor.

aaronmallen avatar aaronmallen commented on July 23, 2024

#152 is passing with your spec?

from activeinteractor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.