expiring_asset_links 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -3
- data/lib/expiring_asset_links/version.rb +1 -1
- data/test/expiring_asset_links_test.rb +5 -7
- data/test/test_helper.rb +16 -2
- metadata +1 -1
data/README.md
CHANGED
@@ -8,14 +8,25 @@ This is helpful when using a WYSIWYG that inserts and previews assets directly f
|
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
-
|
11
|
+
gem install expiring_asset_links
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
15
|
-
###
|
15
|
+
### name your uploader mount `:asset`
|
16
|
+
|
17
|
+
class Images
|
18
|
+
mount_uploader :asset, ImageUploader
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
### specify the fields that will contain :asset links
|
16
23
|
|
17
24
|
class Document
|
18
25
|
attr_expiring_asset_links :body
|
19
26
|
|
20
27
|
end
|
21
|
-
|
28
|
+
|
29
|
+
class Article
|
30
|
+
attr_expiring_asset_links :summary, :body
|
31
|
+
|
32
|
+
end
|
@@ -17,16 +17,14 @@ class ExpiringAssetLinksTest < Test::Unit::TestCase
|
|
17
17
|
config.fog_directory = "test"
|
18
18
|
# config.fog_public = false
|
19
19
|
end
|
20
|
-
|
21
|
-
|
22
20
|
end
|
23
21
|
|
24
22
|
def test_should_assert_true
|
25
|
-
|
26
|
-
document.
|
27
|
-
|
28
|
-
|
29
|
-
assert_equal "<h2>Section One</h2><p>This is the first section in the body of the document. It includes an image.</p><img src=\"
|
23
|
+
file_attachment = FileAttachment.create(name: "test", asset: AssetUploader.new("https://test.s3-us-east-1.amazonaws.com/uploads/test/file_attachment/asset/1/sample.jpg"))
|
24
|
+
document = Document.create(title: "This is the Document Title", body: "<h2>Section One</h2><p>This is the first section in the body of the document. It includes an image.</p><img src=\"#{file_attachment.asset.url}\">")
|
25
|
+
|
26
|
+
assert_equal "<h2>Section One</h2><p>This is the first section in the body of the document. It includes an image.</p><img src=\"FileAttachment{{1}}\">", Document.find(document.id).attributes["body"]
|
27
|
+
assert_equal "<h2>Section One</h2><p>This is the first section in the body of the document. It includes an image.</p><img src=\"https://test.s3-us-east-1.amazonaws.com/uploads/test/file_attachment/asset/1/sample.jpg?AWSAccessKeyId=XXXXXXXXXXXXXXXXXXXX&Signature=XXXXXXXXXXXXXXXXXXXXXXXXXXX%3D&Expires=2222222222\">", Document.find(document.id).body
|
30
28
|
end
|
31
29
|
|
32
30
|
end
|
data/test/test_helper.rb
CHANGED
@@ -19,18 +19,32 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
19
19
|
end
|
20
20
|
create_table :file_attachments do |t|
|
21
21
|
t.integer :id
|
22
|
-
t.integer :
|
22
|
+
t.integer :name
|
23
|
+
t.binary :asset
|
23
24
|
end
|
24
25
|
create_table :image_attachments do |t|
|
25
26
|
t.integer :id
|
26
|
-
t.integer :
|
27
|
+
t.integer :name
|
28
|
+
t.binary :asset
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
32
|
class Document < ActiveRecord::Base
|
31
33
|
attr_expiring_asset_links :body
|
32
34
|
end
|
35
|
+
|
33
36
|
class FileAttachment < ActiveRecord::Base
|
37
|
+
serialize :asset
|
34
38
|
end
|
39
|
+
|
35
40
|
class ImageAttachment < ActiveRecord::Base
|
41
|
+
serialize :asset
|
42
|
+
end
|
43
|
+
|
44
|
+
class AssetUploader < Struct.new(:my_url)
|
45
|
+
def url(*ignore)
|
46
|
+
"#{self.my_url}?AWSAccessKeyId=XXXXXXXXXXXXXXXXXXXX&Signature=XXXXXXXXXXXXXXXXXXXXXXXXXXX%3D&Expires=2222222222"
|
47
|
+
end
|
36
48
|
end
|
49
|
+
|
50
|
+
|