file_blobs_rails 0.2.0 → 0.2.1

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: fc1739959bccd1657b2283239b10875b92ded4c2
4
- data.tar.gz: fda8865e07e1a00d7141b956dbf9e8fa19d53df4
3
+ metadata.gz: 40111b879c3c7a2326df1c2780caa3735f3df649
4
+ data.tar.gz: 1400f0be44fa14a790097dfe459ccd81acc14a43
5
5
  SHA512:
6
- metadata.gz: c53f96a7ec4701ffc194850ef355a5b8830a51742e184833e91427d49370836c2200b45685b361dc6bd92161af47cc5c5a400233f54807441c3c568d6ccc783b
7
- data.tar.gz: 1de57330fe64125016df4aa73a9c849b6cb38a0bfbb47de6b05c73d2e84d71dec7f42dc1814f56eab715ae7bcd71a9f81a390f9a4f43d487b7a1f9aee77a4ec2
6
+ metadata.gz: f0876c5d2c137f48c0e95c685dbeea64bb99f5ebe6152b858f58c7b1c6ee20068e4899c033f4f6b082b0e4da0558a74164f637d35864ef156c29892786747572
7
+ data.tar.gz: 2503663b792555eaa2a76d26c4fdbf40c6f56f9c713b1973157595ba25d41c88121be5c15af6e7db6ab02c8040d26fb5fc36b573740d3498272d0ce96b6b1ad6
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: file_blobs_rails 0.2.0 ruby lib
5
+ # stub: file_blobs_rails 0.2.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "file_blobs_rails"
9
- s.version = "0.2.0"
9
+ s.version = "0.2.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -158,6 +158,13 @@ module ActiveRecordExtensions::ClassMethods
158
158
  # Slow path: we need to copy data across blob tables.
159
159
  self.#{attribute_name}_data = new_file.data
160
160
  end
161
+ elsif new_file.nil?
162
+ # Reset everything to nil.
163
+ self.#{attribute_name}_mime_type = nil
164
+ self.#{attribute_name}_original_name = nil
165
+ self.#{attribute_name}_data = nil
166
+ else
167
+ raise ArgumentError, "Invalid file_blob value: \#{new_file.inspect}"
161
168
  end
162
169
  end
163
170
 
@@ -170,8 +177,12 @@ module ActiveRecordExtensions::ClassMethods
170
177
  # that the large FileBlob doesn't hang off of the object
171
178
  # referencing it; this way, the blob's data can be
172
179
  # garbage-collected by the Ruby VM as early as possible
173
- blob = #{blob_model}.where(id: #{attribute_name}_blob_id).first!
174
- blob.data
180
+ if blob_id = #{attribute_name}_blob_id
181
+ blob = #{blob_model}.where(id: blob_id).first!
182
+ blob.data
183
+ else
184
+ nil
185
+ end
175
186
  end
176
187
 
177
188
  # Convenience setter for the file's content.
@@ -97,4 +97,27 @@ class FileBlobProxyTest < ActiveSupport::TestCase
97
97
  @message.attachment_blob.data
98
98
  assert_equal true, @message.attachment_blob.new_record?
99
99
  end
100
+
101
+ test 'proxy setter on the owner model with nil' do
102
+ @blob_owner.file = nil
103
+
104
+ assert_equal nil, @blob_owner.file_original_name
105
+ assert_equal nil, @blob_owner.file_blob_id
106
+ assert_equal nil, @blob_owner.file_size
107
+ assert_equal nil, @blob_owner.file_data
108
+ assert_equal nil, @blob_owner.file_blob
109
+ end
110
+
111
+ test 'proxy setter on the owner model with an invalid value' do
112
+ exception = assert_raise ArgumentError do
113
+ @blob_owner.file = [4, 2]
114
+ end
115
+ assert_equal 'Invalid file_blob value: [4, 2]', exception.message
116
+
117
+ assert_equal 'ruby.png', @blob_owner.file_original_name
118
+ assert_equal file_blob_id('files/ruby.png'), @blob_owner.file_blob_id
119
+ assert_equal file_blob_size('files/ruby.png'), @blob_owner.file_size
120
+ assert_equal file_blob_data('files/ruby.png'), @blob_owner.file_data
121
+ assert_equal file_blobs(:ruby_png), @blob_owner.file_blob
122
+ end
100
123
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_blobs_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Costan