Skip to content

Instantly share code, notes, and snippets.

@intrip
Created May 14, 2021 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save intrip/0cf590c258a36c0e0fd4cf638354828c to your computer and use it in GitHub Desktop.
Save intrip/0cf590c258a36c0e0fd4cf638354828c to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem "rails", "~> 6.1"
gem "sqlite3"
end
require "active_record/railtie"
require "active_storage/engine"
require "tmpdir"
require "minitest/autorun"
class TestApp < Rails::Application
config.root = __dir__
config.hosts << "example.org"
config.eager_load = false
config.session_store :cookie_store, key: "cookie_store_key"
secrets.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
config.active_storage.service = :local
config.active_storage.service_configurations = {
local: {
root: Dir.tmpdir,
service: "Disk"
}
}
end
ENV["DATABASE_URL"] = "sqlite3::memory:"
Rails.application.initialize!
require ActiveStorage::Engine.root.join("db/migrate/20170806125915_create_active_storage_tables.rb").to_s
ActiveRecord::Schema.define do
CreateActiveStorageTables.new.change
create_table :users, force: true do |t|
t.string :name
t.references :profile
end
end
class User < ActiveRecord::Base
has_one_attached :image
end
class BugTest < Minitest::Test
def test_duplicate_attachments_with_after_save
assert_raises { User.new.as_json(include: [:image]) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment