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

Fixtures refactor #34076

Merged
merged 6 commits into from
Oct 7, 2018
Merged

Fixtures refactor #34076

merged 6 commits into from
Oct 7, 2018

Conversation

gmcgibbon
Copy link
Member

@gmcgibbon gmcgibbon commented Oct 4, 2018

Summary

  • ActiveRecord::FixtureSet class cleanup.

  • Introduce FixtureSet::ModelMetadata, FixtureSet::TableRows, and
    FixtureSet::TableRow for generating insertion hashes for fixtures.

  • Encapsulate FixtureSet.create_fixtures reading and insertion sections
    into 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

@gmcgibbon gmcgibbon force-pushed the fixtures_refactor branch 3 times, most recently from 525a329 to 72d88f8 Compare October 4, 2018 18:38
Copy link
Contributor

@albertoalmagro albertoalmagro left a 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)
Copy link
Contributor

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

Copy link
Member Author

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.
Copy link
Contributor

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...

Copy link
Member Author

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. 👍

Copy link
Contributor

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?

Copy link
Member

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. 😉

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

  1. What is JK or JD here?
  2. connection = block_given? ? yield : ActiveRecord::Base.connection accepts a connection as a block to create_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 my test_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?

@gmcgibbon gmcgibbon force-pushed the fixtures_refactor branch 3 times, most recently from a1c0c2a to 6371853 Compare October 5, 2018 20:37
Copy link
Contributor

@albertoalmagro albertoalmagro left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@eileencodes eileencodes merged commit 651d874 into rails:master Oct 7, 2018
@gmcgibbon gmcgibbon deleted the fixtures_refactor branch October 9, 2018 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants