tests: fix null uploader_ip_addr exceptions in create(:post).
Caused by a change in FactoryBot 5. Associations in factories are now constructed using the same strategy as the base object, meaning that using `build` to construct an object will also construct the associations using `build`. This meant that overriding `create` to do `build` + `save` broke the way that associations were constructed. https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#associations
This commit is contained in:
@@ -3,7 +3,7 @@ FactoryBot.define do
|
|||||||
sequence :md5 do |n|
|
sequence :md5 do |n|
|
||||||
n.to_s
|
n.to_s
|
||||||
end
|
end
|
||||||
uploader :factory => :user
|
uploader
|
||||||
uploader_ip_addr {"127.0.0.1"}
|
uploader_ip_addr {"127.0.0.1"}
|
||||||
tag_string {"tag1 tag2"}
|
tag_string {"tag1 tag2"}
|
||||||
tag_count {2}
|
tag_count {2}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory(:user, aliases: [:creator, :updater]) do
|
factory(:user, aliases: [:creator, :updater, :uploader]) do
|
||||||
sequence :name do |n|
|
sequence :name do |n|
|
||||||
"user#{n}"
|
"user#{n}"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -26,13 +26,6 @@ Shoulda::Matchers.configure do |config|
|
|||||||
end
|
end
|
||||||
|
|
||||||
module TestHelpers
|
module TestHelpers
|
||||||
def create(factory_bot_model, params = {})
|
|
||||||
record = FactoryBot.build(factory_bot_model, params)
|
|
||||||
record.save
|
|
||||||
raise ActiveRecord::RecordInvalid.new(record) if record.errors.any?
|
|
||||||
record
|
|
||||||
end
|
|
||||||
|
|
||||||
def as(user, &block)
|
def as(user, &block)
|
||||||
CurrentUser.as(user, &block)
|
CurrentUser.as(user, &block)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user