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

Generate a spec file when a data_migration is generated #148

Open
bgwilson87 opened this issue Jul 1, 2020 · 2 comments · May be fixed by #162
Open

Generate a spec file when a data_migration is generated #148

bgwilson87 opened this issue Jul 1, 2020 · 2 comments · May be fixed by #162

Comments

@bgwilson87
Copy link

Hi there, I'm migrating from an old gem called datafix https://github.com/dimroc/datafix

It has a nice feature where it generates a spec file for you when you generate a data migration. With complicated data migrations, I find it's best to write some tests to make sure the data migration is doing what I expect. Do you think this is something you could support?

For example
rails g data_migration add_this_to_that

would generate a spec file in addition to the migration file at this location
spec/db/data/20200701180749_add_this_to_that_spec.rb

with this content:

require "rails_helper"
require Rails.root.join("db", "data", "20200701180749_add_this_to_that")

describe AddThisToThat do
  describe ".up" do
    pending "Needs tests"
  end

  describe ".down" do
    pending "Needs tests"
  end
end
@schwern
Copy link

schwern commented Dec 15, 2020

I want this as well and might put a little work into it. My template goes a little further adding the special sauce necessary to keep the test quiet, and handy subject lines.

require "rails_helper"
require Rails.root.join("db", "data", "20200701180749_add_this_to_that")

describe AddThisToThat do
  let(:migrator) {
    described_class.new.tap do |m|
      m.verbose = false
    end
  }

  describe "#up" do
    subject { migrator.migrate(:up) }

    pending "Needs tests"
  end

  describe "#down" do
    subject { migrator.migrate(:down) }

    pending "Needs tests"
  end
end

What do you think?

@schwern schwern linked a pull request Dec 15, 2020 that will close this issue
@ilyakatz
Copy link
Owner

i knows it's not entirely the same, but can this use case can be solved with #232

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

Successfully merging a pull request may close this issue.

3 participants