-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbug_report_template.rb
72 lines (53 loc) · 1.78 KB
/
bug_report_template.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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', '~> 7.1'
gem 'sqlite3'
gem 'active_storage_base64', '~> 3.0.0'
end
require 'active_record/railtie'
require 'active_storage/engine'
require 'tmpdir'
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
end
class User < ActiveRecord::Base
include ActiveStorageSupport::SupportForBase64
has_one_base64_attached :avatar
end
require 'minitest/autorun'
class BugTest < Minitest::Test
def test_attachment
filename = 'generic-logo.png'
file = File.open(File.expand_path(File.join(File.dirname(__FILE__), 'spec', 'fixtures', filename))).read
data = "data:image/png;base64,#{Base64.encode64(file)}"
user = User.create
user.avatar.attach(data: data, filename: filename)
user.save!
assert_equal(filename, user.avatar.filename.to_s)
assert_equal(File.open(ActiveStorage::Blob.service.send(:path_for, user.avatar.key)).read, file)
end
end