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
Get logic out of db rake tasks, and into classes and objects #6761
Conversation
Minimal implementation that supports db:create SQLite replacement
Now isn't that better? And yes, I know that private has no impact on class methods - it's a visual distinction, not a technical one.
|
Does this work and pass the tests as-is? If so I think we may as well merge now and merge more later if/when you do more work, rather than bikeshed the design - IMO it's a clear improvement so I'd be happy to merge. Thanks! |
|
I agree with @jonleighton . Thanks @freelancing-god ! |
|
Rightio - let me add a few more tests, and give the tasks a spin - and if you have any inspiration for an elegant way to have integration tests for this, I'd love to hear it. |
|
I like that direction. I was thinking about doing this after I needed to modify some of the tasks and realized that they don't have too much tests (or at that moment maybe even no tests) and there is now way to test it in isolation. |
|
What's the right way to test ActiveRecord code that refers to the Rails module constant? I was defining it if it wasn't defined in my new test files, and that's fine when they're run by themselves, but not the case when I run the entire set of AR tests. |
|
@freelancing-god that's what done in other sets of tests: https://github.com/rails/rails/blob/master/actionpack/test/abstract_unit.rb#L32, what errors do you see when you run entire AR suite? |
|
@freelancing-god |
|
@drogus (re)opening the module makes sense, but it doesn't seem to work - I get over 100 failing tests (running just test_sqlite3 in ./activerecord), and most are something like this: All I'm doing in the tests I've added that use |
|
@freelancing-god personally I would inject the class Foo
def initialize(environment = Rails)
@environment = environment
end
endYou can then inject a mock in your test. I see you are stubbing methods on |
|
Thanks @jonleighton, took the approach you suggested. Not thrilled at the result for one of the tests, but it'll do for the moment. Just given the rake tests a run in a local test app now... |
|
@jonleighton @josevalim tests are green, and I ran through running db:create, db:drop, db:create:all and db:drop:all for each of SQLite, MySQL and PostgreSQL in a quick test application running off my branch, all worked smoothly. If you are keen to merge this in now, go for it. |
Get logic out of db rake tasks, and into classes and objects
|
Awesome, merged |
|
@freelancing-god injecting Rails is fine, but if you can inject more granular configuration, it would be better. |
|
I see you did what I just said, ignore me. :) |
I wish more people thought like you, Jon :) |
|
@freelancing-god really great work |
|
awesome :) i recently had to dig through rails' rake db code and actually planned to refactor it. |
|
@rubiii no worries - although please, don't hold back from continuing on and cleaning up the other tasks (there's a lot of them!). I'll try to get through some more when I have the chance, but no idea when that'll be. |
|
@freelancing-god i didn't take a look at the other rake tasks yet, but i hope i can contribute something soon. |
Right now, this is a work in progress. I'm pushing it here for a few reasons:
But as to what's happening in these commits, essentially:
And finally, my questions for right now: