Skip to content

Instantly share code, notes, and snippets.

@GBH
Created November 24, 2017 03:37
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 GBH/1efc6c2511765730e647f539aedc4203 to your computer and use it in GitHub Desktop.
Save GBH/1efc6c2511765730e647f539aedc4203 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
gem "bundler", "< 1.16"
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
gem "sqlite3"
end
require "active_record"
require "action_controller/railtie"
require "active_storage/engine"
require "minitest/autorun"
require "logger"
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
end
create_table :active_storage_blobs do |t|
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
t.bigint :byte_size, null: false
t.string :checksum, null: false
t.datetime :created_at, null: false
t.index [ :key ], unique: true
end
create_table :active_storage_attachments do |t|
t.string :name, null: false
t.references :record, null: false, polymorphic: true, index: false
t.references :blob, null: false
t.datetime :created_at, null: false
t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
end
end
class Post < ActiveRecord::Base
has_one_attached :file
end
class BugTest < Minitest::Test
def url_for(attachment)
ApplicationController.render(
inline: "<%= url_for(@attachment) %>",
assigns: {attachment: attachment}
)
end
def test_this
post = Post.create!
payload = {
io: "iamafile",
filename: "test.txt",
content_type: "text/plain"
}
post.file.attach(payload)
assert_equal "", url_for(post.file)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment