uploadcare-rails 1.0.6 → 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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/config/initializers/uploadcare.rb +22 -23
  3. data/lib/uploadcare-rails.rb +6 -5
  4. data/lib/uploadcare/rails/action_view/include_tags.rb +35 -26
  5. data/lib/uploadcare/rails/action_view/uploader_tags.rb +31 -29
  6. data/lib/uploadcare/rails/active_record/has_file.rb +14 -26
  7. data/lib/uploadcare/rails/active_record/has_group.rb +23 -22
  8. data/lib/uploadcare/rails/active_record/has_object.rb +3 -4
  9. data/lib/uploadcare/rails/engine.rb +3 -3
  10. data/lib/uploadcare/rails/formtastic/formtastic.rb +19 -15
  11. data/lib/uploadcare/rails/objects/file.rb +13 -25
  12. data/lib/uploadcare/rails/objects/group.rb +45 -22
  13. data/lib/uploadcare/rails/operations.rb +57 -0
  14. data/lib/uploadcare/rails/settings.rb +26 -30
  15. data/lib/uploadcare/rails/simple_form/simple_form.rb +22 -20
  16. data/lib/uploadcare/rails/version.rb +1 -1
  17. data/spec/caching/file_caching_spec.rb +16 -24
  18. data/spec/caching/group_caching_spec.rb +23 -26
  19. data/{app → spec/dummy/app}/assets/javascripts/uploadcare-1.5.5.min.js +0 -0
  20. data/spec/dummy/app/views/layouts/application.html.erb +2 -2
  21. data/spec/dummy/config/routes.rb +2 -2
  22. data/spec/helpers/include_tags_spec.rb +41 -29
  23. data/spec/models/has_both_file_and_group_spec.rb +19 -17
  24. data/spec/models/has_file_spec.rb +46 -47
  25. data/spec/models/has_group_spec.rb +46 -32
  26. data/spec/objects/file_spec.rb +9 -11
  27. data/spec/objects/group_spec.rb +40 -29
  28. data/spec/operations_spec.rb +28 -0
  29. data/spec/spec_helper.rb +17 -5
  30. metadata +235 -199
  31. data/MIT-LICENSE +0 -20
  32. data/app/assets/javascripts/uploadcare-0.17.0.js +0 -8248
  33. data/app/assets/javascripts/uploadcare-0.17.0.min.js +0 -17
  34. data/app/assets/javascripts/uploadcare-0.18.3.js +0 -8484
  35. data/app/assets/javascripts/uploadcare-0.18.3.min.js +0 -17
  36. data/app/assets/javascripts/uploadcare-1.0.1.js +0 -8430
  37. data/app/assets/javascripts/uploadcare-1.0.1.min.js +0 -17
  38. data/app/assets/javascripts/uploadcare-1.3.1.js +0 -8563
  39. data/app/assets/javascripts/uploadcare-1.3.1.min.js +0 -17
  40. data/app/assets/javascripts/uploadcare-1.5.5.js +0 -9278
  41. data/app/assets/javascripts/uploadcare.js +0 -1
  42. data/spec/dummy/db/test.sqlite3 +0 -0
  43. data/spec/dummy/log/development.log +0 -0
  44. data/spec/dummy/log/test.log +0 -2166
@@ -1,5 +1,5 @@
1
1
  module Uploadcare
2
2
  module Rails
3
- VERSION = "1.0.6"
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  end
@@ -1,34 +1,26 @@
1
- require "spec_helper"
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
- before :each do
6
- @post = Post.new title: "Post title", file: FILE_CDN_URL
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
- after :each do
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
- it "rails cache should updates after load call" do
23
- @post.file.load!
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["datetime_uploaded"].should be_kind_of(String)
18
+ cached['datetime_uploaded'].should be_kind_of(String)
27
19
  end
28
20
 
29
- it "file should stay loaded" do
30
- @post.file.loaded?.should == false
31
- @post.file.load!
32
- @post.file.loaded?.should == true
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 "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- describe Uploadcare::Rails::Group do
4
- before :each do
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 GROUP_CDN_URL
7
+ Rails.cache.delete(GROUP_CDN_URL)
10
8
  end
11
9
 
12
- it "should be not loaded by default" do
13
- @post.file.loaded?.should == false
10
+ it 'should be not loaded by default' do
11
+ expect(post.file).not_to be_loaded
14
12
  end
15
13
 
16
- it "rails cache should be nil" do
17
- cached = Rails.cache.read @post.file.cdn_url
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 "rails cache should updates after load call" do
22
- @post.file.load!
18
+ it 'rails cache should updates after load call' do
19
+ post.file.load!
23
20
  cached = Rails.cache.read GROUP_CDN_URL
24
- cached.should be_kind_of(Hash)
25
- cached["datetime_created"].should be_kind_of(String)
21
+
22
+ expect(cached).to be_a(Hash)
23
+ expect(cached['datetime_created']).to be_a(String)
26
24
  end
27
25
 
28
- it "group should stay loaded" do
29
- @post.file.loaded?.should == false
30
- @post.file.load!
31
- @post.file.loaded?.should == true
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' do
35
- @post.file.load!
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
- it 'group restored from cache should contain Uploadcare::Rails::Files' do
37
+ expect(cached).to be_a(Hash)
38
+ expect(cached['files'].sample).to be_a(Hash)
42
39
  end
43
- end
40
+ end
@@ -2,8 +2,8 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Dummy</title>
5
- <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
6
- <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
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 %>
@@ -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#index"
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 "should include widget from cdn" do
4
+ it 'includes widget from cdn' do
5
5
  tag = helper.include_uploadcare_widget_from_cdn
6
- tag.should be_kind_of(String)
7
- tag.should == ("<script src=\"https://ucarecdn.com/widget/#{UPLOADCARE_SETTINGS.widget_version}/uploadcare/uploadcare-#{UPLOADCARE_SETTINGS.widget_version}.min.js\"></script>")
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
- it "should specify widget version" do
11
- version = "0.13.3"
16
+ describe 'for specifyed version' do
17
+ let(:version) { '0.13.3' }
12
18
 
13
- tag = helper.include_uploadcare_widget_from_cdn({version: version})
14
- tag.should == ("<script src=\"https://ucarecdn.com/widget/#{version}/uploadcare/uploadcare-#{version}.min.js\"></script>")
15
- end
19
+ it 'uses widget version' do
20
+ tag = helper.include_uploadcare_widget_from_cdn(version: version)
16
21
 
17
- it "should load not minified version" do
18
- version = "0.13.3"
19
- min = false
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
- tag = helper.include_uploadcare_widget_from_cdn({version: version, min: min})
22
- tag.should == ("<script src=\"https://ucarecdn.com/widget/#{version}/uploadcare/uploadcare-#{version}.js\"></script>")
23
- end
28
+ it 'loads not minified version' do
29
+ tag =
30
+ helper.include_uploadcare_widget_from_cdn(version: version, min: false)
24
31
 
25
- it "should return js settings" do
26
- settings = helper.uploadcare_settings
27
- settings.should be_kind_of(String)
28
- settings.should_not be_empty
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
- it "should include all uplaodcare settings" do
32
- settings = helper.uploadcare_settings
33
- settings.should have_selector("script", :content => "UPLOADCARE_PUBLIC_KEY")
34
- settings.should have_selector("script", :content => "UPLOADCARE_LOCALE")
35
- settings.should have_selector("script", :content => "UPLOADCARE_PREVIEW_STEP")
36
- settings.should have_selector("script", :content => "UPLOADCARE_CLEARABLE")
37
- settings.should have_selector("script", :content => "UPLOADCARE_TABS")
38
- settings.should have_selector("script", :content => "UPLOADCARE_AUTOSTORE")
39
- settings.should have_selector("script", :content => "UPLOADCARE_MANUAL_START")
40
- settings.should have_selector("script", :content => "UPLOADCARE_PATH_VALUE")
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
- before :each do
5
- @post = PostsWithCollectionAndFile.new title: "Post title",
6
- group: GROUP_CDN_URL,
7
- file: FILE_CDN_URL
8
- @file_method = "file"
9
- @group_method = "group"
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
- @post.should respond_to("has_#{@file_method}_as_uploadcare_file?".to_sym)
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
- @post.should respond_to("has_#{@group_method}_as_uploadcare_group?".to_sym)
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
- @post.has_file_as_uploadcare_file?.should == true
29
- @post.has_group_as_uploadcare_group?.should == true
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
- @post.has_group_as_uploadcare_file?.should == false
34
- @post.has_file_as_uploadcare_group?.should == false
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
- @post.group.should be_kind_of(Uploadcare::Rails::Group)
39
- @post.file.should be_kind_of(Uploadcare::Rails::File)
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 "spec_helper"
2
-
3
- describe :has_uploadcare_file do
4
- before :each do
5
- @post = Post.new title: "Post title", file: FILE_CDN_URL
6
- @method = "file"
7
- end
8
-
9
- after :each do
10
- Rails.cache.delete FILE_CDN_URL
11
- end
12
-
13
- it "should respond to has_uploadcare_file? method" do
14
- @post.should respond_to("has_#{@method}_as_uploadcare_file?".to_sym)
15
- end
16
-
17
- it "should respond to has_uploadcare_group? method" do
18
- @post.should respond_to("has_#{@method}_as_uploadcare_group?".to_sym)
19
- end
20
-
21
- it ":has_uploadcare_file? should return true" do
22
- @post.has_file_as_uploadcare_file?.should == true
23
- end
24
-
25
- it ":has_uploadcare_group? should return false" do
26
- @post.has_file_as_uploadcare_group?.should == false
27
- end
28
-
29
- it "should have uploadcare file" do
30
- @post.file.should be_kind_of(Uploadcare::Rails::File)
31
- end
32
-
33
- it "file should not be loaded by default" do
34
- @post.file.loaded?.should == false
35
- end
36
-
37
- it 'file should be stored after save' do
38
- @post.save
39
- @post.file.stored?.should == true
40
- end
41
-
42
- it 'file should be deleted after destroy' do
43
- @post.save if @post.new_record?
44
- @post.destroy
45
- @post.file.deleted?.should == true
46
- end
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 "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- describe :has_uploadcare_group do
4
- before :each do
5
- @post = PostWithCollection.new title: "Post title", file: GROUP_CDN_URL
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
- it "should respond to has_uploadcare_file? method" do
10
- @post.should respond_to("has_#{@method}_as_uploadcare_file?".to_sym)
7
+ after :each do
8
+ Rails.cache.delete(GROUP_CDN_URL)
11
9
  end
12
10
 
13
- it "should respond to has_uploadcare_group? method" do
14
- @post.should respond_to("has_#{@method}_as_uploadcare_group?".to_sym)
15
- end
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
- it ":has_uploadcare_file? should return true" do
18
- @post.has_file_as_uploadcare_file?.should == false
19
- end
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
- it ":has_uploadcare_group? should return false" do
22
- @post.has_file_as_uploadcare_group?.should == true
23
- end
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
- it "should have uploadcare file" do
26
- @post.file.should be_kind_of(Uploadcare::Rails::Group)
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
- it "file should not be loaded by default" do
30
- @post.file.loaded?.should == false
31
- end
30
+ describe 'object attachment' do
31
+ let(:subject) { post.file }
32
32
 
33
- it 'file should be stored after save' do
34
- @post.save
35
- @post.file.stored?.should == true
36
- end
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
- # it 'file should be deleted after destroy' do
39
- # @post.save if @post.new_record?
40
- # @post.destroy
41
- # @post.file.deleted?.should == true
42
- # end
43
- end
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