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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ### Fake S3 on your filesystem for Paperclip.
4
4
 
5
- Simulate writing and reading from S3 by using your filesystem as a Fake S3.
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 went to the right place. The idea is, if it didn't work on your local filesystem on development or test environments, it won't work on S3!
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
+ ```
@@ -1,4 +1,10 @@
1
1
  module Fakerclip
2
2
  class Engine < ::Rails::Engine
3
+
4
+ initializer 'fakerclip.load_fakerclip' do |app|
5
+ if ['development', 'test'].include?(Rails.env)
6
+ Fakerclip.activate
7
+ end
8
+ end
3
9
  end
4
10
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Fakerclip
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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/excon'
9
- require 'fakerclip/url_generator'
16
+ require 'fakerclip/engine'
17
+ require 'fakerclip/reads'
18
+ require 'fakerclip/writes'
Binary file
@@ -541,3 +541,168 @@ Connecting to database specified by database.yml
541
541
   (0.5ms) commit transaction
542
542
   (0.8ms) DELETE FROM "uploads";
543
543
   (0.7ms) DELETE FROM sqlite_sequence where name = 'uploads';
544
+ Connecting to database specified by database.yml
545
+  (0.0ms) begin transaction
546
+ SQL (6.6ms) 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
+  (0.7ms) commit transaction
550
+  (0.8ms) DELETE FROM "uploads";
551
+  (0.8ms) DELETE FROM sqlite_sequence where name = 'uploads';
552
+  (0.1ms) begin transaction
553
+ SQL (0.4ms) 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]]
554
+ [paperclip] Saving attachments.
555
+ [paperclip] saving files/1/random-bytes.bin
556
+  (0.5ms) commit transaction
557
+  (0.9ms) DELETE FROM "uploads";
558
+  (0.9ms) DELETE FROM sqlite_sequence where name = 'uploads';
559
+ Connecting to database specified by database.yml
560
+  (0.1ms) begin transaction
561
+ SQL (10.1ms) 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
+  (4.9ms) rollback transaction
565
+  (1.1ms) DELETE FROM "uploads";
566
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
567
+  (0.0ms) begin transaction
568
+ SQL (0.4ms) 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: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
+  (0.3ms) rollback transaction
572
+  (0.9ms) DELETE FROM "uploads";
573
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
574
+ Connecting to database specified by database.yml
575
+  (0.0ms) begin transaction
576
+ SQL (5.0ms) 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
+  (0.5ms) rollback transaction
580
+  (0.7ms) DELETE FROM "uploads";
581
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
582
+  (0.0ms) begin transaction
583
+ SQL (0.4ms) 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: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
+  (4.3ms) rollback transaction
587
+  (1.1ms) DELETE FROM "uploads";
588
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
589
+ Connecting to database specified by database.yml
590
+  (0.0ms) begin transaction
591
+ SQL (5.0ms) 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
+  (0.4ms) rollback transaction
595
+  (0.8ms) DELETE FROM "uploads";
596
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
597
+  (0.1ms) begin transaction
598
+ SQL (0.5ms) 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: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
+  (0.5ms) rollback transaction
602
+  (1.1ms) DELETE FROM "uploads";
603
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
604
+ Connecting to database specified by database.yml
605
+  (0.0ms) begin transaction
606
+ SQL (9.2ms) 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
+  (4.7ms) rollback transaction
610
+  (1.1ms) DELETE FROM "uploads";
611
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
612
+  (0.0ms) begin transaction
613
+ SQL (0.3ms) 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: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
+  (0.2ms) rollback transaction
617
+  (5.0ms) DELETE FROM "uploads";
618
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
619
+ Connecting to database specified by database.yml
620
+  (0.0ms) begin transaction
621
+ SQL (5.6ms) 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
+  (4.7ms) rollback transaction
625
+  (1.0ms) DELETE FROM "uploads";
626
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
627
+  (0.0ms) begin transaction
628
+ SQL (0.4ms) 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: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
+  (4.6ms) rollback transaction
632
+  (0.8ms) DELETE FROM "uploads";
633
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
634
+ Connecting to database specified by database.yml
635
+  (0.1ms) begin transaction
636
+ SQL (5.6ms) 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
+  (0.2ms) rollback transaction
640
+  (1.2ms) DELETE FROM "uploads";
641
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
642
+  (0.0ms) begin transaction
643
+ SQL (0.4ms) 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: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
+  (0.5ms) rollback transaction
647
+  (1.0ms) DELETE FROM "uploads";
648
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
649
+ Connecting to database specified by database.yml
650
+  (0.0ms) begin transaction
651
+ SQL (4.8ms) 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
+  (4.7ms) rollback transaction
655
+  (1.1ms) DELETE FROM "uploads";
656
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
657
+  (0.0ms) begin transaction
658
+ SQL (0.4ms) 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: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
+  (0.2ms) rollback transaction
662
+  (5.0ms) DELETE FROM "uploads";
663
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
664
+ Connecting to database specified by database.yml
665
+  (0.0ms) begin transaction
666
+ SQL (5.4ms) 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
+  (4.5ms) rollback transaction
670
+  (1.0ms) DELETE FROM "uploads";
671
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
672
+  (0.1ms) begin transaction
673
+ SQL (0.5ms) 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: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
+  (0.4ms) rollback transaction
677
+  (0.6ms) DELETE FROM "uploads";
678
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
679
+ Connecting to database specified by database.yml
680
+  (0.1ms) begin transaction
681
+ SQL (6.1ms) 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
+  (1.0ms) commit transaction
685
+  (0.8ms) DELETE FROM "uploads";
686
+  (0.8ms) DELETE FROM sqlite_sequence where name = 'uploads';
687
+  (0.0ms) begin transaction
688
+ SQL (0.4ms) 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]]
689
+ [paperclip] Saving attachments.
690
+ [paperclip] saving files/1/random-bytes.bin
691
+  (0.9ms) commit transaction
692
+  (0.7ms) DELETE FROM "uploads";
693
+  (1.1ms) DELETE FROM sqlite_sequence where name = 'uploads';
694
+ Connecting to database specified by database.yml
695
+  (0.0ms) begin transaction
696
+ SQL (4.9ms) 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
+  (0.9ms) commit transaction
700
+  (0.7ms) DELETE FROM "uploads";
701
+  (0.7ms) DELETE FROM sqlite_sequence where name = 'uploads';
702
+  (0.1ms) begin transaction
703
+ SQL (0.4ms) 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]]
704
+ [paperclip] Saving attachments.
705
+ [paperclip] saving files/1/random-bytes.bin
706
+  (0.5ms) commit transaction
707
+  (0.8ms) DELETE FROM "uploads";
708
+  (0.7ms) 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.1
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-11 00:00:00.000000000 Z
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/excon.rb
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:
@@ -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