fakerclip 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -2
- data/lib/fakerclip/engine.rb +6 -0
- data/lib/fakerclip/reads.rb +23 -0
- data/lib/fakerclip/version.rb +1 -1
- data/lib/fakerclip/writes.rb +36 -0
- data/lib/fakerclip.rb +11 -2
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +165 -0
- metadata +5 -10
- data/lib/fakerclip/excon.rb +0 -32
- data/lib/fakerclip/url_generator.rb +0 -18
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
### Fake S3 on your filesystem for Paperclip.
|
4
4
|
|
5
|
-
|
5
|
+
This is a Rails Engine that helps simulate writing and reading from S3, by using your filesystem as a Fake S3.
|
6
6
|
|
7
7
|
Instead of this:
|
8
8
|
``` ruby
|
@@ -24,7 +24,7 @@ has_attachment :foobar, DEFAULT_PAPERCLIP_CONFIG.merge(PATH_CONFIG)
|
|
24
24
|
|
25
25
|
You should be able to write one config per paperclip attachment, specify the S3 bucket/folder setup, and be done with it.
|
26
26
|
|
27
|
-
With FakerClip, your filesystem is treated as an s3 bucket so you don't have to wonder if the changes you made to your s3 bucket configuration
|
27
|
+
With FakerClip, your filesystem is treated as an s3 bucket so you don't have to wonder if the changes you made to your s3 bucket configuration will break in production. The idea is, if it didn't work on your local filesystem on development or test environments, it won't work on S3!
|
28
28
|
|
29
29
|
### Setup
|
30
30
|
|
@@ -36,5 +36,7 @@ That's it! Now, just omit `: { path: 'is/my/local/path' }` from the example abo
|
|
36
36
|
|
37
37
|
### Development
|
38
38
|
|
39
|
+
``` shell
|
39
40
|
bundle exec rake app:db:migrate app:db:test:prepare
|
40
41
|
bundle exec rspec
|
42
|
+
```
|
data/lib/fakerclip/engine.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Fakerclip
|
2
|
+
|
3
|
+
class Reads
|
4
|
+
|
5
|
+
def self.activate
|
6
|
+
Paperclip::Attachment.default_options[:url_generator] = UrlGenerator
|
7
|
+
end
|
8
|
+
|
9
|
+
class UrlGenerator < ::Paperclip::UrlGenerator
|
10
|
+
|
11
|
+
def for(style_name, options)
|
12
|
+
uri = URI.parse(super)
|
13
|
+
|
14
|
+
if uri.to_s.match(/\.s3\.amazonaws\.com/)
|
15
|
+
bucket = uri.host.split(/\./, 2).first
|
16
|
+
"/fake_s3_#{Rails.env}/#{bucket}#{uri.request_uri}"
|
17
|
+
else
|
18
|
+
uri.to_s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/fakerclip/version.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Fakerclip
|
2
|
+
|
3
|
+
class Writes
|
4
|
+
|
5
|
+
def self.activate
|
6
|
+
# stubbing writes to S3
|
7
|
+
::Excon.stub({ method: "PUT" }) do |params|
|
8
|
+
|
9
|
+
# TODO: generate etags for multipart uploads
|
10
|
+
etag = Digest::MD5.hexdigest(params[:body])
|
11
|
+
|
12
|
+
s3_bucket = params[:host].split('.').first
|
13
|
+
s3_file_path = CGI.unescape params[:path]
|
14
|
+
local_s3_path = Rails.root.join(File.join('public', "fake_s3_#{Rails.env}"))
|
15
|
+
local_file_path = File.join(local_s3_path, s3_bucket, s3_file_path)
|
16
|
+
|
17
|
+
# creates the file tree, e.g. public/fake_s3_development/s3-bucket/files/1/
|
18
|
+
FileUtils.mkdir_p File.dirname(local_file_path)
|
19
|
+
|
20
|
+
# writes the file to the fake s3
|
21
|
+
File.open(local_file_path, "wb") {|file| file.write(params[:body]) }
|
22
|
+
|
23
|
+
# TODO: generate alternate statuses, e.g. if the file is not found
|
24
|
+
{
|
25
|
+
status: 200,
|
26
|
+
headers: params[:headers].merge("ETag" => etag),
|
27
|
+
body: params[:body]
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
# TODO: set mocking for Excon to apply only to some-bucket.s3.amazonaws.com and only
|
32
|
+
# while paperclip is making the requests, so we don't clobber other legit requests.
|
33
|
+
::Excon.defaults[:mock] = true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/fakerclip.rb
CHANGED
@@ -3,7 +3,16 @@ require 'paperclip'
|
|
3
3
|
require 'fog'
|
4
4
|
|
5
5
|
module Fakerclip
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def activate
|
10
|
+
Reads.activate
|
11
|
+
Writes.activate
|
12
|
+
end
|
13
|
+
end
|
6
14
|
end
|
7
15
|
|
8
|
-
require 'fakerclip/
|
9
|
-
require 'fakerclip/
|
16
|
+
require 'fakerclip/engine'
|
17
|
+
require 'fakerclip/reads'
|
18
|
+
require 'fakerclip/writes'
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
data/spec/dummy/log/test.log
CHANGED
@@ -541,3 +541,168 @@ Connecting to database specified by database.yml
|
|
541
541
|
[1m[35m (0.5ms)[0m commit transaction
|
542
542
|
[1m[36m (0.8ms)[0m [1mDELETE FROM "uploads";[0m
|
543
543
|
[1m[35m (0.7ms)[0m DELETE FROM sqlite_sequence where name = 'uploads';
|
544
|
+
Connecting to database specified by database.yml
|
545
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
546
|
+
[1m[35mSQL (6.6ms)[0m INSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Thu, 11 Apr 2013 02:13:34 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Thu, 11 Apr 2013 02:13:34 UTC +00:00], ["updated_at", Thu, 11 Apr 2013 02:13:34 UTC +00:00]]
|
547
|
+
[paperclip] Saving attachments.
|
548
|
+
[paperclip] saving files/1/random-bytes.bin
|
549
|
+
[1m[36m (0.7ms)[0m [1mcommit transaction[0m
|
550
|
+
[1m[35m (0.8ms)[0m DELETE FROM "uploads";
|
551
|
+
[1m[36m (0.8ms)[0m [1mDELETE FROM sqlite_sequence where name = 'uploads';[0m
|
552
|
+
[1m[35m (0.1ms)[0m begin transaction
|
553
|
+
[1m[36mSQL (0.4ms)[0m [1mINSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?)[0m [["created_at", Thu, 11 Apr 2013 02:13:34 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Thu, 11 Apr 2013 02:13:34 UTC +00:00], ["updated_at", Thu, 11 Apr 2013 02:13:34 UTC +00:00]]
|
554
|
+
[paperclip] Saving attachments.
|
555
|
+
[paperclip] saving files/1/random-bytes.bin
|
556
|
+
[1m[35m (0.5ms)[0m commit transaction
|
557
|
+
[1m[36m (0.9ms)[0m [1mDELETE FROM "uploads";[0m
|
558
|
+
[1m[35m (0.9ms)[0m DELETE FROM sqlite_sequence where name = 'uploads';
|
559
|
+
Connecting to database specified by database.yml
|
560
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
561
|
+
[1m[35mSQL (10.1ms)[0m INSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Sat, 13 Apr 2013 15:55:30 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 15:55:30 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 15:55:30 UTC +00:00]]
|
562
|
+
[paperclip] Saving attachments.
|
563
|
+
[paperclip] saving files/1/random-bytes.bin
|
564
|
+
[1m[36m (4.9ms)[0m [1mrollback transaction[0m
|
565
|
+
[1m[35m (1.1ms)[0m DELETE FROM "uploads";
|
566
|
+
[1m[36m (0.1ms)[0m [1mDELETE FROM sqlite_sequence where name = 'uploads';[0m
|
567
|
+
[1m[35m (0.0ms)[0m begin transaction
|
568
|
+
[1m[36mSQL (0.4ms)[0m [1mINSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?)[0m [["created_at", Sat, 13 Apr 2013 15:55:35 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 15:55:35 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 15:55:35 UTC +00:00]]
|
569
|
+
[paperclip] Saving attachments.
|
570
|
+
[paperclip] saving files/1/random-bytes.bin
|
571
|
+
[1m[35m (0.3ms)[0m rollback transaction
|
572
|
+
[1m[36m (0.9ms)[0m [1mDELETE FROM "uploads";[0m
|
573
|
+
[1m[35m (0.1ms)[0m DELETE FROM sqlite_sequence where name = 'uploads';
|
574
|
+
Connecting to database specified by database.yml
|
575
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
576
|
+
[1m[35mSQL (5.0ms)[0m INSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Sat, 13 Apr 2013 15:56:35 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 15:56:35 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 15:56:35 UTC +00:00]]
|
577
|
+
[paperclip] Saving attachments.
|
578
|
+
[paperclip] saving files/1/random-bytes.bin
|
579
|
+
[1m[36m (0.5ms)[0m [1mrollback transaction[0m
|
580
|
+
[1m[35m (0.7ms)[0m DELETE FROM "uploads";
|
581
|
+
[1m[36m (0.1ms)[0m [1mDELETE FROM sqlite_sequence where name = 'uploads';[0m
|
582
|
+
[1m[35m (0.0ms)[0m begin transaction
|
583
|
+
[1m[36mSQL (0.4ms)[0m [1mINSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?)[0m [["created_at", Sat, 13 Apr 2013 15:56:37 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 15:56:37 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 15:56:37 UTC +00:00]]
|
584
|
+
[paperclip] Saving attachments.
|
585
|
+
[paperclip] saving files/1/random-bytes.bin
|
586
|
+
[1m[35m (4.3ms)[0m rollback transaction
|
587
|
+
[1m[36m (1.1ms)[0m [1mDELETE FROM "uploads";[0m
|
588
|
+
[1m[35m (0.1ms)[0m DELETE FROM sqlite_sequence where name = 'uploads';
|
589
|
+
Connecting to database specified by database.yml
|
590
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
591
|
+
[1m[35mSQL (5.0ms)[0m INSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Sat, 13 Apr 2013 15:57:03 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 15:57:03 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 15:57:03 UTC +00:00]]
|
592
|
+
[paperclip] Saving attachments.
|
593
|
+
[paperclip] saving files/1/random-bytes.bin
|
594
|
+
[1m[36m (0.4ms)[0m [1mrollback transaction[0m
|
595
|
+
[1m[35m (0.8ms)[0m DELETE FROM "uploads";
|
596
|
+
[1m[36m (0.1ms)[0m [1mDELETE FROM sqlite_sequence where name = 'uploads';[0m
|
597
|
+
[1m[35m (0.1ms)[0m begin transaction
|
598
|
+
[1m[36mSQL (0.5ms)[0m [1mINSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?)[0m [["created_at", Sat, 13 Apr 2013 15:57:07 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 15:57:07 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 15:57:07 UTC +00:00]]
|
599
|
+
[paperclip] Saving attachments.
|
600
|
+
[paperclip] saving files/1/random-bytes.bin
|
601
|
+
[1m[35m (0.5ms)[0m rollback transaction
|
602
|
+
[1m[36m (1.1ms)[0m [1mDELETE FROM "uploads";[0m
|
603
|
+
[1m[35m (0.1ms)[0m DELETE FROM sqlite_sequence where name = 'uploads';
|
604
|
+
Connecting to database specified by database.yml
|
605
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
606
|
+
[1m[35mSQL (9.2ms)[0m INSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Sat, 13 Apr 2013 17:04:13 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 17:04:13 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 17:04:13 UTC +00:00]]
|
607
|
+
[paperclip] Saving attachments.
|
608
|
+
[paperclip] saving files/1/random-bytes.bin
|
609
|
+
[1m[36m (4.7ms)[0m [1mrollback transaction[0m
|
610
|
+
[1m[35m (1.1ms)[0m DELETE FROM "uploads";
|
611
|
+
[1m[36m (0.1ms)[0m [1mDELETE FROM sqlite_sequence where name = 'uploads';[0m
|
612
|
+
[1m[35m (0.0ms)[0m begin transaction
|
613
|
+
[1m[36mSQL (0.3ms)[0m [1mINSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?)[0m [["created_at", Sat, 13 Apr 2013 17:04:29 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 17:04:29 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 17:04:29 UTC +00:00]]
|
614
|
+
[paperclip] Saving attachments.
|
615
|
+
[paperclip] saving files/1/random-bytes.bin
|
616
|
+
[1m[35m (0.2ms)[0m rollback transaction
|
617
|
+
[1m[36m (5.0ms)[0m [1mDELETE FROM "uploads";[0m
|
618
|
+
[1m[35m (0.1ms)[0m DELETE FROM sqlite_sequence where name = 'uploads';
|
619
|
+
Connecting to database specified by database.yml
|
620
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
621
|
+
[1m[35mSQL (5.6ms)[0m INSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Sat, 13 Apr 2013 17:05:09 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 17:05:09 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 17:05:09 UTC +00:00]]
|
622
|
+
[paperclip] Saving attachments.
|
623
|
+
[paperclip] saving files/1/random-bytes.bin
|
624
|
+
[1m[36m (4.7ms)[0m [1mrollback transaction[0m
|
625
|
+
[1m[35m (1.0ms)[0m DELETE FROM "uploads";
|
626
|
+
[1m[36m (0.1ms)[0m [1mDELETE FROM sqlite_sequence where name = 'uploads';[0m
|
627
|
+
[1m[35m (0.0ms)[0m begin transaction
|
628
|
+
[1m[36mSQL (0.4ms)[0m [1mINSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?)[0m [["created_at", Sat, 13 Apr 2013 17:05:15 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 17:05:15 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 17:05:15 UTC +00:00]]
|
629
|
+
[paperclip] Saving attachments.
|
630
|
+
[paperclip] saving files/1/random-bytes.bin
|
631
|
+
[1m[35m (4.6ms)[0m rollback transaction
|
632
|
+
[1m[36m (0.8ms)[0m [1mDELETE FROM "uploads";[0m
|
633
|
+
[1m[35m (0.1ms)[0m DELETE FROM sqlite_sequence where name = 'uploads';
|
634
|
+
Connecting to database specified by database.yml
|
635
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
636
|
+
[1m[35mSQL (5.6ms)[0m INSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Sat, 13 Apr 2013 17:05:25 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 17:05:25 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 17:05:25 UTC +00:00]]
|
637
|
+
[paperclip] Saving attachments.
|
638
|
+
[paperclip] saving files/1/random-bytes.bin
|
639
|
+
[1m[36m (0.2ms)[0m [1mrollback transaction[0m
|
640
|
+
[1m[35m (1.2ms)[0m DELETE FROM "uploads";
|
641
|
+
[1m[36m (0.1ms)[0m [1mDELETE FROM sqlite_sequence where name = 'uploads';[0m
|
642
|
+
[1m[35m (0.0ms)[0m begin transaction
|
643
|
+
[1m[36mSQL (0.4ms)[0m [1mINSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?)[0m [["created_at", Sat, 13 Apr 2013 17:05:30 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 17:05:30 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 17:05:30 UTC +00:00]]
|
644
|
+
[paperclip] Saving attachments.
|
645
|
+
[paperclip] saving files/1/random-bytes.bin
|
646
|
+
[1m[35m (0.5ms)[0m rollback transaction
|
647
|
+
[1m[36m (1.0ms)[0m [1mDELETE FROM "uploads";[0m
|
648
|
+
[1m[35m (0.1ms)[0m DELETE FROM sqlite_sequence where name = 'uploads';
|
649
|
+
Connecting to database specified by database.yml
|
650
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
651
|
+
[1m[35mSQL (4.8ms)[0m INSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Sat, 13 Apr 2013 17:05:46 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 17:05:46 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 17:05:46 UTC +00:00]]
|
652
|
+
[paperclip] Saving attachments.
|
653
|
+
[paperclip] saving files/1/random-bytes.bin
|
654
|
+
[1m[36m (4.7ms)[0m [1mrollback transaction[0m
|
655
|
+
[1m[35m (1.1ms)[0m DELETE FROM "uploads";
|
656
|
+
[1m[36m (0.1ms)[0m [1mDELETE FROM sqlite_sequence where name = 'uploads';[0m
|
657
|
+
[1m[35m (0.0ms)[0m begin transaction
|
658
|
+
[1m[36mSQL (0.4ms)[0m [1mINSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?)[0m [["created_at", Sat, 13 Apr 2013 17:05:56 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 17:05:56 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 17:05:56 UTC +00:00]]
|
659
|
+
[paperclip] Saving attachments.
|
660
|
+
[paperclip] saving files/1/random-bytes.bin
|
661
|
+
[1m[35m (0.2ms)[0m rollback transaction
|
662
|
+
[1m[36m (5.0ms)[0m [1mDELETE FROM "uploads";[0m
|
663
|
+
[1m[35m (0.1ms)[0m DELETE FROM sqlite_sequence where name = 'uploads';
|
664
|
+
Connecting to database specified by database.yml
|
665
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
666
|
+
[1m[35mSQL (5.4ms)[0m INSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Sat, 13 Apr 2013 17:09:48 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 17:09:48 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 17:09:48 UTC +00:00]]
|
667
|
+
[paperclip] Saving attachments.
|
668
|
+
[paperclip] saving files/1/random-bytes.bin
|
669
|
+
[1m[36m (4.5ms)[0m [1mrollback transaction[0m
|
670
|
+
[1m[35m (1.0ms)[0m DELETE FROM "uploads";
|
671
|
+
[1m[36m (0.1ms)[0m [1mDELETE FROM sqlite_sequence where name = 'uploads';[0m
|
672
|
+
[1m[35m (0.1ms)[0m begin transaction
|
673
|
+
[1m[36mSQL (0.5ms)[0m [1mINSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?)[0m [["created_at", Sat, 13 Apr 2013 17:09:53 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 17:09:53 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 17:09:53 UTC +00:00]]
|
674
|
+
[paperclip] Saving attachments.
|
675
|
+
[paperclip] saving files/1/random-bytes.bin
|
676
|
+
[1m[35m (0.4ms)[0m rollback transaction
|
677
|
+
[1m[36m (0.6ms)[0m [1mDELETE FROM "uploads";[0m
|
678
|
+
[1m[35m (0.1ms)[0m DELETE FROM sqlite_sequence where name = 'uploads';
|
679
|
+
Connecting to database specified by database.yml
|
680
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
681
|
+
[1m[35mSQL (6.1ms)[0m INSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Sat, 13 Apr 2013 17:11:53 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 17:11:53 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 17:11:53 UTC +00:00]]
|
682
|
+
[paperclip] Saving attachments.
|
683
|
+
[paperclip] saving files/1/random-bytes.bin
|
684
|
+
[1m[36m (1.0ms)[0m [1mcommit transaction[0m
|
685
|
+
[1m[35m (0.8ms)[0m DELETE FROM "uploads";
|
686
|
+
[1m[36m (0.8ms)[0m [1mDELETE FROM sqlite_sequence where name = 'uploads';[0m
|
687
|
+
[1m[35m (0.0ms)[0m begin transaction
|
688
|
+
[1m[36mSQL (0.4ms)[0m [1mINSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?)[0m [["created_at", Sat, 13 Apr 2013 17:11:53 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 17:11:53 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 17:11:53 UTC +00:00]]
|
689
|
+
[paperclip] Saving attachments.
|
690
|
+
[paperclip] saving files/1/random-bytes.bin
|
691
|
+
[1m[35m (0.9ms)[0m commit transaction
|
692
|
+
[1m[36m (0.7ms)[0m [1mDELETE FROM "uploads";[0m
|
693
|
+
[1m[35m (1.1ms)[0m DELETE FROM sqlite_sequence where name = 'uploads';
|
694
|
+
Connecting to database specified by database.yml
|
695
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
696
|
+
[1m[35mSQL (4.9ms)[0m INSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Sat, 13 Apr 2013 17:18:06 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 17:18:06 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 17:18:06 UTC +00:00]]
|
697
|
+
[paperclip] Saving attachments.
|
698
|
+
[paperclip] saving files/1/random-bytes.bin
|
699
|
+
[1m[36m (0.9ms)[0m [1mcommit transaction[0m
|
700
|
+
[1m[35m (0.7ms)[0m DELETE FROM "uploads";
|
701
|
+
[1m[36m (0.7ms)[0m [1mDELETE FROM sqlite_sequence where name = 'uploads';[0m
|
702
|
+
[1m[35m (0.1ms)[0m begin transaction
|
703
|
+
[1m[36mSQL (0.4ms)[0m [1mINSERT INTO "uploads" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?)[0m [["created_at", Sat, 13 Apr 2013 17:18:06 UTC +00:00], ["file_content_type", "application/octet-stream"], ["file_file_name", "random-bytes.bin"], ["file_file_size", 32], ["file_updated_at", Sat, 13 Apr 2013 17:18:06 UTC +00:00], ["updated_at", Sat, 13 Apr 2013 17:18:06 UTC +00:00]]
|
704
|
+
[paperclip] Saving attachments.
|
705
|
+
[paperclip] saving files/1/random-bytes.bin
|
706
|
+
[1m[35m (0.5ms)[0m commit transaction
|
707
|
+
[1m[36m (0.8ms)[0m [1mDELETE FROM "uploads";[0m
|
708
|
+
[1m[35m (0.7ms)[0m DELETE FROM sqlite_sequence where name = 'uploads';
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fakerclip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -148,9 +148,9 @@ extensions: []
|
|
148
148
|
extra_rdoc_files: []
|
149
149
|
files:
|
150
150
|
- lib/fakerclip/engine.rb
|
151
|
-
- lib/fakerclip/
|
152
|
-
- lib/fakerclip/url_generator.rb
|
151
|
+
- lib/fakerclip/reads.rb
|
153
152
|
- lib/fakerclip/version.rb
|
153
|
+
- lib/fakerclip/writes.rb
|
154
154
|
- lib/fakerclip.rb
|
155
155
|
- lib/tasks/fakerclip_tasks.rake
|
156
156
|
- MIT-LICENSE
|
@@ -208,18 +208,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
208
208
|
- - ! '>='
|
209
209
|
- !ruby/object:Gem::Version
|
210
210
|
version: '0'
|
211
|
-
segments:
|
212
|
-
- 0
|
213
|
-
hash: 2894709188411294337
|
214
211
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
215
212
|
none: false
|
216
213
|
requirements:
|
217
214
|
- - ! '>='
|
218
215
|
- !ruby/object:Gem::Version
|
219
216
|
version: '0'
|
220
|
-
segments:
|
221
|
-
- 0
|
222
|
-
hash: 2894709188411294337
|
223
217
|
requirements: []
|
224
218
|
rubyforge_project:
|
225
219
|
rubygems_version: 1.8.23
|
@@ -267,3 +261,4 @@ test_files:
|
|
267
261
|
- spec/factories/uploads.rb
|
268
262
|
- spec/lib/fakerclip_spec.rb
|
269
263
|
- spec/spec_helper.rb
|
264
|
+
has_rdoc:
|
data/lib/fakerclip/excon.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
module Fakerclip
|
2
|
-
|
3
|
-
# stubbing writes to S3
|
4
|
-
::Excon.stub({ method: "PUT" }) do |params|
|
5
|
-
|
6
|
-
# TODO: generate etags for multipart uploads
|
7
|
-
etag = Digest::MD5.hexdigest(params[:body])
|
8
|
-
|
9
|
-
s3_bucket = params[:host].split('.').first
|
10
|
-
s3_file_path = CGI.unescape params[:path]
|
11
|
-
local_s3_path = Rails.root.join(File.join('public', "fake_s3_#{Rails.env}"))
|
12
|
-
local_file_path = File.join(local_s3_path, s3_bucket, s3_file_path)
|
13
|
-
|
14
|
-
# creates the file tree, e.g. public/fake_s3_development/s3-bucket/files/1/
|
15
|
-
FileUtils.mkdir_p File.dirname(local_file_path)
|
16
|
-
|
17
|
-
# writes the file to the fake s3
|
18
|
-
File.open(local_file_path, "wb") {|file| file.write(params[:body]) }
|
19
|
-
|
20
|
-
# TODO: generate alternate statuses, e.g. if the file is not found
|
21
|
-
{
|
22
|
-
status: 200,
|
23
|
-
headers: params[:headers].merge("ETag" => etag),
|
24
|
-
body: params[:body]
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
# TODO: set mocking for Excon to apply only to some-bucket.s3.amazonaws.com and only
|
29
|
-
# while paperclip is making the requests, so we don't clobber other legit requests.
|
30
|
-
::Excon.defaults[:mock] = true
|
31
|
-
|
32
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Fakerclip
|
2
|
-
|
3
|
-
class UrlGenerator < ::Paperclip::UrlGenerator
|
4
|
-
|
5
|
-
def for(style_name, options)
|
6
|
-
uri = URI.parse(super)
|
7
|
-
|
8
|
-
if uri.to_s.match(/\.s3\.amazonaws\.com/)
|
9
|
-
bucket = uri.host.split(/\./, 2).first
|
10
|
-
"/fake_s3_#{Rails.env}/#{bucket}#{uri.request_uri}"
|
11
|
-
else
|
12
|
-
uri.to_s
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
Paperclip::Attachment.default_options[:url_generator] = Fakerclip::UrlGenerator
|
18
|
-
end
|