carrierwave_direct 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df532738055d7fe9993268699211f219bdf0eeb2
4
- data.tar.gz: 73234daa2e001178a73ef9caec211d2aaecfd3c6
3
+ metadata.gz: 4f9e56f05064fcec0e706c91c80c85c5e4bdbf93
4
+ data.tar.gz: 0f8c4b55fc49a71f4e4a8ac5992e82a684ffb99b
5
5
  SHA512:
6
- metadata.gz: fa994ea1bdab12573044260fc76389f0bde0866a355eb648c82726637e26247dca2aaab1e08c2122380f9704a8a59c90c4c422754e3d79fc581651fd83563452
7
- data.tar.gz: b4c5109688c2dfe132686f9ea3f86e7ae7d08d8c7f66216d7385569b9f715e5ca0e41325b00c25bbe2e519aa864164d2483b3a400d88754ad92bbef67db04950
6
+ metadata.gz: 47fe09989e7dba3b47476aaa6c3137e2d01f9809778ff3763a3121c922bc0690816593add6a3a625be6174e9e0f2c00e1b8d9221372e4a9890953cc28e0d8a1a
7
+ data.tar.gz: ae5b467e4542cd5940df6aca828396b82eb0df9647a0b283ae4abf7c3babdf862041c46a76290f5081bd70c78fe1772a6cda347d3c550d56d415582c000b0ca2
@@ -2,3 +2,11 @@ rvm:
2
2
  - 1.9.3
3
3
  - 2.0.0
4
4
  - 2.1.0
5
+ install:
6
+ - 'travis_retry bundle install'
7
+ script: 'bundle exec rspec spec'
8
+ gemfile:
9
+ - Gemfile
10
+ - gemfiles/3.2.gemfile
11
+ - gemfiles/4.0.gemfile
12
+ - gemfiles/4.1.gemfile
@@ -1,6 +1,24 @@
1
+ ### 0.0.15
2
+
3
+ [Full Changes](https://github.com/dwilkie/carrierwave_direct/compare/v0.0.14...v0.0.15)
4
+
5
+ Features:
6
+ * Allow format validators to be used on update (Grey Baker @greysteil)
7
+ * Add cache_dir to allowed paths (Grey Baker @greysteil)
8
+
9
+ Bug Fixes:
10
+ * Use Carrierwave to generate URL's (Petrik de Heus @p8)
11
+
12
+ Misc:
13
+ * README update (Samuel Reh @samuelreh)
14
+ * Fix typo in README (Brandon Conway @brandoncc)
15
+ * Fix specs for rspec 3 (Hanachin @hanachin)
16
+ * Fix typo in nl.yml (Petrik de Heus @p8)
17
+ * Add multiple rails versions support to travis (Petrik de Heus @p8)
18
+
1
19
  ### 0.0.14
2
20
 
3
- [Full Changes](https://github.com/dwilkie/carrierwave_direct/compare/v0.0.13...master)
21
+ [Full Changes](https://github.com/dwilkie/carrierwave_direct/compare/v0.0.13...v0.0.14)
4
22
 
5
23
  Features:
6
24
  * Add ability to set content type in upload form (John Kamenik @jkamenik)
data/README.md CHANGED
@@ -172,6 +172,9 @@ Note if `User` is not an ActiveRecord object e.g.
172
172
 
173
173
  ```ruby
174
174
  class User
175
+ extend CarrierWave::Mount
176
+ extend CarrierWaveDirect::Mount
177
+
175
178
  mount_uploader :avatar, AvatarUploader
176
179
  end
177
180
  ```
@@ -337,7 +340,7 @@ class AvatarProcessor
337
340
  end
338
341
  ```
339
342
 
340
- The method `self.remote_avatar_url=` from [CarrierWave](https://github.com/jnicklas/carrierwave) downloads the avatar from S3 and processes it. `save` then re-uploads the processed avatar to to S3
343
+ The method `self.remote_avatar_url=` from [CarrierWave](https://github.com/jnicklas/carrierwave) downloads the avatar from S3 and processes it. `save` then re-uploads the processed avatar to S3
341
344
 
342
345
  ## Uploading from a remote location
343
346
 
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "carrierwave"
4
+ gem "uuidtools"
5
+ gem "fog"
6
+
7
+ group :test do
8
+ gem "rspec", '3.0.0'
9
+ gem "timecop"
10
+ gem "rails", "~>3.2.12"
11
+ gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
12
+ gem "capybara"
13
+ # gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
14
+ end
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "carrierwave"
4
+ gem "uuidtools"
5
+ gem "fog"
6
+
7
+ group :test do
8
+ gem "rspec", '3.0.0'
9
+ gem "timecop"
10
+ gem "rails", "~>4.0.0"
11
+ gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
12
+ gem "capybara"
13
+ # gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
14
+ end
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "carrierwave"
4
+ gem "uuidtools"
5
+ gem "fog"
6
+
7
+ group :test do
8
+ gem "rspec", '3.0.0'
9
+ gem "timecop"
10
+ gem "rails", "~>4.1.0"
11
+ gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
12
+ gem "capybara"
13
+ # gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
14
+ end
@@ -5,5 +5,5 @@ nl:
5
5
  carrierwave_direct_upload_missing: geüpload bestand ontbreekt
6
6
  carrierwave_direct_attachment_missing: bestand ontbreekt
7
7
  carrierwave_direct_filename_invalid: "is ongeldig. "
8
- carrierwave_direct_allowed_extensions: Toegestane betandstypen zijn %{extensions}
8
+ carrierwave_direct_allowed_extensions: Toegestane bestandstypen zijn %{extensions}
9
9
  carrierwave_direct_allowed_schemes: "Toegestane schema's zijn %{schemes}"
@@ -25,9 +25,9 @@ module CarrierWaveDirect
25
25
 
26
26
  validates_is_attached column if uploader_option(column.to_sym, :validate_is_attached)
27
27
  validates_is_uploaded column if uploader_option(column.to_sym, :validate_is_uploaded)
28
- validates_filename_uniqueness_of column if uploader_option(column.to_sym, :validate_unique_filename)
29
- validates_filename_format_of column if uploader_option(column.to_sym, :validate_filename_format)
30
- validates_remote_net_url_format_of column if uploader_option(column.to_sym, :validate_remote_net_url_format)
28
+ validates_filename_uniqueness_of(column, on: :create) if uploader_option(column.to_sym, :validate_unique_filename)
29
+ validates_filename_format_of(column, on: :create) if uploader_option(column.to_sym, :validate_filename_format)
30
+ validates_remote_net_url_format_of(column, on: :create) if uploader_option(column.to_sym, :validate_remote_net_url_format)
31
31
 
32
32
  self.instance_eval <<-RUBY, __FILE__, __LINE__+1
33
33
  attr_accessor :skip_is_attached_validations
@@ -61,7 +61,7 @@ module CarrierWaveDirect
61
61
  def key
62
62
  return @key if @key.present?
63
63
  if present?
64
- self.key = URI.parse(encoded_url).path[1 .. -1] # explicitly set key
64
+ self.key = decoded_key # explicitly set key
65
65
  else
66
66
  @key = "#{store_dir}/#{guid}/#{FILENAME_WILDCARD}"
67
67
  end
@@ -82,7 +82,7 @@ module CarrierWaveDirect
82
82
  end
83
83
 
84
84
  def key_regexp
85
- /\A#{store_dir}\/[a-f\d\-]+\/.+\.(?i)#{extension_regexp}(?-i)\z/
85
+ /\A(#{store_dir}|#{cache_dir})\/[a-f\d\-]+\/.+\.(?i)#{extension_regexp}(?-i)\z/
86
86
  end
87
87
 
88
88
  def extension_regexp
@@ -107,8 +107,8 @@ module CarrierWaveDirect
107
107
 
108
108
  private
109
109
 
110
- def encoded_url
111
- URI.encode(URI.decode(url), " []+()")
110
+ def decoded_key
111
+ URI.decode(URI.parse(url).path[1 .. -1])
112
112
  end
113
113
 
114
114
  def key_from_file(fname)
@@ -3,14 +3,11 @@ module CarrierWaveDirect
3
3
  module DirectUrl
4
4
 
5
5
  def direct_fog_url(options = {})
6
- fog_uri = CarrierWave::Storage::Fog::File.new(self, CarrierWave::Storage::Fog.new(self), nil).public_url
7
6
  if options[:with_path]
8
- uri = URI.parse(fog_uri.chomp('/'))
9
- path = "/#{URI.decode(key)}"
10
- uri.path += URI.escape(path)
11
- fog_uri = uri.to_s
7
+ url
8
+ else
9
+ CarrierWave::Storage::Fog::File.new(self, CarrierWave::Storage::Fog.new(self), nil).public_url
12
10
  end
13
- fog_uri
14
11
  end
15
12
 
16
13
  end
@@ -11,7 +11,7 @@ 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?"))
14
+ if record.errors[attribute].empty? && (record.send("has_#{attribute}_upload?") || record.send("has_remote_#{attribute}_net_url?"))
15
15
  column = record.class.uploader_options[attribute].fetch(:mount_on, attribute)
16
16
  if record.class.where(column => record.send(attribute).filename).exists?
17
17
  record.errors.add(attribute, :carrierwave_direct_filename_taken)
@@ -22,7 +22,7 @@ module CarrierWaveDirect
22
22
 
23
23
  class FilenameFormatValidator < ::ActiveModel::EachValidator
24
24
  def validate_each(record, attribute, value)
25
- if record.new_record? && record.send("has_#{attribute}_upload?") && record.key !~ record.send(attribute).key_regexp
25
+ if record.send("has_#{attribute}_upload?") && record.key !~ record.send(attribute).key_regexp
26
26
  extensions = record.send(attribute).extension_white_list
27
27
  message = I18n.t("errors.messages.carrierwave_direct_filename_invalid")
28
28
 
@@ -37,7 +37,7 @@ module CarrierWaveDirect
37
37
 
38
38
  class RemoteNetUrlFormatValidator < ::ActiveModel::EachValidator
39
39
  def validate_each(record, attribute, value)
40
- if record.new_record? && record.send("has_remote_#{attribute}_net_url?")
40
+ if record.send("has_remote_#{attribute}_net_url?")
41
41
  remote_net_url = record.send("remote_#{attribute}_net_url")
42
42
  uploader = record.send(attribute)
43
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.14"
4
+ VERSION = "0.0.15"
5
5
  end
6
6
 
@@ -5,6 +5,7 @@ SAMPLE_DATA = {
5
5
  :key => "some key",
6
6
  :guid => "guid",
7
7
  :store_dir => "store_dir",
8
+ :cache_dir => "cache_dir",
8
9
  :extension_regexp => "(avi)",
9
10
  :url => "http://example.com/some_url",
10
11
  :expiration => 60,
@@ -154,7 +154,7 @@ describe CarrierWaveDirect::ActiveRecord do
154
154
 
155
155
  describe ".validates_filename_uniqueness_of" do
156
156
  it "should be turned on by default" do
157
- party_class.should_receive(:validates_filename_uniqueness_of).with(:video)
157
+ party_class.should_receive(:validates_filename_uniqueness_of).with(:video, on: :create)
158
158
  mount_uploader
159
159
  end
160
160
 
@@ -205,7 +205,7 @@ describe CarrierWaveDirect::ActiveRecord do
205
205
 
206
206
  describe ".validates_filename_format_of" do
207
207
  it "should be turned on by default" do
208
- party_class.should_receive(:validates_filename_format_of).with(:video)
208
+ party_class.should_receive(:validates_filename_format_of).with(:video, on: :create)
209
209
  mount_uploader
210
210
  end
211
211
 
@@ -282,7 +282,7 @@ describe CarrierWaveDirect::ActiveRecord do
282
282
 
283
283
  describe ".validates_remote_net_url_format_of" do
284
284
  it "should be turned on by default" do
285
- party_class.should_receive(:validates_remote_net_url_format_of).with(:video)
285
+ party_class.should_receive(:validates_remote_net_url_format_of).with(:video, on: :create)
286
286
  mount_uploader
287
287
  end
288
288
 
@@ -545,7 +545,7 @@ describe CarrierWaveDirect::ActiveRecord do
545
545
 
546
546
  context "does not have an upload" do
547
547
  it "should be true" do
548
- subject.filename_valid?.should be_true
548
+ subject.filename_valid?.should be true
549
549
  end
550
550
 
551
551
  it_should_behave_like "having empty errors"
@@ -558,7 +558,7 @@ describe CarrierWaveDirect::ActiveRecord do
558
558
  end
559
559
 
560
560
  it "should be true" do
561
- subject.filename_valid?.should be_true
561
+ subject.filename_valid?.should be true
562
562
  end
563
563
 
564
564
  it_should_behave_like "having empty errors"
@@ -568,7 +568,7 @@ describe CarrierWaveDirect::ActiveRecord do
568
568
  before { subject.key = sample_key(:model_class => subject.class, :valid => false) }
569
569
 
570
570
  it "should be false" do
571
- subject.filename_valid?.should be_false
571
+ subject.filename_valid?.should be false
572
572
  end
573
573
 
574
574
  context "after the call, #errors" do
@@ -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,19 +12,19 @@ describe CarrierWaveDirect::Uploader::Configuration do
12
12
 
13
13
  describe "default configuration" do
14
14
  it "returns false for validate_is_attached" do
15
- expect(subject.validate_is_attached).to be_false
15
+ expect(subject.validate_is_attached).to be false
16
16
  end
17
17
 
18
18
  it "returns false for validate_is_uploaded" do
19
- expect(subject.validate_is_uploaded).to be_false
19
+ expect(subject.validate_is_uploaded).to be false
20
20
  end
21
21
 
22
22
  it "return true for validate_unique_filename" do
23
- expect(subject.validate_unique_filename).to be_true
23
+ expect(subject.validate_unique_filename).to be true
24
24
  end
25
25
 
26
26
  it "returns true for validate_remote_net_url_format" do
27
- expect(subject.validate_remote_net_url_format).to be_true
27
+ expect(subject.validate_remote_net_url_format).to be true
28
28
  end
29
29
 
30
30
  it "has upload_expiration of 10 hours" do
@@ -40,7 +40,7 @@ describe CarrierWaveDirect::Uploader::Configuration do
40
40
  end
41
41
 
42
42
  it "returns false for use_action_status" do
43
- expect(subject.use_action_status).to be_false
43
+ expect(subject.use_action_status).to be false
44
44
  end
45
45
  end
46
46
  end
@@ -15,38 +15,9 @@ describe CarrierWaveDirect::Uploader::DirectUrl do
15
15
  end
16
16
 
17
17
  context ":with_path => true" do
18
-
19
- context "#key is set to '#{sample(:path_with_special_chars)}'" do
20
- before { subject.key = sample(:path_with_special_chars) }
21
-
22
- it "should return the full url with '/#{URI.escape(sample(:path_with_special_chars))}' as the path" do
23
- direct_fog_url = CarrierWave::Storage::Fog::File.new(
24
- subject, nil, nil
25
- ).public_url
26
- expect(subject.direct_fog_url(:with_path => true)).to eq direct_fog_url + "#{URI.escape(sample(:path_with_special_chars))}"
27
- end
28
- end
29
-
30
- context "#key is set to '#{sample(:path_with_escaped_chars)}'" do
31
- before { subject.key = sample(:path_with_escaped_chars) }
32
-
33
- it "should return the full url with '/#{sample(:path_with_escaped_chars)}' as the path" do
34
- direct_fog_url = CarrierWave::Storage::Fog::File.new(
35
- subject, nil, nil
36
- ).public_url
37
- expect(subject.direct_fog_url(:with_path => true)).to eq direct_fog_url + sample(:path_with_escaped_chars)
38
- end
39
- end
40
-
41
- context "#key is set to '#{sample(:path)}'" do
42
- before { subject.key = sample(:path) }
43
-
44
- it "should return the full url with '/#{sample(:path)}' as the path" do
45
- direct_fog_url = CarrierWave::Storage::Fog::File.new(
46
- subject, nil, nil
47
- ).public_url
48
- expect(subject.direct_fog_url(:with_path => true)).to eq direct_fog_url + "#{sample(:path)}"
49
- end
18
+ it "should return the full url set by carrierwave" do
19
+ allow(subject).to receive(:url).and_return("url")
20
+ expect(subject.direct_fog_url(:with_path => true)).to eq "url"
50
21
  end
51
22
  end
52
23
  end
@@ -111,6 +111,7 @@ describe CarrierWaveDirect::Uploader do
111
111
  context "where #store_dir returns '#{sample(:store_dir)}'" do
112
112
  before do
113
113
  allow(subject).to receive(:store_dir).and_return(sample(:store_dir))
114
+ allow(subject).to receive(:cache_dir).and_return(sample(:cache_dir))
114
115
  end
115
116
 
116
117
  context "and #extension_regexp returns '#{sample(:extension_regexp)}'" do
@@ -118,8 +119,8 @@ describe CarrierWaveDirect::Uploader do
118
119
  allow(subject).to receive(:extension_regexp).and_return(sample(:extension_regexp))
119
120
  end
120
121
 
121
- it "should return /\\A#{sample(:store_dir)}\\/#{GUID_REGEXP}\\/.+\\.#{sample(:extension_regexp)}\\z/" do
122
- expect(subject.key_regexp).to eq /\A#{sample(:store_dir)}\/#{GUID_REGEXP}\/.+\.(?i)#{sample(:extension_regexp)}(?-i)\z/
122
+ it "should return /\\A(#{sample(:store_dir)}|#{sample(:cache_dir)})\\/#{GUID_REGEXP}\\/.+\\.#{sample(:extension_regexp)}\\z/" do
123
+ expect(subject.key_regexp).to eq /\A(#{sample(:store_dir)}|#{sample(:cache_dir)})\/#{GUID_REGEXP}\/.+\.(?i)#{sample(:extension_regexp)}(?-i)\z/
123
124
  end
124
125
  end
125
126
  end
@@ -239,28 +240,16 @@ describe CarrierWaveDirect::Uploader do
239
240
  end
240
241
  end
241
242
 
242
- context "and the model's remote #{sample(:mounted_as)} url has whitespace in it" do
243
+ context "and the model's remote #{sample(:mounted_as)} url has special characters in it" do
243
244
  before do
244
245
  allow(mounted_model).to receive(
245
246
  "remote_#{mounted_subject.mounted_as}_url"
246
- ).and_return("http://anyurl.com/any_path/video_dir/filename 2.avi")
247
+ ).and_return("http://anyurl.com/any_path/video_dir/filename ()+[]2.avi")
247
248
  end
248
249
 
249
- it "should be sanitized (whitespace replaced with _)" do
250
+ it "should be sanitized (special characters replaced with _)" do
250
251
  mounted_subject.filename
251
- expect(mounted_subject.key).to match /filename_2.avi$/
252
- end
253
- end
254
-
255
- context "and the model's remote url contains escape characters" do
256
- before do
257
- subject.key = nil
258
- allow(subject).to receive(:present?).and_return(:true)
259
- allow(subject).to receive(:url).and_return("http://anyurl.com/any_path/video_dir/filename ()+[]2.avi")
260
- end
261
-
262
- it "should be escaped and replaced with non whitespace characters" do
263
- expect(subject.key).to match /filename%20%28%29%2B%5B%5D2.avi/
252
+ expect(mounted_subject.key).to match /filename___\+__2.avi$/
264
253
  end
265
254
  end
266
255
 
@@ -272,7 +261,7 @@ describe CarrierWaveDirect::Uploader do
272
261
  end
273
262
 
274
263
  it "should not double escape already escaped characters" do
275
- expect(subject.key).to match /filename%20%28%29%2B%5B%5D2.avi/
264
+ expect(subject.key).to match /filename \(\)\+\[\]2.avi/
276
265
  end
277
266
 
278
267
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave_direct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Wilkie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-24 00:00:00.000000000 Z
11
+ date: 2015-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -137,6 +137,9 @@ files:
137
137
  - README.md
138
138
  - Rakefile
139
139
  - carrierwave_direct.gemspec
140
+ - gemfiles/3.2.gemfile
141
+ - gemfiles/4.0.gemfile
142
+ - gemfiles/4.1.gemfile
140
143
  - lib/carrierwave_direct.rb
141
144
  - lib/carrierwave_direct/action_view_extensions/form_helper.rb
142
145
  - lib/carrierwave_direct/form_builder.rb