jorgemanrubia/forceps

Does not work with many-to-many association

zoras opened this issue · 7 comments

The forceps gem does not recognize many-to-many association and skips the model while copying.

class Cat < ActiveRecord::Base
  has_and_belongs_to_many :family_members
end

class FamilyMember < ActiveRecord::Base
  has_and_belongs_to_many :cats
end

When we try to access Forceps::Remote::Cat it raises the error:
NameError: uninitialized constant Forceps::Remote::Cat

I am too facing the same issue. copy_to_local method does not work to those tables having many to many relationship.

Hey guys, thanks for reporting this. I have copied habtm associations in the past so this must be some kind of bug. I'll try to find some time for it in the next days. I'd appreciate if you could submit a Pull Request containing a test reproducing the problem you are seeing (as here). That would be really helpful.

I tried running the existing tests with rake test and all tests are failing with errors like ActiveRecord::StatementInvalid: Could not find table 'users'. It would be helpful if you listed the testing and contribution guidelines in the Readme :)

These are the changes I had to make locally before I could get tests to run:

https://github.com/mavenlink/forceps/compare/mavenlink:master...getting_tests_to_run

I also had to go into https://github.com/jorgemanrubia/forceps/tree/master/test/dummy and run RAILS_ENV=test rake db:create db:migrate and RAILS_ENV=remote rake db:create db:migrate, I think.

@cantino Thanks! Could you create a PR with that? I could reproduce the problem in my box. There seem to be a weird problem introduced by recent release of newer minitest and Rails 3. I am very interested in merging that patch (we might need to tweak it a little bit to make it work with Rails 4 in travis).

I am still interested in maintaining compatibility with Rails 3, although that's certainly something will drop at some point.

Thanks you!

@zoras I will add some info about how to run the suite. You are right this is much needed

@jorgemanrubia the existing test for has_and_belongs_to_many is passing fine
https://github.com/jorgemanrubia/forceps/blob/master/test/clone_structures_test.rb#L35

Seems I forgot to eager load the Rails app prior to Forceps.configure, my bad!
I'll be closing this issue. BTW, Awesome gem 👍

great, thanks!