-
Notifications
You must be signed in to change notification settings - Fork 896
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
Remove missing factory spec and all blank factories #16768
Conversation
@bdunne Please verify that none of the other pluggable provider repos (or any other repo for that matter) have child factories that might depend on one of these as a parent factory. |
I generally dislike this as you're breaking [or rather, continuing the MIQ tradition of ignoring] the expectation that when you create the most top-level, generic factory for something it should return for you a valid object with dummy data. By just delegating to I do realize this argument is against the greater argument of "Do you really need a factory for every single thing?", and that these changes really just remove empty factories that don't work anyway, so... ¯\_(ツ)_/¯ I guess. I'm just sad that it perpetuates bad factory use. 👍 |
00cfbb4
to
6a5e90a
Compare
spec/models/miq_alert_spec.rb
Outdated
@@ -159,7 +159,7 @@ | |||
it "miq_alert_status.description = miq_alert.description event if overriden by ems_event.description" do | |||
@alert.evaluate( | |||
[@vm.class.base_class.name, @vm.id], | |||
:ems_event => FactoryGirl.create(:ems_event, :message => "oh no!", :type => 'WhateverEvent') | |||
:ems_event => FactoryGirl.create(:ems_event, :message => "oh no!") |
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 think the rationale was that we should never create an event that's of the base type because the table uses STI
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.
EmsEvent appears to be the leaf subclass.
EmsEvent.descendants
=> []
EventStream.descendants.collect(&:name)
=> ["EmsEvent", "MiqEvent", "RequestEvent", "CustomEvent"]
Should it be delegating to |
Yeah, on master... manageiq (master)$ RAILS_ENV=test rails c
irb(main):001:0> require './spec/spec_helper'
=> true
irb(main):002:0> FactoryGirl.create(:customization_template_sysprep)
ActiveRecord::RecordInvalid: Validation failed: Name has already been taken
from /home/bdunne/.gem/ruby/2.3.3/gems/activerecord-5.0.6/lib/active_record/validations.rb:78:in `raise_validation_error'
from /home/bdunne/.gem/ruby/2.3.3/gems/activerecord-5.0.6/lib/active_record/validations.rb:50:in `save!'
from /home/bdunne/.gem/ruby/2.3.3/gems/activerecord-5.0.6/lib/active_record/attribute_methods/dirty.rb:30:in `save!' |
6a5e90a
to
a000567
Compare
Okay @Fryguy I reviewed all of the plugins and added back the factory for |
@chrisarcand For this PR, I'm intending to clean up what we have by removing what shouldn't exist (SchemaMigrations factory), stuff that's wrong, and factories that don't serve a purpose (because they don't set any default values). Also, based on the factories that exist and the ways that they are used, there seems to be a lot of confusion about the purpose and usage of FactoryGirl. Bigger picture: I'm generally questioning our need for FactoryGirl. |
Heads up from ui-classic:
|
@himdel are those errors related to this PR? I don't see those factories being removed here and this PR isn't even merged. 😕 |
This pull request is not mergeable. Please rebase and repush. |
@jrafanie Yes they are, I figured I'd give this a try, to catch the failures before this is merged for once :) This is from running with ui-classic on master (yesterday) and manageig on this PR. |
That's interesting, because I didn't change anything with |
a000567
to
7a79bf3
Compare
7a79bf3
to
ff96bdc
Compare
ff96bdc
to
b6f8d72
Compare
end | ||
|
||
def registered_factory_symbols | ||
@registered_factory_symbols ||= FactoryGirl.factories.collect { |i| i.name.to_sym } |
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.
Since the .include? in this could be called over and over, might be better to put it in a Set.
b6f8d72
to
1aebba0
Compare
This pull request is not mergeable. Please rebase and repush. |
1aebba0
to
183f0d6
Compare
183f0d6
to
bec4a2b
Compare
This pull request is not mergeable. Please rebase and repush. |
Enhance FactoryGirl.create and FactoryGirl.build to super if the factory exists, otherwise call create or new directly. - No longer need to create an empty factory every time a new class is created - No longer need factories for things that shouldn't have factories (SchemaMigrations and join tables) - Many of the factories were incorrect to begin with (not inheriting from the base factory)
bec4a2b
to
c79a3b4
Compare
Checked commit bdunne@c79a3b4 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0 |
This looks neat. 👍 cuts down on a lot of boiler plate. Can we just use |
This also solves the problem on #16728 (comment) |
Also, @kbrock I'd love to use |
Fixes test failures after merging ManageIQ/manageiq#16768
Enhance FactoryGirl.create and FactoryGirl.build to super if the factory exists, otherwise call create or new directly.
cc @jrafanie for the ✂️ 🔥 🎁