mongoid / mongoid-history

Multi-user non-linear history tracking, auditing, undo, redo for mongoid.
https://rubygems.org/gems/mongoid-history
MIT License
393 stars 129 forks source link

wrong number of arguments #238

Open francelwebdev opened 4 years ago

francelwebdev commented 4 years ago

Hi, This gem supports Mongoid 7?

dblock commented 4 years ago

From README, "This gem supports Mongoid 3, 4, 5 on Ruby 1.9.3 or newer and Mongoid 6 and 7 on Ruby 2.2.2+." and Travis CI, https://github.com/mongoid/mongoid-history/blob/master/.travis.yml#L15.

However if I am reading your mind correctly you're having issues with Mongoid 7.1, similar to https://github.com/mongoid/mongoid-locker/issues/85. Appreciate a pull request with a fix.

francelwebdev commented 4 years ago

Good evening, I get this error (wrong number of arguments (given 2, expected 1)) when I go to the index page of my companies controller. Below the code of my company model. I use ruby 2.7.1 and Rails 6.0.2.2 and latest mongoid-history.

`class Company

include Mongoid::Document
include Mongoid::Timestamps

# include Mongoid::Attributes::Dynamic

include Mongoid::History::Trackable

field :name, type: String
field :roles, type: Array
field :website, type: String
field :address, type: String
field :country, type: String
field :phone_number, type: String
field :email_address, type: String
field :tax_identification_number, type: String
field :rccm, type: String

paginates_per 1

track_history(:on => [:fields]) # all fields will be tracked

index({name: 1, tax_identification_number: 1, rccm: 1, email_address: 1, phone_number: 1, website: 1}, {unique: true})

has_many :contacts, class_name: "Contact", dependent: :delete_all

accepts_nested_attributes_for :contacts, reject_if: :all_blank, allow_destroy: true

has_many :customer_proformas, class_name: 'CustomerProforma', dependent: :delete_all

has_many :supplier_proformas, class_name: 'SupplierProforma', dependent: :delete_all

has_many :purchase_orders, class_name: "PurchaseOrder", dependent: :delete_all

has_many :customer_invoices, class_name: 'CustomerInvoice', dependent: :delete_all

has_many :supplier_invoices, class_name: 'SupplierInvoice', dependent: :delete_all

validates :name, presence: true, uniqueness: { case_sensitive: false }
validates :roles, presence: true
validates :phone_number, uniqueness: true, allow_blank: true
validates :email_address, uniqueness: true, allow_blank: true
validates :website, uniqueness: true, allow_blank: true
validates :tax_identification_number, uniqueness: true, allow_blank: true
validates :rccm, uniqueness: true, allow_blank: true

before_create :transformer_le_nom_de_lentreprise_en_majuscule

private

def transformer_le_nom_de_lentreprise_en_majuscule
    self.name.upcase!
end

end `

dblock commented 4 years ago

Please help. Make a PR that uses Mongoid 7.1, demonstrate the failure, try to fix.

cgriego commented 4 years ago

This is a bug in Mongoid 7.1.0. https://jira.mongodb.org/browse/MONGOID-4849

francelwebdev commented 4 years ago

Hello, Okay, thank you. I'm going to try this to see if it solves the problem. Thanks again.

francelwebdev commented 4 years ago

I am now using version 7.0.6 of Mongoid and I get this error (undefined method `collection_name' for Company:Class) when I update the index page of the controller companies.

dblock commented 4 years ago

@francelwebdev Help us help you?

  1. Check out the code for this project, and run it with mongoid 7.0.6 (export MONGOID_VERSION=7.0.6, bundle install, rake) and see what fails.
  2. Add mongoid 7.0.6 to https://github.com/mongoid/mongoid-history/blob/master/.travis.yml and PR that. Let's confirm CI fails the same unit tests.
  3. Repeat with 7.1.
  4. Fix the bugs by implementing the workarounds. If we are sure it's too hard, we can punt and document.
francelwebdev commented 4 years ago

Hi, I still haven't found a solution to my problem. When I make rails console and instantiate my model with CustomerProforma.new, I get this error: ArgumentError: wrong number of arguments (given 2, expected 1) from /home/francel/.asdf/installs/ruby/2.7.1/lib/ruby/2.7.0/forwardable.rb:130:ininstance_delegate' `.

francelwebdev commented 4 years ago

ArgumentError: wrong number of arguments (given 2, expected 1) from /home/francel/.asdf/installs/ruby/2.7.1/lib/ruby/2.7.0/forwardable.rb:130:ininstance_delegate' `

please help me solve the problem.

dblock commented 4 years ago

@francelwebdev Did you do what I suggested in https://github.com/mongoid/mongoid-history/issues/238#issuecomment-613456001?

francelwebdev commented 4 years ago

Sorry, I am a beginner and I do not master that. Here is the project repository. https://github.com/francelwebdev/jmaplus_erp_crm.git

dblock commented 4 years ago

This project is a safe place for you to try and figure it out @francelwebdev! Here to help. You should definitely be able to do 1-3 above. I'll do my best to look at a fix if you can get those in.

p-mongo commented 4 years ago

FYI I have a project that uses Mongoid 7.1.2 and mongoid-history 0.8.2, I don't think I read history in any capacity but at least everything loads and I assume writes.

arthurmde commented 2 years ago

Hi,

I've been experiencing the same issue when trying to upgrade my app to Rails 6.

I cloned mongoid-history's repository and ran the tests as suggested by @dblock in this comment. I could not reproduce any problems there. Everything worked well and the tests passed.

After more investigation, I noticed that in my case this problem only happens in classes that include both Mongoid::History::Trackable and Mongoid::Locker, such as:

class Foo
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Locker
  include Mongoid::History::Trackable

  track_history on: [:all], modifier_field_optional: true
end

The including order does not make any difference. However, if you call track_history before including the Mongoid::Locker, it will work fine:

class Test
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::History::Trackable

  track_history on: [:all], modifier_field_optional: true

   include Mongoid::Locker
end

A similar workaround is suggested here.


Below are the versions of related gems:


Current fix: