Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RSpec ActiveStorage:错误ActiveRecord::RecordNotFound:无法';找不到带有';id';_Ruby On Rails_Rspec_Rails Activestorage - Fatal编程技术网

Ruby on rails RSpec ActiveStorage:错误ActiveRecord::RecordNotFound:无法';找不到带有';id';

Ruby on rails RSpec ActiveStorage:错误ActiveRecord::RecordNotFound:无法';找不到带有';id';,ruby-on-rails,rspec,rails-activestorage,Ruby On Rails,Rspec,Rails Activestorage,嗨,伙计们,我能得到一些帮助来找出我的RSpec测试出了什么问题吗。我在互联网上到处找,没有找到任何能说明我为什么会犯这个错误的原因 我要做的是测试一个实例变量是否有来自数据库的数据。当测试到达创建活动记录和活动存储Blob的制造商时,就会发生错误。我已经添加了数据库清理器gem,但不确定是否有什么东西弄乱了它,或者在使用RSpec、活动存储和DBcleaner时遗漏了什么 奇怪的是,我有另一个测试,也创建了相同的制造对象,我没有得到错误,你会看到下面。如果我在下面注释掉测试,那么其他测试运行得

嗨,伙计们,我能得到一些帮助来找出我的RSpec测试出了什么问题吗。我在互联网上到处找,没有找到任何能说明我为什么会犯这个错误的原因

我要做的是测试一个实例变量是否有来自数据库的数据。当测试到达创建活动记录和活动存储Blob的制造商时,就会发生错误。我已经添加了数据库清理器gem,但不确定是否有什么东西弄乱了它,或者在使用RSpec、活动存储和DBcleaner时遗漏了什么

奇怪的是,我有另一个测试,也创建了相同的制造对象,我没有得到错误,你会看到下面。如果我在下面注释掉测试,那么其他测试运行得很好。任何帮助都将不胜感激。在这个问题上被困了几个小时:$

更新:我试图调查图形制造商运行后发生的情况,以及我使用附件查看附件时发生的情况?方法每一份文件都附呈。所有四个文件都作为附件返回。我原以为清理器会有问题,所以我添加了rails\u助手,以便在每次测试完成后清理所有文件

config.after(:each) do
 DatabaseCleaner.clean
 ActiveStorage::Attachment.all.each { |attachment| attachment.purge }
end 
这将在每次测试运行后获取所有附件并删除附件和blob。但这并没有起到任何作用。仍然不确定发生了什么

任何帮助都将不胜感激

谢谢:)

错误:

1) Dashboard::VendorDashboardsController GET sales Authenticated assigns instance variable with purchases for that store
 Failure/Error: graphic =  Fabricate(:graphic, store:store)
 
 ActiveRecord::RecordNotFound:
   Couldn't find ActiveStorage::Blob with 'id'=1
 # ./spec/controllers/Dashboard/vendor_dashboards_controller_spec.rb:26:in `block (4 levels) in <top (required)>'
制造者

Fabricator(:graphic)do

store

name "Icon Set"

language "Spanish"

standard_license_price 10.00

business_license_price 100.00

reviewed true

status "Approved"

files_included "PSD, CSS"

category "Vectors"

subject "Characters"

support "3 Month Support"

layered true

high_resolution true

pixel_dimensions "2000x2000"

software_required "Illustrator"

thumbnail_image ActiveStorage::Blob.create_after_upload!(io: File.open(Rails.root.join('spec', 'support', 'assets', 'graphics', 'Advertise.png'), 'rb'), filename: 'Advertise.png',content_type: 'image/png').signed_id

main_image ActiveStorage::Blob.create_after_upload!(io: File.open(Rails.root.join('spec', 'support', 'assets', 'graphics', 'Chat.png'), 'rb'), filename: 'Chat.png',content_type: 'image/png').signed_id

product_images ActiveStorage::Blob.create_after_upload!(io: File.open(Rails.root.join('spec', 'support', 'assets', 'graphics', 'Chat.png'), 'rb'), filename: 'Chat.png',content_type: 'image/png').signed_id

graphic_asset_files ActiveStorage::Blob.create_after_upload!(io: File.open(Rails.root.join('spec', 'support', 'assets', 'graphics', 'test_illustrations.zip'), 'rb'), filename: 'test_illustrations.zip',content_type: 'application/zip').signed_id

description "This is the best graphic design"

end
RAILS帮助文件

# This file is copied to spec/ when you run 'rails generate rspec:install'

require 'spec_helper'

ENV['RAILS_ENV'] ||= 'test'

require File.expand_path('../config/environment', __dir__)

# Prevent database truncation if the environment is production

abort("The Rails environment is running in production mode!") if Rails.env.production?

require 'rspec/rails'



begin

ActiveRecord::Migration.maintain_test_schema!

rescue ActiveRecord::PendingMigrationError => e

puts e.to_s.strip

exit 1

end

RSpec.configure do |config|

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures

config.fixture_path = "#{::Rails.root}/spec/fixtures"



config.use_transactional_fixtures = false



config.infer_spec_type_from_file_location!



# Filter lines from Rails gems in backtraces.

config.filter_rails_from_backtrace!

config.include Rails.application.routes.url_helpers

config.include Sorcery::TestHelpers::Rails::Controller, type: :controller

config.include Sorcery::TestHelpers::Rails::Integration, type: :feature







config.before(:suite) do

DatabaseCleaner.clean_with(:truncation)

end



config.before(:each) do

DatabaseCleaner.strategy = :truncation

end



config.before(:each, :js => true) do

DatabaseCleaner.strategy = :truncation

end



config.before(:each) do

DatabaseCleaner.start

end



config.after(:each) do

DatabaseCleaner.clean

end





Shoulda::Matchers.configure do |config|

config.integrate do |with|

with.test_framework :rspec

with.library :rails

end

end



end

工厂的问题是,属性值在文件加载时只计算一次。然后,它们被所有对象重用

thumbnail_image ActiveStorage::Blob.create_after_upload!(...).signed_id
在这里用一个街区

thumbnail_image { ActiveStorage::Blob.create_after_upload!(...).signed_id }

这样,对于每个新制作的对象,您将获得自己的blob。

工厂的问题是,属性值在文件加载时只计算一次。然后,它们被所有对象重用

thumbnail_image ActiveStorage::Blob.create_after_upload!(...).signed_id
在这里用一个街区

thumbnail_image { ActiveStorage::Blob.create_after_upload!(...).signed_id }
这样,对于每个新制作的对象,您将获得自己的blob