refile 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of refile might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -2
- data/.travis.yml +2 -0
- data/.yardopts +1 -0
- data/CONTRIBUTING.md +33 -0
- data/History.md +9 -0
- data/README.md +67 -16
- data/app/assets/javascripts/refile.js +19 -17
- data/lib/refile.rb +36 -6
- data/lib/refile/app.rb +15 -12
- data/lib/refile/attacher.rb +119 -49
- data/lib/refile/attachment.rb +29 -16
- data/lib/refile/attachment/active_record.rb +5 -2
- data/lib/refile/backend/file_system.rb +61 -1
- data/lib/refile/backend/s3.rb +66 -0
- data/lib/refile/custom_logger.rb +46 -0
- data/lib/refile/file.rb +32 -1
- data/lib/refile/image_processing.rb +72 -3
- data/lib/refile/rails.rb +2 -8
- data/lib/refile/rails/attachment_helper.rb +77 -19
- data/lib/refile/signature.rb +16 -1
- data/lib/refile/type.rb +28 -0
- data/lib/refile/version.rb +1 -1
- data/refile.gemspec +1 -1
- data/spec/refile/active_record_helper.rb +27 -0
- data/spec/refile/attachment/active_record_spec.rb +92 -0
- data/spec/refile/attachment_spec.rb +153 -28
- data/spec/refile/custom_logger_spec.rb +22 -0
- data/spec/refile/features/direct_upload_spec.rb +19 -2
- data/spec/refile/features/normal_upload_spec.rb +41 -11
- data/spec/refile/features/presigned_upload_spec.rb +1 -2
- data/spec/refile/rails/attachment_helper_spec.rb +1 -1
- data/spec/refile/test_app.rb +16 -14
- data/spec/refile/test_app/app/controllers/direct_posts_controller.rb +1 -1
- data/spec/refile/test_app/app/controllers/normal_posts_controller.rb +1 -1
- data/spec/refile/test_app/app/controllers/presigned_posts_controller.rb +1 -1
- data/spec/refile/test_app/app/views/direct_posts/new.html.erb +4 -0
- data/spec/refile/test_app/app/views/normal_posts/show.html.erb +5 -3
- metadata +27 -17
@@ -0,0 +1,22 @@
|
|
1
|
+
require "active_support/logger"
|
2
|
+
require "refile/custom_logger"
|
3
|
+
|
4
|
+
describe Refile::CustomLogger do
|
5
|
+
let(:rack_app) do
|
6
|
+
->(_) { [200, {}, ["Success"]] }
|
7
|
+
end
|
8
|
+
let(:io) { StringIO.new }
|
9
|
+
let(:env) do
|
10
|
+
{ "QUERY_STRING" => "",
|
11
|
+
"REQUEST_METHOD" => "POST",
|
12
|
+
"PATH_INFO" => "/" }
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:expected_format) { /^Prefix: \[[^\]]+\] POST "\/" 200 \d+\.\d+ms\n\n$/ }
|
16
|
+
|
17
|
+
it "uses a dynamic logger" do
|
18
|
+
_, _, body = described_class.new(rack_app, "Prefix", -> { ActiveSupport::Logger.new(io) }).call(env)
|
19
|
+
body.close
|
20
|
+
expect(io.tap(&:rewind).read).to match(expected_format)
|
21
|
+
end
|
22
|
+
end
|
@@ -13,8 +13,10 @@ feature "Direct HTTP post file uploads", :js do
|
|
13
13
|
click_button "Create"
|
14
14
|
|
15
15
|
expect(page).to have_selector("h1", text: "A cool post")
|
16
|
-
|
17
|
-
expect(
|
16
|
+
expect(page).to have_selector(".content-type", text: "text/plain")
|
17
|
+
expect(page).to have_selector(".size", text: "6")
|
18
|
+
expect(page).to have_selector(".filename", text: "hello.txt")
|
19
|
+
expect(download_link("Document")).to eq("hello")
|
18
20
|
end
|
19
21
|
|
20
22
|
scenario "Fail to upload a file that is too large" do
|
@@ -25,4 +27,19 @@ feature "Direct HTTP post file uploads", :js do
|
|
25
27
|
expect(page).to have_content("Upload started")
|
26
28
|
expect(page).to have_content("Upload failure error")
|
27
29
|
end
|
30
|
+
|
31
|
+
scenario "Fail to upload a file that has wrong format" do
|
32
|
+
visit "/direct/posts/new"
|
33
|
+
fill_in "Title", with: "A cool post"
|
34
|
+
attach_file "Image", path("large.txt")
|
35
|
+
|
36
|
+
expect(page).to have_content("Upload started")
|
37
|
+
expect(page).to have_content("Upload success")
|
38
|
+
expect(page).to have_content("Upload complete")
|
39
|
+
|
40
|
+
click_button "Create"
|
41
|
+
|
42
|
+
expect(page).to have_selector(".field_with_errors")
|
43
|
+
expect(page).to have_content("Image has an invalid file format")
|
44
|
+
end
|
28
45
|
end
|
@@ -8,8 +8,10 @@ feature "Normal HTTP Post file uploads" do
|
|
8
8
|
click_button "Create"
|
9
9
|
|
10
10
|
expect(page).to have_selector("h1", text: "A cool post")
|
11
|
-
|
12
|
-
expect(page
|
11
|
+
expect(page).to have_selector(".content-type", text: "text/plain")
|
12
|
+
expect(page).to have_selector(".size", text: "6")
|
13
|
+
expect(page).to have_selector(".filename", text: "hello.txt")
|
14
|
+
expect(download_link("Document")).to eq("hello")
|
13
15
|
end
|
14
16
|
|
15
17
|
scenario "Fail to upload a file that is too large" do
|
@@ -32,7 +34,22 @@ feature "Normal HTTP Post file uploads" do
|
|
32
34
|
expect(page).to have_content("Image has an invalid file format")
|
33
35
|
end
|
34
36
|
|
35
|
-
scenario "
|
37
|
+
scenario "Fail to upload a file that has the wrong format then submit" do
|
38
|
+
visit "/normal/posts/new"
|
39
|
+
fill_in "Title", with: "A cool post"
|
40
|
+
attach_file "Image", path("hello.txt")
|
41
|
+
click_button "Create"
|
42
|
+
|
43
|
+
expect(page).to have_selector(".field_with_errors")
|
44
|
+
expect(page).to have_content("Image has an invalid file format")
|
45
|
+
click_button "Create"
|
46
|
+
expect(page).to have_selector("h1", text: "A cool post")
|
47
|
+
expect(page).not_to have_link("Document")
|
48
|
+
end
|
49
|
+
|
50
|
+
# FIXME: the only reason this is js:true is because the rack_test driver
|
51
|
+
# doesn't submit file+metadata correctly.
|
52
|
+
scenario "Upload a file via form redisplay", js: true do
|
36
53
|
visit "/normal/posts/new"
|
37
54
|
attach_file "Document", path("hello.txt")
|
38
55
|
click_button "Create"
|
@@ -40,8 +57,10 @@ feature "Normal HTTP Post file uploads" do
|
|
40
57
|
click_button "Create"
|
41
58
|
|
42
59
|
expect(page).to have_selector("h1", text: "A cool post")
|
43
|
-
|
44
|
-
expect(page
|
60
|
+
expect(page).to have_selector(".content-type", text: "text/plain")
|
61
|
+
expect(page).to have_selector(".size", text: "6")
|
62
|
+
expect(page).to have_selector(".filename", text: "hello.txt")
|
63
|
+
expect(download_link("Document")).to eq("hello")
|
45
64
|
end
|
46
65
|
|
47
66
|
scenario "Format conversion" do
|
@@ -51,8 +70,7 @@ feature "Normal HTTP Post file uploads" do
|
|
51
70
|
click_button "Create"
|
52
71
|
|
53
72
|
expect(page).to have_selector("h1", text: "A cool post")
|
54
|
-
|
55
|
-
expect(page.source.chomp).to eq("HELLO")
|
73
|
+
expect(download_link("Convert to Upper")).to eq("HELLO")
|
56
74
|
end
|
57
75
|
|
58
76
|
scenario "Successfully remove an uploaded file" do
|
@@ -68,7 +86,10 @@ feature "Normal HTTP Post file uploads" do
|
|
68
86
|
check "Remove document"
|
69
87
|
click_button "Update"
|
70
88
|
expect(page).to have_selector("h1", text: "A cool post")
|
71
|
-
expect(page).
|
89
|
+
expect(page).not_to have_selector(:link, "Document")
|
90
|
+
expect(page).not_to have_selector(".content-type", text: "text/plain")
|
91
|
+
expect(page).not_to have_selector(".size", text: "6")
|
92
|
+
expect(page).not_to have_selector(".filename", text: "hello.txt")
|
72
93
|
end
|
73
94
|
|
74
95
|
scenario "Successfully remove a record with an uploaded file" do
|
@@ -83,7 +104,14 @@ feature "Normal HTTP Post file uploads" do
|
|
83
104
|
end
|
84
105
|
|
85
106
|
scenario "Upload a file from a remote URL" do
|
86
|
-
stub_request(:get, "http://www.example.com/some_file").to_return(
|
107
|
+
stub_request(:get, "http://www.example.com/some_file").to_return(
|
108
|
+
status: 200,
|
109
|
+
body: "abc",
|
110
|
+
headers: {
|
111
|
+
"Content-Length" => 3,
|
112
|
+
"Content-Type" => "image/png"
|
113
|
+
}
|
114
|
+
)
|
87
115
|
|
88
116
|
visit "/normal/posts/new"
|
89
117
|
fill_in "Title", with: "A cool post"
|
@@ -91,7 +119,9 @@ feature "Normal HTTP Post file uploads" do
|
|
91
119
|
click_button "Create"
|
92
120
|
|
93
121
|
expect(page).to have_selector("h1", text: "A cool post")
|
94
|
-
|
95
|
-
expect(page
|
122
|
+
expect(download_link("Document")).to eq("abc")
|
123
|
+
expect(page).to have_selector(".content-type", text: "image/png")
|
124
|
+
expect(page).to have_selector(".size", text: "3")
|
125
|
+
expect(page).to have_selector(".filename", text: "some_file")
|
96
126
|
end
|
97
127
|
end
|
@@ -13,8 +13,7 @@ feature "Direct HTTP post file uploads", :js do
|
|
13
13
|
click_button "Create"
|
14
14
|
|
15
15
|
expect(page).to have_selector("h1", text: "A cool post")
|
16
|
-
|
17
|
-
expect(result).to eq("hello")
|
16
|
+
expect(download_link("Document")).to eq("hello")
|
18
17
|
end
|
19
18
|
|
20
19
|
scenario "Fail to upload a file that is too large" do
|
@@ -3,7 +3,7 @@ require "active_support/inflector"
|
|
3
3
|
require "refile/rails/attachment_helper"
|
4
4
|
|
5
5
|
describe Refile::AttachmentHelper do
|
6
|
-
describe "#attachment_url" do
|
6
|
+
describe "#attachment_url", pending: "rewrite without mocks" do
|
7
7
|
let(:view) { Struct.new(:main_app, :request).new(main_app, request) }
|
8
8
|
let(:main_app) { double :main_app, refile_app_path: "attachments" }
|
9
9
|
let(:request) { double :request, base_url: "http://www.example.com" }
|
data/spec/refile/test_app.rb
CHANGED
@@ -19,25 +19,12 @@ module Refile
|
|
19
19
|
TestApp.initialize!
|
20
20
|
end
|
21
21
|
|
22
|
-
class TestMigration < ActiveRecord::Migration
|
23
|
-
def self.up
|
24
|
-
create_table :posts, force: true do |t|
|
25
|
-
t.column :title, :string
|
26
|
-
t.column :image_id, :string
|
27
|
-
t.column :document_id, :string
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
quietly do
|
33
|
-
TestMigration.up
|
34
|
-
end
|
35
|
-
|
36
22
|
require "rspec"
|
37
23
|
require "rspec/rails"
|
38
24
|
require "capybara/rails"
|
39
25
|
require "capybara/rspec"
|
40
26
|
require "refile/spec_helper"
|
27
|
+
require "refile/active_record_helper"
|
41
28
|
|
42
29
|
if ENV["SAUCE_BROWSER"]
|
43
30
|
Capybara.register_driver :selenium do |app|
|
@@ -56,7 +43,22 @@ end
|
|
56
43
|
Refile.allow_origin = "*"
|
57
44
|
Refile.host = "//localhost:56120"
|
58
45
|
|
46
|
+
module TestAppHelpers
|
47
|
+
def download_link(text)
|
48
|
+
url = find_link(text)[:href]
|
49
|
+
if Capybara.current_driver == :rack_test
|
50
|
+
using_session :other do
|
51
|
+
visit(url)
|
52
|
+
page.source.chomp
|
53
|
+
end
|
54
|
+
else
|
55
|
+
Net::HTTP.get_response(URI(url)).body.chomp
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
59
60
|
RSpec.configure do |config|
|
61
|
+
config.include TestAppHelpers, type: :feature
|
60
62
|
config.before(:all) do
|
61
63
|
Refile.logger = Rails.logger
|
62
64
|
end
|
@@ -4,7 +4,7 @@ class DirectPostsController < ApplicationController
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def create
|
7
|
-
@post = Post.new(params.require(:post).permit(:title, :
|
7
|
+
@post = Post.new(params.require(:post).permit(:title, :document, :image))
|
8
8
|
|
9
9
|
if @post.save
|
10
10
|
redirect_to [:normal, @post]
|
@@ -43,6 +43,6 @@ class NormalPostsController < ApplicationController
|
|
43
43
|
private
|
44
44
|
|
45
45
|
def post_params
|
46
|
-
params.require(:post).permit(:title, :image, :
|
46
|
+
params.require(:post).permit(:title, :image, :document, :remove_document, :remote_document_url)
|
47
47
|
end
|
48
48
|
end
|
@@ -4,7 +4,7 @@ class PresignedPostsController < ApplicationController
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def create
|
7
|
-
@post = Post.new(params.require(:post).permit(:title, :
|
7
|
+
@post = Post.new(params.require(:post).permit(:title, :document))
|
8
8
|
|
9
9
|
if @post.save
|
10
10
|
redirect_to [:normal, @post]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<h1><%= @post.title %></h1
|
1
|
+
<h1><%= @post.title %></h1>
|
2
2
|
|
3
3
|
<% if @post.image %>
|
4
4
|
<%= attachment_image_tag(@post, :image) %>
|
@@ -6,9 +6,11 @@
|
|
6
6
|
|
7
7
|
<% if @post.document %>
|
8
8
|
<%= link_to "Document", attachment_url(@post, :document) %>
|
9
|
-
<% end %>
|
10
9
|
|
11
|
-
|
10
|
+
<p class="content-type"><%= @post.document_content_type %></p>
|
11
|
+
<p class="size"><%= @post.document_size %></p>
|
12
|
+
<p class="filename"><%= @post.document_filename %></p>
|
13
|
+
|
12
14
|
<%= link_to "Convert to Upper", attachment_url(@post, :document, :convert_case, format: "up") %>
|
13
15
|
<% end %>
|
14
16
|
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: refile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Nicklas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rest-client
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.7.2
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 1.7.2
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: sinatra
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -262,6 +248,20 @@ dependencies:
|
|
262
248
|
- - ">="
|
263
249
|
- !ruby/object:Gem::Version
|
264
250
|
version: '0'
|
251
|
+
- !ruby/object:Gem::Dependency
|
252
|
+
name: redcarpet
|
253
|
+
requirement: !ruby/object:Gem::Requirement
|
254
|
+
requirements:
|
255
|
+
- - ">="
|
256
|
+
- !ruby/object:Gem::Version
|
257
|
+
version: '0'
|
258
|
+
type: :development
|
259
|
+
prerelease: false
|
260
|
+
version_requirements: !ruby/object:Gem::Requirement
|
261
|
+
requirements:
|
262
|
+
- - ">="
|
263
|
+
- !ruby/object:Gem::Version
|
264
|
+
version: '0'
|
265
265
|
description:
|
266
266
|
email:
|
267
267
|
- jonas.nicklas@gmail.com
|
@@ -273,6 +273,8 @@ files:
|
|
273
273
|
- ".rspec"
|
274
274
|
- ".rubocop.yml"
|
275
275
|
- ".travis.yml"
|
276
|
+
- ".yardopts"
|
277
|
+
- CONTRIBUTING.md
|
276
278
|
- Gemfile
|
277
279
|
- History.md
|
278
280
|
- LICENSE.txt
|
@@ -289,19 +291,24 @@ files:
|
|
289
291
|
- lib/refile/attachment/active_record.rb
|
290
292
|
- lib/refile/backend/file_system.rb
|
291
293
|
- lib/refile/backend/s3.rb
|
294
|
+
- lib/refile/custom_logger.rb
|
292
295
|
- lib/refile/file.rb
|
293
296
|
- lib/refile/image_processing.rb
|
294
297
|
- lib/refile/rails.rb
|
295
298
|
- lib/refile/rails/attachment_helper.rb
|
296
299
|
- lib/refile/random_hasher.rb
|
297
300
|
- lib/refile/signature.rb
|
301
|
+
- lib/refile/type.rb
|
298
302
|
- lib/refile/version.rb
|
299
303
|
- refile.gemspec
|
304
|
+
- spec/refile/active_record_helper.rb
|
300
305
|
- spec/refile/app_spec.rb
|
306
|
+
- spec/refile/attachment/active_record_spec.rb
|
301
307
|
- spec/refile/attachment_spec.rb
|
302
308
|
- spec/refile/backend/file_system_spec.rb
|
303
309
|
- spec/refile/backend/s3_spec.rb
|
304
310
|
- spec/refile/backend_examples.rb
|
311
|
+
- spec/refile/custom_logger_spec.rb
|
305
312
|
- spec/refile/features/direct_upload_spec.rb
|
306
313
|
- spec/refile/features/normal_upload_spec.rb
|
307
314
|
- spec/refile/features/presigned_upload_spec.rb
|
@@ -351,16 +358,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
351
358
|
version: '0'
|
352
359
|
requirements: []
|
353
360
|
rubyforge_project:
|
354
|
-
rubygems_version: 2.4.
|
361
|
+
rubygems_version: 2.4.5
|
355
362
|
signing_key:
|
356
363
|
specification_version: 4
|
357
364
|
summary: Simple and powerful file upload library
|
358
365
|
test_files:
|
366
|
+
- spec/refile/active_record_helper.rb
|
359
367
|
- spec/refile/app_spec.rb
|
368
|
+
- spec/refile/attachment/active_record_spec.rb
|
360
369
|
- spec/refile/attachment_spec.rb
|
361
370
|
- spec/refile/backend/file_system_spec.rb
|
362
371
|
- spec/refile/backend/s3_spec.rb
|
363
372
|
- spec/refile/backend_examples.rb
|
373
|
+
- spec/refile/custom_logger_spec.rb
|
364
374
|
- spec/refile/features/direct_upload_spec.rb
|
365
375
|
- spec/refile/features/normal_upload_spec.rb
|
366
376
|
- spec/refile/features/presigned_upload_spec.rb
|