Giter Site home page Giter Site logo

Comments (5)

zeisler avatar zeisler commented on July 20, 2024

Can isolate this down to the minimum ActiveRecord model code that causes the issue?

from active_mocker.

markburns avatar markburns commented on July 20, 2024

Closing as have seen working in an isolated app and am guessing it is down to some very specific peculiarity of our app

from active_mocker.

markburns avatar markburns commented on July 20, 2024

Managed to replicate. I mean, it is a bit crazy code, so not sure how easy it is to support, but here it is:

ActiveRecord::Schema.define(version: 20160427124939) do
  create_table "bars", force: :cascade do |t|
    t.integer  "foo_id"
    t.string   "some_other_attribute"
  end

  create_table "foos", force: :cascade do |t|
    t.string   "some_attribute"
  end
end

class Foo < ActiveRecord::Base
  has_one :bar

  def bar_with_default
    bar = bar_without_default
    return bar if bar
    Bar.new(some_other_attribute: "Some default bar attribute")
  end
  alias_method_chain :bar, :default
end

class Bar < ActiveRecord::Base
end
ERROR_VERBOSITY=3 spring rake active_mocker:build                                                                                                                                                                    [2.3.0]
Running via Spring preloader in process 35809
Generating Mocks |======================================================>>| 100%
Foo has the following errors:
undefined method `bar' for class `#<Module:0x007f895ddfc648>::Foo'
error
undefined method `bar' for class `#<Module:0x007f895ddfc648>::Foo'
/Users/markburns/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method'
/Users/markburns/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method_chain'
/Users/markburns/code/delete_me/app/models/foo.rb:10:in `<class:Foo>'
/Users/markburns/code/delete_me/app/models/foo.rb:1:in `call'
/Users/markburns/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/dissociated_introspection-0.4.1/lib/dissociated_introspection/eval_sandbox.rb:13:in `module_eval'
/Users/markburns/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/dissociated_introspection-0.4.1/lib/dissociated_introspection/eval_sandbox.rb:13:in `call'
/Users/markburns/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/dissociated_introspection-0.4.1/lib/dissociated_introspection/inspection.rb:90:in `load_sandbox'
/Users/markburns/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/dissociated_introspection-0.4.1/lib/dissociated_introspection/inspection.rb:86:in `get_sandbox_class'
/Users/markburns/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/dissociated_introspection-0.4.1/lib/dissociated_introspection/inspection.rb:15:in `get_class'
/Users/markburns/code/active_mocker/lib/active_mocker/mock_creator.rb:132:in `constants'
(erb):2:in `block in partials'
/Users/markburns/.rbenv/versions/2.3.0/lib/ruby/2.3.0/erb.rb:864:in `eval'
/Users/markburns/.rbenv/versions/2.3.0/lib/ruby/2.3.0/erb.rb:864:in `result'
/Users/markburns/code/active_mocker/lib/active_mocker/mock_creator.rb:103:in `block in partials'
/Users/markburns/code/active_mocker/lib/active_mocker/mock_creator.rb:99:in `each'
/Users/markburns/code/active_mocker/lib/active_mocker/mock_creator.rb:99:in `each_with_object'
/Users/markburns/code/active_mocker/lib/active_mocker/mock_creator.rb:99:in `partials'
(erb):7:in `template_creator_default'
/Users/markburns/.rbenv/versions/2.3.0/lib/ruby/2.3.0/erb.rb:864:in `eval'
/Users/markburns/.rbenv/versions/2.3.0/lib/ruby/2.3.0/erb.rb:864:in `result'
/Users/markburns/code/active_mocker/lib/active_mocker/template_creator.rb:15:in `render'
/Users/markburns/code/active_mocker/lib/active_mocker/mock_creator.rb:29:in `create'

from active_mocker.

zeisler avatar zeisler commented on July 20, 2024

Thanks for the repo steps. The change will need to be made in dissociated_introspection. This should not be a difficult change.

from active_mocker.

zeisler avatar zeisler commented on July 20, 2024

@markburns can you try this out on latest master? I made a change that could at least allow it to not fail.

from active_mocker.

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.