2017-10-20 15:20:28 -04:00
|
|
|
describe FactoryBot, "aliases" do
|
2019-10-15 12:42:52 -04:00
|
|
|
it "for an attribute should include the original attribute and a version suffixed with '_id'" do
|
|
|
|
aliases = FactoryBot.aliases_for(:test)
|
|
|
|
|
|
|
|
expect(aliases).to include(:test, :test_id)
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2019-10-15 12:42:52 -04:00
|
|
|
it "for a foreign key should include both the suffixed and un-suffixed variants" do
|
|
|
|
aliases = FactoryBot.aliases_for(:test_id)
|
|
|
|
|
|
|
|
expect(aliases).to include(:test, :test_id)
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2019-10-15 12:42:52 -04:00
|
|
|
it "for an attribute which starts with an underscore should not include a non-underscored version" do
|
|
|
|
aliases = FactoryBot.aliases_for(:_id)
|
|
|
|
|
|
|
|
expect(aliases).not_to include(:id)
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
2011-08-13 01:03:12 -04:00
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2017-10-20 15:20:28 -04:00
|
|
|
describe FactoryBot, "after defining an alias" do
|
2019-10-15 12:42:52 -04:00
|
|
|
it "the list of aliases should include a variant with no suffix at all, and one with an '_id' suffix" do
|
2017-10-20 15:20:28 -04:00
|
|
|
FactoryBot.aliases << [/(.*)_suffix/, '\1']
|
2019-10-15 12:42:52 -04:00
|
|
|
aliases = FactoryBot.aliases_for(:test_suffix)
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2019-10-15 12:42:52 -04:00
|
|
|
expect(aliases).to include(:test, :test_suffix_id)
|
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|