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

Default User model is not working unless you add mongoid_userstamp_user call #23

Open
marcocanderle opened this issue Dec 1, 2014 · 4 comments

Comments

@marcocanderle
Copy link

I think this might be related with the other 2 issues you have open in this gem, but I had a long debugging session till I found out that unless you explicitly add the mongoid_userstamp_user call on the model where you want to use the userstamps, the gem won't be applied to the model if you just use:
include Mongoid::Userstamp
as the readme implies in the first example.

I'm using the gem in combination with https://github.com/aq1018/mongoid-history . I'm using the following gemset (short version):

gem 'rails', '4.1.8'
# Mongoid
gem 'mongoid', github: 'mongoid/mongoid'
gem 'mongoid_slug', github: 'digitalplaywright/mongoid-slug'
gem 'mongoid-history'
gem 'mongoid_userstamp'

# Users & Policies
gem 'devise', '~> 3.4.0'
gem 'devise-encryptable', '~> 0.2.0'  
gem 'devise_invitable', github: 'scambra/devise_invitable'
gem 'devise-scrypt'
gem 'pundit'
gem 'enumerize'
......

Using Ruby 2.1.4

My models (reduced version) are as follows:

#The model used for HistoryTracker gem
class HistoryTracker
   include Mongoid::History::Tracker
   include Mongoid::Userstamp

   mongoid_userstamp #Gem won't work unless I add this line explicitly
end

class User
  include Mongoid::Document
  include Mongoid::Userstamp::User
  include Mongoid::Attributes::Dynamic
  include Mongoid::Timestamps
  extend Enumerize

  has_and_belongs_to_many :accounts

  devise :invitable, :encryptable, :database_authenticatable, :registerable, :lockable,
     :recoverable, :confirmable, :rememberable, :trackable, :validatable, :timeoutable

end

class Model1
  include Mongoid::Document
  include Mongoid::Attributes::Dynamic
  include Mongoid::Timestamps
  include Mongoid::History::Trackable

  belongs_to :account

  track_history track_create: true
end

class Account
  include Mongoid::Document
  include Mongoid::Attributes::Dynamic
  include Mongoid::Timestamps
   include Mongoid::History::Trackable
  include Mongoid::Slug

  has_and_belongs_to_many :users

  track_history on: [:filing_frequency, :status] #log account changes

end

I think the issue is with the default call to mongoid_userstamp, which for some reason doesn't happen as expected.

@marcocanderle
Copy link
Author

BTW, the error I get if I don't do what explained is:

    undefined method `updated_by' for #<HistoryTracker:0x007f7d9c5824d0>

@marcocanderle
Copy link
Author

I edited my initial comments with the updated code with the general solution for using it with HistoryTracker. The mongoid_userstamp gem won't work and will issue the mentioned error unless I explicitly include mongoid_userstamp on the HistoryTracker model.

Note that without using HistoryTracker, I still had to include the mongoid_userstamp call to make it work properly.

@johnnyshields
Copy link
Collaborator

Can you reduce this down to a failing RSpec and commit it, so I can attempt to fix it?

marcocanderle added a commit to marcocanderle/mongoid_userstamp that referenced this issue Dec 2, 2014
@marcocanderle
Copy link
Author

Just sent you the pull request but I would need your advice on how to solve that issue I mention on the pull request. thanks!

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