Last active
September 21, 2018 07:45
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hoge < ApplicationRecord | |
. | |
. | |
. | |
has_one_attached :attached | |
. | |
. | |
. | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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