jnunemaker-grip 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -7,3 +7,4 @@ tmp/**/*
7
7
  config/database.yml
8
8
  coverage/*
9
9
  coverage/**/*
10
+ pkg
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jnunemaker-grip}
8
- s.version = "0.1"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Nunemaker"]
@@ -22,8 +22,12 @@ module Grip
22
22
  define_method("#{name}=") do |file|
23
23
  self["#{name}_id"] = Mongo::ObjectID.new
24
24
  self["#{name}_size"] = File.size(file)
25
- self["#{name}_name"] = File.basename(file.path)
26
25
  self["#{name}_type"] = Wand.wave(file.path)
26
+ self["#{name}_name"] = if file.respond_to?(:original_filename)
27
+ file.original_filename
28
+ else
29
+ File.basename(file.path)
30
+ end
27
31
  self.class.attachment_definitions[name] = file
28
32
  end
29
33
  end
@@ -1,3 +1,3 @@
1
1
  module Grip
2
- Version = '0.1'
2
+ Version = '0.1.1'
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'test/unit'
2
+ require 'tempfile'
2
3
  require 'pp'
3
4
 
4
5
  require 'mongo_mapper'
@@ -32,9 +32,6 @@ class GripTest < Test::Unit::TestCase
32
32
  assert_equal 27582, @doc.image_size
33
33
  assert_equal 8775, @doc.pdf_size
34
34
 
35
- assert_equal 'cthulhu.png', @doc.image_name
36
- assert_equal 'sample.pdf', @doc.pdf_name
37
-
38
35
  assert_equal "image/png", @doc.image_type
39
36
  assert_equal "application/pdf", @doc.pdf_type
40
37
 
@@ -47,6 +44,25 @@ class GripTest < Test::Unit::TestCase
47
44
  assert_equal "application/pdf", @grid.get(@doc.pdf_id).content_type
48
45
  end
49
46
 
47
+ test "assigns file name from path if original file name not available" do
48
+ assert_equal 'cthulhu.png', @doc.image_name
49
+ assert_equal 'sample.pdf', @doc.pdf_name
50
+ end
51
+
52
+ test "assigns file name from original filename if available" do
53
+ begin
54
+ file = Tempfile.new('testing.txt')
55
+ def file.original_filename
56
+ 'testing.txt'
57
+ end
58
+
59
+ doc = Foo.create(:image => file)
60
+ assert_equal 'testing.txt', doc.image_name
61
+ ensure
62
+ file.close
63
+ end
64
+ end
65
+
50
66
  test "responds to keys" do
51
67
  [ :pdf_size, :pdf_id, :pdf_name, :pdf_type,
52
68
  :image_size, :image_id, :image_name, :image_type
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jnunemaker-grip
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.1"
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker