carrierwave-base64 1.3 → 1.4

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: f6b7f164c614c501edd82cdc4f902e3cbf830a67
4
- data.tar.gz: 6330e788f837fdf14cac8f330f3c2403a3b9ebea
3
+ metadata.gz: b81321c57f7f1474d1fa455b97329989f4484d5d
4
+ data.tar.gz: 2d0f412d61b8fe5f22801a89263ea618f68794f1
5
5
  SHA512:
6
- metadata.gz: 13b57035d23637c2baa0fcd87a5cb47d9bdb5849e5550c046ce768370dbcaa3c1bdf75dd7b49aced83dbb4438e3f0c970798cbe6a9a5dc3970597b8b6033d93e
7
- data.tar.gz: 24efd2af689ccab46857d7047ab252ab2ec2f06aee343ff825bebb15b2da4120f1a39a6366f2c3701db63239c3fef5578ea52e1b83299f46aa7486fd4094a99c
6
+ metadata.gz: 3117dcaef41677818a683f1f46fce1607e0dbe8081e37ea630a20b65acbb699663e3e332a0d9370c546c8dffc5cb305900d6fa642e548fa73235dc4ccf0ec855
7
+ data.tar.gz: 2fd4303a312208ce26434e2abca58be7d0d6085411c21881c4a3b7f11f0fc4e171c61e2fb45baa3ac03875d011e50467cd1d8e584dd1592348f478f88b66a2cf
@@ -3,27 +3,27 @@ module Carrierwave
3
3
  class Base64StringIO < StringIO
4
4
  class ArgumentError < StandardError; end
5
5
 
6
- attr_accessor :image_format
6
+ attr_accessor :file_format
7
7
 
8
- def initialize(encoded_image)
9
- description, encoded_bytes = encoded_image.split(",")
8
+ def initialize(encoded_file)
9
+ description, encoded_bytes = encoded_file.split(",")
10
10
 
11
11
  raise ArgumentError unless encoded_bytes
12
12
 
13
- @image_format = get_image_format description
13
+ @file_format = get_file_format description
14
14
  bytes = ::Base64.decode64 encoded_bytes
15
15
 
16
16
  super bytes
17
17
  end
18
18
 
19
19
  def original_filename
20
- File.basename("image.#{@image_format}")
20
+ File.basename("file.#{@file_format}")
21
21
  end
22
22
 
23
23
  private
24
24
 
25
- def get_image_format(description)
26
- regex = /\Adata:image\/([a-z]+);base64\z/i
25
+ def get_file_format(description)
26
+ regex = /([a-z]+);base64\z/
27
27
  regex.match(description).try(:[], 1)
28
28
  end
29
29
  end
@@ -7,7 +7,7 @@ module Carrierwave
7
7
  mount_uploader attribute, uploader_class
8
8
 
9
9
  define_method "#{attribute}=" do |data|
10
- if data.present? && data.is_a?(String) && data.strip.start_with?("data:image")
10
+ if data.present? && data.is_a?(String) && data.strip.start_with?("data")
11
11
  super(Carrierwave::Base64::Base64StringIO.new(data.strip))
12
12
  else
13
13
  super(data)
@@ -1,5 +1,5 @@
1
1
  module Carrierwave
2
2
  module Base64
3
- VERSION = "1.3"
3
+ VERSION = "1.4"
4
4
  end
5
5
  end
@@ -6,11 +6,24 @@ RSpec.describe Carrierwave::Base64::Base64StringIO do
6
6
  subject { described_class.new image_data }
7
7
 
8
8
  it "determines the image format from the Dara URI scheme" do
9
- expect(subject.image_format).to eql("jpg")
9
+ expect(subject.file_format).to eql("jpg")
10
10
  end
11
11
 
12
12
  it "should respond to :original_filename" do
13
- expect(subject.original_filename).to eql("image.jpg")
13
+ expect(subject.original_filename).to eql("file.jpg")
14
+ end
15
+ end
16
+
17
+ context "correct pdf data" do
18
+ let(:image_data) { "data:application/pdf;base64,/9j/4AAQSkZJRgABAQEASABKdhH//2Q==" }
19
+ subject { described_class.new image_data }
20
+
21
+ it "determines the image format from the Dara URI scheme" do
22
+ expect(subject.file_format).to eql("pdf")
23
+ end
24
+
25
+ it "should respond to :original_filename" do
26
+ expect(subject.original_filename).to eql("file.pdf")
14
27
  end
15
28
  end
16
29
 
@@ -28,7 +28,7 @@ RSpec.describe Carrierwave::Base64::ActiveRecord do
28
28
  subject.image = File.read(file_path("fixtures", "base64_image.fixture")).strip
29
29
  subject.save!
30
30
  subject.reload
31
- expect(subject.image.current_path).to eq file_path("../uploads", "image.jpg")
31
+ expect(subject.image.current_path).to eq file_path("../uploads", "file.jpg")
32
32
  end
33
33
  end
34
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-base64
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.3'
4
+ version: '1.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yury Lebedev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-26 00:00:00.000000000 Z
11
+ date: 2015-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave