dynamic_paperclip 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,13 +32,14 @@ module DynamicPaperclip
32
32
  def dynamic_url(definition)
33
33
  raise DynamicPaperclip::Errors::SecretNotSet, "No secret has been configured. Please run the dynamic_paperclip:install generator." unless DynamicPaperclip.config.secret.present?
34
34
 
35
- style_name = StyleNaming.dynamic_style_name_from_definition(definition)
35
+ escaped_style_name = StyleNaming.dynamic_style_name_from_definition(definition)
36
+ unescaped_style_name = StyleNaming.dynamic_style_name_from_definition(definition, false)
36
37
 
37
- url = url(style_name)
38
+ url = url(unescaped_style_name)
38
39
 
39
40
  delimiter_char = url.match(/\?.+=/) ? '&' : '?'
40
41
 
41
- "#{url}#{delimiter_char}s=#{UrlSecurity.generate_hash(style_name)}".html_safe
42
+ "#{url}#{delimiter_char}s=#{UrlSecurity.generate_hash(escaped_style_name)}"
42
43
  end
43
44
 
44
45
  private
@@ -2,9 +2,9 @@ module DynamicPaperclip
2
2
  module StyleNaming
3
3
  # Generate style name from style definition,
4
4
  # only supports strings at the moment
5
- def self.dynamic_style_name_from_definition(options)
5
+ def self.dynamic_style_name_from_definition(options, uri_escape=true)
6
6
  if options.is_a?(String)
7
- "dynamic_#{URI.escape(options)}".to_sym
7
+ "dynamic_#{uri_escape ? URI.escape(options) : options}".to_sym
8
8
  else
9
9
  raise 'Only String options are supported with dynamic attachments'
10
10
  end
@@ -1,3 +1,3 @@
1
1
  module DynamicPaperclip
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
Binary file
@@ -17557,3 +17557,195 @@ Completed 200 OK in 0.4ms (ActiveRecord: 0.0ms)
17557
17557
   (0.0ms) rollback transaction
17558
17558
   (0.0ms) begin transaction
17559
17559
   (0.0ms) rollback transaction
17560
+ Connecting to database specified by database.yml
17561
+  (20.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
17562
+ Migrating to CreatePhotos (20131102002336)
17563
+  (0.1ms) begin transaction
17564
+ Fixture Delete (0.3ms) DELETE FROM "photos"
17565
+ Fixture Insert (0.1ms) INSERT INTO "photos" ("id", "image_file_name", "image_content_type", "created_at", "updated_at") VALUES (1, 'rails.png', 'image/png', '2013-11-04 20:12:05', '2013-11-04 20:12:05')
17566
+  (0.5ms) commit transaction
17567
+  (0.0ms) begin transaction
17568
+ Photo Load (0.2ms) SELECT "photos".* FROM "photos" WHERE "photos"."id" = ? LIMIT 1 [["id", 1]]
17569
+  (0.1ms) rollback transaction
17570
+  (0.0ms) begin transaction
17571
+ Photo Load (0.1ms) SELECT "photos".* FROM "photos" WHERE "photos"."id" = ? LIMIT 1 [["id", 1]]
17572
+  (0.0ms) rollback transaction
17573
+  (0.0ms) begin transaction
17574
+ Photo Load (0.1ms) SELECT "photos".* FROM "photos" WHERE "photos"."id" = ? LIMIT 1 [["id", 1]]
17575
+  (0.0ms) rollback transaction
17576
+  (0.0ms) begin transaction
17577
+ Photo Load (0.1ms) SELECT "photos".* FROM "photos" WHERE "photos"."id" = ? LIMIT 1 [["id", 1]]
17578
+  (0.0ms) rollback transaction
17579
+  (0.0ms) begin transaction
17580
+ Photo Load (0.1ms) SELECT "photos".* FROM "photos" WHERE "photos"."id" = ? LIMIT 1 [["id", 1]]
17581
+  (0.1ms) rollback transaction
17582
+  (0.0ms) begin transaction
17583
+  (0.0ms) rollback transaction
17584
+  (0.0ms) begin transaction
17585
+ Photo Load (0.1ms) SELECT "photos".* FROM "photos" WHERE "photos"."id" = ? LIMIT 1 [["id", 1]]
17586
+ Started GET "/system/photos/images/000/000/001/dynamic_100x100/rails.png?s=d2dcb69d514d1030ce01404ebc422423eccf1b02" for 127.0.0.1 at 2013-11-04 15:12:06 -0500
17587
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_photo as PNG
17588
+ Parameters: {"s"=>"d2dcb69d514d1030ce01404ebc422423eccf1b02", "attachment"=>"images", "id_partition"=>"000/000/001", "definition"=>"100x100", "filename"=>"rails"}
17589
+ Photo Load (0.1ms) SELECT "photos".* FROM "photos" WHERE "photos"."id" = ? LIMIT 1 [["id", 1]]
17590
+ Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/sd/669fr45168q7jsmsp132kqfr0000gn/T/rails20131104-21282-5a7lc0.png[0]'
17591
+ Command :: identify -format %m '/var/folders/sd/669fr45168q7jsmsp132kqfr0000gn/T/rails20131104-21282-5a7lc0.png[0]'
17592
+ Command :: identify -format %m '/var/folders/sd/669fr45168q7jsmsp132kqfr0000gn/T/rails20131104-21282-5a7lc0.png[0]'
17593
+ Command :: identify -format %m '/var/folders/sd/669fr45168q7jsmsp132kqfr0000gn/T/rails20131104-21282-5a7lc0.png[0]'
17594
+ Command :: convert '/var/folders/sd/669fr45168q7jsmsp132kqfr0000gn/T/rails20131104-21282-5a7lc0.png[0]' -auto-orient -resize "100x100" '/var/folders/sd/669fr45168q7jsmsp132kqfr0000gn/T/rails20131104-21282-5a7lc020131104-21282-3pqm6l'
17595
+ Command :: file -b --mime '/var/folders/sd/669fr45168q7jsmsp132kqfr0000gn/T/rails20131104-21282-5a7lc020131104-21282-3pqm6l'
17596
+  (0.1ms) SAVEPOINT active_record_1
17597
+  (0.3ms) UPDATE "photos" SET "image_file_size" = 6646, "image_updated_at" = '2013-11-04 20:12:06.144999', "image_file_name" = 'rails.png', "updated_at" = '2013-11-04 20:12:06.261596' WHERE "photos"."id" = 1
17598
+  (0.0ms) RELEASE SAVEPOINT active_record_1
17599
+ Sent file /Users/jimbo/OSS/dynamic_paperclip/test/dummy/public/system/photos/images/000/000/001/dynamic_100x100/rails.png (0.1ms)
17600
+ Completed 200 OK in 127.7ms (ActiveRecord: 0.5ms)
17601
+  (0.4ms) rollback transaction
17602
+  (0.1ms) begin transaction
17603
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17604
+ Parameters: {"attachment"=>"images", "id"=>"1", "definition"=>"42x42", "filename"=>"file", "s"=>"a9009b02490c94166d05d0df83e572e8e0bacc92"}
17605
+ Sent file /Users/jimbo/OSS/dynamic_paperclip/test/fixtures/rails.png (0.1ms)
17606
+ Completed 200 OK in 1.3ms (ActiveRecord: 0.0ms)
17607
+  (0.1ms) rollback transaction
17608
+  (0.0ms) begin transaction
17609
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17610
+ Parameters: {"attachment"=>"image_with_id_partition_in_urls", "id_partition"=>"000/010/042", "definition"=>"42x42", "filename"=>"file", "s"=>"a9009b02490c94166d05d0df83e572e8e0bacc92"}
17611
+ Sent file /Users/jimbo/OSS/dynamic_paperclip/test/fixtures/rails.png (0.1ms)
17612
+ Completed 200 OK in 0.6ms (ActiveRecord: 0.0ms)
17613
+  (0.0ms) rollback transaction
17614
+  (0.0ms) begin transaction
17615
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17616
+ Parameters: {"attachment"=>"images", "id"=>"1", "definition"=>"42x42", "filename"=>"file", "s"=>"a9009b02490c94166d05d0df83e572e8e0bacc92"}
17617
+ Sent file /Users/jimbo/OSS/dynamic_paperclip/test/fixtures/rails.png (0.1ms)
17618
+ Completed 200 OK in 0.6ms (ActiveRecord: 0.0ms)
17619
+  (0.1ms) rollback transaction
17620
+  (0.0ms) begin transaction
17621
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17622
+ Parameters: {"attachment"=>"images", "id"=>"1", "definition"=>"42x42", "filename"=>"file", "s"=>"a9009b02490c94166d05d0df83e572e8e0bacc92"}
17623
+ Sent file /Users/jimbo/OSS/dynamic_paperclip/test/fixtures/rails.png (0.1ms)
17624
+ Completed 200 OK in 0.6ms (ActiveRecord: 0.0ms)
17625
+  (0.1ms) rollback transaction
17626
+  (0.0ms) begin transaction
17627
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17628
+ Parameters: {"attachment"=>"bars", "id"=>"1", "style"=>"style", "filename"=>"file"}
17629
+ Completed 500 Internal Server Error in 0.4ms
17630
+  (0.0ms) rollback transaction
17631
+  (0.0ms) begin transaction
17632
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17633
+ Parameters: {"attachment"=>"images", "id"=>"1", "definition"=>"42x42", "filename"=>"file", "s"=>"this is an invalid hash"}
17634
+ Completed 500 Internal Server Error in 0.5ms
17635
+  (0.0ms) rollback transaction
17636
+  (0.0ms) begin transaction
17637
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17638
+ Parameters: {"attachment"=>"images", "style"=>"style", "filename"=>"file"}
17639
+ Completed 500 Internal Server Error in 0.4ms
17640
+  (0.0ms) rollback transaction
17641
+  (0.0ms) begin transaction
17642
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17643
+ Parameters: {"attachment"=>"images", "id"=>"1", "definition"=>"42x42", "filename"=>"file", "s"=>"a9009b02490c94166d05d0df83e572e8e0bacc92"}
17644
+ Sent file /Users/jimbo/OSS/dynamic_paperclip/test/fixtures/rails.png (0.1ms)
17645
+ Completed 200 OK in 0.5ms (ActiveRecord: 0.0ms)
17646
+  (0.0ms) rollback transaction
17647
+  (0.0ms) begin transaction
17648
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17649
+ Parameters: {"attachment"=>"images", "id"=>"1", "definition"=>"42x42", "filename"=>"file", "s"=>"a9009b02490c94166d05d0df83e572e8e0bacc92"}
17650
+ Completed 200 OK in 0.4ms (ActiveRecord: 0.0ms)
17651
+  (0.0ms) rollback transaction
17652
+  (0.0ms) begin transaction
17653
+  (0.0ms) rollback transaction
17654
+  (0.0ms) begin transaction
17655
+  (0.0ms) rollback transaction
17656
+ Connecting to database specified by database.yml
17657
+  (15.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
17658
+ Migrating to CreatePhotos (20131102002336)
17659
+  (0.1ms) begin transaction
17660
+ Fixture Delete (0.3ms) DELETE FROM "photos"
17661
+ Fixture Insert (0.1ms) INSERT INTO "photos" ("id", "image_file_name", "image_content_type", "created_at", "updated_at") VALUES (1, 'rails.png', 'image/png', '2013-11-04 20:12:18', '2013-11-04 20:12:18')
17662
+  (0.9ms) commit transaction
17663
+  (0.0ms) begin transaction
17664
+ Photo Load (0.2ms) SELECT "photos".* FROM "photos" WHERE "photos"."id" = ? LIMIT 1 [["id", 1]]
17665
+  (0.1ms) rollback transaction
17666
+  (0.0ms) begin transaction
17667
+ Photo Load (0.1ms) SELECT "photos".* FROM "photos" WHERE "photos"."id" = ? LIMIT 1 [["id", 1]]
17668
+  (0.0ms) rollback transaction
17669
+  (0.0ms) begin transaction
17670
+ Photo Load (0.1ms) SELECT "photos".* FROM "photos" WHERE "photos"."id" = ? LIMIT 1 [["id", 1]]
17671
+  (0.0ms) rollback transaction
17672
+  (0.0ms) begin transaction
17673
+ Photo Load (0.1ms) SELECT "photos".* FROM "photos" WHERE "photos"."id" = ? LIMIT 1 [["id", 1]]
17674
+  (0.0ms) rollback transaction
17675
+  (0.0ms) begin transaction
17676
+ Photo Load (0.1ms) SELECT "photos".* FROM "photos" WHERE "photos"."id" = ? LIMIT 1 [["id", 1]]
17677
+  (0.1ms) rollback transaction
17678
+  (0.0ms) begin transaction
17679
+  (0.0ms) rollback transaction
17680
+  (0.0ms) begin transaction
17681
+ Photo Load (0.1ms) SELECT "photos".* FROM "photos" WHERE "photos"."id" = ? LIMIT 1 [["id", 1]]
17682
+ Started GET "/system/photos/images/000/000/001/dynamic_100x100/rails.png?s=d2dcb69d514d1030ce01404ebc422423eccf1b02" for 127.0.0.1 at 2013-11-04 15:12:19 -0500
17683
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_photo as PNG
17684
+ Parameters: {"s"=>"d2dcb69d514d1030ce01404ebc422423eccf1b02", "attachment"=>"images", "id_partition"=>"000/000/001", "definition"=>"100x100", "filename"=>"rails"}
17685
+ Photo Load (0.1ms) SELECT "photos".* FROM "photos" WHERE "photos"."id" = ? LIMIT 1 [["id", 1]]
17686
+ Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/sd/669fr45168q7jsmsp132kqfr0000gn/T/rails20131104-21351-1vyc03p.png[0]'
17687
+ Command :: identify -format %m '/var/folders/sd/669fr45168q7jsmsp132kqfr0000gn/T/rails20131104-21351-1vyc03p.png[0]'
17688
+ Command :: identify -format %m '/var/folders/sd/669fr45168q7jsmsp132kqfr0000gn/T/rails20131104-21351-1vyc03p.png[0]'
17689
+ Command :: identify -format %m '/var/folders/sd/669fr45168q7jsmsp132kqfr0000gn/T/rails20131104-21351-1vyc03p.png[0]'
17690
+ Command :: convert '/var/folders/sd/669fr45168q7jsmsp132kqfr0000gn/T/rails20131104-21351-1vyc03p.png[0]' -auto-orient -resize "100x100" '/var/folders/sd/669fr45168q7jsmsp132kqfr0000gn/T/rails20131104-21351-1vyc03p20131104-21351-1jbznws'
17691
+ Command :: file -b --mime '/var/folders/sd/669fr45168q7jsmsp132kqfr0000gn/T/rails20131104-21351-1vyc03p20131104-21351-1jbznws'
17692
+  (0.1ms) SAVEPOINT active_record_1
17693
+  (0.3ms) UPDATE "photos" SET "image_file_size" = 6646, "image_updated_at" = '2013-11-04 20:12:19.111059', "image_file_name" = 'rails.png', "updated_at" = '2013-11-04 20:12:19.216641' WHERE "photos"."id" = 1
17694
+  (0.0ms) RELEASE SAVEPOINT active_record_1
17695
+ Sent file /Users/jimbo/OSS/dynamic_paperclip/test/dummy/public/system/photos/images/000/000/001/dynamic_100x100/rails.png (0.1ms)
17696
+ Completed 200 OK in 115.6ms (ActiveRecord: 0.5ms)
17697
+  (0.4ms) rollback transaction
17698
+  (0.1ms) begin transaction
17699
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17700
+ Parameters: {"attachment"=>"images", "id"=>"1", "definition"=>"42x42", "filename"=>"file", "s"=>"a9009b02490c94166d05d0df83e572e8e0bacc92"}
17701
+ Sent file /Users/jimbo/OSS/dynamic_paperclip/test/fixtures/rails.png (0.1ms)
17702
+ Completed 200 OK in 1.1ms (ActiveRecord: 0.0ms)
17703
+  (0.0ms) rollback transaction
17704
+  (0.0ms) begin transaction
17705
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17706
+ Parameters: {"attachment"=>"image_with_id_partition_in_urls", "id_partition"=>"000/010/042", "definition"=>"42x42", "filename"=>"file", "s"=>"a9009b02490c94166d05d0df83e572e8e0bacc92"}
17707
+ Sent file /Users/jimbo/OSS/dynamic_paperclip/test/fixtures/rails.png (0.1ms)
17708
+ Completed 200 OK in 0.6ms (ActiveRecord: 0.0ms)
17709
+  (0.0ms) rollback transaction
17710
+  (0.0ms) begin transaction
17711
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17712
+ Parameters: {"attachment"=>"images", "id"=>"1", "definition"=>"42x42", "filename"=>"file", "s"=>"a9009b02490c94166d05d0df83e572e8e0bacc92"}
17713
+ Sent file /Users/jimbo/OSS/dynamic_paperclip/test/fixtures/rails.png (0.1ms)
17714
+ Completed 200 OK in 0.6ms (ActiveRecord: 0.0ms)
17715
+  (0.0ms) rollback transaction
17716
+  (0.0ms) begin transaction
17717
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17718
+ Parameters: {"attachment"=>"images", "id"=>"1", "definition"=>"42x42", "filename"=>"file", "s"=>"a9009b02490c94166d05d0df83e572e8e0bacc92"}
17719
+ Sent file /Users/jimbo/OSS/dynamic_paperclip/test/fixtures/rails.png (0.1ms)
17720
+ Completed 200 OK in 0.7ms (ActiveRecord: 0.0ms)
17721
+  (0.1ms) rollback transaction
17722
+  (0.0ms) begin transaction
17723
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17724
+ Parameters: {"attachment"=>"bars", "id"=>"1", "style"=>"style", "filename"=>"file"}
17725
+ Completed 500 Internal Server Error in 0.4ms
17726
+  (0.0ms) rollback transaction
17727
+  (0.0ms) begin transaction
17728
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17729
+ Parameters: {"attachment"=>"images", "id"=>"1", "definition"=>"42x42", "filename"=>"file", "s"=>"this is an invalid hash"}
17730
+ Completed 500 Internal Server Error in 0.5ms
17731
+  (0.0ms) rollback transaction
17732
+  (0.0ms) begin transaction
17733
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17734
+ Parameters: {"attachment"=>"images", "style"=>"style", "filename"=>"file"}
17735
+ Completed 500 Internal Server Error in 0.4ms
17736
+  (0.0ms) rollback transaction
17737
+  (0.0ms) begin transaction
17738
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17739
+ Parameters: {"attachment"=>"images", "id"=>"1", "definition"=>"42x42", "filename"=>"file", "s"=>"a9009b02490c94166d05d0df83e572e8e0bacc92"}
17740
+ Sent file /Users/jimbo/OSS/dynamic_paperclip/test/fixtures/rails.png (0.1ms)
17741
+ Completed 200 OK in 0.6ms (ActiveRecord: 0.0ms)
17742
+  (0.0ms) rollback transaction
17743
+  (0.0ms) begin transaction
17744
+ Processing by DynamicPaperclip::AttachmentStylesController#generate_foo as HTML
17745
+ Parameters: {"attachment"=>"images", "id"=>"1", "definition"=>"42x42", "filename"=>"file", "s"=>"a9009b02490c94166d05d0df83e572e8e0bacc92"}
17746
+ Completed 200 OK in 0.4ms (ActiveRecord: 0.0ms)
17747
+  (0.0ms) rollback transaction
17748
+  (0.0ms) begin transaction
17749
+  (0.0ms) rollback transaction
17750
+  (0.0ms) begin transaction
17751
+  (0.0ms) rollback transaction
@@ -10,7 +10,7 @@ class AttachmentTest < ActiveSupport::TestCase
10
10
  should 'generate correct secure attachment URL when given a style definition' do
11
11
  DynamicPaperclip::Config.any_instance.stubs(:secret).returns('abc123')
12
12
 
13
- assert_equal "/system/photos/images/000/000/001/dynamic_50x50%2523/rails.png?s=#{Digest::SHA1.hexdigest("abc123dynamic_50x50%23")}", photos(:rails).image.dynamic_url('50x50#')
13
+ assert_equal "/system/photos/images/000/000/001/dynamic_50x50%23/rails.png?s=#{Digest::SHA1.hexdigest("abc123dynamic_50x50%23")}", photos(:rails).image.dynamic_url('50x50#')
14
14
  end
15
15
 
16
16
  should 'raise error if no secret has been configured' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic_paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: