Я только что переключился на использование ActiveStorage на рельсах 5.1.4, и я новичок в TDD и изо всех сил пытаюсь выяснить, как тестировать модель, которая has_one_attached :avatar
require 'rails_helper'
RSpec.describe User, :type => :model do
let (:valid_user) { FactoryBot.build(:user) }
describe "Upload avatar" do
context "with a valid image" do
it "saves the image" do
valid_user.save!
saved_file = valid_user.avatar.attach(io: File.open("/home/ubuntu/workspace/spec/fixtures/files/avatar.jpg"), filename: "face.jpg", content_type: "image/jpg")
expect(saved_file).to be_an_instance_of(ActiveStorage::Attachment::One)
end
end
end
end
Но я получаю следующую ошибку:
Failures:
1) User Upload avatar with a valid image saves the image
Failure/Error:
saved_file = valid_user.avatar.attach(io: File.open("/home/ubuntu/workspace/spec/fixtures/files/avatar.jpg"), filename: "face.jpg",
content_type: "image/jpg")
NoMethodError:
undefined method `upload' for nil:NilClass
Did you mean? load
# /usr/local/rvm/gems/ruby-2.3.4/gems/activestorage-0.1/lib/active_storage/blob.rb:48:in `upload'
# /usr/local/rvm/gems/ruby-2.3.4/gems/activestorage-0.1/lib/active_storage/blob.rb:21:in `block in build_after_upload'
# /usr/local/rvm/gems/ruby-2.3.4/gems/activestorage-0.1/lib/active_storage/blob.rb:16:in `tap'
# /usr/local/rvm/gems/ruby-2.3.4/gems/activestorage-0.1/lib/active_storage/blob.rb:16:in `build_after_upload'
# /usr/local/rvm/gems/ruby-2.3.4/gems/activestorage-0.1/lib/active_storage/blob.rb:26:in `create_after_upload!'
# /usr/local/rvm/gems/ruby-2.3.4/gems/activestorage-0.1/lib/active_storage/attached.rb:25:in `create_blob_from'
# /usr/local/rvm/gems/ruby-2.3.4/gems/activestorage-0.1/lib/active_storage/attached/one.rb:9:in `attach'
# ./spec/models/user_spec.rb:47:in `block (4 levels) in <top (required)>'
Любые подсказки?