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 +4 -4
- data/VERSION +1 -1
- data/file_blobs_rails.gemspec +2 -2
- data/lib/file_blobs_rails/active_record_extensions.rb +13 -2
- data/test/file_blob_proxy_test.rb +23 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40111b879c3c7a2326df1c2780caa3735f3df649
|
4
|
+
data.tar.gz: 1400f0be44fa14a790097dfe459ccd81acc14a43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0876c5d2c137f48c0e95c685dbeea64bb99f5ebe6152b858f58c7b1c6ee20068e4899c033f4f6b082b0e4da0558a74164f637d35864ef156c29892786747572
|
7
|
+
data.tar.gz: 2503663b792555eaa2a76d26c4fdbf40c6f56f9c713b1973157595ba25d41c88121be5c15af6e7db6ab02c8040d26fb5fc36b573740d3498272d0ce96b6b1ad6
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/file_blobs_rails.gemspec
CHANGED
@@ -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.
|
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.
|
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
|
-
|
174
|
-
|
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
|