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

Mongoid removed the remove_all method? #4

Open
gotjosh opened this issue Jul 20, 2015 · 3 comments
Open

Mongoid removed the remove_all method? #4

gotjosh opened this issue Jul 20, 2015 · 3 comments

Comments

@gotjosh
Copy link

gotjosh commented Jul 20, 2015

I tried setting up database_cleaner on a project using mongoid 5.0.0.beta, it seems they removed the remove_all method so it's no longer working.

Here's the error I'm getting:

/Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/database_cleaner-1.4.1/lib/database_cleaner/moped/truncation_base.rb:14:in `block in clean': undefined method `remove_all' for #<Mongo::Collection::View:0x007fd6600c6c08> (NoMethodError)
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/database_cleaner-1.4.1/lib/database_cleaner/moped/truncation_base.rb:14:in `each'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/database_cleaner-1.4.1/lib/database_cleaner/moped/truncation_base.rb:14:in `clean'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/database_cleaner-1.4.1/lib/database_cleaner/base.rb:40:in `clean_with'
    from /Users/gotjosh/rails/aplus/spec/rails_helper.rb:15:in `block (2 levels) in <top (required)>'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/rspec-core-3.2.2/lib/rspec/core/example.rb:333:in `instance_exec'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/rspec-core-3.2.2/lib/rspec/core/example.rb:333:in `instance_exec'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/rspec-core-3.2.2/lib/rspec/core/hooks.rb:357:in `run'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1559:in `block in run_hooks_with'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1559:in `each'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1559:in `run_hooks_with'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1525:in `with_suite_hooks'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:109:in `block in run_specs'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/rspec-core-3.2.2/lib/rspec/core/reporter.rb:62:in `report'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:108:in `run_specs'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:86:in `run'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:70:in `run'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:38:in `invoke'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/gems/rspec-core-3.2.2/exe/rspec:4:in `<top (required)>'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/bin/rspec:23:in `load'
    from /Users/gotjosh/.rbenv/versions/2.2.2/gemsets/aplus/bin/rspec:23:in `<main>'
@gotjosh
Copy link
Author

gotjosh commented Jul 20, 2015

In order to make it work, had to monkey patch the Mongo Ruby driver class.

module Mongo
  class Collection
    class View
      def remove_all
        remove(0)
      end
    end
  end
end

If someone could point me in the right direction I would be more than happy to submit a Pull Request so that it matches the correct version.

@Elyasin
Copy link

Elyasin commented Aug 5, 2015

I ran into the same issue. Mongoid 5 does not use Moped anymore. Instead it uses the Ruby driver Mongo I think.

It would be nice to have a cleaner for Mongoid 5. Me too, if someone is willing to guide me a little bit, I would be happy to contribute.

@adamdilek
Copy link

Its not great great great solution.

Now I'm using

class DatabaseCleaner
  def self.clean
    models.each do |model|
      model.all.each(&:delete)
    end
  end

  def self.models
    if @models.to_a == []
      Rails.application.eager_load!
      @models = Mongoid.models
      @models.delete(TagSystem)
      @models.delete(Tag)
    end
    @models
  end
end

When you guys official support i will be very happy.

@botandrose botandrose transferred this issue from DatabaseCleaner/database_cleaner Feb 18, 2020
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

3 participants