前提・実現したいこと
Rails初心者です。
現在RailsでWebアプリケーションを作成し、Rspecでテストを行なっているのですが、Active Storageの画像が、Rspecのテストで通らず困っています。
お分かりになる方がいらっしゃいましたら、ご回答いただけると非常に助かります。
発生している問題・エラーメッセージ
bundle exec rspecコマンド後 ActiveSupport::MessageVerifier::InvalidSignature:
spec/models/user_spec.rb
require 'rails_helper' describe User do describe '#create' do context 'can not save' do it 'is valid with a name,avatar,profile, email, password, password_confirmation' do expect(valid_user.avatar).to be_attached expect(build(:user)).to be_valid end it 'is valid with a password that has more than 6 characters' do user = build(:user, password: '1234567', password_confirmation: '1234567') expect(user).to be_valid end end end end
該当のソースコード
spec/factories/user.rb
1FactoryBot.define do 2 3 factory :user do 4 name {"田中太郎"} 5 password {"123456"} 6 password_confirmation {"123456"} 7 profile {"第一営業所属"} 8 sequence(:email) {Faker::Internet.email} 9 avatar {"IMG_1969.JPG"} 10 end 11end
app/models/user.rb
has_one_attached :avatar
app/models/application_record.rb
class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end
app/models/attacehd_validator.rb
class AttachedValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) record.errors.add(attribute, :attached, options) unless value.attached? end end
補足情報(FW/ツールのバージョンなど)
Active Storageにはバリデーションがかかっています。
Ruby version 2.5.1
Rails version 5.2.3
あなたの回答
tips
プレビュー