Using Rails 4, Zeus 0.13.3, rspec-rails edge and mongoid edge

Simple STI model:

File my_model.rb in /model directory

class MyModel
  include Mongoid::Document

  field :my_field
end

File my_sti.rb in /model/my_model directory

class MyModel
  class MySti << ::MyModel

    field :some_other_field
  end
end 

Everything works as expected in console and web. When I run the spec via bundler:

bundle exec rspec spec

It'all good, but the issue is when I run them with zeus, it throws:

<class:MySti>': undefined methodfield' for MyModel::MySti:Class (NoMethodError)

2 ways of getting around the issue that I found so far:

  • commenting the field declaration in the STI, specs are running fine, but obviously business logic is not!

  • re-adding the include Mongoid::Document definition in the MySti class: spec and logic works fine with that, but I should not have to do that, and I am weary of possible unintended consequences of doing that.

Any ideas ?

1

There are 1 answers

0
David Moore On

Does adding a delegate work?

from documentation

class Greeter < ActiveRecord::Base
  def hello
    'hello'
  end

  def goodbye
    'goodbye'
  end
end

class Foo < ActiveRecord::Base
  belongs_to :greeter
  delegate :hello, to: :greeter
end

Foo.new.hello   # => "hello"
Foo.new.goodbye # => NoMethodError: