-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Fix tests in activerecord/test/cases/tasks/database_tasks_test.rb
#33781
Conversation
r? @kaspth (@rails-bot has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super clear on why we prefer to stub some of these instead of just setting/unsetting in setup/teardown. Can you explain? In general I think these tests need to be re-written.
The legacy db tasks test is for testing the to_h
version of the configurations.
stubbing isn't preferable over setting/unsetting in setup/teardown, and vice versa. I just reverted changes were made in ActiveRecord::Base::configurations do
flunk # it'll be never executed
end the same issues in the rails/activerecord$ bin/test test/cases/tasks/legacy_database_tasks_test.rb Using sqlite3
Run options: --seed 55195
# Running:
................................
Finished in 0.058142s, 550.3800 runs/s, 0.0000 assertions/s.
32 runs, 0 assertions, 0 failures, 0 errors, 0 skips As you can see 0 assertions. I guessed you want tests def with_stubbed_configurations
old_configurations = ActiveRecord::Base.configurations.to_h
ActiveRecord::Base.configurations = @configurations
ActiveRecord::Base.stub(:configurations, ActiveRecord::Base.configurations.to_h) do
yield
end
ensure
ActiveRecord::Base.configurations = old_configurations
end but it causes erros in tests cases like
I'm also not sure whether it should work in that case.
Why do you think so, these tests react on changes in the rails codebase and that is ok? |
Ok, yea I get why the legacy one fails - the rake tasks will still use the object version internally (and should) so the legacy test isn't that necessary anymore. It was when I had a previous API implemented but I ended up changing everything and forgetting that that test wasn't really necessary once I changed the API. Can you delete the legacy file and push up so it's one commit? |
After rails#33637 some tests in `activerecord/test/cases/tasks/database_tasks_test.rb` don't assert anything. We used to stub `ActiveRecord::Base::configurations` method in those tests like `ActiveRecord::Base.stub(:configurations, @Configurations) {}`. Since rails#33637 `ActiveRecord::Base::configurations` is a `ActiveRecord::DatabaseConfigurations` object(not a Hash object) we can't do so anymore. `ActiveRecord::DatabaseConfigurations` object builds during `ActiveRecord::Base::configurations=`. We can replace `ActiveRecord::Base.stub(:configurations, @Configurations) {}` to ``` begin old_configurations = ActiveRecord::Base.configurations ActiveRecord::Base.configurations = @Configurations # ... ensure ActiveRecord::Base.configurations = old_configurations end ``` Also I fixed tests in `activerecord/test/cases/tasks/legacy_database_tasks_test.rb` But currently It looks like duplication of `activerecord/test/cases/tasks/database_tasks_test.rb`. We should improve those tests or remove them. I've tried (in `activerecord/test/cases/tasks/legacy_database_tasks_test.rb` file): ``` def with_stubbed_configurations old_configurations = ActiveRecord::Base.configurations.to_h ActiveRecord::Base.configurations = @Configurations ActiveRecord::Base.stub(:configurations, ActiveRecord::Base.configurations.to_h) do yield end ensure ActiveRecord::Base.configurations = old_configurations end ``` but it causes erros in tests cases. After discussion we decided to remove `activerecord/test/cases/tasks/legacy_database_tasks_test.rb` Related to rails#33637
38cb486
to
5f244f6
Compare
Agreed. I removed |
After #33637 some tests in
activerecord/test/cases/tasks/database_tasks_test.rb
don't assert anything.
We used to stub
ActiveRecord::Base::configurations
method in thosetests like
ActiveRecord::Base.stub(:configurations, @configurations) {}
.Since #33637
ActiveRecord::Base::configurations
is aActiveRecord::DatabaseConfigurations
object(not a Hash object) we can't do so anymore.
ActiveRecord::DatabaseConfigurations
object builds duringActiveRecord::Base::configurations=
.We can replace
ActiveRecord::Base.stub(:configurations, @configurations) {}
toAlso I fixed tests in
activerecord/test/cases/tasks/legacy_database_tasks_test.rb
But currently It looks like duplication of
activerecord/test/cases/tasks/database_tasks_test.rb
.We should improve those tests or remove them.
I've tried (in
activerecord/test/cases/tasks/legacy_database_tasks_test.rb
file):but it causes erros in tests cases.
@eileencodes What exactly do we want to test in
activerecord/test/cases/tasks/legacy_database_tasks_test.rb
file?Related to #33637
/cc @eileencodes