1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/spec/factory_bot/aliases_spec.rb

29 lines
943 B
Ruby
Raw Permalink Normal View History

describe FactoryBot, "aliases" do
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
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
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
end
2009-04-11 11:27:23 -04:00
describe FactoryBot, "after defining an alias" do
it "the list of aliases should include a variant with no suffix at all, and one with an '_id' suffix" do
FactoryBot.aliases << [/(.*)_suffix/, '\1']
aliases = FactoryBot.aliases_for(:test_suffix)
2009-04-11 11:27:23 -04:00
expect(aliases).to include(:test, :test_suffix_id)
end
2009-04-11 11:27:23 -04:00
end