Skip to content

Instantly share code, notes, and snippets.

@h-sakano
Last active September 21, 2018 07:45
Show Gist options
  • Save h-sakano/50092b1c17fe8ddc0bbe5382fb8587a4 to your computer and use it in GitHub Desktop.
Save h-sakano/50092b1c17fe8ddc0bbe5382fb8587a4 to your computer and use it in GitHub Desktop.
ActiveStorageを使用したモデルに関連するRequest SpecでActiveSupport::MessageVerifier::InvalidSignatureが発生する問題の解決策 ref: https://qiita.com/h-sakano/items/fc297f91a7bafc0b4d6d
- attached { fixture_file_upload Rails.root.join('spec', 'fixtures', 'files', 'test.jpg'), 'image/jpg' }
+
+ after(:build) do |hoge|
+ hoge.attached = fixture_file_upload(Rails.root.join('spec', 'fixtures', 'files', 'test.jpg'), 'image/jpg')
+ end
class Hoge < ApplicationRecord
.
.
.
has_one_attached :attached
.
.
.
end
FactoryBot.define do
factory :hoge do
name { Faker::Name.name }
.
.
.
attached { fixture_file_upload(Rails.root.join('spec', 'fixtures', 'files', 'test.jpg'), 'image/jpg') }
.
.
.
trait :edit do
name "HOGE"
end
end
end
FactoryBot.define do
factory :hoge do
name { Faker::Name.name }
.
.
.
attached { fixture_file_upload(Rails.root.join('spec', 'fixtures', 'files', 'test.jpg'), 'image/jpg') }
.
.
.
trait :edit do
name "HOGE"
end
end
end
require 'rails_helper'
RSpec.describe "Hogehoges", type: :request do
.
.
.
describe 'PUT #update' do
let!(:hoge) { create(:hoge) }
context 'when sign_in admin user' do
before do
sign_in @admin_user
end
it 'can update name' do
# テストが失敗したので、例外の内容を出力してみると、「ActiveSupport::MessageVerifier::InvalidSignature」だった
expect do
put bad_report_url bad_report, params: { bad_report: attributes_for(:bad_report, :edit) }
end.to change { BadReport.find(hoge.id).name }.from(hoge.name).to("HOGE")
end
end
end
.
.
.
end
require 'rails_helper'
RSpec.describe "Hoges", type: :request do
.
.
.
describe 'PUT #update' do
let!(:hoge) { create(:hoge) }
context 'when sign_in admin user' do
before do
sign_in @admin_user
end
it 'can update name' do
# テストが失敗したので、例外の内容を出力してみると、「ActiveSupport::MessageVerifier::InvalidSignature」だった
expect do
put bad_report_url bad_report, params: { bad_report: attributes_for(:bad_report, :edit) }
end.to change { BadReport.find(hoge.id).name }.from(hoge.name).to("HOGE")
end
end
end
.
.
.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment