Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Introduce the Dummy. #70

Merged
merged 9 commits into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
.byebug_history
test/dummy/db/*.sqlite3
test/dummy/db/*.sqlite3-journal
test/dummy/log/*.log
test/dummy/tmp/
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
resolve("ActiveStorage::Variant") { |variant| route_for(:rails_variant, variant) }


get "/rails/active_storage/disk/:encoded_key/*filename" => "active_storage/disk#show", as: :rails_disk_blob
put "/rails/active_storage/disk/:encoded_token" => "active_storage/disk#update", as: :update_rails_disk_blob
get "/rails/active_storage/disk/:encoded_key/*filename" => "active_storage/disk#show", as: :rails_disk_service
put "/rails/active_storage/disk/:encoded_token" => "active_storage/disk#update", as: :update_rails_disk_service
post "/rails/active_storage/direct_uploads" => "active_storage/direct_uploads#create", as: :rails_direct_uploads
end
4 changes: 2 additions & 2 deletions lib/active_storage/service/disk_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def url(key, expires_in:, disposition:, filename:, content_type:)

generated_url =
if defined?(Rails.application)
Rails.application.routes.url_helpers.rails_disk_blob_path \
Rails.application.routes.url_helpers.rails_disk_service_path \
verified_key_with_expiration,
disposition: disposition, filename: filename, content_type: content_type
else
Expand Down Expand Up @@ -87,7 +87,7 @@ def url_for_direct_upload(key, expires_in:, content_type:, content_length:, chec

generated_url =
if defined?(Rails.application)
Rails.application.routes.url_helpers.update_rails_disk_blob_path verified_token_with_expiration
Rails.application.routes.url_helpers.update_rails_disk_service_path verified_token_with_expiration
else
"/rails/active_storage/disk/#{verified_token_with_expiration}"
end
Expand Down
36 changes: 12 additions & 24 deletions test/controllers/direct_uploads_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
require "test_helper"
require "database/setup"

require "active_storage/direct_uploads_controller"

if SERVICE_CONFIGURATIONS[:s3]
class ActiveStorage::S3DirectUploadsControllerTest < ActionController::TestCase
class ActiveStorage::S3DirectUploadsControllerTest < ActionDispatch::IntegrationTest
setup do
@routes = Routes
@controller = ActiveStorage::DirectUploadsController.new

@old_service = ActiveStorage::Blob.service
ActiveStorage::Blob.service = ActiveStorage::Service.configure(:s3, SERVICE_CONFIGURATIONS)
end
Expand All @@ -18,10 +13,10 @@ class ActiveStorage::S3DirectUploadsControllerTest < ActionController::TestCase
end

test "creating new direct upload" do
post :create, params: { blob: {
filename: "hello.txt", byte_size: 6, checksum: Digest::MD5.base64digest("Hello"), content_type: "text/plain" } }
post rails_direct_uploads_url, params: { blob: {
filename: "hello.txt", byte_size: 6, checksum: Digest::MD5.base64digest("Hello"), content_type: "text/plain" } }

JSON.parse(@response.body).tap do |details|
response.parsed_body.tap do |details|
assert_match(/#{SERVICE_CONFIGURATIONS[:s3][:bucket]}\.s3.(\S+)?amazonaws\.com/, details["upload_to_url"])
assert_equal "hello.txt", ActiveStorage::Blob.find_signed(details["signed_blob_id"]).filename.to_s
end
Expand All @@ -32,10 +27,8 @@ class ActiveStorage::S3DirectUploadsControllerTest < ActionController::TestCase
end

if SERVICE_CONFIGURATIONS[:gcs]
class ActiveStorage::GCSDirectUploadsControllerTest < ActionController::TestCase
class ActiveStorage::GCSDirectUploadsControllerTest < ActionDispatch::IntegrationTest
setup do
@routes = Routes
@controller = ActiveStorage::DirectUploadsController.new
@config = SERVICE_CONFIGURATIONS[:gcs]

@old_service = ActiveStorage::Blob.service
Expand All @@ -47,10 +40,10 @@ class ActiveStorage::GCSDirectUploadsControllerTest < ActionController::TestCase
end

test "creating new direct upload" do
post :create, params: { blob: {
filename: "hello.txt", byte_size: 6, checksum: Digest::MD5.base64digest("Hello"), content_type: "text/plain" } }
post rails_direct_uploads_url, params: { blob: {
filename: "hello.txt", byte_size: 6, checksum: Digest::MD5.base64digest("Hello"), content_type: "text/plain" } }

JSON.parse(@response.body).tap do |details|
@response.parsed_body.tap do |details|
assert_match %r{storage\.googleapis\.com/#{@config[:bucket]}}, details["upload_to_url"]
assert_equal "hello.txt", ActiveStorage::Blob.find_signed(details["signed_blob_id"]).filename.to_s
end
Expand All @@ -60,17 +53,12 @@ class ActiveStorage::GCSDirectUploadsControllerTest < ActionController::TestCase
puts "Skipping GCS Direct Upload tests because no GCS configuration was supplied"
end

class ActiveStorage::DiskDirectUploadsControllerTest < ActionController::TestCase
setup do
@routes = Routes
@controller = ActiveStorage::DirectUploadsController.new
end

class ActiveStorage::DiskDirectUploadsControllerTest < ActionDispatch::IntegrationTest
test "creating new direct upload" do
post :create, params: { blob: {
filename: "hello.txt", byte_size: 6, checksum: Digest::MD5.base64digest("Hello"), content_type: "text/plain" } }
post rails_direct_uploads_url, params: { blob: {
filename: "hello.txt", byte_size: 6, checksum: Digest::MD5.base64digest("Hello"), content_type: "text/plain" } }

JSON.parse(@response.body).tap do |details|
@response.parsed_body.tap do |details|
assert_match /rails\/active_storage\/disk/, details["upload_to_url"]
assert_equal "hello.txt", ActiveStorage::Blob.find_signed(details["signed_blob_id"]).filename.to_s
end
Expand Down
37 changes: 19 additions & 18 deletions test/controllers/disk_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
require "test_helper"
require "database/setup"

require "active_storage/disk_controller"

class ActiveStorage::DiskControllerTest < ActionController::TestCase
setup do
@routes = Routes
@controller = ActiveStorage::DiskController.new
end

class ActiveStorage::DiskControllerTest < ActionDispatch::IntegrationTest
test "showing blob inline" do
blob = create_blob

get :show, params: { filename: blob.filename, encoded_key: ActiveStorage.verifier.generate(blob.key, expires_in: 5.minutes, purpose: :blob_key) }
assert_equal "inline; filename=\"#{blob.filename}\"", @response.headers["Content-Disposition"]
get rails_disk_service_url(
filename: "hello.txt",
content_type: blob.content_type,
encoded_key: ActiveStorage.verifier.generate(blob.key, expires_in: 5.minutes, purpose: :blob_key)
)

assert_equal "inline; filename=\"#{blob.filename.base}\"", @response.headers["Content-Disposition"]
assert_equal "text/plain", @response.headers["Content-Type"]
end

test "showing blob as attachment" do
test "sending blob as attachment" do
blob = create_blob

get :show, params: { filename: blob.filename, encoded_key: ActiveStorage.verifier.generate(blob.key, expires_in: 5.minutes, purpose: :blob_key), disposition: :attachment }
assert_equal "attachment; filename=\"#{blob.filename}\"", @response.headers["Content-Disposition"]
get rails_disk_service_url(
filename: blob.filename,
content_type: blob.content_type,
encoded_key: ActiveStorage.verifier.generate(blob.key, expires_in: 5.minutes, purpose: :blob_key),
disposition: :attachment
)

assert_equal "attachment; filename=\"#{blob.filename.base}\"", @response.headers["Content-Disposition"]
assert_equal "text/plain", @response.headers["Content-Type"]
end

test "directly uploading blob with integrity" do
data = "Something else entirely!"
blob = create_blob_before_direct_upload byte_size: data.size, checksum: Digest::MD5.base64digest(data)

token = ActiveStorage.verifier.generate(
{
key: blob.key,
Expand All @@ -40,9 +43,8 @@ class ActiveStorage::DiskControllerTest < ActionController::TestCase
purpose: :blob_token
)

@request.content_type = "text/plain"
put update_rails_disk_service_url(encoded_token: token), params: data, headers: { "Content-Type" => "text/plain" }

put :update, body: data, params: { encoded_token: token }
assert_response :no_content
assert_equal data, blob.download
end
Expand All @@ -62,9 +64,8 @@ class ActiveStorage::DiskControllerTest < ActionController::TestCase
purpose: :blob_token
)

@request.content_type = "text/plain"
put update_rails_disk_service_url(encoded_token: token), params: { body: data }

put :update, body: data, params: { encoded_token: token }
assert_response :unprocessable_entity
assert_not blob.service.exist?(blob.key)
end
Expand Down
13 changes: 4 additions & 9 deletions test/controllers/variants_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
require "test_helper"
require "database/setup"

require "active_storage/variants_controller"

class ActiveStorage::VariantsControllerTest < ActionController::TestCase
class ActiveStorage::VariantsControllerTest < ActionDispatch::IntegrationTest
setup do
@routes = Routes
@controller = ActiveStorage::VariantsController.new

@blob = create_image_blob filename: "racecar.jpg"
end

test "showing variant inline" do
get :show, params: {
get rails_blob_variation_url(
filename: @blob.filename,
signed_blob_id: @blob.signed_id,
variation_key: ActiveStorage::Variation.encode(resize: "100x100") }
variation_key: ActiveStorage::Variation.encode(resize: "100x100"))

assert_redirected_to /racecar.jpg\?disposition=inline/
assert_redirected_to /racecar.jpg\?.*disposition=inline/

image = read_image_variant(@blob.variant(resize: "100x100"))
assert_equal 100, image.width
Expand Down
3 changes: 3 additions & 0 deletions test/dummy/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require_relative 'config/application'

Rails.application.load_tasks
5 changes: 5 additions & 0 deletions test/dummy/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
//= link active_storage_manifest.js
Empty file.
13 changes: 13 additions & 0 deletions test/dummy/app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require_tree .
15 changes: 15 additions & 0 deletions test/dummy/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*/
3 changes: 3 additions & 0 deletions test/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
end
Empty file.
2 changes: 2 additions & 0 deletions test/dummy/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApplicationHelper
end
2 changes: 2 additions & 0 deletions test/dummy/app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationJob < ActiveJob::Base
end
3 changes: 3 additions & 0 deletions test/dummy/app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
Empty file.
14 changes: 14 additions & 0 deletions test/dummy/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy</title>
<%= csrf_meta_tags %>

<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
</head>

<body>
<%= yield %>
</body>
</html>
3 changes: 3 additions & 0 deletions test/dummy/bin/bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
4 changes: 4 additions & 0 deletions test/dummy/bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
4 changes: 4 additions & 0 deletions test/dummy/bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run
11 changes: 11 additions & 0 deletions test/dummy/bin/yarn
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby
VENDOR_PATH = File.expand_path('..', __dir__)
Dir.chdir(VENDOR_PATH) do
begin
exec "yarnpkg #{ARGV.join(" ")}"
rescue Errno::ENOENT
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
exit 1
end
end
5 changes: 5 additions & 0 deletions test/dummy/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file is used by Rack-based servers to start the application.

require_relative 'config/environment'

run Rails.application
25 changes: 25 additions & 0 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require_relative 'boot'

require "rails"
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_view/railtie"
require "sprockets/railtie"
#require "action_mailer/railtie"
#require "rails/test_unit/railtie"
#require "action_cable/engine"


Bundler.require(*Rails.groups)
require "active_storage"

module Dummy
class Application < Rails::Application
config.load_defaults 5.1

config.active_storage.service = :local
end
end

5 changes: 5 additions & 0 deletions test/dummy/config/boot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)

require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
25 changes: 25 additions & 0 deletions test/dummy/config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000

development:
<<: *default
database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3

production:
<<: *default
database: db/production.sqlite3
5 changes: 5 additions & 0 deletions test/dummy/config/environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Load the Rails application.
require_relative 'application'

# Initialize the Rails application.
Rails.application.initialize!
Loading