carrierwave_direct 0.0.13 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +15 -1
  4. data/Changelog.md +130 -0
  5. data/Gemfile +1 -1
  6. data/README.md +82 -45
  7. data/carrierwave_direct.gemspec +3 -4
  8. data/gemfiles/3.2.gemfile +13 -0
  9. data/gemfiles/4.0.gemfile +13 -0
  10. data/gemfiles/4.1.gemfile +13 -0
  11. data/lib/carrierwave_direct/form_builder.rb +48 -11
  12. data/lib/carrierwave_direct/locale/nl.yml +9 -0
  13. data/lib/carrierwave_direct/mount.rb +16 -4
  14. data/lib/carrierwave_direct/orm/activerecord.rb +4 -4
  15. data/lib/carrierwave_direct/test/capybara_helpers.rb +7 -5
  16. data/lib/carrierwave_direct/uploader/configuration.rb +4 -2
  17. data/lib/carrierwave_direct/uploader/content_type.rb +28 -0
  18. data/lib/carrierwave_direct/uploader/direct_url.rb +15 -0
  19. data/lib/carrierwave_direct/uploader.rb +79 -68
  20. data/lib/carrierwave_direct/validations/active_model.rb +5 -4
  21. data/lib/carrierwave_direct/version.rb +1 -1
  22. data/lib/carrierwave_direct.rb +6 -8
  23. data/spec/action_view_extensions/form_helper_spec.rb +4 -5
  24. data/spec/data/sample_data.rb +41 -0
  25. data/spec/form_builder_spec.rb +139 -6
  26. data/spec/mount_spec.rb +13 -26
  27. data/spec/orm/activerecord_spec.rb +69 -19
  28. data/spec/spec_helper.rb +16 -2
  29. data/spec/support/form_builder_helpers.rb +1 -0
  30. data/spec/support/model_helpers.rb +7 -7
  31. data/spec/support/view_helpers.rb +12 -2
  32. data/spec/test/capybara_helpers_spec.rb +28 -26
  33. data/spec/test/helpers_spec.rb +9 -11
  34. data/spec/uploader/configuration_spec.rb +46 -0
  35. data/spec/uploader/content_type_spec.rb +40 -0
  36. data/spec/uploader/direct_url_spec.rb +26 -0
  37. data/spec/uploader_spec.rb +145 -184
  38. metadata +40 -39
@@ -15,10 +15,18 @@ describe CarrierWaveDirect::ActiveRecord do
15
15
  create_table :parties, :force => true do |t|
16
16
  t.column :video, :string
17
17
  end
18
+
19
+ create_table :dances, :force => true do |t|
20
+ t.column :location, :string
21
+ end
22
+ create_table :resources, :force => true do |t|
23
+ t.column :file, :string
24
+ end
18
25
  end
19
26
 
20
27
  def self.down
21
28
  drop_table :parties
29
+ drop_table :dances
22
30
  end
23
31
  end
24
32
 
@@ -26,6 +34,13 @@ describe CarrierWaveDirect::ActiveRecord do
26
34
  mount_uploader :video, DirectUploader
27
35
  end
28
36
 
37
+ class Dance < ActiveRecord::Base
38
+ end
39
+
40
+ class Resource < ActiveRecord::Base
41
+ mount_uploader :file, DirectUploader
42
+ end
43
+
29
44
  ActiveRecord::Base.establish_connection(dbconfig)
30
45
 
31
46
  # turn off migration output
@@ -61,17 +76,17 @@ describe CarrierWaveDirect::ActiveRecord do
61
76
 
62
77
  shared_examples_for "an invalid filename" do
63
78
  it "should not be valid on create" do
64
- subject.should_not be_valid
79
+ expect(subject).to_not be_valid
65
80
  end
66
81
 
67
82
  it "should be valid on update" do
68
83
  subject.save(:validate => false)
69
- subject.should be_valid
84
+ expect(subject).to be_valid
70
85
  end
71
86
 
72
87
  it "should use i18n for the error messages" do
73
88
  subject.valid?
74
- subject.errors[:video].should == [
89
+ expect(subject.errors[:video]).to eq [
75
90
  I18n.t("errors.messages.carrierwave_direct_filename_invalid") +
76
91
  I18n.t("errors.messages.carrierwave_direct_allowed_extensions", :extensions => %w{avi mp4}.to_sentence)
77
92
  ]
@@ -96,14 +111,14 @@ describe CarrierWaveDirect::ActiveRecord do
96
111
  end
97
112
  end
98
113
 
99
- subject.errors[:remote_video_net_url].should == [ messages ]
114
+ expect(subject.errors[:remote_video_net_url]).to eq [ messages ]
100
115
  end
101
116
  end
102
117
 
103
118
  shared_examples_for "without an upload" do
104
119
  before do
105
120
  subject.remote_video_net_url = remote_video_net_url
106
- subject.key = upload_path
121
+ subject.video_key = upload_path
107
122
  end
108
123
 
109
124
  it "should not be valid on create" do
@@ -146,10 +161,21 @@ describe CarrierWaveDirect::ActiveRecord do
146
161
 
147
162
  describe ".validates_filename_uniqueness_of" do
148
163
  it "should be turned on by default" do
149
- party_class.should_receive(:validates_filename_uniqueness_of).with(:video)
164
+ party_class.should_receive(:validates_filename_uniqueness_of).with(:video, on: :create)
150
165
  mount_uploader
151
166
  end
152
167
 
168
+ context "mount_on: option is used" do
169
+ let(:dance) { Dance.new }
170
+
171
+ before { Dance.mount_uploader(:non_existing_column, DirectUploader, mount_on: :location) }
172
+ before { dance.non_existing_column_key = sample_key}
173
+
174
+ it "uses the column it's mounted on for checking uniqueness" do
175
+ expect { dance.valid? }.to_not raise_error
176
+ end
177
+ end
178
+
153
179
  context "another Party with a duplicate video filename" do
154
180
  before do
155
181
  subject.video.key = sample_key
@@ -186,14 +212,14 @@ describe CarrierWaveDirect::ActiveRecord do
186
212
 
187
213
  describe ".validates_filename_format_of" do
188
214
  it "should be turned on by default" do
189
- party_class.should_receive(:validates_filename_format_of).with(:video)
215
+ party_class.should_receive(:validates_filename_format_of).with(:video, on: :create)
190
216
  mount_uploader
191
217
  end
192
218
 
193
219
  context "where the file upload is" do
194
220
  context "nil" do
195
221
  before do
196
- subject.key = nil
222
+ subject.video_key = nil
197
223
  end
198
224
 
199
225
  it "should be valid" do
@@ -203,7 +229,7 @@ describe CarrierWaveDirect::ActiveRecord do
203
229
 
204
230
  context "blank" do
205
231
  before do
206
- subject.key = ""
232
+ subject.video_key = ""
207
233
  end
208
234
 
209
235
  it "should be valid" do
@@ -219,7 +245,7 @@ describe CarrierWaveDirect::ActiveRecord do
219
245
 
220
246
  context "and the uploaded file's extension is included in the list" do
221
247
  before do
222
- subject.key = sample_key(:extension => "avi")
248
+ subject.video_key = sample_key(:extension => "avi")
223
249
  end
224
250
 
225
251
  it "should be valid" do
@@ -229,7 +255,7 @@ describe CarrierWaveDirect::ActiveRecord do
229
255
 
230
256
  context "but uploaded file's extension is not included in the list" do
231
257
  before do
232
- subject.key = sample_key(:extension => "mp3")
258
+ subject.video_key = sample_key(:extension => "mp3")
233
259
  end
234
260
 
235
261
  it_should_behave_like "an invalid filename"
@@ -263,7 +289,7 @@ describe CarrierWaveDirect::ActiveRecord do
263
289
 
264
290
  describe ".validates_remote_net_url_format_of" do
265
291
  it "should be turned on by default" do
266
- party_class.should_receive(:validates_remote_net_url_format_of).with(:video)
292
+ party_class.should_receive(:validates_remote_net_url_format_of).with(:video, on: :create)
267
293
  mount_uploader
268
294
  end
269
295
 
@@ -449,7 +475,7 @@ describe CarrierWaveDirect::ActiveRecord do
449
475
 
450
476
  context "with an upload by file" do
451
477
  before do
452
- subject.key = sample_key
478
+ subject.video_key = sample_key
453
479
  end
454
480
 
455
481
  it "should be valid" do
@@ -501,7 +527,7 @@ describe CarrierWaveDirect::ActiveRecord do
501
527
 
502
528
  describe "#key" do
503
529
  it "should be accessible" do
504
- party_class.new(:key => "some key").key.should == "some key"
530
+ party_class.new(:video_key => "some key").video_key.should == "some key"
505
531
  end
506
532
  end
507
533
 
@@ -526,7 +552,7 @@ describe CarrierWaveDirect::ActiveRecord do
526
552
 
527
553
  context "does not have an upload" do
528
554
  it "should be true" do
529
- subject.filename_valid?.should be_true
555
+ subject.filename_valid?.should be true
530
556
  end
531
557
 
532
558
  it_should_behave_like "having empty errors"
@@ -535,21 +561,21 @@ describe CarrierWaveDirect::ActiveRecord do
535
561
  context "has an upload" do
536
562
  context "with a valid filename" do
537
563
  before do
538
- subject.key = sample_key(:model_class => subject.class)
564
+ subject.video_key = sample_key(:model_class => subject.class)
539
565
  end
540
566
 
541
567
  it "should be true" do
542
- subject.filename_valid?.should be_true
568
+ subject.filename_valid?.should be true
543
569
  end
544
570
 
545
571
  it_should_behave_like "having empty errors"
546
572
  end
547
573
 
548
574
  context "with an invalid filename" do
549
- before { subject.key = sample_key(:model_class => subject.class, :valid => false) }
575
+ before { subject.video_key = sample_key(:model_class => subject.class, :valid => false) }
550
576
 
551
577
  it "should be false" do
552
- subject.filename_valid?.should be_false
578
+ subject.filename_valid?.should be false
553
579
  end
554
580
 
555
581
  context "after the call, #errors" do
@@ -563,4 +589,28 @@ describe CarrierWaveDirect::ActiveRecord do
563
589
  end
564
590
  end
565
591
  end
592
+
593
+ describe "class Resource < ActiveRecord::Base; mount_uploader :file, DirectUploader; end" do
594
+ include UploaderHelpers
595
+ include ModelHelpers
596
+
597
+ let(:resource_class) do
598
+ Class.new(Resource)
599
+ end
600
+
601
+ let(:subject) do
602
+ resource = resource_class.new
603
+ end
604
+
605
+ def mount_uploader
606
+ resource_class.mount_uploader :file, DirectUploader
607
+ end
608
+
609
+ #See resource table migration
610
+ it "should be valid still when a file column exists in table" do
611
+ expect(subject).to be_valid
612
+ end
613
+
614
+
615
+ end
566
616
  end
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,20 @@ require File.dirname(__FILE__) << '/support/view_helpers' # Catch dependency ord
8
8
 
9
9
  Dir[ File.dirname(__FILE__) << "/support/**/*.rb"].each {|file| require file }
10
10
 
11
- RSpec.configure do |c|
12
- c.treat_symbols_as_metadata_keys_with_true_values = true
11
+ module Rails
12
+ def self.env
13
+ ActiveSupport::StringInquirer.new("test")
14
+ end
15
+ end
16
+
17
+ RSpec.configure do |config|
18
+ config.expect_with :rspec do |c|
19
+ c.syntax = [:expect, :should]
20
+ end
21
+ end
22
+
23
+ RSpec.configure do |config|
24
+ config.mock_with :rspec do |mocks|
25
+ mocks.syntax = [:expect, :should]
26
+ end
13
27
  end
@@ -12,6 +12,7 @@ require 'carrierwave_direct/action_view_extensions/form_helper'
12
12
 
13
13
  module FormBuilderHelpers
14
14
  include ActionView::Helpers::FormHelper
15
+ include ActionView::Helpers::FormOptionsHelper
15
16
  include CarrierWaveDirect::ActionViewExtensions::FormHelper
16
17
  include ActionView::Context
17
18
 
@@ -16,16 +16,16 @@ module ModelHelpers
16
16
  if options[:accessible]
17
17
  if options[:accessible] == true
18
18
  it "should == '#{sample_data}'" do
19
- accessor_value.should == sample_data
19
+ expect(accessor_value).to eq sample_data
20
20
  end
21
21
  else
22
22
  it "##{options[:accessible].keys.first} should be #{options[:accessible].values.first}" do
23
- subject.send(options[:accessible].keys.first).should == options[:accessible].values.first
23
+ expect(subject.send(options[:accessible].keys.first)).to eq options[:accessible].values.first
24
24
  end
25
25
  end
26
26
  else
27
27
  it "should be nil" do
28
- accessor_value.should be_nil
28
+ expect(accessor_value).to be_nil
29
29
  end
30
30
  end
31
31
  end
@@ -38,14 +38,14 @@ module ModelHelpers
38
38
  describe "##{name} = '#{sample_data}'" do
39
39
  it "should set the #{delegation_object}'s #{delegation_method}" do
40
40
  subject.send("#{name}=", sample_data)
41
- subject.send(delegation_object).send(delegation_method).should == sample_data
41
+ expect(subject.send(delegation_object).send(delegation_method)).to eq sample_data
42
42
  end
43
43
  end
44
44
 
45
45
  describe "##{name}" do
46
46
  it "should return the #{delegation_method} from the #{delegation_object}" do
47
47
  subject.send(delegation_object).send("#{delegation_method}=", sample_data)
48
- subject.send(name).should == sample_data
48
+ expect(subject.send(name)).to eq sample_data
49
49
  end
50
50
 
51
51
  it_should_be_accessible(name, sample_data, options)
@@ -62,7 +62,7 @@ module ModelHelpers
62
62
  end
63
63
 
64
64
  it "should respond to ##{name}=" do
65
- subject.should respond_to("#{name}=")
65
+ expect(subject).to respond_to("#{name}=")
66
66
  end
67
67
 
68
68
  describe "##{name}" do
@@ -70,7 +70,7 @@ module ModelHelpers
70
70
  before { subject.send("#{name}=", sample_data) }
71
71
 
72
72
  it "should == '#{sample_data}'" do
73
- subject.send(name).should == sample_data
73
+ expect(subject.send(name)).to eq sample_data
74
74
  end
75
75
  end
76
76
 
@@ -10,7 +10,7 @@ module ViewHelpers
10
10
  end
11
11
 
12
12
  def have_parent_selector(options = {})
13
- have_selector(:xpath, parent_selector_xpath, options)
13
+ have_selector(:xpath, parent_selector_xpath, options.merge(visible: false))
14
14
  end
15
15
 
16
16
  def parent_selector_xpath
@@ -36,12 +36,22 @@ module ViewHelpers
36
36
  end
37
37
 
38
38
  def have_input(resource_name, input, options = {})
39
+ count = (options.delete :count).to_i
40
+ selector_options = count > 0 ? {:count => count} : {}
41
+
39
42
  options[:type] ||= input
40
43
  options[:id] ||= "#{resource_name}_#{input}"
41
44
  options[:name] ||= "#{resource_name}[#{input}]"
42
45
  options[:required] ||= "required" unless options[:required] == false
43
46
  parent_selector << "input[#{to_xpath_attributes(options)}]"
44
- have_parent_selector
47
+ have_parent_selector selector_options
48
+ end
49
+
50
+ def have_content_type(content_type,selected=nil)
51
+ options = {:value => content_type}
52
+ options[:selected] = 'selected' if selected
53
+
54
+ have_selector :xpath, ".//select[@name=\"Content-Type\"]/option[#{to_xpath_attributes(options)}]"
45
55
  end
46
56
  end
47
57
 
@@ -8,22 +8,26 @@ describe CarrierWaveDirect::Test::CapybaraHelpers do
8
8
  end
9
9
 
10
10
  let(:subject) { ExampleSpec.new }
11
- let(:page) { mock("Page").as_null_object }
12
- let(:selector) { mock("Selector") }
11
+ let(:page) { double("Page").as_null_object }
12
+ let(:selector) { double("Selector") }
13
13
 
14
14
  def stub_page
15
- subject.stub(:page).and_return(page)
15
+ allow(subject).to receive(:page).and_return(page)
16
16
  end
17
17
 
18
- def find_element_value(css, value)
19
- page.stub(:find).with(css).and_return(selector)
20
- selector.stub(:value).and_return(value)
18
+ def find_element_value(css, value, options = nil)
19
+ if options
20
+ allow(page).to receive(:find).with(css, options).and_return(selector)
21
+ else
22
+ allow(page).to receive(:find).with(css).and_return(selector)
23
+ end
24
+ allow(selector).to receive(:value).and_return(value)
21
25
  end
22
26
 
23
27
  describe "#attach_file_for_direct_upload" do
24
28
  context "'path/to/file.ext'" do
25
29
  it "should attach a file with the locator => 'file'" do
26
- subject.should_receive(:attach_file).with("file", "path/to/file.ext")
30
+ expect(subject).to receive(:attach_file).with("file", "path/to/file.ext")
27
31
  subject.attach_file_for_direct_upload "path/to/file.ext"
28
32
  end
29
33
  end
@@ -40,19 +44,19 @@ describe CarrierWaveDirect::Test::CapybaraHelpers do
40
44
 
41
45
  def stub_common
42
46
  stub_page
43
- find_element_value("input[@name='success_action_redirect']", "http://example.com")
44
- subject.stub(:visit)
47
+ find_element_value("input[name='success_action_redirect']", "http://example.com?custom_param=value", visible: false)
48
+ allow(subject).to receive(:visit)
45
49
  end
46
50
 
47
51
  before do
48
- subject.stub(:click_button)
52
+ allow(subject).to receive(:click_button)
49
53
  end
50
54
 
51
55
  shared_examples_for "submitting the form" do
52
56
  let(:options) { {} }
53
57
 
54
58
  it "should submit the form" do
55
- subject.should_receive(:click_button).with("Upload!")
59
+ expect(subject).to receive(:click_button).with("Upload!")
56
60
  upload_directly(options.merge(:button_locator => "Upload!"))
57
61
  end
58
62
  end
@@ -61,7 +65,7 @@ describe CarrierWaveDirect::Test::CapybaraHelpers do
61
65
  let(:options) { { :success => false } }
62
66
 
63
67
  it "should not redirect" do
64
- subject.should_not_receive(:visit)
68
+ expect(subject).to_not receive(:visit)
65
69
  upload_directly(options)
66
70
  end
67
71
  end
@@ -69,30 +73,30 @@ describe CarrierWaveDirect::Test::CapybaraHelpers do
69
73
  context "passing no options" do
70
74
  before do
71
75
  stub_common
72
- subject.stub(:find_key).and_return("upload_dir/guid/$filename")
73
- subject.stub(:find_upload_path).and_return("path/to/file.ext")
76
+ allow(subject).to receive(:find_key).and_return("upload_dir/guid/$filename")
77
+ allow(subject).to receive(:find_upload_path).and_return("path/to/file.ext")
74
78
  end
75
79
 
76
80
  it_should_behave_like "submitting the form"
77
81
 
78
- it "should redirect to the page's success_action_redirect url" do
79
- subject.should_receive(:visit).with(/^http:\/\/example.com/)
82
+ it "should redirect to the page's success_action_redirect url and preserve custom parameters" do
83
+ expect(subject).to receive(:visit).with(/^http:\/\/example.com\?.*custom_param=value/)
80
84
  upload_directly
81
85
  end
82
86
 
83
87
  context "the redirect url's params" do
84
88
  it "should include the bucket name" do
85
- subject.should_receive(:visit).with(/bucket=/)
89
+ expect(subject).to receive(:visit).with(/bucket=/)
86
90
  upload_directly
87
91
  end
88
92
 
89
93
  it "should include an etag" do
90
- subject.should_receive(:visit).with(/etag=/)
94
+ expect(subject).to receive(:visit).with(/etag=/)
91
95
  upload_directly
92
96
  end
93
97
 
94
98
  it "should include the key derived from the form" do
95
- subject.should_receive(:visit).with(/key=upload_dir%2Fguid%2Ffile.ext/)
99
+ expect(subject).to receive(:visit).with(/key=upload_dir%2Fguid%2Ffile.ext/)
96
100
  upload_directly
97
101
  end
98
102
  end
@@ -106,7 +110,7 @@ describe CarrierWaveDirect::Test::CapybaraHelpers do
106
110
 
107
111
  context "the redirect url's params" do
108
112
  it "should include the key from the :redirect_key option" do
109
- subject.should_receive(:visit).with(/key=some\+redirect\+key/)
113
+ expect(subject).to receive(:visit).with(/key=some\+redirect\+key/)
110
114
  upload_directly(:redirect_key => "some redirect key")
111
115
  end
112
116
  end
@@ -137,24 +141,22 @@ describe CarrierWaveDirect::Test::CapybaraHelpers do
137
141
  describe "#find_key" do
138
142
  before do
139
143
  stub_page
140
- find_element_value("input[@name='key']", "key")
144
+ find_element_value("input[name='key']", "key", visible: false)
141
145
  end
142
146
 
143
147
  it "should try to find the key on the page" do
144
- subject.find_key.should == "key"
148
+ expect(subject.find_key).to eq "key"
145
149
  end
146
150
  end
147
151
 
148
152
  describe "#find_upload_path" do
149
153
  before do
150
154
  stub_page
151
- find_element_value("input[@name='file']", "upload path")
155
+ find_element_value("input[name='file']", "upload path", visible: false)
152
156
  end
153
157
 
154
158
  it "should try to find the upload path on the page" do
155
- subject.find_upload_path.should == "upload path"
159
+ expect(subject.find_upload_path).to eq "upload path"
156
160
  end
157
161
  end
158
-
159
162
  end
160
-
@@ -13,23 +13,23 @@ describe CarrierWaveDirect::Test::Helpers do
13
13
 
14
14
  shared_examples_for "returning the default extension" do
15
15
  it "should return '*/guid/filename.extension'" do
16
- sample_key(direct_uploader).should =~ /#{GUID_REGEXP}\/filename\.extension$/
16
+ expect(sample_key(direct_uploader)).to match /#{GUID_REGEXP}\/filename\.extension$/
17
17
  end
18
18
  end
19
19
 
20
20
  context "['exe', 'bmp']" do
21
21
  before do
22
- direct_uploader.stub(:extension_white_list).and_return(%w{exe bmp})
22
+ allow(direct_uploader).to receive(:extension_white_list).and_return(%w{exe bmp})
23
23
  end
24
24
 
25
25
  it "should return '*/guid/filename.exe'" do
26
- sample_key(direct_uploader).should =~ /#{GUID_REGEXP}\/filename\.exe$/
26
+ expect(sample_key(direct_uploader)).to match /#{GUID_REGEXP}\/filename\.exe$/
27
27
  end
28
28
  end
29
29
 
30
30
  context "[]" do
31
31
  before do
32
- direct_uploader.stub(:extension_white_list).and_return([])
32
+ allow(direct_uploader).to receive(:extension_white_list).and_return([])
33
33
  end
34
34
 
35
35
  it_should_behave_like "returning the default extension"
@@ -37,7 +37,7 @@ describe CarrierWaveDirect::Test::Helpers do
37
37
 
38
38
  context "nil" do
39
39
  before do
40
- direct_uploader.stub(:extension_white_list).and_return(nil)
40
+ allow(direct_uploader).to receive(:extension_white_list).and_return(nil)
41
41
  end
42
42
 
43
43
  it_should_behave_like "returning the default extension"
@@ -47,9 +47,7 @@ describe CarrierWaveDirect::Test::Helpers do
47
47
 
48
48
  context "with no options" do
49
49
  it "should return '*/guid/filename.extension'" do
50
- sample_key(
51
- direct_uploader
52
- ).should =~ /#{GUID_REGEXP}\/filename\.extension$/
50
+ expect(sample_key(direct_uploader)).to match /#{GUID_REGEXP}\/filename\.extension$/
53
51
  end
54
52
  end
55
53
 
@@ -64,7 +62,7 @@ describe CarrierWaveDirect::Test::Helpers do
64
62
 
65
63
  shared_examples_for "a custom filename" do
66
64
  it "should return '*/guid/some_file.reg'" do
67
- sample_key(direct_uploader, options).should =~ /#{GUID_REGEXP}\/some_file\.reg$/
65
+ expect(sample_key(direct_uploader, options)).to match /#{GUID_REGEXP}\/some_file\.reg$/
68
66
  end
69
67
  end
70
68
 
@@ -82,10 +80,10 @@ describe CarrierWaveDirect::Test::Helpers do
82
80
 
83
81
  context ":base => 'upload_dir/porno/movie/${filename}'" do
84
82
  it "should return 'upload_dir/porno/movie/guid/filename.extension'" do
85
- sample_key(
83
+ expect(sample_key(
86
84
  direct_uploader,
87
85
  :base => "upload_dir/porno/movie/${filename}"
88
- ).should == "upload_dir/porno/movie/filename.extension"
86
+ )).to eq "upload_dir/porno/movie/filename.extension"
89
87
  end
90
88
  end
91
89
  context ":filename => 'some_file.reg'" do
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe CarrierWaveDirect::Uploader::Configuration do
4
+ include UploaderHelpers
5
+ include ModelHelpers
6
+
7
+ let(:subject) { DirectUploader }
8
+
9
+ before do
10
+ subject.reset_direct_config
11
+ end
12
+
13
+ describe "default configuration" do
14
+ it "returns false for validate_is_attached" do
15
+ expect(subject.validate_is_attached).to be false
16
+ end
17
+
18
+ it "returns false for validate_is_uploaded" do
19
+ expect(subject.validate_is_uploaded).to be false
20
+ end
21
+
22
+ it "return true for validate_unique_filename" do
23
+ expect(subject.validate_unique_filename).to be true
24
+ end
25
+
26
+ it "returns true for validate_remote_net_url_format" do
27
+ expect(subject.validate_remote_net_url_format).to be true
28
+ end
29
+
30
+ it "has upload_expiration of 10 hours" do
31
+ expect(subject.upload_expiration).to eq 36000
32
+ end
33
+
34
+ it "has min_file_size of 1 byte" do
35
+ expect(subject.min_file_size).to eq 1
36
+ end
37
+
38
+ it "has max_file_size of 5 MB" do
39
+ expect(subject.max_file_size).to eq 5242880
40
+ end
41
+
42
+ it "returns false for use_action_status" do
43
+ expect(subject.use_action_status).to be false
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe CarrierWaveDirect::Uploader::ContentType do
6
+ subject { DirectUploader.new }
7
+
8
+ describe "#content_type" do
9
+ it "defaults to binary/octet-stream when there is no default_content_type" do
10
+ allow(subject.class).to receive(:default_content_type).and_return(nil)
11
+ expect(subject.content_type).to eq 'binary/octet-stream'
12
+ end
13
+
14
+ it "returns the default_content_type if set" do
15
+ allow(subject.class).to receive(:default_content_type).and_return('video/mp4')
16
+ expect(subject.content_type).to eq 'video/mp4'
17
+ end
18
+ end
19
+
20
+ describe "#content_types" do
21
+ it "should default to common media types" do
22
+ expect(subject.content_types).to eq %w(application/atom+xml application/ecmascript application/json
23
+ application/javascript application/octet-stream application/ogg
24
+ application/pdf application/postscript application/rss+xml
25
+ application/font-woff application/xhtml+xml application/xml
26
+ application/xml-dtd application/zip application/gzip audio/basic
27
+ audio/mp4 audio/mpeg audio/ogg audio/vorbis audio/vnd.rn-realaudio
28
+ audio/vnd.wave audio/webm image/gif image/jpeg image/pjpeg image/png
29
+ image/svg+xml image/tiff text/cmd text/css text/csv text/html
30
+ text/javascript text/plain text/vcard text/xml video/mpeg video/mp4
31
+ video/ogg video/quicktime video/webm video/x-matroska video/x-ms-wmv
32
+ video/x-flv)
33
+ end
34
+
35
+ it "should be the configured value" do
36
+ allow(subject.class).to receive(:allowed_content_types).and_return(['audio/ogg'])
37
+ expect(subject.content_types).to eq ['audio/ogg']
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ #
3
+ require 'spec_helper'
4
+ require 'data/sample_data'
5
+
6
+ describe CarrierWaveDirect::Uploader::DirectUrl do
7
+
8
+ let(:subject) { DirectUploader.new }
9
+
10
+ let(:mounted_subject) { DirectUploader.new(mounted_model, sample(:mounted_as)) }
11
+
12
+ describe "#direct_fog_url" do
13
+ it "should return the result from CarrierWave::Storage::Fog::File#public_url" do
14
+ expect(subject.direct_fog_url).to eq CarrierWave::Storage::Fog::File.new(
15
+ subject, nil, nil
16
+ ).public_url
17
+ end
18
+
19
+ context ":with_path => true" do
20
+ it "should return the full url set by carrierwave" do
21
+ allow(subject).to receive(:url).and_return("url")
22
+ expect(subject.direct_fog_url(:with_path => true)).to eq "url"
23
+ end
24
+ end
25
+ end
26
+ end