You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a basic object in my application I use to import data from an external source. The factory I use for testing these objects looks like this:
factory :imported_object do
sequence(:source_id) { |n| "id_#{n}" }
source { 'default_source' }
end
Note: These are just plain text attributes. They are not a reference to some ruby object, or rails model. I have no factories or anything called source
Part of what I wanted to test was that the source_id attribute was required to be unique onlyfor particular sources, but I discovered that this does not work:
I suspect FactoryBot is trying to force these attributes to act like ActiveRecord associations, since rewriting my project to use "source_name" instead of "source" resolves the issue.
However, I probably shouldn't have to rewrite a project to start using FactoryBot, so hopefully there's something that could be done to fix this - or at the very least throw an error when you try to do it, saying FactoryBot doesn't support it (so I could have changed my product much sooner in this process)
I might look at this myself eventually, but it will probably take a week or two
The text was updated successfully, but these errors were encountered:
Since we already have another issue to track this problem, I'm going to close this issue for now. If this turns out to be a different problem let me know and we can reopen the issue.
I have a basic object in my application I use to import data from an external source. The factory I use for testing these objects looks like this:
Note: These are just plain text attributes. They are not a reference to some ruby object, or rails model. I have no factories or anything called
source
Part of what I wanted to test was that the source_id attribute was required to be unique onlyfor particular sources, but I discovered that this does not work:
imported_object = build(:imported_object, source: '5', source_id: 'different_source')
Attempting to build (or create) that object results in
#<ScanResult id: nil, source_id: nil, source: nil %>
which is not terribly useful for my tests.
I suspect FactoryBot is trying to force these attributes to act like ActiveRecord associations, since rewriting my project to use "source_name" instead of "source" resolves the issue.
However, I probably shouldn't have to rewrite a project to start using FactoryBot, so hopefully there's something that could be done to fix this - or at the very least throw an error when you try to do it, saying FactoryBot doesn't support it (so I could have changed my product much sooner in this process)
I might look at this myself eventually, but it will probably take a week or two
The text was updated successfully, but these errors were encountered: