uploadcare-rails 1.0.6 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/initializers/uploadcare.rb +22 -23
- data/lib/uploadcare-rails.rb +6 -5
- data/lib/uploadcare/rails/action_view/include_tags.rb +35 -26
- data/lib/uploadcare/rails/action_view/uploader_tags.rb +31 -29
- data/lib/uploadcare/rails/active_record/has_file.rb +14 -26
- data/lib/uploadcare/rails/active_record/has_group.rb +23 -22
- data/lib/uploadcare/rails/active_record/has_object.rb +3 -4
- data/lib/uploadcare/rails/engine.rb +3 -3
- data/lib/uploadcare/rails/formtastic/formtastic.rb +19 -15
- data/lib/uploadcare/rails/objects/file.rb +13 -25
- data/lib/uploadcare/rails/objects/group.rb +45 -22
- data/lib/uploadcare/rails/operations.rb +57 -0
- data/lib/uploadcare/rails/settings.rb +26 -30
- data/lib/uploadcare/rails/simple_form/simple_form.rb +22 -20
- data/lib/uploadcare/rails/version.rb +1 -1
- data/spec/caching/file_caching_spec.rb +16 -24
- data/spec/caching/group_caching_spec.rb +23 -26
- data/{app → spec/dummy/app}/assets/javascripts/uploadcare-1.5.5.min.js +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +2 -2
- data/spec/dummy/config/routes.rb +2 -2
- data/spec/helpers/include_tags_spec.rb +41 -29
- data/spec/models/has_both_file_and_group_spec.rb +19 -17
- data/spec/models/has_file_spec.rb +46 -47
- data/spec/models/has_group_spec.rb +46 -32
- data/spec/objects/file_spec.rb +9 -11
- data/spec/objects/group_spec.rb +40 -29
- data/spec/operations_spec.rb +28 -0
- data/spec/spec_helper.rb +17 -5
- metadata +235 -199
- data/MIT-LICENSE +0 -20
- data/app/assets/javascripts/uploadcare-0.17.0.js +0 -8248
- data/app/assets/javascripts/uploadcare-0.17.0.min.js +0 -17
- data/app/assets/javascripts/uploadcare-0.18.3.js +0 -8484
- data/app/assets/javascripts/uploadcare-0.18.3.min.js +0 -17
- data/app/assets/javascripts/uploadcare-1.0.1.js +0 -8430
- data/app/assets/javascripts/uploadcare-1.0.1.min.js +0 -17
- data/app/assets/javascripts/uploadcare-1.3.1.js +0 -8563
- data/app/assets/javascripts/uploadcare-1.3.1.min.js +0 -17
- data/app/assets/javascripts/uploadcare-1.5.5.js +0 -9278
- data/app/assets/javascripts/uploadcare.js +0 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/test.log +0 -2166
@@ -1,34 +1,26 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Uploadcare::Rails::File do
|
3
|
+
describe Uploadcare::Rails::File, :vcr do
|
4
|
+
let(:post) { Post.new(title: 'Post title', file: FILE_CDN_URL) }
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
context 'when object is not persisted' do
|
7
|
+
it 'its file is not loaded' do
|
8
|
+
expect(post.file).not_to be_loaded
|
9
|
+
end
|
7
10
|
end
|
8
11
|
|
9
|
-
|
10
|
-
Rails.cache.delete FILE_CDN_URL
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should be not loaded by default" do
|
14
|
-
@post.file.loaded?.should == false
|
15
|
-
end
|
16
|
-
|
17
|
-
it "rails cache for unloaded file should be nil" do
|
18
|
-
cached = Rails.cache.read @post.file.cdn_url
|
19
|
-
cached.should == nil
|
20
|
-
end
|
12
|
+
skip { expect(Rails.cache.read(post.file.cdn_url)).to be_nil }
|
21
13
|
|
22
|
-
|
23
|
-
|
14
|
+
skip 'rails cache should updates after load call' do
|
15
|
+
post.file.load!
|
24
16
|
cached = Rails.cache.read FILE_CDN_URL
|
25
17
|
cached.should be_kind_of(Hash)
|
26
|
-
cached[
|
18
|
+
cached['datetime_uploaded'].should be_kind_of(String)
|
27
19
|
end
|
28
20
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
21
|
+
skip 'file should stay loaded' do
|
22
|
+
post.file.loaded?.should == false
|
23
|
+
post.file.load!
|
24
|
+
post.file.loaded?.should == true
|
33
25
|
end
|
34
|
-
end
|
26
|
+
end
|
@@ -1,43 +1,40 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Uploadcare::Rails::Group do
|
4
|
-
|
5
|
-
@post = PostWithCollection.new title: "Post title", file: GROUP_CDN_URL
|
6
|
-
end
|
3
|
+
describe Uploadcare::Rails::Group, :vcr do
|
4
|
+
let(:post) { PostWithCollection.new(title: 'Title', file: GROUP_CDN_URL) }
|
7
5
|
|
8
6
|
after :each do
|
9
|
-
Rails.cache.delete
|
7
|
+
Rails.cache.delete(GROUP_CDN_URL)
|
10
8
|
end
|
11
9
|
|
12
|
-
it
|
13
|
-
|
10
|
+
it 'should be not loaded by default' do
|
11
|
+
expect(post.file).not_to be_loaded
|
14
12
|
end
|
15
13
|
|
16
|
-
it
|
17
|
-
|
18
|
-
cached.should == nil
|
14
|
+
it 'rails cache should be nil' do
|
15
|
+
expect(Rails.cache.read(post.file.cdn_url)).to be_nil
|
19
16
|
end
|
20
17
|
|
21
|
-
it
|
22
|
-
|
18
|
+
it 'rails cache should updates after load call' do
|
19
|
+
post.file.load!
|
23
20
|
cached = Rails.cache.read GROUP_CDN_URL
|
24
|
-
|
25
|
-
cached
|
21
|
+
|
22
|
+
expect(cached).to be_a(Hash)
|
23
|
+
expect(cached['datetime_created']).to be_a(String)
|
26
24
|
end
|
27
25
|
|
28
|
-
it
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
it 'group should stay loaded' do
|
27
|
+
expect(post.file).not_to be_loaded
|
28
|
+
post.file.load!
|
29
|
+
expect(post.file).to be_loaded
|
32
30
|
end
|
33
31
|
|
34
|
-
it 'cached group should contained json representation of files'
|
35
|
-
|
32
|
+
it 'cached group should contained json representation of files',
|
33
|
+
vcr: { cassette_name: 'group_cahsing_file_load'} do
|
34
|
+
post.file.load!
|
36
35
|
cached = Rails.cache.read GROUP_CDN_URL
|
37
|
-
cached.should be_kind_of(Hash)
|
38
|
-
cached["files"].sample.should be_kind_of(Hash)
|
39
|
-
end
|
40
36
|
|
41
|
-
|
37
|
+
expect(cached).to be_a(Hash)
|
38
|
+
expect(cached['files'].sample).to be_a(Hash)
|
42
39
|
end
|
43
|
-
end
|
40
|
+
end
|
File without changes
|
@@ -2,8 +2,8 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title>Dummy</title>
|
5
|
-
<%= stylesheet_link_tag
|
6
|
-
<%= javascript_include_tag
|
5
|
+
<%= stylesheet_link_tag :application, media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag :application, 'data-turbolinks-track' => true %>
|
7
7
|
<%= csrf_meta_tags %>
|
8
8
|
<%= include_uploadcare_widget_from_cdn %>
|
9
9
|
<%= uploadcare_settings %>
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
Dummy::Application.routes.draw do
|
2
2
|
resources :posts_with_collection_and_files
|
3
3
|
|
4
|
-
root to: "posts#
|
4
|
+
root to: "posts#new"
|
5
5
|
resources :posts
|
6
6
|
resources :post_with_collections
|
7
|
-
|
7
|
+
|
8
8
|
|
9
9
|
# The priority is based upon order of creation: first created -> highest priority.
|
10
10
|
# See how all your routes lay out with "rake routes".
|
@@ -1,42 +1,54 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Uploadcare::Rails do
|
4
|
-
it
|
4
|
+
it 'includes widget from cdn' do
|
5
5
|
tag = helper.include_uploadcare_widget_from_cdn
|
6
|
-
|
7
|
-
tag.
|
6
|
+
|
7
|
+
expect(tag).to eq(
|
8
|
+
[
|
9
|
+
"<script src=\"https://ucarecdn.com/widget/",
|
10
|
+
UPLOADCARE_SETTINGS.widget_version,
|
11
|
+
'/uploadcare/uploadcare.min.js"></script>'
|
12
|
+
].join
|
13
|
+
)
|
8
14
|
end
|
9
15
|
|
10
|
-
|
11
|
-
version
|
16
|
+
describe 'for specifyed version' do
|
17
|
+
let(:version) { '0.13.3' }
|
12
18
|
|
13
|
-
|
14
|
-
|
15
|
-
end
|
19
|
+
it 'uses widget version' do
|
20
|
+
tag = helper.include_uploadcare_widget_from_cdn(version: version)
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
expect(tag).to eq(
|
23
|
+
"<script src=\"https://ucarecdn.com/widget/#{ version }/"\
|
24
|
+
'uploadcare/uploadcare.min.js"></script>'
|
25
|
+
)
|
26
|
+
end
|
20
27
|
|
21
|
-
|
22
|
-
|
23
|
-
|
28
|
+
it 'loads not minified version' do
|
29
|
+
tag =
|
30
|
+
helper.include_uploadcare_widget_from_cdn(version: version, min: false)
|
24
31
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
32
|
+
expect(tag).to eq(
|
33
|
+
"<script src=\"https://ucarecdn.com/widget/#{ version }/"\
|
34
|
+
'uploadcare/uploadcare.js"></script>'
|
35
|
+
)
|
36
|
+
end
|
29
37
|
end
|
30
38
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
describe 'uploadcare settings' do
|
40
|
+
let(:subject) { helper.uploadcare_settings }
|
41
|
+
|
42
|
+
it { is_expected.to be_a(String) }
|
43
|
+
it { is_expected.not_to be_empty }
|
44
|
+
%w(
|
45
|
+
UPLOADCARE_LOCALE UPLOADCARE_PREVIEW_STEP
|
46
|
+
UPLOADCARE_PUBLIC_KEY UPLOADCARE_CLEARABLE
|
47
|
+
UPLOADCARE_TABS UPLOADCARE_AUTOSTORE
|
48
|
+
UPLOADCARE_MANUAL_START UPLOADCARE_PATH_VALUE).each do |content|
|
49
|
+
it 'contains expected selector' do
|
50
|
+
is_expected.to have_selector('script', content: content)
|
51
|
+
end
|
52
|
+
end
|
41
53
|
end
|
42
|
-
end
|
54
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe :has_both_file_and_group_spec do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
let(:subject) do
|
5
|
+
PostsWithCollectionAndFile.new(
|
6
|
+
title: "Post title",
|
7
|
+
group: GROUP_CDN_URL,
|
8
|
+
file: FILE_CDN_URL
|
9
|
+
)
|
10
10
|
end
|
11
11
|
|
12
12
|
after :each do
|
@@ -14,28 +14,30 @@ describe :has_both_file_and_group_spec do
|
|
14
14
|
Rails.cache.delete GROUP_CDN_URL
|
15
15
|
end
|
16
16
|
|
17
|
+
it 'creates empty post' do
|
18
|
+
expect(PostsWithCollectionAndFile.create).to be_persisted
|
19
|
+
end
|
20
|
+
|
17
21
|
it "should respond to has_uploadcare_file? method" do
|
18
|
-
|
19
|
-
@post.should respond_to("has_#{@file_method}_as_uploadcare_file?".to_sym)
|
22
|
+
is_expected.to respond_to("has_file_as_uploadcare_file?".to_sym)
|
20
23
|
end
|
21
24
|
|
22
25
|
it "should respond to has_uploadcare_group? method" do
|
23
|
-
|
24
|
-
@post.should respond_to("has_#{@group_method}_as_uploadcare_group?".to_sym)
|
26
|
+
is_expected.to respond_to("has_group_as_uploadcare_group?".to_sym)
|
25
27
|
end
|
26
28
|
|
27
29
|
it ":has_uploadcare_file? should return true" do
|
28
|
-
|
29
|
-
|
30
|
+
is_expected.to be_has_file_as_uploadcare_file
|
31
|
+
is_expected.to be_has_group_as_uploadcare_group
|
30
32
|
end
|
31
33
|
|
32
34
|
it ":has_uploadcare_group? should return false" do
|
33
|
-
|
34
|
-
|
35
|
+
is_expected.not_to be_has_group_as_uploadcare_file
|
36
|
+
is_expected.not_to be_has_file_as_uploadcare_group
|
35
37
|
end
|
36
38
|
|
37
39
|
it "should have uploadcare file" do
|
38
|
-
|
39
|
-
|
40
|
+
expect(subject.group).to be_an(Uploadcare::Rails::Group)
|
41
|
+
expect(subject.file).to be_an(Uploadcare::Rails::File)
|
40
42
|
end
|
41
|
-
end
|
43
|
+
end
|
@@ -1,47 +1,46 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
describe :has_uploadcare_file do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe :has_uploadcare_file, :vcr do
|
4
|
+
let(:post) { Post.new(title: 'Post title', file: FILE_CDN_URL) }
|
5
|
+
let(:subject) { post }
|
6
|
+
let(:method) { 'file' }
|
7
|
+
|
8
|
+
describe 'object with uploadcare_file' do
|
9
|
+
it 'creates blank post' do
|
10
|
+
Post.create!
|
11
|
+
end
|
12
|
+
it 'responds to has_uploadcare_file? method' do
|
13
|
+
is_expected.to respond_to(:has_file_as_uploadcare_file?)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'responds to has_uploadcare_group? method' do
|
17
|
+
is_expected.to respond_to(:has_file_as_uploadcare_group?)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'has Uploadcare::Rails::File' do
|
21
|
+
expect(post.file).to be_an(Uploadcare::Rails::File)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'stores file after save' do
|
25
|
+
post.save
|
26
|
+
expect(post.file).to be_stored
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'deletes file after destroy',
|
30
|
+
vcr: 'has_upload_care_file_destroy_file' do
|
31
|
+
post.save
|
32
|
+
post.destroy
|
33
|
+
expect(post.file).to be_deleted
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'instanse methods' do
|
38
|
+
it '#has_uploadcare_file? returns true' do
|
39
|
+
expect(post.has_file_as_uploadcare_file?).to be_truthy
|
40
|
+
end
|
41
|
+
|
42
|
+
it '#has_uploadcare_group? returns false' do
|
43
|
+
expect(post.has_file_as_uploadcare_group?).to be_falsey
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,43 +1,57 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe :has_uploadcare_group do
|
4
|
-
|
5
|
-
|
6
|
-
@method = "file"
|
7
|
-
end
|
3
|
+
describe :has_uploadcare_group, :vcr do
|
4
|
+
let(:post) { PostWithCollection.new(title: 'Title', file: GROUP_CDN_URL) }
|
5
|
+
let(:method) { 'file' }
|
8
6
|
|
9
|
-
|
10
|
-
|
7
|
+
after :each do
|
8
|
+
Rails.cache.delete(GROUP_CDN_URL)
|
11
9
|
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
describe 'object with group' do
|
12
|
+
let(:subject) { post }
|
13
|
+
it 'should respond to has_uploadcare_file? method' do
|
14
|
+
is_expected.to respond_to('has_file_as_uploadcare_file?'.to_sym)
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
it 'should respond to has_uploadcare_group? method' do
|
18
|
+
is_expected.to respond_to('has_file_as_uploadcare_group?'.to_sym)
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
it ':has_uploadcare_file? should return true' do
|
22
|
+
is_expected.not_to be_has_file_as_uploadcare_file
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
it ':has_uploadcare_group? should return false' do
|
26
|
+
is_expected.to be_has_file_as_uploadcare_group
|
27
|
+
end
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
30
|
+
describe 'object attachment' do
|
31
|
+
let(:subject) { post.file }
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
it 'should have uploadcare file' do
|
34
|
+
is_expected.to be_an(Uploadcare::Rails::Group)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'dont loads group by default' do
|
38
|
+
is_expected.not_to be_loaded
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'contains files inside' do
|
42
|
+
expect(subject.load.files.last).to be_an(Uploadcare::Rails::File)
|
43
|
+
end
|
37
44
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
45
|
+
it 'stores group after save', vcr: { cassette_name: 'has_uploadcare_group_save' } do
|
46
|
+
post.save
|
47
|
+
is_expected.to be_stored
|
48
|
+
end
|
49
|
+
|
50
|
+
skip 'deleteds group after destroy' do
|
51
|
+
post.save
|
52
|
+
post.file.load
|
53
|
+
post.destroy
|
54
|
+
expect(post.file).to be_deleted
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|