未验证 提交 c93f3f02 编写于 作者: E Eileen M. Uchitelle 提交者: GitHub

Merge pull request #40046 from composerinteralia/renaming-man

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