-
Notifications
You must be signed in to change notification settings - Fork 497
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
Add option to skip call to purge_before_load in parallel::load_schema and parallel::load_structure #529
base: master
Are you sure you want to change the base?
Conversation
|
|
announcing things does not help anyone ... nobody is reading 'updates' :D |
errored: ideally also add a test that fails without this ... |
def purge_before_load | ||
"db:test:purge" if Gem::Version.new(Rails.version) > Gem::Version.new('4.2.0') | ||
"db:test:purge" if purge_before_load? && Gem::Version.new(Rails.version) > Gem::Version.new('4.2.0') |
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.
cannot use Rails.version since this might be used without rails ... ActiveRecord::Version::STRING
should work
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.
Why would this be used without Rails? All tasks that call this method depend on Rails' rake tasks
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 always though as this only needing ActiveRecord to work ... tasks come from https://github.com/rails/rails/blob/master/activerecord/lib/active_record/railties/databases.rake ... which is a railtie ... adding rails to the mix seems to still be unnecessary to me ... maybe ActiveRecord.version => #<Gem::Version "5.0.0.1">
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.
bah ... does not work on rails 3 ... maybe ActiveRecord::VERSION::STRING
is best ...
subject { ParallelTests::Tasks.purge_before_load } | ||
context 'Rails version is 4.3.1' do | ||
before do | ||
class Rails; end |
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.
defining a class at runtime is a bad idea :D
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.
How would you stub the call to Rails.version
instead?
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.
define it global ... and then either add it there or stub it ...
@@ -29,6 +29,42 @@ | |||
end | |||
end | |||
|
|||
describe '.purge_before_load?' do | |||
subject { ParallelTests::Tasks.purge_before_load? } | |||
context "PURGE_BEFORE_LOAD is set to 'false'" do |
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.
FYI I'd test this like so: (less nesting / context switching and 1 change per test)
it "is true" do
exoect(subject).to eq true
end
it "is false when set to false" do
with_env(PURGE_BEFORE_LOAD: 'false') do
expect(subject).to eq false
end
end
it "is true when set to true" do
with_env(PURGE_BEFORE_LOAD: 'true') do
expect(subject).to eq true
end
end
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'll refactor it. However, I prefer to use expect(ENV)
to set envs because it will fail if the env doesn't get used anymore because someone changed the code.
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.
just FYI either way works :)
It should be possible to skip the call to purge_before_load in the parallel::load_schema and parallel::load_structure tasks as this resembles the behaviour of db:structure:load and db:schema:load tasks.