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

Issues loading specific seeds #95

Open
erikaxel opened this issue Jan 8, 2025 · 8 comments
Open

Issues loading specific seeds #95

erikaxel opened this issue Jan 8, 2025 · 8 comments

Comments

@erikaxel
Copy link

erikaxel commented Jan 8, 2025

I had some small issues loading specific seeds. Some documentation issues and one bug.

Wrong path suggested?
The docs suggest using db/seeds/tests/cases. I didn't get that to work, instead I used db/seeds/cases. In the dummy app, the seeds are put under db/seeds/test/cases (note the lacking s). However, since the rest of the list is without the specific environment, I think it would make sense to just use db/seeds/cases in the documentation here?

Add rspec suggestion
The documentation only suggests how to load seeds from minitest, should we add it for rspec as well?

RSpec.describe 'Pagination' do
  before { seed "cases/pagination" }
end

seed silently fails on missing file
Since I had the wrong path (due to the first documentation issue) my tests failed, but it took me a while to figure out because seed silently fails if it doesn't find the file. I think it would have been easier to figure out if it complained on missing files.

kaspth added a commit that referenced this issue Jan 8, 2025
It's a typo that I meant to fix a while ago, but forgot.

We do support `db/seeds/test/**` loading, but the directory should match the `Rails.env` name like `test` singular.

Ref #95
kaspth added a commit that referenced this issue Jan 8, 2025
It's a typo that I meant to fix a while ago, but forgot.

We do support `db/seeds/test/**` loading, but the directory should match the `Rails.env` name like `test` singular.

Ref #95
@kaspth
Copy link
Owner

kaspth commented Jan 8, 2025

The docs suggest using db/seeds/tests/cases. I didn't get that to work, instead I used db/seeds/cases. In the dummy app, the seeds are put under db/seeds/test/cases (note the lacking s).

Yeah, that's a typo. I spotted it a while ago, but then forgot to fix it. I just fixed it in #97.

However, since the rest of the list is without the specific environment, I think it would make sense to just use db/seeds/cases in the documentation here?

The nesting is on purpose, since cases doesn't really make sense outside of the test environment. It's also trying to mirror TestCase as a name ala ActiveSupport::TestCase.

@kaspth
Copy link
Owner

kaspth commented Jan 8, 2025

The documentation only suggests how to load seeds from minitest, should we add it for rspec as well?

Hm. I haven't used RSpec much personally, so I'm wondering about RSpec specific documentation maintenance in general. I suppose we could add that snippet.

kaspth added a commit that referenced this issue Jan 8, 2025
Ref #95

Needs a `type: :feature` too to match the integration example above.
@kaspth
Copy link
Owner

kaspth commented Jan 8, 2025

Ok, documenting the RSpec version in #98

@kaspth
Copy link
Owner

kaspth commented Jan 8, 2025

Since I had the wrong path (due to the first documentation issue) my tests failed, but it took me a while to figure out because seed silently fails if it doesn't find the file. I think it would have been easier to figure out if it complained on missing files.

Yeah, we should probably raise in case no files are found.

kaspth added a commit that referenced this issue Jan 8, 2025
Ref #95

Needs a `type: :feature` too to match the integration example above.
kaspth added a commit that referenced this issue Jan 9, 2025
* Raise when `seed` finds no files.

Ref #95

In case users pass a typo'ed name/path to `seed` we won't give them any indication of what's going on.

Running a test fails silently.

Now we raise when we can't find any files.

* Split glob per path pattern

In case a user does `seed :accounts, :missing` we want to raise when we can't load from `:missing`.

Previously, we'd proceed silently because `:accounts` found files.
@kaspth
Copy link
Owner

kaspth commented Jan 9, 2025

After #99, we're now raising in case a pattern can't be found. So for seed :accounts, :missing, we'll raise that :missing can't find any files.

@erikaxel
Copy link
Author

erikaxel commented Jan 9, 2025

The nesting is on purpose, since cases doesn't really make sense outside of the test environment. It's also trying to mirror TestCase as a name ala ActiveSupport::TestCase.

We were actually thinking that reusing special cases between dev/test makes a lot of sense for us. The case of pagination is a good example. When we want to develop on a pagination feature, it is usually a hassle to create all the objects needed to force the pagination to work, so instead by including it in the default seed, all developers would have easy access to the case. This is even more true when the cases get more esoteric and difficult to setup. So we were planning on adding something like the following in seeds.rb:

if Rails.env.development?
    seed 'cases/pagination' 
    # and all other special cases we want in default dev
end

@kaspth
Copy link
Owner

kaspth commented Jan 9, 2025

We were actually thinking that reusing special cases between dev/test makes a lot of sense for us. The case of pagination is a good example.

Ahh, I see! That's interesting.

So we were planning on adding something like the following in seeds.rb:

Ah yeah, I can see what you mean. I think I'd do this:

if Rails.env.development?
  seed :cases # Loads from db/seeds/cases/**/* and db/seeds/development/cases/**/*
end

This lets you add shared and development specific cases without needing to update db/seeds.rb. And in tests you can then seed "cases/<something>" to get them on a case-by-case basis.

I'll need to think about this more and I probably want to document this in the README too.

@kaspth
Copy link
Owner

kaspth commented Jan 21, 2025

Ok, I just used a cases/lookbook over in #100 and I'm really liking it.

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

2 participants