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

Do not skip generator on :revoke behavior #274

Conversation

mauriciopasquier
Copy link
Contributor

This PR fixes the rails generators when run in reverse, that is with rails destroy, so they remove the corresponding generated migrations.

I didn't add tests because I'm not sure if this behavior is intented, maybe to be cautious about what you remove? Let me know if you want me to add them. Also, thanks for your amazing work with this gem and globalize ^^

@shioyama
Copy link
Owner

Thanks very much! I didn't even know about rails destroy, thanks for teaching me something new 😄

I didn't add tests because I'm not sure if this behavior is intented, maybe to be cautious about what you remove?

I think it sounds like a good idea, could you add specs for this? Then I can merge it.

Thanks again!

@shioyama shioyama added the rails label Sep 16, 2018
@mauriciopasquier
Copy link
Contributor Author

No problem! ^^
I'm having some difficulties reproducing this destroy behavior on the specs, but I'm on it.

@shioyama
Copy link
Owner

Hmm... it looks like generator_spec doesn't support destroy, which makes this more tricky to test. I think unless you've got something already, it's fine to merge without a spec for this one, and maybe add one later.

@shioyama
Copy link
Owner

I merged this in abff813, but if you'd like to add a spec please go ahead 😄

@shioyama shioyama closed this Sep 18, 2018
@mauriciopasquier
Copy link
Contributor Author

Thank you!

For what it's worth, these are the specs I have right now.

I still don't understand why, but invoking the generator with behavior: :revoke from the spec does remove the migrations, unlike calling rails destroy mobility:install from a rails app.

@shioyama
Copy link
Owner

Still not quite sure why that spec isn't working, but the reason it passes even without the change is that in this line:

if behavior == :invoke && self.class.migration_exists?(migration_dir, template)

The conditional self.class.migration_exists?(migration_dir, template) returns false in any case.

The problem would seem to be that migration_dir is not using the correct (test) root, so I changed it to:

migration_dir = File.expand_path(destination_root, "db/migrate")

which I can check actually has the files, but still migration_exists? returns false... puzzled.

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

Successfully merging this pull request may close these issues.

2 participants