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:
evazion
2019-08-04 11:12:55 -05:00
parent fc4fa9dc6c
commit 7c8c4e9f82
3 changed files with 2 additions and 9 deletions

View File

@@ -3,7 +3,7 @@ FactoryBot.define do
sequence :md5 do |n|
n.to_s
end
uploader :factory => :user
uploader
uploader_ip_addr {"127.0.0.1"}
tag_string {"tag1 tag2"}
tag_count {2}

View File

@@ -1,5 +1,5 @@
FactoryBot.define do
factory(:user, aliases: [:creator, :updater]) do
factory(:user, aliases: [:creator, :updater, :uploader]) do
sequence :name do |n|
"user#{n}"
end

View File

@@ -26,13 +26,6 @@ Shoulda::Matchers.configure do |config|
end
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)
CurrentUser.as(user, &block)
end