uploadcare-rails 1.1.0 → 1.1.1
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/config/initializers/uploadcare.rb +4 -4
- data/lib/uploadcare-rails.rb +7 -4
- data/lib/uploadcare/rails/action_view/include_tags.rb +1 -1
- data/lib/uploadcare/rails/active_record/has_file.rb +3 -3
- data/lib/uploadcare/rails/active_record/has_group.rb +3 -3
- data/lib/uploadcare/rails/formtastic/formtastic.rb +14 -0
- data/lib/uploadcare/rails/settings.rb +4 -5
- data/lib/uploadcare/rails/version.rb +1 -1
- data/spec/cassettes/Uploadcare_Rails_File/should_load_itself.yml +107 -0
- data/spec/cassettes/Uploadcare_Rails_Group/group_should_stay_loaded.yml +107 -0
- data/spec/cassettes/Uploadcare_Rails_Group/rails_cache_should_updates_after_load_call.yml +107 -0
- data/spec/cassettes/group_cahsing_file_load.yml +107 -0
- data/spec/cassettes/has_uploadcare_file/object_with_uploadcare_file/deletes_file_after_destroy.yml +1283 -0
- data/spec/cassettes/has_uploadcare_file/object_with_uploadcare_file/stores_file_after_save.yml +381 -0
- data/spec/cassettes/has_uploadcare_group/object_attachment/contains_files_inside.yml +523 -0
- data/spec/cassettes/has_uploadcare_group_save.yml +543 -0
- data/spec/cassettes/load_group.yml +107 -0
- data/spec/dummy/db/migrate/20171012001801_create_tables.rb +27 -0
- data/spec/dummy/db/schema.rb +14 -15
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +2360 -0
- data/spec/dummy/tmp/cache/2AF/761/https%3A%2F%2Fucarecdn.com%2F595319d0-a113-459f-91bd-b29c7183467b%2F +0 -0
- data/spec/dummy/tmp/cache/301/D41/https%3A%2F%2Fucarecdn.com%2F81332043-fa2c-452f-936b-737d87ab2ae2%2F +0 -0
- data/spec/dummy/tmp/cache/30A/7C1/https%3A%2F%2Fucarecdn.com%2F39b34128-a001-46fd-9773-1b6ad46e6b9e%2F +0 -0
- data/spec/dummy/tmp/cache/340/A41/https%3A%2F%2Fucarecdn.com%2F090bcb5f-6d19-456c-b4a3-d753e690926f%2F +0 -0
- data/spec/dummy/tmp/cache/3AB/5A1/https%3A%2F%2Fucarecdn.com%2F7eb0161b-cebe-4316-946b-694de6f77ef9%2F +0 -0
- data/spec/dummy/tmp/cache/3FC/5C1/https%3A%2F%2Fucarecdn.com%2Fc3f0464b-ce9a-4281-8eaa-5c55783ccedf%2F +0 -0
- data/spec/dummy/tmp/cache/431/5C1/https%3A%2F%2Fucarecdn.com%2Fa1b1bb40-bd89-4f9c-b809-e84920f24a01%7E2%2F +0 -0
- data/spec/dummy/tmp/cache/44B/7A1/https%3A%2F%2Fucarecdn.com%2Fd6c785a8-9761-4602-88de-65ddb04ddc6a%7E2%2F +0 -0
- data/spec/generators/uploadcare_config_generator_spec.rb +39 -0
- data/spec/helpers/form_helpers_has_file_spec.rb +5 -5
- data/spec/helpers/form_helpers_has_group_spec.rb +6 -6
- data/spec/helpers/form_helpers_spec.rb +5 -5
- data/spec/helpers/formtastic_spec.rb +19 -26
- data/spec/helpers/include_tags_spec.rb +7 -7
- data/spec/helpers/simple_form_spec.rb +19 -27
- data/spec/helpers/uploader_tags_spec.rb +11 -5
- data/spec/objects/group_spec.rb +4 -4
- data/spec/support/generators.rb +38 -0
- data/spec/tmp/config/uploadcare.yml +71 -0
- data/spec/uploadcare/rails/settings_spec.rb +136 -0
- metadata +254 -198
- data/spec/dummy/db/migrate/20131119080328_create_posts.rb +0 -10
- data/spec/dummy/db/migrate/20131220083857_create_post_with_collections.rb +0 -10
- data/spec/dummy/db/migrate/20140320092807_create_posts_with_collection_and_files.rb +0 -10
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require_relative '../support/generators'
|
3
|
+
require 'generators/uploadcare_config_generator'
|
4
|
+
|
5
|
+
RSpec.describe UploadcareConfigGenerator, :type => :generator do
|
6
|
+
destination File.expand_path('../tmp', __dir__)
|
7
|
+
let(:config_file_path) { 'spec/tmp/config/uploadcare.yml' }
|
8
|
+
let(:defaults) do
|
9
|
+
{
|
10
|
+
"public_key"=>"demopublickey",
|
11
|
+
"private_key"=>"demoprivatekey",
|
12
|
+
"live"=>true, "cache_files"=>true,
|
13
|
+
"cache_groups"=>true,
|
14
|
+
"store_after_save"=>true,
|
15
|
+
"delete_after_destroy"=>true,
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
before do
|
20
|
+
prepare_destination
|
21
|
+
expect(File.exists?(config_file_path)).to be(false)
|
22
|
+
run_generator
|
23
|
+
end
|
24
|
+
|
25
|
+
it "generates config/uploadcare.yml" do
|
26
|
+
expect(File.exists?(config_file_path)).to be(true)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "config/uploadcare.yml contains default config" do
|
30
|
+
expect(YAML.load_file(config_file_path)).to eq(
|
31
|
+
"defaults" => defaults,
|
32
|
+
"development" => defaults,
|
33
|
+
"production" => defaults,
|
34
|
+
"test" => defaults,
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
@@ -10,21 +10,21 @@ describe Uploadcare::Rails::ActionView::FormBuilder, type: :helper do
|
|
10
10
|
# not that post has uc file
|
11
11
|
tag = @form.uploadcare_field :file
|
12
12
|
tag.should be_kind_of(String)
|
13
|
-
tag.
|
13
|
+
expect(tag).to have_selector('input[type="hidden"][data-multiple="false"]', visible: :all)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should override uploadcare- attribute" do
|
17
17
|
tag = @form.uploadcare_field :file, :uploadcare => {:multiple => true}
|
18
|
-
tag.
|
18
|
+
expect(tag).to have_selector('input[type="hidden"][data-multiple="false"]', visible: :all)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should override data- attribute" do
|
22
22
|
tag = @form.uploadcare_field :file, :data => {:multiple => true}
|
23
|
-
tag.
|
23
|
+
expect(tag).to have_selector('input[type="hidden"][data-multiple="false"]', visible: :all)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should override data- and uploadcare- attributes" do
|
27
27
|
tag = @form.uploadcare_field :file, :data => {:multiple => true}, :uploadcare => {:multiple => true}
|
28
|
-
tag.
|
28
|
+
expect(tag).to have_selector('input[type="hidden"][data-multiple="false"]', visible: :all)
|
29
29
|
end
|
30
|
-
end
|
30
|
+
end
|
@@ -9,22 +9,22 @@ describe Uploadcare::Rails::ActionView::FormBuilder, type: :helper do
|
|
9
9
|
it "should include uploader tag for name" do
|
10
10
|
# not that post has uc file
|
11
11
|
tag = @form.uploadcare_field :file
|
12
|
-
tag.
|
13
|
-
tag.
|
12
|
+
expect(tag).to be_kind_of(String)
|
13
|
+
expect(tag).to have_selector('input[type="hidden"][data-multiple="true"]', visible: :all)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should override uploadcare- attribute" do
|
17
17
|
tag = @form.uploadcare_field :file, :uploadcare => {:multiple => false}
|
18
|
-
tag.
|
18
|
+
expect(tag).to have_selector('input[type="hidden"][data-multiple="true"]', visible: :all)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should override data- attribute" do
|
22
22
|
tag = @form.uploadcare_field :file, :data => {:multiple => false}
|
23
|
-
tag.
|
23
|
+
expect(tag).to have_selector('input[type="hidden"][data-multiple="true"]', visible: :all)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should override data- and uploadcare- attributes" do
|
27
27
|
tag = @form.uploadcare_field :file, :data => {:multiple => false}, :uploadcare => {:multiple => false}
|
28
|
-
tag.
|
28
|
+
expect(tag).to have_selector('input[type="hidden"][data-multiple="true"]', visible: :all)
|
29
29
|
end
|
30
|
-
end
|
30
|
+
end
|
@@ -13,21 +13,21 @@ describe Uploadcare::Rails::ActionView::FormBuilder, type: :helper do
|
|
13
13
|
|
14
14
|
it "should have role attr" do
|
15
15
|
tag = @form.uploadcare_field :file, :uploadcare => {:multiple => true}
|
16
|
-
tag.
|
16
|
+
expect(tag).to have_selector('input[role="uploadcare-uploader"]', visible: :all)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should have custom data-attributes" do
|
20
20
|
tag = @form.uploadcare_field :file, :data => {:custom => true}
|
21
|
-
tag.
|
21
|
+
expect(tag).to have_selector('input[data-custom="true"]', visible: :all)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should have uploadcare namespace translated into data- attributes" do
|
25
25
|
tag = @form.uploadcare_field :file, :uploadcare => {:custom => true}
|
26
|
-
tag.
|
26
|
+
expect(tag).to have_selector('input[data-custom="true"]', visible: :all)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should override data namespace with uploadcare namespace" do
|
30
30
|
tag = @form.uploadcare_field :file, :uploadcare => {:custom => true}, :data => {:custom => false}
|
31
|
-
tag.
|
31
|
+
expect(tag).to have_selector('input[data-custom="true"]', visible: :all)
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
@@ -1,32 +1,25 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
if req
|
10
|
-
require 'uploadcare/rails/formtastic/formtastic'
|
11
|
-
describe "Uploadcare::Rails::Formtastic", type: :helper do
|
12
|
-
before :each do
|
13
|
-
@post = Post.new
|
14
|
-
@form = Formtastic::FormBuilder.new(:post, @post, helper, {})
|
15
|
-
end
|
3
|
+
describe "Uploadcare::Rails::Formtastic", type: :helper do
|
4
|
+
before :each do
|
5
|
+
@post = Post.new
|
6
|
+
@form = Formtastic::FormBuilder.new(:post, @post, helper, {})
|
7
|
+
end
|
16
8
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
9
|
+
it 'should create smart uploader field' do
|
10
|
+
tag = @form.input :file, as: :uploadcare_uploader
|
11
|
+
expect(tag).to have_selector('input[role="uploadcare-uploader"]', visible: :all)
|
12
|
+
end
|
21
13
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
14
|
+
it 'should create single uploader field' do
|
15
|
+
tag = @form.input :file, as: :uploadcare_single_uploader
|
16
|
+
expect(tag)
|
17
|
+
.to have_selector('input[role="uploadcare-uploader"][data-multiple="false"]', visible: :all)
|
18
|
+
end
|
26
19
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
20
|
+
it 'should create multiple uploader field' do
|
21
|
+
tag = @form.input :file, as: :uploadcare_multiple_uploader
|
22
|
+
expect(tag)
|
23
|
+
.to have_selector('input[role="uploadcare-uploader"][data-multiple="true"]', visible: :all)
|
31
24
|
end
|
32
|
-
end
|
25
|
+
end
|
@@ -6,9 +6,9 @@ describe Uploadcare::Rails do
|
|
6
6
|
|
7
7
|
expect(tag).to eq(
|
8
8
|
[
|
9
|
-
"<script src=\"https://ucarecdn.com/widget/",
|
9
|
+
"<script src=\"https://ucarecdn.com/libs/widget/",
|
10
10
|
UPLOADCARE_SETTINGS.widget_version,
|
11
|
-
'/uploadcare
|
11
|
+
'/uploadcare.min.js"></script>'
|
12
12
|
].join
|
13
13
|
)
|
14
14
|
end
|
@@ -20,8 +20,8 @@ describe Uploadcare::Rails do
|
|
20
20
|
tag = helper.include_uploadcare_widget_from_cdn(version: version)
|
21
21
|
|
22
22
|
expect(tag).to eq(
|
23
|
-
"<script src=\"https://ucarecdn.com/widget/#{ version }/"\
|
24
|
-
'uploadcare
|
23
|
+
"<script src=\"https://ucarecdn.com/libs/widget/#{ version }/"\
|
24
|
+
'uploadcare.min.js"></script>'
|
25
25
|
)
|
26
26
|
end
|
27
27
|
|
@@ -30,8 +30,8 @@ describe Uploadcare::Rails do
|
|
30
30
|
helper.include_uploadcare_widget_from_cdn(version: version, min: false)
|
31
31
|
|
32
32
|
expect(tag).to eq(
|
33
|
-
"<script src=\"https://ucarecdn.com/widget/#{ version }/"\
|
34
|
-
'uploadcare
|
33
|
+
"<script src=\"https://ucarecdn.com/libs/widget/#{ version }/"\
|
34
|
+
'uploadcare.js"></script>'
|
35
35
|
)
|
36
36
|
end
|
37
37
|
end
|
@@ -47,7 +47,7 @@ describe Uploadcare::Rails do
|
|
47
47
|
UPLOADCARE_TABS UPLOADCARE_AUTOSTORE
|
48
48
|
UPLOADCARE_MANUAL_START UPLOADCARE_PATH_VALUE).each do |content|
|
49
49
|
it 'contains expected selector' do
|
50
|
-
is_expected.to
|
50
|
+
is_expected.to have_xpath("//script[text()[contains(.,'UPLOADCARE')]]", visible: :all)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -1,33 +1,25 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
if req
|
10
|
-
require 'uploadcare/rails/simple_form/simple_form'
|
11
|
-
|
12
|
-
describe "Uploadcare::Rails::SimpleForm", type: :helper do
|
13
|
-
before :each do
|
14
|
-
@post = Post.new
|
15
|
-
@form = SimpleForm::FormBuilder.new(:post, @post, helper, {})
|
16
|
-
end
|
3
|
+
describe "Uploadcare::Rails::SimpleForm", type: :helper do
|
4
|
+
before :each do
|
5
|
+
@post = Post.new
|
6
|
+
@form = SimpleForm::FormBuilder.new(:post, @post, helper, {})
|
7
|
+
end
|
17
8
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
it 'should create smart uploader field' do
|
10
|
+
tag = @form.input :file, as: :uploadcare_uploader
|
11
|
+
expect(tag).to have_selector('input[role="uploadcare-uploader"]', visible: :all)
|
12
|
+
end
|
22
13
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
it 'should create single uploader field' do
|
15
|
+
tag = @form.input :file, as: :uploadcare_single_uploader
|
16
|
+
expect(tag)
|
17
|
+
.to have_selector('input[role="uploadcare-uploader"][data-multiple="false"]', visible: :all)
|
18
|
+
end
|
27
19
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
20
|
+
it 'should create multiple uploader field' do
|
21
|
+
tag = @form.input :file, as: :uploadcare_multiple_uploader
|
22
|
+
expect(tag)
|
23
|
+
.to have_selector('input[role="uploadcare-uploader"][data-multiple="true"]', visible: :all)
|
32
24
|
end
|
33
|
-
end
|
25
|
+
end
|
@@ -1,15 +1,21 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Uploadcare::Rails::ActionView::UploaderTags do
|
4
|
+
let(:expected_selector) do
|
5
|
+
'input[type="hidden"][role="uploadcare-uploader"][data-path-value="true"]'
|
6
|
+
end
|
7
|
+
|
4
8
|
it "should include uploader tag for name" do
|
5
9
|
tag = helper.uploadcare_uploader_tag :file
|
6
|
-
|
7
|
-
tag.
|
10
|
+
|
11
|
+
expect(tag).to be_kind_of(String)
|
12
|
+
expect(tag).to have_selector(expected_selector, visible: :all)
|
8
13
|
end
|
9
14
|
|
10
15
|
it "should include uploader field for object" do
|
11
16
|
tag = helper.uploadcare_uploader_field :post, :file
|
12
|
-
|
13
|
-
tag.
|
17
|
+
|
18
|
+
expect(tag).to be_kind_of(String)
|
19
|
+
expect(tag).to have_selector(expected_selector, visible: :all)
|
14
20
|
end
|
15
|
-
end
|
21
|
+
end
|
data/spec/objects/group_spec.rb
CHANGED
@@ -42,10 +42,10 @@ describe Uploadcare::Rails::Group, :vcr do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'builds images url' do
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
allow_any_instance_of(Uploadcare::Api).to receive(:options) { {static_url_base: 'http://example.com'} }
|
46
|
+
expected = "http://example.com/#{ subject.uuid }/nth/0/-/resize/200x200/"
|
47
|
+
|
48
|
+
expect(subject.urls(size: '200x200').first).to eq(expected)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rails/generators/test_case'
|
2
|
+
|
3
|
+
module Uploadcare
|
4
|
+
module Rails
|
5
|
+
module Generators
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
cattr_accessor :test_case, :test_case_instance
|
10
|
+
|
11
|
+
self.test_case = Class.new(::Rails::Generators::TestCase) do
|
12
|
+
def fake_test_case; end
|
13
|
+
def add_assertion; end
|
14
|
+
end
|
15
|
+
self.test_case_instance = self.test_case.new(:fake_test_case)
|
16
|
+
self.test_case.generator_class = described_class
|
17
|
+
end
|
18
|
+
|
19
|
+
def prepare_destination
|
20
|
+
self.test_case_instance.send :prepare_destination
|
21
|
+
end
|
22
|
+
|
23
|
+
def run_generator
|
24
|
+
self.test_case_instance.run_generator
|
25
|
+
end
|
26
|
+
|
27
|
+
module ClassMethods
|
28
|
+
def destination(path)
|
29
|
+
self.test_case.destination_root = path
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
RSpec.configure do |c|
|
37
|
+
c.include Uploadcare::Rails::Generators, type: :generator
|
38
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
public_key: "demopublickey" # replace it with your public key
|
3
|
+
private_key: "demoprivatekey" # replace it with your private key
|
4
|
+
|
5
|
+
# instances of widget initialized for you on page load
|
6
|
+
live: true
|
7
|
+
|
8
|
+
# cache files json dumps to prevent calling to server if it posible
|
9
|
+
cache_files: true
|
10
|
+
|
11
|
+
# cache groups json dumps to prevent calling to server if it posible
|
12
|
+
cache_groups: true
|
13
|
+
|
14
|
+
# store file or group after model is created or updated
|
15
|
+
store_after_save: true
|
16
|
+
|
17
|
+
# deletes file or group after model object is deleted
|
18
|
+
delete_after_destroy: true
|
19
|
+
|
20
|
+
# Avaliable options are listed at https://uploadcare.com/documentation/widget/#advanced-configuration
|
21
|
+
# please note, that for options marker as Global: N/A - there is no practical meaning
|
22
|
+
# of putting this option here, as it will not have any effect.
|
23
|
+
# But it also will not break anything.
|
24
|
+
|
25
|
+
# for preview step use:
|
26
|
+
# preview_step: false # true or false
|
27
|
+
|
28
|
+
# for clearable option (allows user to remove uploaded file from widget) use:
|
29
|
+
# clearable: false # true or false
|
30
|
+
|
31
|
+
# for setting tabs use tabs option:
|
32
|
+
# tabs: "url file facebook" # etc
|
33
|
+
# read more here: https://uploadcare.com/documentation/widget/#tabs
|
34
|
+
#
|
35
|
+
# Full list of tabs:
|
36
|
+
# |----------------------------------------|
|
37
|
+
# | Code | File Source | Default |
|
38
|
+
# |------------|-----------------|---------|
|
39
|
+
# | url | Any URL | On |
|
40
|
+
# | file | Local disk | On |
|
41
|
+
# | facebook | Facebook | On |
|
42
|
+
# | dropbox | Dropbox | Off |
|
43
|
+
# | gdrive | Google Drive | On |
|
44
|
+
# | box | Box | On |
|
45
|
+
# | skydrive | SkyDrive | On |
|
46
|
+
# | instagram | Instagram | On |
|
47
|
+
# | evernote | Evernote | On |
|
48
|
+
# | vk | VK | Off |
|
49
|
+
# |________________________________________|
|
50
|
+
|
51
|
+
# for locale option use:
|
52
|
+
# locale: "en"
|
53
|
+
|
54
|
+
# for autostore option use:
|
55
|
+
# autostore: true #true or false
|
56
|
+
|
57
|
+
# for manual start (which means you will need to initialize uploaders yourself) use:
|
58
|
+
# manual_start: false # true or false
|
59
|
+
|
60
|
+
# for path value use:
|
61
|
+
# path_value: true # true or false
|
62
|
+
# (important for input values - see https://uploadcare.com/documentation/widget/#input-value)
|
63
|
+
|
64
|
+
development:
|
65
|
+
<<: *defaults
|
66
|
+
|
67
|
+
test:
|
68
|
+
<<: *defaults
|
69
|
+
|
70
|
+
production:
|
71
|
+
<<: *defaults
|