Prevent CI failure caused by factories using duplicate #name attributes

This commit is contained in:
Ryan Lue 2019-01-25 14:28:15 +01:00 committed by Thorsten Eckel
parent a97e959119
commit db69e55158
3 changed files with 41 additions and 3 deletions

View file

@ -1,5 +1,17 @@
FactoryBot.define do FactoryBot.define do
factory :'history/type', aliases: %i[history_type] do factory :'history/type', aliases: %i[history_type] do
name { Faker::Verb.past_participle } name do
# The following line ensures that the name generated by Faker
# does not conflict with any existing names in the DB.
# There's a special syntax for this
# (Faker::Verb.unique.exclude(:past_participle, [], History::Type.pluck(:name)),
# but it's not available yet in the current release of Faker (1.9.1).
Faker::Verb.unique
.instance_variable_get(:@previous_results)
.dig([:past_participle, []])
.merge(History::Type.pluck(:name))
Faker::Verb.unique.past_participle
end
end end
end end

View file

@ -1,6 +1,19 @@
FactoryBot.define do FactoryBot.define do
factory :'ticket/state', aliases: %i[ticket_state] do factory :'ticket/state', aliases: %i[ticket_state] do
name { Faker::Verb.past_participle } name do
# The following line ensures that the name generated by Faker
# does not conflict with any existing names in the DB.
# There's a special syntax for this
# (Faker::Verb.unique.exclude(:past_participle, [], Ticket::State.pluck(:name)),
# but it's not available yet in the current release of Faker (1.9.1).
Faker::Verb.unique
.instance_variable_get(:@previous_results)
.dig([:past_participle, []])
.merge(Ticket::State.pluck(:name))
Faker::Verb.unique.past_participle
end
association :state_type, factory: :'ticket/state_type' association :state_type, factory: :'ticket/state_type'
updated_by_id { 1 } updated_by_id { 1 }
created_by_id { 1 } created_by_id { 1 }

View file

@ -1,6 +1,19 @@
FactoryBot.define do FactoryBot.define do
factory :'ticket/state_type', aliases: %i[ticket_state_type] do factory :'ticket/state_type', aliases: %i[ticket_state_type] do
name { Faker::Verb.past_participle } name do
# The following line ensures that the name generated by Faker
# does not conflict with any existing names in the DB.
# There's a special syntax for this
# (Faker::Verb.unique.exclude(:past_participle, [], Ticket::StateType.pluck(:name)),
# but it's not available yet in the current release of Faker (1.9.1).
Faker::Verb.unique
.instance_variable_get(:@previous_results)
.dig([:past_participle, []])
.merge(Ticket::StateType.pluck(:name))
Faker::Verb.unique.past_participle
end
updated_by_id { 1 } updated_by_id { 1 }
created_by_id { 1 } created_by_id { 1 }
end end