Merge pull request #40046 from composerinteralia/renaming-man
Rename test models for inclusivity
This commit is contained in:
commit
c93f3f0226
@ -316,7 +316,7 @@ data_sources:
|
||||
triangles: true
|
||||
non_poly_ones: true
|
||||
non_poly_twos: true
|
||||
men: true
|
||||
humans: true
|
||||
faces: true
|
||||
interests: true
|
||||
zines: true
|
||||
|
@ -120,7 +120,7 @@ class Sink < ActiveRecord::Base
|
||||
end
|
||||
|
||||
class Source < ActiveRecord::Base
|
||||
self.table_name = "men"
|
||||
self.table_name = "humans"
|
||||
has_and_belongs_to_many :sinks, join_table: :edges
|
||||
end
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,7 @@
|
||||
require "models/liquid"
|
||||
require "models/molecule"
|
||||
require "models/electron"
|
||||
require "models/man"
|
||||
require "models/human"
|
||||
require "models/interest"
|
||||
require "models/pirate"
|
||||
require "models/parrot"
|
||||
@ -240,13 +240,13 @@ def test_scoped_allows_conditions
|
||||
end
|
||||
|
||||
test "inverses get set of subsets of the association" do
|
||||
man = Man.create
|
||||
man.interests.create
|
||||
human = Human.create
|
||||
human.interests.create
|
||||
|
||||
man = Man.find(man.id)
|
||||
human = Human.find(human.id)
|
||||
|
||||
assert_queries(1) do
|
||||
assert_equal man, man.interests.where("1=1").first.man
|
||||
assert_equal human, human.interests.where("1=1").first.human
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
require "models/bird"
|
||||
require "models/parrot"
|
||||
require "models/treasure"
|
||||
require "models/man"
|
||||
require "models/human"
|
||||
require "models/interest"
|
||||
require "models/owner"
|
||||
require "models/pet"
|
||||
@ -140,19 +140,19 @@ def test_do_not_allow_assigning_foreign_key_when_reusing_existing_new_record
|
||||
end
|
||||
|
||||
def test_reject_if_with_a_proc_which_returns_true_always_for_has_many
|
||||
Man.accepts_nested_attributes_for :interests, reject_if: proc { |attributes| true }
|
||||
man = Man.create(name: "John")
|
||||
interest = man.interests.create(topic: "photography")
|
||||
man.update(interests_attributes: { topic: "gardening", id: interest.id })
|
||||
Human.accepts_nested_attributes_for :interests, reject_if: proc { |attributes| true }
|
||||
human = Human.create(name: "John")
|
||||
interest = human.interests.create(topic: "photography")
|
||||
human.update(interests_attributes: { topic: "gardening", id: interest.id })
|
||||
assert_equal "photography", interest.reload.topic
|
||||
end
|
||||
|
||||
def test_destroy_works_independent_of_reject_if
|
||||
Man.accepts_nested_attributes_for :interests, reject_if: proc { |attributes| true }, allow_destroy: true
|
||||
man = Man.create(name: "Jon")
|
||||
interest = man.interests.create(topic: "the ladies")
|
||||
man.update(interests_attributes: { _destroy: "1", id: interest.id })
|
||||
assert_empty man.reload.interests
|
||||
Human.accepts_nested_attributes_for :interests, reject_if: proc { |attributes| true }, allow_destroy: true
|
||||
human = Human.create(name: "Jon")
|
||||
interest = human.interests.create(topic: "the ladies")
|
||||
human.update(interests_attributes: { _destroy: "1", id: interest.id })
|
||||
assert_empty human.reload.interests
|
||||
end
|
||||
|
||||
def test_reject_if_is_not_short_circuited_if_allow_destroy_is_false
|
||||
@ -169,10 +169,10 @@ def test_reject_if_is_not_short_circuited_if_allow_destroy_is_false
|
||||
end
|
||||
|
||||
def test_has_many_association_updating_a_single_record
|
||||
Man.accepts_nested_attributes_for(:interests)
|
||||
man = Man.create(name: "John")
|
||||
interest = man.interests.create(topic: "photography")
|
||||
man.update(interests_attributes: { topic: "gardening", id: interest.id })
|
||||
Human.accepts_nested_attributes_for(:interests)
|
||||
human = Human.create(name: "John")
|
||||
interest = human.interests.create(topic: "photography")
|
||||
human.update(interests_attributes: { topic: "gardening", id: interest.id })
|
||||
assert_equal "gardening", interest.reload.topic
|
||||
end
|
||||
|
||||
@ -186,12 +186,12 @@ def test_reject_if_with_blank_nested_attributes_id
|
||||
end
|
||||
|
||||
def test_first_and_array_index_zero_methods_return_the_same_value_when_nested_attributes_are_set_to_update_existing_record
|
||||
Man.accepts_nested_attributes_for(:interests)
|
||||
man = Man.create(name: "John")
|
||||
interest = man.interests.create topic: "gardening"
|
||||
man = Man.find man.id
|
||||
man.interests_attributes = [{ id: interest.id, topic: "gardening" }]
|
||||
assert_equal man.interests.first.topic, man.interests[0].topic
|
||||
Human.accepts_nested_attributes_for(:interests)
|
||||
human = Human.create(name: "John")
|
||||
interest = human.interests.create topic: "gardening"
|
||||
human = Human.find human.id
|
||||
human.interests_attributes = [{ id: interest.id, topic: "gardening" }]
|
||||
assert_equal human.interests.first.topic, human.interests[0].topic
|
||||
end
|
||||
|
||||
def test_allows_class_to_override_setter_and_call_super
|
||||
@ -219,10 +219,10 @@ def test_accepts_nested_attributes_for_can_be_overridden_in_subclasses
|
||||
end
|
||||
|
||||
def test_should_not_create_duplicates_with_create_with
|
||||
Man.accepts_nested_attributes_for(:interests)
|
||||
Human.accepts_nested_attributes_for(:interests)
|
||||
|
||||
assert_difference("Interest.count", 1) do
|
||||
Man.create_with(
|
||||
Human.create_with(
|
||||
interests_attributes: [{ topic: "Pirate king" }]
|
||||
).find_or_create_by!(
|
||||
name: "Monkey D. Luffy"
|
||||
@ -817,17 +817,17 @@ def test_should_automatically_enable_autosave_on_the_association
|
||||
end
|
||||
|
||||
def test_validate_presence_of_parent_works_with_inverse_of
|
||||
Man.accepts_nested_attributes_for(:interests)
|
||||
assert_equal :man, Man.reflect_on_association(:interests).options[:inverse_of]
|
||||
assert_equal :interests, Interest.reflect_on_association(:man).options[:inverse_of]
|
||||
Human.accepts_nested_attributes_for(:interests)
|
||||
assert_equal :human, Human.reflect_on_association(:interests).options[:inverse_of]
|
||||
assert_equal :interests, Interest.reflect_on_association(:human).options[:inverse_of]
|
||||
|
||||
repair_validations(Interest) do
|
||||
Interest.validates_presence_of(:man)
|
||||
assert_difference "Man.count" do
|
||||
Interest.validates_presence_of(:human)
|
||||
assert_difference "Human.count" do
|
||||
assert_difference "Interest.count", 2 do
|
||||
man = Man.create!(name: "John",
|
||||
human = Human.create!(name: "John",
|
||||
interests_attributes: [{ topic: "Cars" }, { topic: "Sports" }])
|
||||
assert_equal 2, man.interests.count
|
||||
assert_equal 2, human.interests.count
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -839,14 +839,14 @@ def test_can_use_symbols_as_object_identifier
|
||||
end
|
||||
|
||||
def test_numeric_column_changes_from_zero_to_no_empty_string
|
||||
Man.accepts_nested_attributes_for(:interests)
|
||||
Human.accepts_nested_attributes_for(:interests)
|
||||
|
||||
repair_validations(Interest) do
|
||||
Interest.validates_numericality_of(:zine_id)
|
||||
man = Man.create(name: "John")
|
||||
interest = man.interests.create(topic: "bar", zine_id: 0)
|
||||
human = Human.create(name: "John")
|
||||
interest = human.interests.create(topic: "bar", zine_id: 0)
|
||||
assert interest.save
|
||||
assert_not man.update(interests_attributes: { id: interest.id, zine_id: "foo" })
|
||||
assert_not human.update(interests_attributes: { id: interest.id, zine_id: "foo" })
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
require "cases/helper"
|
||||
require "models/post"
|
||||
require "models/author"
|
||||
require "models/man"
|
||||
require "models/human"
|
||||
require "models/essay"
|
||||
require "models/comment"
|
||||
require "models/categorization"
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
module ActiveRecord
|
||||
class WhereChainTest < ActiveRecord::TestCase
|
||||
fixtures :posts, :comments, :authors, :men, :essays
|
||||
fixtures :posts, :comments, :authors, :humans, :essays
|
||||
|
||||
def test_missing_with_association
|
||||
assert posts(:authorless).author.blank?
|
||||
@ -105,8 +105,8 @@ def test_rewhere_with_nested_condition
|
||||
end
|
||||
|
||||
def test_rewhere_with_polymorphic_association
|
||||
relation = Essay.where(writer: authors(:david)).rewhere(writer: men(:steve))
|
||||
expected = Essay.where(writer: men(:steve))
|
||||
relation = Essay.where(writer: authors(:david)).rewhere(writer: humans(:steve))
|
||||
expected = Essay.where(writer: humans(:steve))
|
||||
|
||||
assert_equal expected.to_a, relation.to_a
|
||||
end
|
||||
|
@ -3,12 +3,12 @@
|
||||
require "cases/helper"
|
||||
require "models/face"
|
||||
require "models/interest"
|
||||
require "models/man"
|
||||
require "models/human"
|
||||
require "models/topic"
|
||||
|
||||
class AbsenceValidationTest < ActiveRecord::TestCase
|
||||
def test_non_association
|
||||
boy_klass = Class.new(Man) do
|
||||
boy_klass = Class.new(Human) do
|
||||
def self.name; "Boy" end
|
||||
validates_absence_of :name
|
||||
end
|
||||
@ -18,7 +18,7 @@ def self.name; "Boy" end
|
||||
end
|
||||
|
||||
def test_has_one_marked_for_destruction
|
||||
boy_klass = Class.new(Man) do
|
||||
boy_klass = Class.new(Human) do
|
||||
def self.name; "Boy" end
|
||||
validates_absence_of :face
|
||||
end
|
||||
@ -32,7 +32,7 @@ def self.name; "Boy" end
|
||||
end
|
||||
|
||||
def test_has_many_marked_for_destruction
|
||||
boy_klass = Class.new(Man) do
|
||||
boy_klass = Class.new(Human) do
|
||||
def self.name; "Boy" end
|
||||
validates_absence_of :interests
|
||||
end
|
||||
@ -48,7 +48,7 @@ def self.name; "Boy" end
|
||||
end
|
||||
|
||||
def test_does_not_call_to_a_on_associations
|
||||
boy_klass = Class.new(Man) do
|
||||
boy_klass = Class.new(Human) do
|
||||
def self.name; "Boy" end
|
||||
validates_absence_of :face
|
||||
end
|
||||
|
@ -3,7 +3,7 @@
|
||||
require "cases/helper"
|
||||
require "models/topic"
|
||||
require "models/reply"
|
||||
require "models/man"
|
||||
require "models/human"
|
||||
require "models/interest"
|
||||
|
||||
class AssociationValidationTest < ActiveRecord::TestCase
|
||||
@ -80,20 +80,20 @@ def test_validates_associated_missing
|
||||
|
||||
def test_validates_presence_of_belongs_to_association__parent_is_new_record
|
||||
repair_validations(Interest) do
|
||||
# Note that Interest and Man have the :inverse_of option set
|
||||
Interest.validates_presence_of(:man)
|
||||
man = Man.new(name: "John")
|
||||
interest = man.interests.build(topic: "Airplanes")
|
||||
assert interest.valid?, "Expected interest to be valid, but was not. Interest should have a man object associated"
|
||||
# Note that Interest and Human have the :inverse_of option set
|
||||
Interest.validates_presence_of(:human)
|
||||
human = Human.new(name: "John")
|
||||
interest = human.interests.build(topic: "Airplanes")
|
||||
assert interest.valid?, "Expected interest to be valid, but was not. Interest should have a human object associated"
|
||||
end
|
||||
end
|
||||
|
||||
def test_validates_presence_of_belongs_to_association__existing_parent
|
||||
repair_validations(Interest) do
|
||||
Interest.validates_presence_of(:man)
|
||||
man = Man.create!(name: "John")
|
||||
interest = man.interests.build(topic: "Airplanes")
|
||||
assert interest.valid?, "Expected interest to be valid, but was not. Interest should have a man object associated"
|
||||
Interest.validates_presence_of(:human)
|
||||
human = Human.create!(name: "John")
|
||||
interest = human.interests.build(topic: "Airplanes")
|
||||
assert interest.valid?, "Expected interest to be valid, but was not. Interest should have a human object associated"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,14 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cases/helper"
|
||||
require "models/man"
|
||||
require "models/human"
|
||||
require "models/face"
|
||||
require "models/interest"
|
||||
require "models/speedometer"
|
||||
require "models/dashboard"
|
||||
|
||||
class PresenceValidationTest < ActiveRecord::TestCase
|
||||
class Boy < Man; end
|
||||
class Boy < Human; end
|
||||
|
||||
repair_validations(Boy)
|
||||
|
||||
|
2
activerecord/test/fixtures/essays.yml
vendored
2
activerecord/test/fixtures/essays.yml
vendored
@ -12,5 +12,5 @@ mary_stay_home:
|
||||
|
||||
steve_connecting_the_dots:
|
||||
name: Connecting The Dots
|
||||
writer_type: Man
|
||||
writer_type: Human
|
||||
writer_id: Steve
|
||||
|
6
activerecord/test/fixtures/faces.yml
vendored
6
activerecord/test/fixtures/faces.yml
vendored
@ -1,11 +1,11 @@
|
||||
trusting:
|
||||
description: trusting
|
||||
man: gordon
|
||||
human: gordon
|
||||
|
||||
weather_beaten:
|
||||
description: weather beaten
|
||||
man: steve
|
||||
human: steve
|
||||
|
||||
confused:
|
||||
description: confused
|
||||
polymorphic_man: gordon (Man)
|
||||
polymorphic_human: gordon (Human)
|
||||
|
14
activerecord/test/fixtures/interests.yml
vendored
14
activerecord/test/fixtures/interests.yml
vendored
@ -1,33 +1,33 @@
|
||||
trainspotting:
|
||||
topic: Trainspotting
|
||||
zine: staying_in
|
||||
man: gordon
|
||||
human: gordon
|
||||
|
||||
birdwatching:
|
||||
topic: Birdwatching
|
||||
zine: staying_in
|
||||
man: gordon
|
||||
human: gordon
|
||||
|
||||
stamp_collecting:
|
||||
topic: Stamp Collecting
|
||||
zine: staying_in
|
||||
man: gordon
|
||||
human: gordon
|
||||
|
||||
hunting:
|
||||
topic: Hunting
|
||||
zine: going_out
|
||||
man: steve
|
||||
human: steve
|
||||
|
||||
woodsmanship:
|
||||
topic: Woodsmanship
|
||||
zine: going_out
|
||||
man: steve
|
||||
human: steve
|
||||
|
||||
survival:
|
||||
topic: Survival
|
||||
zine: going_out
|
||||
man: steve
|
||||
human: steve
|
||||
|
||||
llama_wrangling:
|
||||
topic: Llama Wrangling
|
||||
polymorphic_man: gordon (Man)
|
||||
polymorphic_human: gordon (Human)
|
||||
|
@ -1,16 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Face < ActiveRecord::Base
|
||||
belongs_to :man, inverse_of: :face
|
||||
belongs_to :human, polymorphic: true
|
||||
belongs_to :polymorphic_man, polymorphic: true, inverse_of: :polymorphic_face
|
||||
belongs_to :human, inverse_of: :face
|
||||
belongs_to :super_human, polymorphic: true
|
||||
belongs_to :polymorphic_human, polymorphic: true, inverse_of: :polymorphic_face
|
||||
# Oracle identifier length is limited to 30 bytes or less, `polymorphic` renamed `poly`
|
||||
belongs_to :poly_man_without_inverse, polymorphic: true
|
||||
belongs_to :poly_human_without_inverse, polymorphic: true
|
||||
# These are "broken" inverse_of associations for the purposes of testing
|
||||
belongs_to :horrible_man, class_name: "Man", inverse_of: :horrible_face
|
||||
belongs_to :horrible_polymorphic_man, polymorphic: true, inverse_of: :horrible_polymorphic_face
|
||||
belongs_to :horrible_human, class_name: "Human", inverse_of: :horrible_face
|
||||
belongs_to :horrible_polymorphic_human, polymorphic: true, inverse_of: :horrible_polymorphic_face
|
||||
|
||||
validate do
|
||||
man
|
||||
human
|
||||
end
|
||||
end
|
||||
|
@ -1,28 +1,30 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Man < ActiveRecord::Base
|
||||
has_one :face, inverse_of: :man
|
||||
has_one :polymorphic_face, class_name: "Face", as: :polymorphic_man, inverse_of: :polymorphic_man
|
||||
has_one :polymorphic_face_without_inverse, class_name: "Face", as: :poly_man_without_inverse
|
||||
has_many :interests, inverse_of: :man
|
||||
class Human < ActiveRecord::Base
|
||||
self.table_name = "humans"
|
||||
|
||||
has_one :face, inverse_of: :human
|
||||
has_one :polymorphic_face, class_name: "Face", as: :polymorphic_human, inverse_of: :polymorphic_human
|
||||
has_one :polymorphic_face_without_inverse, class_name: "Face", as: :poly_human_without_inverse
|
||||
has_many :interests, inverse_of: :human
|
||||
has_many :interests_with_callbacks,
|
||||
class_name: "Interest",
|
||||
before_add: :add_called,
|
||||
after_add: :add_called,
|
||||
inverse_of: :man_with_callbacks
|
||||
inverse_of: :human_with_callbacks
|
||||
has_many :polymorphic_interests,
|
||||
class_name: "Interest",
|
||||
as: :polymorphic_man,
|
||||
inverse_of: :polymorphic_man
|
||||
as: :polymorphic_human,
|
||||
inverse_of: :polymorphic_human
|
||||
has_many :polymorphic_interests_with_callbacks,
|
||||
class_name: "Interest",
|
||||
as: :polymorphic_man,
|
||||
as: :polymorphic_human,
|
||||
before_add: :add_called,
|
||||
after_add: :add_called,
|
||||
inverse_of: :polymorphic_man
|
||||
inverse_of: :polymorphic_human
|
||||
# These are "broken" inverse_of associations for the purposes of testing
|
||||
has_one :dirty_face, class_name: "Face", inverse_of: :dirty_man
|
||||
has_many :secret_interests, class_name: "Interest", inverse_of: :secret_man
|
||||
has_one :dirty_face, class_name: "Face", inverse_of: :dirty_human
|
||||
has_many :secret_interests, class_name: "Interest", inverse_of: :secret_human
|
||||
has_one :mixed_case_monkey
|
||||
|
||||
attribute :add_callback_called, :boolean, default: false
|
||||
@ -32,5 +34,5 @@ def add_called(_interest)
|
||||
end
|
||||
end
|
||||
|
||||
class Human < Man
|
||||
class SuperHuman < Human
|
||||
end
|
@ -1,15 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Interest < ActiveRecord::Base
|
||||
belongs_to :man, inverse_of: :interests
|
||||
belongs_to :man_with_callbacks,
|
||||
class_name: "Man",
|
||||
foreign_key: :man_id,
|
||||
belongs_to :human, inverse_of: :interests
|
||||
belongs_to :human_with_callbacks,
|
||||
class_name: "Human",
|
||||
foreign_key: :human_id,
|
||||
inverse_of: :interests_with_callbacks
|
||||
belongs_to :polymorphic_man, polymorphic: true, inverse_of: :polymorphic_interests
|
||||
belongs_to :polymorphic_man_with_callbacks,
|
||||
foreign_key: :polymorphic_man_id,
|
||||
foreign_type: :polymorphic_man_type,
|
||||
belongs_to :polymorphic_human, polymorphic: true, inverse_of: :polymorphic_interests
|
||||
belongs_to :polymorphic_human_with_callbacks,
|
||||
foreign_key: :polymorphic_human_id,
|
||||
foreign_type: :polymorphic_human_type,
|
||||
polymorphic: true,
|
||||
inverse_of: :polymorphic_interests_with_callbacks
|
||||
belongs_to :zine, inverse_of: :interests
|
||||
|
@ -1,5 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class MixedCaseMonkey < ActiveRecord::Base
|
||||
belongs_to :man
|
||||
belongs_to :human
|
||||
end
|
||||
|
@ -1009,27 +1009,27 @@
|
||||
create_table(t, force: true) { }
|
||||
end
|
||||
|
||||
create_table :men, force: true do |t|
|
||||
create_table :humans, force: true do |t|
|
||||
t.string :name
|
||||
end
|
||||
|
||||
create_table :faces, force: true do |t|
|
||||
t.string :description
|
||||
t.integer :man_id
|
||||
t.integer :polymorphic_man_id
|
||||
t.string :polymorphic_man_type
|
||||
t.integer :poly_man_without_inverse_id
|
||||
t.string :poly_man_without_inverse_type
|
||||
t.integer :horrible_polymorphic_man_id
|
||||
t.string :horrible_polymorphic_man_type
|
||||
t.references :human, polymorphic: true, index: false
|
||||
t.integer :human_id
|
||||
t.integer :polymorphic_human_id
|
||||
t.string :polymorphic_human_type
|
||||
t.integer :poly_human_without_inverse_id
|
||||
t.string :poly_human_without_inverse_type
|
||||
t.integer :horrible_polymorphic_human_id
|
||||
t.string :horrible_polymorphic_human_type
|
||||
t.references :super_human, polymorphic: true, index: false
|
||||
end
|
||||
|
||||
create_table :interests, force: true do |t|
|
||||
t.string :topic
|
||||
t.integer :man_id
|
||||
t.integer :polymorphic_man_id
|
||||
t.string :polymorphic_man_type
|
||||
t.integer :human_id
|
||||
t.integer :polymorphic_human_id
|
||||
t.string :polymorphic_human_type
|
||||
t.integer :zine_id
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user