grip 0.6.12 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.12
1
+ 0.7.2
data/grip.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{grip}
8
- s.version = "0.6.12"
8
+ s.version = "0.7.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["twoism", "jnunemaker"]
12
- s.date = %q{2010-01-31}
12
+ s.date = %q{2010-02-17}
13
13
  s.description = %q{GridFS attachments for MongoMapper}
14
14
  s.email = %q{signalstatic@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -23,11 +23,12 @@ module Grip
23
23
  before_destroy :destroy_file
24
24
 
25
25
  def file=new_file
26
+ return if new_file.nil? || (new_file.is_a?(String) && new_file.blank?)
26
27
  raise InvalidFile unless (new_file.is_a?(File) || new_file.is_a?(Tempfile))
27
28
 
28
29
  self.file_name = new_file.is_a?(Tempfile) ? new_file.original_filename : File.basename(new_file.path)
29
30
  self.file_size = File.size(new_file.path)
30
- self.content_type = MIME::Types.type_for(new_file.path)
31
+ self.content_type = MIME::Types.type_for(self.file_name)
31
32
 
32
33
  write_to_grid self, new_file
33
34
  end
@@ -60,7 +61,7 @@ module Grip
60
61
  new_attachment.owner_type = self.class.to_s
61
62
  new_attachment.file_name = File.basename(file_hash[:uploaded_file].path)
62
63
  new_attachment.file_size = File.size(file_hash[:resized_file].path)
63
- new_attachment.content_type = MIME::Types.type_for(file_hash[:uploaded_file].path)[0].content_type
64
+ new_attachment.content_type = MIME::Types.type_for(new_attachment.file_name)
64
65
  new_attachment.save!
65
66
 
66
67
  write_to_grid new_attachment, file_hash[:resized_file]
@@ -73,6 +74,10 @@ module Grip
73
74
  GridFS::GridStore.unlink(self.class.database, grid_key)
74
75
  end
75
76
 
77
+ def has_file?
78
+ !self.file_name.nil?
79
+ end
80
+
76
81
  def write_to_grid attachment, new_file
77
82
  GridFS::GridStore.open(self.class.database, attachment.grid_key, 'w', :content_type => attachment.content_type) do |f|
78
83
  f.write new_file.read
@@ -80,6 +85,7 @@ module Grip
80
85
  end
81
86
 
82
87
  def read_from_grid key
88
+ return nil unless has_file?
83
89
  GridFS::GridStore.new(self.class.database, key, 'r')
84
90
  end
85
91
  end
@@ -25,6 +25,7 @@ module Grip
25
25
  end
26
26
 
27
27
  define_method("#{name}=") do |new_file|
28
+ return if new_file.nil? || (new_file.is_a?(String) && new_file.blank?)
28
29
  raise InvalidFile unless (new_file.is_a?(File) || new_file.is_a?(Tempfile))
29
30
  uploaded_files[name] ||= {}
30
31
  uploaded_files[name][:file] = new_file
@@ -2,7 +2,7 @@ require "test_helper"
2
2
 
3
3
  include Grip
4
4
 
5
- class GripAttachmentTest < Test::Unit::TestCase
5
+ class TestAttachment < Test::Unit::TestCase
6
6
  context "An Attachment" do
7
7
  setup do
8
8
  @attachment = Attachment.new( :name => "image", :owner_type => "Mock", :owner_id => Mongo::ObjectID.new )
@@ -59,6 +59,15 @@ class GripAttachmentTest < Test::Unit::TestCase
59
59
  end
60
60
  end
61
61
 
62
+ context "with an empty string or nil" do
63
+
64
+ should "set image to nil" do
65
+ @attachment.file = ""
66
+ assert_nil @attachment.file
67
+ end
68
+
69
+ end
70
+
62
71
  end
63
72
 
64
73
  end
@@ -30,6 +30,11 @@ class HasAttachmentTest < Test::Unit::TestCase
30
30
  assert_equal(1, Doc.after_save.collect(&:method).count)
31
31
  end
32
32
 
33
+ should "set to nill with an empty string or nil" do
34
+ @document.image = ""
35
+ assert_nil @document.image
36
+ end
37
+
33
38
  context "when assigned a file" do
34
39
  setup do
35
40
  @document.image = @image
data/test/test_helper.rb CHANGED
@@ -7,7 +7,7 @@ require 'factory_girl'
7
7
  require 'factories'
8
8
  require 'RMagick'
9
9
 
10
- TEST_DB = 'test-grip'
10
+ TEST_DB = 'test-grip' unless Object.const_defined?("TEST_DB")
11
11
 
12
12
  MongoMapper.database = TEST_DB
13
13
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.12
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - twoism
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-31 00:00:00 -05:00
13
+ date: 2010-02-17 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency