Skip to content
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

Userstamp is not added when userstamp was not explicitly called #30

Open
rjurado01 opened this issue May 6, 2016 · 1 comment
Open

Comments

@rjurado01
Copy link

I have this test:

RSpec.describe Product do
  it "chech bug" do
    class User
      include Mongoid::Document
      include Mongoid::Userstamp::User
    end

    class Product
      include Mongoid::Document
      include Mongoid::Userstamp
    end

    p = Product.create
    expect(p.created_by).to be eq(nil)
  end
end

This show this error:

  1) Product chech bug
     Failure/Error: p.created_by

     NoMethodError:
       undefined method `created_by' for #<Product _id: 572c8a3f8675c36e39000001, >

The problem that I can see is that this code:

module Mongoid
module Userstamp
  class Railtie < Rails::Railtie
    config.to_prepare do
      Mongoid::Userstamp.model_classes.each do |model_class|
        unless model_class.included_modules.include?(Mongoid::Userstamp::Model)
          model_class.send(:include, Mongoid::Userstamp::Model)
        end
      end
    end

Is executed before Mongoid::Userstamp is included in class:

module Mongoid
  module Userstamp
    extend ActiveSupport::Concern
    included do
      Mongoid::Userstamp.add_model_class(self)
    end
    ...

Then Mongoid::Userstamp.model_classes is equal to []

It is a bug?

@alexwbuschle
Copy link

Hey @rjurado01 I tried to set the user_model on the tracked models and that worker.
Just put mongoid_userstamp user_model: 'User' :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants