-
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
Fixtures refactor #34076
Fixtures refactor #34076
Conversation
525a329
to
72d88f8
Compare
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.
Awesome @gmcgibbon ! I have left you two inline comments, please tell me what you think about them.
end | ||
|
||
def reflection_class | ||
@refelction_class ||= if @row.include?(model_metadata.inheritance_column_name) |
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.
Little typo here @refelction_class
-> @reflection_class
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.
🤦♂️ Thanks, I'll fix that!
fixture_set_names = Array(fixture_set_names).map(&:to_s) | ||
class_names = ClassCache.new class_names, config | ||
|
||
# FIXME: Apparently JK uses this. |
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.
This is not in the scope of this PR, but maybe we can get rid of this comment, it has already been here for many years...
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.
Yeah, I was meaning to comment on this as well. We will address it after some feedback from the core team. 👍
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.
JK also became JD in the intervening years 😄 — Now I'm curious @jeremy, are you still using it?
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.
Let's leave it. Normally I'd say a test is sufficient but I know this comment has stopped me from messing with this line before and I'd rather not break Basecamp's fixtures. Also I get a good laugh from it whenever I see it. 😉
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.
Asking here out of curiosity and behaviour I discovered today around this method
- What is JK or JD here?
connection = block_given? ? yield : ActiveRecord::Base.connection
accepts a connection as a block tocreate_fixtures
which appratenly fixed an issue I was having for my project's test suite where I was able to create fixtures for different shards in mytest_helper.rb
, purely because of this line. Rougly I ended up doing something like this,
# worked
ActiveRecord::FixtureSet.create_fixtures('test/fixtures', 'posts') { ActiveRecord::Base.connecting_to(shard: :a) }
For some reason,
# This did not work
ActiveRecord::Base.connected_to(shard: :a) { ActiveRecord::FixtureSet.create_fixtures('test/fixtures', 'posts') }
@eileencodes any thoughts on the behaviour?
a1c0c2a
to
6371853
Compare
…to FixtureSet::TableRows
6371853
to
cfeabbf
Compare
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.
Independently of JK/JD I'm +1 on this PR 😉 Thanks @gmcgibbon !
end | ||
|
||
def instantiate_fixtures(object, fixture_set, load_instances = true) | ||
return unless load_instances |
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.
❤️
Summary
ActiveRecord::FixtureSet
class cleanup.Introduce
FixtureSet::ModelMetadata
,FixtureSet::TableRows
, andFixtureSet::TableRow
for generating insertion hashes for fixtures.Encapsulate
FixtureSet.create_fixtures
reading and insertion sectionsinto separate private methods.
Most of this is just trying to break the process of generating and inserting fixture hashes into smaller pieces.
r? @rafaelfranca
/cc @eileencodes