kilt-cms 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.rdoc +8 -8
- data/Rakefile +1 -0
- data/app/assets/images/kilt/logo.png +0 -0
- data/app/assets/images/kilt/tartan.png +0 -0
- data/app/assets/stylesheets/kilt/screen.css +1962 -4
- data/app/controllers/kilt/kilt_controller.rb +14 -6
- data/app/views/kilt/kilt/_field_setup.html.erb +6 -0
- data/app/views/kilt/kilt/_form.html.erb +9 -5
- data/app/views/kilt/kilt/index.html.erb +0 -2
- data/app/views/kilt/kilt/list.html.erb +3 -3
- data/app/views/layouts/kilt/cms.html.erb +12 -1
- data/app/views/layouts/kilt/cms/_default_creds_warning.html.erb +4 -0
- data/app/views/layouts/kilt/cms/_menu.html.erb +1 -7
- data/lib/generators/kilt/backend_generator.rb +0 -1
- data/lib/generators/kilt/templates/backend/creds.yml.example +6 -2
- data/lib/kilt.rb +17 -25
- data/lib/kilt/base.rb +3 -1
- data/lib/kilt/engine.rb +1 -2
- data/lib/kilt/object.rb +1 -1
- data/lib/kilt/slugger.rb +55 -0
- data/lib/kilt/upload.rb +18 -46
- data/lib/kilt/upload/local.rb +17 -0
- data/lib/kilt/upload/s3.rb +24 -0
- data/lib/kilt/utils.rb +1 -5
- data/lib/kilt_object.rb +7 -2
- data/lib/kilt_view_model.rb +44 -0
- data/test/dummy/config/kilt/config.yml +11 -2
- data/test/dummy/config/kilt/creds.yml.example +6 -2
- data/test/generators/kilt/backend_generator_spec.rb +0 -7
- data/test/kilt/upload_spec.rb +309 -0
- data/test/kilt/utils_spec.rb +4 -12
- data/test/kilt_spec.rb +132 -26
- data/test/kilt_view_model_spec.rb +128 -0
- data/test/minitest_helper.rb +6 -5
- metadata +47 -231
- data/lib/generators/kilt/frontend_generator.rb +0 -37
- data/lib/generators/kilt/templates/backend/creds.yml.rethinkdb.example +0 -22
- data/lib/generators/kilt/templates/frontend/application.html.erb +0 -24
- data/lib/generators/kilt/templates/frontend/assets/javascripts/application.js +0 -14
- data/lib/generators/kilt/templates/frontend/assets/javascripts/html5shiv.js +0 -2
- data/lib/generators/kilt/templates/frontend/assets/javascripts/mediaqueries.js +0 -1
- data/lib/generators/kilt/templates/frontend/assets/stylesheets/application.css +0 -13
- data/lib/generators/kilt/templates/frontend/assets/stylesheets/screen.css +0 -160
- data/lib/generators/kilt/templates/frontend/dummy.js.erb +0 -11
- data/lib/generators/kilt/templates/frontend/home_controller.rb.erb +0 -4
- data/lib/generators/kilt/templates/frontend/index.html.erb +0 -5
- data/lib/kilt/db/rethink_db.rb +0 -108
- data/test/dummy/config/kilt/creds.yml +0 -16
- data/test/dummy/log/development.log +0 -84143
- data/test/dummy/log/test.log +0 -36
- data/test/dummy/public/uploads/image/photo.JPG +0 -0
- data/test/dummy/public/uploads/image/timbo.jpg +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/03cdc43618f8bef3dfc725a1886c40ed +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/0d8e5c7178ebdb79e5b9cc4ef439eae8 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/13a3d23d13c1459a86283c4fe577a775 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/18837248cb3274df9b7c6b0a5dcd56a5 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/1c198a7e1d4ae808a6adf4c4809061eb +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/20dffc9385ea740ceca470ee4e4b2197 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/23733156ea27da67211ba7ff763d76f0 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2e57def2c82ce30227eefea2360d5f50 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/3148655edeef1c319d57d0f9570acfd5 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/32ab48c63ad3bb6ddc1f419e51adb5db +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/36715e644093cfcb33ac795f3c9d66fe +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/36f9a7f6f43adb582ac6eec43b58eb30 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/36fff19076c588427464432f563a8d2d +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/3878e0f19bbd21176b1bcc46160a3df3 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/3cee919b5b764629fbb01de361ad1b99 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/3d69f4783ceef2f5455635de03e6c62a +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/3d8ca1585ee95c5efb388645d66cf377 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/3e0acde4cdc501f590a21ede6fac0b97 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/413be9c73d25c7febe933f4619da7cf8 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/4a935342c0113b534ad7622234965544 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/4b5c4a1edd3823a6a6c39e06b6eb230a +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/4c5736bf0bd429296d1a32930364897e +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/4f26158b7a804a3e3c47ce0ceff2798c +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/542fc810f9cd36e7bed9a3e5e9670995 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/56f1e7d57d31bf3315e1e33732d57faa +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/5bea4c2d87ec725262213ed51575b485 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/5eb5178b706a9b8bd0362b7ed487339a +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/5fa6492da1cba5232b9e9799b5e2bf8f +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/5fe3d26a30497da82978c9f7ee53068b +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/66f697b8e4167ad9ebefbd8b5fc65b23 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/6b6e86e81f5e8f80bb2b3d1e8f7ed7f3 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/6c2ddc22c04321c269de383e37cb519b +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/6caab0d3b759107ab41492546763aaf0 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/6d83c6efd2bf1080ba1dead9fcfdd0db +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/7035e5c60f5da3b7fc12c472677483d0 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/704c682957c2beb38a1927ddb66cc557 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/70d4b3b9e59d0e01e90eebf94dbc2c47 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/74b6c3e00222b8bf31b0ecf50fcb0d38 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/8127282074e6ffd457b72c228a69f0c0 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/8ffacb4ba6e6ca3da12ac1100f664b30 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/91021bdb7ebb3d4f6fdf4e49909d4c07 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/914095efd3b33401a7f29f9fb05d72d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/9dd98bca318fb820a8451cafce020588 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/9f2c00a36b5b8c713a797b508c778a65 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/a88ab4e49bb7203b8e0586c38efdd2b0 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/acfc15d25fde8b933b06c91324755751 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/b259805c84c81064f20700498328f109 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/b7e1f059a53a1e79df01a336fb1f50f0 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/c0671678b70011547b80da0669d031cc +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/c1006115f345f87cc152b851154e9e34 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cf0d5ad037fbf541c6b982abf73b9938 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d6973c1d43f8ca41b98a6b640fda2616 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/da31523b2e8cf32dd8db9f304d5b7395 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/dc676330961fd22be77c48cb77ec065f +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/ddc29f2c13cd99d017fd526b61dcb951 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/de45247cb814cafe20e9e46c79e470fe +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/df0b7c3ac590a286561806e813c2974f +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/dfa8b85e3c1273b7e69839e4e607c3e1 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/e22d705d0c889ec4837f183a9beec0f3 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/e3a4ad3549e1e57d03698a36daeff406 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/e7ba95a61b1b9381906a88610dceb6dd +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/ef7c8ce46dfc9e9087ce84dbdfdd0011 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f3e1a8ba304f70dccefd77356c900ebc +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f4b5dd06a6113950c0f481cbc5a31a66 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/data/meta_request/1c3d4a4b-d7e1-4126-8bfc-572acbc2f675.json +0 -1
- data/test/dummy/tmp/data/meta_request/449ff78e-30d2-4cc5-bbb7-3397d04a4c46.json +0 -1
- data/test/dummy/tmp/data/meta_request/5974cfb9-99bd-4d5c-a4e1-6e352ecd2dd8.json +0 -1
- data/test/dummy/tmp/data/meta_request/960de12b-b1c5-4d44-937b-e3d8c00d682c.json +0 -1
- data/test/dummy/tmp/data/meta_request/9df9ad77-1b70-4fb7-ad18-f31f28c60c6c.json +0 -1
- data/test/dummy/tmp/data/meta_request/a5374758-4e16-487a-ab11-9a69a1abed2e.json +0 -1
- data/test/dummy/tmp/data/meta_request/a65d97b2-df1f-445e-99d5-615c4db5c4e1.json +0 -1
- data/test/dummy/tmp/data/meta_request/b3693c6f-23cd-4afe-ae82-38078eaa643a.json +0 -1
- data/test/dummy/tmp/data/meta_request/daa1c80a-bad3-4bc1-8f67-d586979cbedc.json +0 -1
- data/test/dummy/tmp/data/meta_request/e2e7621f-08e5-46dd-83c2-b87eb6d5fd45.json +0 -1
@@ -0,0 +1,24 @@
|
|
1
|
+
module Kilt
|
2
|
+
module Upload
|
3
|
+
module S3
|
4
|
+
def self.upload type, file_reference
|
5
|
+
Kilt::Utils.ensure_s3_bucket_exists
|
6
|
+
if file_reference
|
7
|
+
begin
|
8
|
+
s3 = AWS::S3.new(
|
9
|
+
:access_key_id => Kilt.config.s3.key,
|
10
|
+
:secret_access_key => Kilt.config.s3.secret)
|
11
|
+
bucket = s3.buckets[Kilt.config.s3.bucket]
|
12
|
+
new_file = bucket.objects["#{type}/#{file_reference.original_filename}"]
|
13
|
+
new_file.write(Pathname.new(file_reference.tempfile), :acl => :public_read)
|
14
|
+
file_reference.original_filename
|
15
|
+
rescue
|
16
|
+
''
|
17
|
+
end
|
18
|
+
else
|
19
|
+
''
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/kilt/utils.rb
CHANGED
data/lib/kilt_object.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
class KiltViewModel
|
2
|
+
|
3
|
+
def self.build input
|
4
|
+
this_is_a_collection(input) ? build_view_models_from(input)
|
5
|
+
: build_a_view_model_from(input)
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize subject = {}
|
9
|
+
@subject = subject
|
10
|
+
end
|
11
|
+
|
12
|
+
def [] id
|
13
|
+
@subject[id.to_s] || @subject[id.to_s.to_sym]
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(meth, *args, &blk)
|
17
|
+
@subject[meth.to_s] || @subject[meth]
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def build_a_view_model_from record
|
25
|
+
eval("#{record['type']}_view_model".classify).new record
|
26
|
+
rescue
|
27
|
+
KiltViewModel.new record
|
28
|
+
end
|
29
|
+
|
30
|
+
def this_is_a_collection input
|
31
|
+
input.is_a?(Array) || input.is_a?(Kilt::ObjectCollection)
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_view_models_from records
|
35
|
+
records.map { |r| build_a_view_model_from r }
|
36
|
+
.sort_by do |x|
|
37
|
+
sequence = x.sequence.to_s.to_i
|
38
|
+
sequence.to_s == x.sequence.to_s ? sequence : 99999999999
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
name:
|
1
|
+
name: Test Kilt CMS App
|
2
2
|
storage:
|
3
3
|
strategy: local
|
4
4
|
objects:
|
@@ -14,4 +14,13 @@ objects:
|
|
14
14
|
image: image
|
15
15
|
vimeo_video: vimeo
|
16
16
|
youtube_video: youtube
|
17
|
-
other: file
|
17
|
+
other: file
|
18
|
+
satchel:
|
19
|
+
fields:
|
20
|
+
name: text
|
21
|
+
weight: number
|
22
|
+
description: longtext
|
23
|
+
dictionary:
|
24
|
+
fields:
|
25
|
+
name: text
|
26
|
+
|
@@ -7,5 +7,9 @@ s3:
|
|
7
7
|
secret: <S3 secret>
|
8
8
|
bucket: <S3 bucket>
|
9
9
|
auth:
|
10
|
-
username:
|
11
|
-
password:
|
10
|
+
username: admin
|
11
|
+
password: changeme
|
12
|
+
default_auth:
|
13
|
+
username: admin
|
14
|
+
password: changeme
|
15
|
+
note: "Feel free to remove default_auth when you change your username/password"
|
@@ -44,13 +44,6 @@ describe Kilt::Generators::BackendGenerator do
|
|
44
44
|
generator.generate
|
45
45
|
end
|
46
46
|
|
47
|
-
it "should copy the rethinkdb credential file to the app" do
|
48
|
-
root_result = Object.new
|
49
|
-
root.stubs(:join).with('config', 'kilt', 'creds.yml.rethinkdb.example').returns root_result
|
50
|
-
generator.expects(:copy_file).with 'creds.yml.rethinkdb.example', root_result
|
51
|
-
generator.generate
|
52
|
-
end
|
53
|
-
|
54
47
|
it "should copy the kilt.rb file as an app initializer" do
|
55
48
|
root_result = Object.new
|
56
49
|
root.stubs(:join).with('config', 'initializers', 'kilt.rb').returns root_result
|
@@ -0,0 +1,309 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../minitest_helper')
|
2
|
+
|
3
|
+
describe Kilt::Upload do
|
4
|
+
|
5
|
+
let(:config) { Struct.new(:storage).new storage }
|
6
|
+
let(:storage) { Struct.new(:strategy).new strategy }
|
7
|
+
|
8
|
+
before do
|
9
|
+
Kilt.stubs(:config).returns config
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "do" do
|
13
|
+
|
14
|
+
let(:type) { Object.new }
|
15
|
+
|
16
|
+
let(:root) { Object.new }
|
17
|
+
|
18
|
+
let(:file_reference) do
|
19
|
+
Struct.new(:original_filename, :read, :tempfile).new SecureRandom.uuid, nil, Object.new
|
20
|
+
end
|
21
|
+
|
22
|
+
before do
|
23
|
+
Rails.stubs(:root).returns root
|
24
|
+
root.stubs(:join).returns nil
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "using the local strategy" do
|
28
|
+
|
29
|
+
let(:strategy) { 'local' }
|
30
|
+
|
31
|
+
before do
|
32
|
+
Kilt::Utils.stubs(:ensure_local_storage_dir_exists)
|
33
|
+
File.stubs(:open)
|
34
|
+
root.stubs(:join).returns Object.new
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should ensure that the local storage dir exists" do
|
38
|
+
File.stubs(:open)
|
39
|
+
Kilt::Utils.expects(:ensure_local_storage_dir_exists)
|
40
|
+
Kilt::Upload.do type, file_reference
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should write the file to local storage" do
|
44
|
+
location = Object.new
|
45
|
+
root.stubs(:join)
|
46
|
+
.with('public', 'uploads', type, file_reference.original_filename)
|
47
|
+
.returns location
|
48
|
+
|
49
|
+
File.expects(:open).with location, 'wb'
|
50
|
+
|
51
|
+
Kilt::Upload.do type, file_reference
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return the original file reference" do
|
55
|
+
result = Kilt::Upload.do type, file_reference
|
56
|
+
result.must_be_same_as file_reference.original_filename
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "given no file reference" do
|
60
|
+
it "should no try to write a file" do
|
61
|
+
File.stubs(:open).raises 'An error'
|
62
|
+
Kilt::Upload.do type, nil
|
63
|
+
# no error should be thrown
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return an empty string" do
|
67
|
+
Kilt::Upload.do(type, nil).must_equal ''
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "actually writing the file locally" do
|
74
|
+
|
75
|
+
let(:strategy) { 'local' }
|
76
|
+
|
77
|
+
let(:test_file) { "test/test_s3.txt" }
|
78
|
+
|
79
|
+
before do
|
80
|
+
File.delete(test_file) if File.exists? test_file
|
81
|
+
end
|
82
|
+
|
83
|
+
after do
|
84
|
+
File.delete(test_file) if File.exists? test_file
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should write the file" do
|
88
|
+
Kilt::Utils.stubs(:ensure_local_storage_dir_exists)
|
89
|
+
|
90
|
+
random_content = SecureRandom.uuid
|
91
|
+
file_reference.stubs(:read).returns random_content
|
92
|
+
root.stubs(:join).returns test_file
|
93
|
+
|
94
|
+
Kilt::Upload.do type, file_reference
|
95
|
+
|
96
|
+
File.open(test_file).read.must_equal random_content
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "uploading a file to s3" do
|
102
|
+
|
103
|
+
let(:strategy) { 's3' }
|
104
|
+
|
105
|
+
let(:type) { SecureRandom.uuid }
|
106
|
+
|
107
|
+
let(:s3_config) do
|
108
|
+
Struct.new(:key, :secret, :bucket)
|
109
|
+
.new(Object.new, Object.new, Object.new)
|
110
|
+
end
|
111
|
+
|
112
|
+
let(:s3) { Object.new }
|
113
|
+
let(:bucket) { Object.new }
|
114
|
+
let(:buckets) { Object.new }
|
115
|
+
let(:objects) { Object.new }
|
116
|
+
let(:the_file) { Object.new }
|
117
|
+
|
118
|
+
let(:the_location_of_the_temp_file) { Object.new }
|
119
|
+
|
120
|
+
before do
|
121
|
+
Kilt::Utils.stubs(:ensure_s3_bucket_exists)
|
122
|
+
config.stubs(:s3).returns s3_config
|
123
|
+
|
124
|
+
AWS::S3.stubs(:new)
|
125
|
+
.with(access_key_id: s3_config.key,
|
126
|
+
secret_access_key: s3_config.secret)
|
127
|
+
.returns s3
|
128
|
+
|
129
|
+
s3.stubs(:buckets).returns buckets
|
130
|
+
buckets.stubs(:[]).with(s3_config.bucket).returns bucket
|
131
|
+
|
132
|
+
bucket.stubs(:objects).returns objects
|
133
|
+
|
134
|
+
objects.stubs(:[])
|
135
|
+
.with("#{type}/#{file_reference.original_filename}")
|
136
|
+
.returns the_file
|
137
|
+
|
138
|
+
Pathname.stubs(:new)
|
139
|
+
.with(file_reference.tempfile)
|
140
|
+
.returns the_location_of_the_temp_file
|
141
|
+
|
142
|
+
the_file.stubs(:write)
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should ensure that the s3 bucket exists" do
|
146
|
+
Kilt::Utils.expects(:ensure_s3_bucket_exists)
|
147
|
+
Kilt::Upload.do type, file_reference
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should write the file to the bucket" do
|
151
|
+
the_file.expects(:write).with(the_location_of_the_temp_file, { acl: :public_read } )
|
152
|
+
Kilt::Upload.do type, file_reference
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should return the original filename" do
|
156
|
+
result = Kilt::Upload.do type, file_reference
|
157
|
+
result.must_be_same_as file_reference.original_filename
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "when the s3 write fails" do
|
161
|
+
|
162
|
+
before do
|
163
|
+
the_file.expects(:write).raises 'error'
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should eat the error" do
|
167
|
+
# this better not fail
|
168
|
+
Kilt::Upload.do type, file_reference
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should return an empty string" do
|
172
|
+
result = Kilt::Upload.do type, file_reference
|
173
|
+
result.must_equal ''
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
describe "when there is an error getting the s3 object" do
|
179
|
+
before do
|
180
|
+
AWS::S3.stubs(:new).raises 'error'
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should eat the error" do
|
184
|
+
# this better not fail
|
185
|
+
Kilt::Upload.do type, file_reference
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should return an empty string" do
|
189
|
+
result = Kilt::Upload.do type, file_reference
|
190
|
+
result.must_equal ''
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
describe "when no file reference is passed with a s3 type" do
|
197
|
+
|
198
|
+
let(:strategy) { 's3' }
|
199
|
+
|
200
|
+
before do
|
201
|
+
Kilt::Utils.stubs(:ensure_s3_bucket_exists)
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should ensure that the s3 bucket exists" do
|
205
|
+
Kilt::Utils.expects(:ensure_s3_bucket_exists)
|
206
|
+
Kilt::Upload.do type, nil
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should not attempt to hit s3" do
|
210
|
+
AWS::S3.expects(:new).never
|
211
|
+
Kilt::Upload.do type, nil
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should return an empty string" do
|
215
|
+
result = Kilt::Upload.do type, nil
|
216
|
+
result.must_equal ''
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
describe "uploading different fields" do
|
224
|
+
|
225
|
+
let(:strategy) { Object.new }
|
226
|
+
let(:file_reference) { Object.new }
|
227
|
+
|
228
|
+
[:image, :file].each do |type|
|
229
|
+
|
230
|
+
describe type do
|
231
|
+
|
232
|
+
it "should call the do method and return the result" do
|
233
|
+
expected_result = Object.new
|
234
|
+
|
235
|
+
Kilt::Upload.stubs(:do)
|
236
|
+
.with(type.to_s, file_reference)
|
237
|
+
.returns expected_result
|
238
|
+
|
239
|
+
result = Kilt::Upload.send type, file_reference
|
240
|
+
|
241
|
+
result.must_be_same_as expected_result
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|
247
|
+
|
248
|
+
end
|
249
|
+
|
250
|
+
describe "uploadable fields" do
|
251
|
+
|
252
|
+
let(:strategy) { nil }
|
253
|
+
|
254
|
+
describe "and no config was set" do
|
255
|
+
|
256
|
+
before do
|
257
|
+
config.stubs(:uploadable_fields).returns nil
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should return file and image" do
|
261
|
+
fields = Kilt::Upload.uploadable_fields
|
262
|
+
fields.count.must_equal 2
|
263
|
+
fields.include?('file').must_equal true
|
264
|
+
fields.include?('image').must_equal true
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
describe "and the fields were overridden by config" do
|
269
|
+
|
270
|
+
before do
|
271
|
+
config.stubs(:uploadable_fields).returns 'a, b, c'
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should return file and image" do
|
275
|
+
fields = Kilt::Upload.uploadable_fields
|
276
|
+
fields.include?('file').must_equal true
|
277
|
+
fields.include?('image').must_equal true
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should return the fields" do
|
281
|
+
fields = Kilt::Upload.uploadable_fields
|
282
|
+
fields.include?('a').must_equal true
|
283
|
+
fields.include?('b').must_equal true
|
284
|
+
fields.include?('c').must_equal true
|
285
|
+
end
|
286
|
+
|
287
|
+
end
|
288
|
+
|
289
|
+
describe "and some edge cases" do
|
290
|
+
|
291
|
+
before do
|
292
|
+
config.stubs(:uploadable_fields).returns 'r, r, r, file, image, q, s'
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should return every type only once" do
|
296
|
+
fields = Kilt::Upload.uploadable_fields
|
297
|
+
fields.count.must_equal 5
|
298
|
+
fields.include?('r').must_equal true
|
299
|
+
fields.include?('q').must_equal true
|
300
|
+
fields.include?('s').must_equal true
|
301
|
+
fields.include?('file').must_equal true
|
302
|
+
fields.include?('image').must_equal true
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|
308
|
+
|
309
|
+
end
|