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
@@ -0,0 +1,28 @@
1
+ module CarrierWaveDirect
2
+ module Uploader
3
+ module ContentType
4
+
5
+ def content_type
6
+ default_content_type ? default_content_type : 'binary/octet-stream'
7
+ end
8
+
9
+ def content_types
10
+ types = allowed_content_types
11
+
12
+ return types if types.is_a? Array
13
+
14
+ %w(application/atom+xml application/ecmascript application/json
15
+ application/javascript application/octet-stream application/ogg
16
+ application/pdf application/postscript application/rss+xml
17
+ application/font-woff application/xhtml+xml application/xml
18
+ application/xml-dtd application/zip application/gzip audio/basic
19
+ audio/mp4 audio/mpeg audio/ogg audio/vorbis audio/vnd.rn-realaudio
20
+ audio/vnd.wave audio/webm image/gif image/jpeg image/pjpeg
21
+ image/png image/svg+xml image/tiff text/cmd text/css text/csv
22
+ text/html text/javascript text/plain text/vcard text/xml video/mpeg
23
+ video/mp4 video/ogg video/quicktime video/webm video/x-matroska
24
+ video/x-ms-wmv video/x-flv)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ module CarrierWaveDirect
2
+ module Uploader
3
+ module DirectUrl
4
+
5
+ def direct_fog_url(options = {})
6
+ if options[:with_path]
7
+ url
8
+ else
9
+ CarrierWave::Storage::Fog::File.new(self, CarrierWave::Storage::Fog.new(self), nil).public_url
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -1,8 +1,11 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require "securerandom"
4
+ require "carrierwave_direct/uploader/content_type"
5
+ require "carrierwave_direct/uploader/direct_url"
6
+
3
7
  module CarrierWaveDirect
4
8
  module Uploader
5
-
6
9
  extend ActiveSupport::Concern
7
10
 
8
11
  FILENAME_WILDCARD = "${filename}"
@@ -20,84 +23,73 @@ module CarrierWaveDirect
20
23
  end
21
24
  end
22
25
 
23
- def direct_fog_url(options = {})
24
- fog_uri = CarrierWave::Storage::Fog::File.new(self, CarrierWave::Storage::Fog.new(self), nil).public_url
25
- if options[:with_path]
26
- uri = URI.parse(fog_uri.chomp('/'))
27
- path = "/#{key}"
28
- uri.path += URI.escape(path)
29
- fog_uri = uri.to_s
30
- end
31
- fog_uri
26
+ include CarrierWaveDirect::Uploader::ContentType
27
+ include CarrierWaveDirect::Uploader::DirectUrl
28
+
29
+ def acl
30
+ fog_public ? 'public-read' : 'private'
32
31
  end
33
32
 
34
- def guid
35
- UUIDTools::UUID.random_create
33
+ def policy(options = {}, &block)
34
+ options[:expiration] ||= upload_expiration
35
+ options[:min_file_size] ||= min_file_size
36
+ options[:max_file_size] ||= max_file_size
37
+
38
+ @policy ||= generate_policy(options, &block)
36
39
  end
37
40
 
38
- def key=(k)
39
- @key = k
40
- update_version_keys(:with => @key)
41
+ def clear_policy!
42
+ @policy = nil
43
+ end
44
+
45
+ def signature
46
+ Base64.encode64(
47
+ OpenSSL::HMAC.digest(
48
+ OpenSSL::Digest.new('sha1'),
49
+ aws_secret_access_key, policy
50
+ )
51
+ ).gsub("\n","")
52
+ end
53
+
54
+ def url_scheme_white_list
55
+ nil
56
+ end
57
+
58
+ def persisted?
59
+ false
41
60
  end
42
61
 
43
62
  def key
44
63
  return @key if @key.present?
45
64
  if present?
46
- self.key = URI.parse(URI.encode(url)).path[1 .. -1] # explicitly set key
65
+ identifier = model.send("#{mounted_as}_identifier")
66
+ self.key = "#{store_dir}/#{identifier}"
47
67
  else
48
68
  @key = "#{store_dir}/#{guid}/#{FILENAME_WILDCARD}"
49
69
  end
50
70
  @key
51
71
  end
52
72
 
53
- def has_key?
54
- key !~ /#{Regexp.escape(FILENAME_WILDCARD)}\z/
73
+ def key=(k)
74
+ @key = k
75
+ update_version_keys(:with => @key)
55
76
  end
56
77
 
57
- def acl
58
- fog_public ? 'public-read' : 'private'
78
+ def guid
79
+ SecureRandom.uuid
59
80
  end
60
81
 
61
- def policy(options = {})
62
- options[:expiration] ||= self.class.upload_expiration
63
- options[:min_file_size] ||= self.class.min_file_size
64
- options[:max_file_size] ||= self.class.max_file_size
65
-
66
- conditions = [
67
- ["starts-with", "$utf8", ""],
68
- ["starts-with", "$key", key.sub(/#{Regexp.escape(FILENAME_WILDCARD)}\z/, "")]
69
- ]
70
- conditions << ["starts-with", "$Content-Type", ""] if self.class.will_include_content_type
71
- conditions << {"bucket" => fog_directory}
72
- conditions << {"acl" => acl}
73
-
74
- if self.class.use_action_status
75
- conditions << {"success_action_status" => success_action_status}
76
- else
77
- conditions << {"success_action_redirect" => success_action_redirect}
78
- end
79
-
80
- conditions << ["content-length-range", options[:min_file_size], options[:max_file_size]]
81
-
82
- Base64.encode64(
83
- {
84
- 'expiration' => Time.now.utc + options[:expiration],
85
- 'conditions' => conditions
86
- }.to_json
87
- ).gsub("\n","")
82
+ def has_key?
83
+ key !~ /#{Regexp.escape(FILENAME_WILDCARD)}\z/
88
84
  end
89
85
 
90
- def signature
91
- Base64.encode64(
92
- OpenSSL::HMAC.digest(
93
- OpenSSL::Digest::Digest.new('sha1'),
94
- aws_secret_access_key, policy
95
- )
96
- ).gsub("\n","")
86
+ def key_regexp
87
+ /\A(#{store_dir}|#{cache_dir})\/[a-f\d\-]+\/.+\.(?i)#{extension_regexp}(?-i)\z/
97
88
  end
98
89
 
99
- def persisted?
100
- false
90
+ def extension_regexp
91
+ allowed_file_types = extension_white_list
92
+ extension_regexp = allowed_file_types.present? && allowed_file_types.any? ? "(#{allowed_file_types.join("|")})" : "\\w+"
101
93
  end
102
94
 
103
95
  def filename
@@ -115,21 +107,12 @@ module CarrierWaveDirect
115
107
  filename_parts.join("/")
116
108
  end
117
109
 
118
- def key_regexp
119
- /\A#{store_dir}\/[a-f\d\-]+\/.+\.(?i)#{extension_regexp}(?-i)\z/
120
- end
121
-
122
- def extension_regexp
123
- allowed_file_types = extension_white_list
124
- extension_regexp = allowed_file_types.present? && allowed_file_types.any? ? "(#{allowed_file_types.join("|")})" : "\\w+"
125
- end
110
+ private
126
111
 
127
- def url_scheme_white_list
128
- nil
112
+ def decoded_key
113
+ URI.decode(URI.parse(url).path[1 .. -1])
129
114
  end
130
115
 
131
- private
132
-
133
116
  def key_from_file(fname)
134
117
  new_key_parts = key.split("/")
135
118
  new_key_parts.pop
@@ -150,5 +133,33 @@ module CarrierWaveDirect
150
133
  extname = File.extname(for_file)
151
134
  [for_file.chomp(extname), version_name].compact.join('_') << extname
152
135
  end
136
+
137
+ def generate_policy(options)
138
+ conditions = []
139
+
140
+ conditions << ["starts-with", "$utf8", ""] if options[:enforce_utf8]
141
+ conditions << ["starts-with", "$key", key.sub(/#{Regexp.escape(FILENAME_WILDCARD)}\z/, "")]
142
+
143
+ conditions << ["starts-with", "$Content-Type", ""] if will_include_content_type
144
+ conditions << {"bucket" => fog_directory}
145
+ conditions << {"acl" => acl}
146
+
147
+ if use_action_status
148
+ conditions << {"success_action_status" => success_action_status}
149
+ else
150
+ conditions << {"success_action_redirect" => success_action_redirect}
151
+ end
152
+
153
+ conditions << ["content-length-range", options[:min_file_size], options[:max_file_size]]
154
+
155
+ yield conditions if block_given?
156
+
157
+ Base64.encode64(
158
+ {
159
+ 'expiration' => (Time.now + options[:expiration]).utc.iso8601,
160
+ 'conditions' => conditions
161
+ }.to_json
162
+ ).gsub("\n","")
163
+ end
153
164
  end
154
165
  end
@@ -11,8 +11,9 @@ module CarrierWaveDirect
11
11
 
12
12
  class UniqueFilenameValidator < ::ActiveModel::EachValidator
13
13
  def validate_each(record, attribute, value)
14
- if record.new_record? && record.errors[attribute].empty? && (record.send("has_#{attribute}_upload?") || record.send("has_remote_#{attribute}_net_url?"))
15
- if record.class.where(attribute => record.send(attribute).filename).exists?
14
+ if record.errors[attribute].empty? && (record.send("has_#{attribute}_upload?") || record.send("has_remote_#{attribute}_net_url?"))
15
+ column = record.class.uploader_options[attribute].fetch(:mount_on, attribute)
16
+ if record.class.where(column => record.send(attribute).filename).exists?
16
17
  record.errors.add(attribute, :carrierwave_direct_filename_taken)
17
18
  end
18
19
  end
@@ -21,7 +22,7 @@ module CarrierWaveDirect
21
22
 
22
23
  class FilenameFormatValidator < ::ActiveModel::EachValidator
23
24
  def validate_each(record, attribute, value)
24
- if record.new_record? && record.send("has_#{attribute}_upload?") && record.key !~ record.send(attribute).key_regexp
25
+ if record.send("has_#{attribute}_upload?") && record.send("#{attribute}_key") !~ record.send(attribute).key_regexp
25
26
  extensions = record.send(attribute).extension_white_list
26
27
  message = I18n.t("errors.messages.carrierwave_direct_filename_invalid")
27
28
 
@@ -36,7 +37,7 @@ module CarrierWaveDirect
36
37
 
37
38
  class RemoteNetUrlFormatValidator < ::ActiveModel::EachValidator
38
39
  def validate_each(record, attribute, value)
39
- if record.new_record? && record.send("has_remote_#{attribute}_net_url?")
40
+ if record.send("has_remote_#{attribute}_net_url?")
40
41
  remote_net_url = record.send("remote_#{attribute}_net_url")
41
42
  uploader = record.send(attribute)
42
43
  url_scheme_white_list = uploader.url_scheme_white_list
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module CarrierwaveDirect
4
- VERSION = "0.0.13"
4
+ VERSION = "0.0.17"
5
5
  end
6
6
 
@@ -1,18 +1,12 @@
1
1
  # encoding: utf-8
2
2
 
3
- require "carrierwave_direct/version"
4
-
5
3
  require "carrierwave"
6
- require "uuidtools"
7
- require "fog"
4
+ require "fog/aws"
8
5
 
9
6
  module CarrierWaveDirect
10
7
 
11
- autoload :Uploader, "carrierwave_direct/uploader"
12
- autoload :Mount, "carrierwave_direct/mount"
13
-
14
8
  module Uploader
15
- autoload :Configuration, 'carrierwave_direct/uploader/configuration'
9
+ require "carrierwave_direct/uploader/configuration"
16
10
 
17
11
  CarrierWave::Uploader::Base.send(:include, Configuration)
18
12
  end
@@ -43,3 +37,7 @@ if defined?(Rails)
43
37
  end
44
38
  end
45
39
 
40
+ require "carrierwave_direct/mount"
41
+ require "carrierwave_direct/uploader"
42
+ require "carrierwave_direct/version"
43
+
@@ -8,28 +8,27 @@ describe CarrierWaveDirect::ActionViewExtensions::FormHelper do
8
8
  describe "#direct_upload_form_for" do
9
9
  it "should yield an instance of CarrierWaveDirect::FormBuilder" do
10
10
  direct_upload_form_for(direct_uploader) do |f|
11
- f.should be_instance_of(CarrierWaveDirect::FormBuilder)
11
+ expect(f).to be_instance_of(CarrierWaveDirect::FormBuilder)
12
12
  end
13
13
  end
14
14
 
15
15
  context "the form" do
16
16
  before do
17
- direct_uploader.stub(:direct_fog_url).and_return("http://example.com")
17
+ allow(direct_uploader).to receive(:direct_fog_url).and_return("http://example.com")
18
18
  end
19
19
 
20
20
  it "should post to the uploader's #direct_fog_url as a multipart form" do
21
- form.should submit_to(
21
+ expect(form).to submit_to(
22
22
  :action => "http://example.com", :method => "post", :enctype => "multipart/form-data"
23
23
  )
24
24
  end
25
25
 
26
26
  it "should include any html options passed as through :html" do
27
- form(:html => { :target => "_blank_iframe" }).should submit_to(
27
+ expect(form(:html => { :target => "_blank_iframe" })).to submit_to(
28
28
  :action => "http://example.com", :method => "post", :enctype => "multipart/form-data", :target => "_blank_iframe"
29
29
  )
30
30
  end
31
31
  end
32
32
  end
33
-
34
33
  end
35
34
 
@@ -0,0 +1,41 @@
1
+ SAMPLE_DATA = {
2
+ :path => "upload_dir/bliind.exe",
3
+ :path_with_special_chars => "upload_dir/some file & blah.exe",
4
+ :path_with_escaped_chars => "upload_dir/some%20file%20&%20blah.exe",
5
+ :key => "some key",
6
+ :guid => "guid",
7
+ :store_dir => "store_dir",
8
+ :cache_dir => "cache_dir",
9
+ :extension_regexp => "(avi)",
10
+ :url => "http://example.com/some_url",
11
+ :expiration => 60,
12
+ :min_file_size => 1024,
13
+ :max_file_size => 10485760,
14
+ :file_url => "http://anyurl.com/any_path/video_dir/filename.avi",
15
+ :mounted_model_name => "Porno",
16
+ :mounted_as => :video,
17
+ :filename => "filename",
18
+ :extension => ".avi",
19
+ :version => :thumb,
20
+ :s3_bucket_url => "https://s3-bucket.s3.amazonaws.com"
21
+ }
22
+
23
+ SAMPLE_DATA.merge!(
24
+ :stored_filename_base => "#{sample(:guid)}/#{sample(:filename)}"
25
+ )
26
+
27
+ SAMPLE_DATA.merge!(
28
+ :stored_filename => "#{sample(:stored_filename_base)}#{sample(:extension)}",
29
+ :stored_version_filename => "#{sample(:stored_filename_base)}_#{sample(:version)}#{sample(:extension)}"
30
+ )
31
+
32
+ SAMPLE_DATA.merge!(
33
+ :s3_key => "#{sample(:store_dir)}/#{sample(:stored_filename)}"
34
+ )
35
+
36
+ SAMPLE_DATA.merge!(
37
+ :s3_file_url => "#{sample(:s3_bucket_url)}/#{sample(:s3_key)}"
38
+ )
39
+
40
+ SAMPLE_DATA.freeze
41
+
@@ -1,6 +1,45 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
+ require 'erb'
5
+
6
+ class CarrierWaveDirect::FormBuilder
7
+ attr_accessor :template, :object
8
+
9
+ public :content_choices_options
10
+ end
11
+
12
+ shared_examples_for 'hidden values form' do
13
+ hidden_fields = [
14
+ :key,
15
+ {:aws_access_key_id => "AWSAccessKeyId"},
16
+ :acl,
17
+ :success_action_redirect,
18
+ :policy,
19
+ :signature
20
+ ]
21
+
22
+ hidden_fields.each do |input|
23
+ if input.is_a?(Hash)
24
+ key = input.keys.first
25
+ name = input[key]
26
+ else
27
+ key = name = input
28
+ end
29
+
30
+ it "should have a hidden field for '#{name}'" do
31
+ allow(direct_uploader).to receive(key).and_return(key.to_s)
32
+ expect(subject).to have_input(
33
+ :direct_uploader,
34
+ key,
35
+ :type => :hidden,
36
+ :name => name,
37
+ :value => key,
38
+ :required => false
39
+ )
40
+ end
41
+ end
42
+ end
4
43
 
5
44
  describe CarrierWaveDirect::FormBuilder do
6
45
  include FormBuilderHelpers
@@ -12,7 +51,11 @@ describe CarrierWaveDirect::FormBuilder do
12
51
  end
13
52
 
14
53
  def form_with_file_field_and_no_redirect
15
- form {|f| f.file_field :video, use_action_status: true }
54
+ allow(@direct_uploader.class).to receive(:use_action_status).and_return(true)
55
+
56
+ form do |f|
57
+ f.file_field :video
58
+ end
16
59
  end
17
60
 
18
61
  default_hidden_fields = [
@@ -34,6 +77,8 @@ describe CarrierWaveDirect::FormBuilder do
34
77
 
35
78
  # http://aws.amazon.com/articles/1434?_encoding=UTF8
36
79
  context "form" do
80
+ let(:subject) {form_with_default_file_field}
81
+ it_should_behave_like 'hidden values form'
37
82
 
38
83
  default_hidden_fields.each do |input|
39
84
  if input.is_a?(Hash)
@@ -44,8 +89,8 @@ describe CarrierWaveDirect::FormBuilder do
44
89
  end
45
90
 
46
91
  it "should have a hidden field for '#{name}'" do
47
- direct_uploader.stub(key).and_return(key.to_s)
48
- form_with_default_file_field.should have_input(
92
+ allow(direct_uploader).to receive(key).and_return(key.to_s)
93
+ expect(form_with_default_file_field).to have_input(
49
94
  :direct_uploader,
50
95
  key,
51
96
  :type => :hidden,
@@ -65,8 +110,8 @@ describe CarrierWaveDirect::FormBuilder do
65
110
  end
66
111
 
67
112
  it "should have a hidden field for '#{name}'" do
68
- direct_uploader.stub(key).and_return(key.to_s)
69
- form_with_file_field_and_no_redirect.should have_input(
113
+ allow(direct_uploader).to receive(key).and_return(key.to_s)
114
+ expect(form_with_file_field_and_no_redirect).to have_input(
70
115
  :direct_uploader,
71
116
  key,
72
117
  :type => :hidden,
@@ -78,7 +123,7 @@ describe CarrierWaveDirect::FormBuilder do
78
123
  end
79
124
 
80
125
  it "should have an input for a file to upload" do
81
- form_with_default_file_field.should have_input(
126
+ expect(form_with_default_file_field).to have_input(
82
127
  :direct_uploader,
83
128
  :video,
84
129
  :type => :file,
@@ -88,4 +133,92 @@ describe CarrierWaveDirect::FormBuilder do
88
133
  end
89
134
  end
90
135
  end
136
+
137
+ describe "#content_type_select" do
138
+ context "form" do
139
+ let(:subject) do
140
+ form do |f|
141
+ f.content_type_select
142
+ end
143
+ end
144
+
145
+ before do
146
+ allow(direct_uploader.class).to receive(:will_include_content_type).and_return(true)
147
+ end
148
+
149
+ it 'should select the default content type' do
150
+ allow(direct_uploader).to receive(:content_type).and_return('video/mp4')
151
+ expect(subject).to have_content_type 'video/mp4', true
152
+ end
153
+
154
+ it 'should include the default content types' do
155
+ allow(direct_uploader).to receive(:content_types).and_return(['text/foo','text/bar'])
156
+ expect(subject).to have_content_type 'text/foo', false
157
+ expect(subject).to have_content_type 'text/bar', false
158
+ end
159
+
160
+ it 'should select the passed in content type' do
161
+ dom = form {|f| f.content_type_select nil, 'video/mp4'}
162
+ expect(dom).to have_content_type 'video/mp4', true
163
+ end
164
+
165
+ it 'should include most content types' do
166
+ %w(application/atom+xml application/ecmascript application/json application/javascript application/octet-stream application/ogg application/pdf application/postscript application/rss+xml application/font-woff application/xhtml+xml application/xml application/xml-dtd application/zip application/gzip audio/basic audio/mp4 audio/mpeg audio/ogg audio/vorbis audio/vnd.rn-realaudio audio/vnd.wave audio/webm image/gif image/jpeg image/pjpeg image/png image/svg+xml image/tiff text/cmd text/css text/csv text/html text/javascript text/plain text/vcard text/xml video/mpeg video/mp4 video/ogg video/quicktime video/webm video/x-matroska video/x-ms-wmv video/x-flv).each do |type|
167
+ expect(subject).to have_content_type type
168
+ end
169
+ end
170
+ end
171
+ end
172
+
173
+ describe "#content_type_label" do
174
+ context "form" do
175
+ let(:subject) do
176
+ form do |f|
177
+ f.content_type_label
178
+ end
179
+ end
180
+
181
+ end
182
+ end
183
+
184
+ describe 'full form' do
185
+ let(:dom) do
186
+ form do |f|
187
+ f.content_type_label <<
188
+ f.content_type_select <<
189
+ f.file_field(:video)
190
+ end
191
+ end
192
+
193
+ before do
194
+ allow(direct_uploader).to receive('key').and_return('foo')
195
+ allow(direct_uploader.class).to receive(:will_include_content_type).and_return(true)
196
+ end
197
+
198
+ it 'should only include the hidden values once' do
199
+ expect(dom).to have_input(
200
+ :direct_uploader,
201
+ 'key',
202
+ :type => :hidden,
203
+ :name => 'key',
204
+ :value => 'foo',
205
+ :required => false,
206
+ :count => 1
207
+ )
208
+ end
209
+
210
+ it 'should include Content-Type twice' do
211
+ expect(dom).to have_input(
212
+ :direct_uploader,
213
+ :content_type,
214
+ :type => :hidden,
215
+ :name => 'Content-Type',
216
+ :value => 'binary/octet-stream',
217
+ :required => false,
218
+ :count => 1
219
+ )
220
+
221
+ expect(dom).to have_selector :xpath, './/select[@name="Content-Type"]', :count => 1
222
+ end
223
+ end
91
224
  end
data/spec/mount_spec.rb CHANGED
@@ -17,43 +17,30 @@ describe CarrierWaveDirect::Mount do
17
17
  it_should_have_accessor(:remote_video_net_url)
18
18
 
19
19
  describe "#has_video_upload?" do
20
- context "video does not have a key" do
21
- before { subject.video.stub(:has_key?).and_return(false) }
22
-
23
- it "should return false" do
24
- subject.should_not have_video_upload
25
- end
20
+ it "returns false when video does not have a key" do
21
+ allow(subject.video).to receive(:has_key?).and_return(false)
22
+ expect(subject).to_not have_video_upload
26
23
  end
27
24
 
28
- context "video has a key" do
29
- before { subject.video.stub(:has_key?).and_return(true) }
30
-
31
- it "should return true" do
32
- subject.should have_video_upload
33
- end
25
+ it "returns true when video has a key" do
26
+ allow(subject.video).to receive(:has_key?).and_return(true)
27
+ expect(subject).to have_video_upload
34
28
  end
35
29
  end
36
30
 
37
31
  describe "#has_remote_video_net_url?" do
38
- context "remote_video_net_url is nil" do
39
- before { subject.remote_video_net_url = nil }
40
-
41
- it "should return false" do
42
- subject.should_not have_remote_video_net_url
43
- end
32
+ it "returns false when remote_video_net_url is nil" do
33
+ subject.remote_video_net_url = nil
34
+ expect(subject).to_not have_remote_video_net_url
44
35
  end
45
36
 
46
- context "remote_video_net_url is not nil" do
47
- before { subject.remote_video_net_url = "something" }
48
-
49
- it "should return true" do
50
- subject.should have_remote_video_net_url
51
- end
37
+ it "returns true when remote_video_net_url is not nil" do
38
+ subject.remote_video_net_url = :not_nil
39
+ expect(subject).to have_remote_video_net_url
52
40
  end
53
41
  end
54
42
 
55
- it_should_delegate(:key, :to => "video#key", :accessible => {"has_video_upload?" => false})
56
-
43
+ it_should_delegate(:video_key, :to => "video#key", :accessible => { "has_video_upload?" => false })
57
44
  end
58
45
  end
59
46