grip 0.6.7 → 0.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Rakefile +25 -21
- data/VERSION +1 -1
- data/grip.gemspec +16 -9
- data/lib/grip.rb +18 -4
- data/lib/grip/attachment.rb +54 -54
- data/lib/grip/has_attachment.rb +57 -56
- data/test/factories.rb +1 -1
- data/test/grip_attachment_test.rb +12 -12
- data/test/has_attachment_test.rb +20 -15
- data/test/models.rb +1 -1
- data/test/test_helper.rb +7 -6
- metadata +33 -5
- data/test/growler.rb +0 -9
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -2,27 +2,31 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'rake/testtask'
|
4
4
|
require 'rake/rdoctask'
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
5
|
+
require 'jeweler'
|
6
|
+
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = 'grip'
|
9
|
+
gem.summary = %(GridFS attachments for MongoMapper)
|
10
|
+
gem.description = %(GridFS attachments for MongoMapper)
|
11
|
+
gem.email = 'signalstatic@gmail.com'
|
12
|
+
gem.homepage = 'http://github.com/twoism/grip'
|
13
|
+
gem.authors = %w(twoism jnunemaker)
|
14
|
+
|
15
|
+
gem.add_dependency('mongo_mapper', '>= 0.6.10')
|
16
|
+
gem.add_dependency('rmagick', '>= 2.12.2')
|
17
|
+
gem.add_dependency('miso', '>= 0.3.1')
|
18
|
+
|
19
|
+
gem.add_development_dependency('factory_girl', '1.2.3')
|
20
|
+
gem.add_development_dependency('shoulda', '2.10.2')
|
21
21
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
|
23
|
+
Jeweler::GemcutterTasks.new
|
24
|
+
|
25
|
+
Rake::TestTask.new do |test|
|
26
|
+
test.libs << 'test'
|
27
|
+
test.ruby_opts << '-rubygems'
|
28
|
+
test.pattern = 'test/**/*_test.rb'
|
29
|
+
test.verbose = true
|
26
30
|
end
|
27
|
-
|
31
|
+
|
28
32
|
task :default => :test
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.8
|
data/grip.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{grip}
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.8"
|
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"]
|
@@ -31,7 +31,6 @@ Gem::Specification.new do |s|
|
|
31
31
|
"test/fixtures/fennec-fox.jpg",
|
32
32
|
"test/fixtures/sample.pdf",
|
33
33
|
"test/grip_attachment_test.rb",
|
34
|
-
"test/growler.rb",
|
35
34
|
"test/has_attachment_test.rb",
|
36
35
|
"test/models.rb",
|
37
36
|
"test/test_helper.rb"
|
@@ -44,7 +43,6 @@ Gem::Specification.new do |s|
|
|
44
43
|
s.test_files = [
|
45
44
|
"test/factories.rb",
|
46
45
|
"test/grip_attachment_test.rb",
|
47
|
-
"test/growler.rb",
|
48
46
|
"test/has_attachment_test.rb",
|
49
47
|
"test/models.rb",
|
50
48
|
"test/test_helper.rb"
|
@@ -55,15 +53,24 @@ Gem::Specification.new do |s|
|
|
55
53
|
s.specification_version = 3
|
56
54
|
|
57
55
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
58
|
-
s.add_runtime_dependency(%q<
|
59
|
-
s.add_runtime_dependency(%q<
|
56
|
+
s.add_runtime_dependency(%q<mongo_mapper>, [">= 0.6.10"])
|
57
|
+
s.add_runtime_dependency(%q<rmagick>, [">= 2.12.2"])
|
58
|
+
s.add_runtime_dependency(%q<miso>, [">= 0.3.1"])
|
59
|
+
s.add_development_dependency(%q<factory_girl>, ["= 1.2.3"])
|
60
|
+
s.add_development_dependency(%q<shoulda>, ["= 2.10.2"])
|
60
61
|
else
|
61
|
-
s.add_dependency(%q<
|
62
|
-
s.add_dependency(%q<
|
62
|
+
s.add_dependency(%q<mongo_mapper>, [">= 0.6.10"])
|
63
|
+
s.add_dependency(%q<rmagick>, [">= 2.12.2"])
|
64
|
+
s.add_dependency(%q<miso>, [">= 0.3.1"])
|
65
|
+
s.add_dependency(%q<factory_girl>, ["= 1.2.3"])
|
66
|
+
s.add_dependency(%q<shoulda>, ["= 2.10.2"])
|
63
67
|
end
|
64
68
|
else
|
65
|
-
s.add_dependency(%q<
|
66
|
-
s.add_dependency(%q<
|
69
|
+
s.add_dependency(%q<mongo_mapper>, [">= 0.6.10"])
|
70
|
+
s.add_dependency(%q<rmagick>, [">= 2.12.2"])
|
71
|
+
s.add_dependency(%q<miso>, [">= 0.3.1"])
|
72
|
+
s.add_dependency(%q<factory_girl>, ["= 1.2.3"])
|
73
|
+
s.add_dependency(%q<shoulda>, ["= 2.10.2"])
|
67
74
|
end
|
68
75
|
end
|
69
76
|
|
data/lib/grip.rb
CHANGED
@@ -1,8 +1,22 @@
|
|
1
|
-
|
1
|
+
if RUBY_VERSION =~ /1.9.[0-9]/
|
2
|
+
require 'fileutils'
|
3
|
+
else
|
4
|
+
require 'ftools'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'mongo_mapper'
|
8
|
+
require 'mongo/gridfs'
|
9
|
+
require 'mime/types'
|
10
|
+
require 'tempfile'
|
11
|
+
require 'RMagick'
|
12
|
+
require 'miso'
|
2
13
|
|
3
14
|
module Grip
|
4
|
-
class GripError < StandardError;
|
5
|
-
|
15
|
+
class GripError < StandardError;
|
16
|
+
end
|
17
|
+
class InvalidFile < GripError;
|
18
|
+
end
|
6
19
|
end
|
7
20
|
|
8
|
-
|
21
|
+
require 'grip/attachment'
|
22
|
+
require 'grip/has_attachment'
|
data/lib/grip/attachment.rb
CHANGED
@@ -2,85 +2,85 @@ module Grip
|
|
2
2
|
class Attachment
|
3
3
|
include MongoMapper::Document
|
4
4
|
|
5
|
-
belongs_to :owner,
|
5
|
+
belongs_to :owner,
|
6
6
|
:polymorphic => true
|
7
|
-
|
8
|
-
many :attached_variants,
|
9
|
-
:as => :owner,
|
10
|
-
:class_name => "Grip::Attachment",
|
7
|
+
|
8
|
+
many :attached_variants,
|
9
|
+
:as => :owner,
|
10
|
+
:class_name => "Grip::Attachment",
|
11
11
|
:dependent => :destroy
|
12
|
-
|
13
|
-
key :owner_id,
|
14
|
-
key :owner_type,
|
15
|
-
|
16
|
-
key :name,
|
17
|
-
key :file_name,
|
18
|
-
key :file_size,
|
19
|
-
key :content_type,
|
20
|
-
key :variants,
|
21
|
-
|
12
|
+
|
13
|
+
key :owner_id, ObjectId, :required => true
|
14
|
+
key :owner_type, String, :required => true
|
15
|
+
|
16
|
+
key :name, String
|
17
|
+
key :file_name, String
|
18
|
+
key :file_size, Integer
|
19
|
+
key :content_type, String
|
20
|
+
key :variants, Hash
|
21
|
+
|
22
22
|
after_save :build_variants
|
23
23
|
before_destroy :destroy_file
|
24
|
-
|
24
|
+
|
25
25
|
def file=new_file
|
26
26
|
raise InvalidFile unless (new_file.is_a?(File) || new_file.is_a?(Tempfile))
|
27
|
-
|
27
|
+
|
28
28
|
self.file_name = new_file.is_a?(Tempfile) ? new_file.original_filename : File.basename(new_file.path)
|
29
29
|
self.file_size = File.size(new_file.path)
|
30
30
|
self.content_type = MIME::Types.type_for(new_file.path)
|
31
|
-
|
32
|
-
write_to_grid self,new_file
|
31
|
+
|
32
|
+
write_to_grid self, new_file
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def file
|
36
36
|
read_from_grid grid_key
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def grid_key
|
40
40
|
"#{owner_type.pluralize}/#{owner_id}/#{name}".downcase
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def self.create_method method_name, &block
|
44
44
|
define_method(method_name) do |*args|
|
45
45
|
yield *args
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
private
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
self.class.create_method "#{variant}=".to_sym do |file_hash|
|
58
|
-
|
59
|
-
new_attachment = Attachment.find_or_initialize_by_name_and_owner_id("#{variant.to_s}",self._id)
|
60
|
-
new_attachment.owner_type = self.class.to_s
|
61
|
-
new_attachment.file_name = File.basename(file_hash[:uploaded_file].path)
|
62
|
-
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)
|
64
|
-
new_attachment.save!
|
65
|
-
|
66
|
-
write_to_grid new_attachment, file_hash[:resized_file]
|
67
|
-
end
|
68
|
-
|
50
|
+
def build_variants
|
51
|
+
self.variants.each do |variant, dimensions|
|
52
|
+
|
53
|
+
self.class.create_method variant.to_sym do
|
54
|
+
attached_variants.find_or_create_by_name("#{variant.to_s}")
|
69
55
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
56
|
+
|
57
|
+
self.class.create_method "#{variant}=".to_sym do |file_hash|
|
58
|
+
|
59
|
+
new_attachment = Attachment.find_or_initialize_by_name_and_owner_id("#{variant.to_s}", self._id)
|
60
|
+
new_attachment.owner_type = self.class.to_s
|
61
|
+
new_attachment.file_name = File.basename(file_hash[:uploaded_file].path)
|
62
|
+
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.save!
|
65
|
+
|
66
|
+
write_to_grid new_attachment, file_hash[:resized_file]
|
79
67
|
end
|
68
|
+
|
80
69
|
end
|
81
|
-
|
82
|
-
|
83
|
-
|
70
|
+
end
|
71
|
+
|
72
|
+
def destroy_file
|
73
|
+
GridFS::GridStore.unlink(self.class.database, grid_key)
|
74
|
+
end
|
75
|
+
|
76
|
+
def write_to_grid attachment, new_file
|
77
|
+
GridFS::GridStore.open(self.class.database, attachment.grid_key, 'w', :content_type => attachment.content_type) do |f|
|
78
|
+
f.write new_file.read
|
84
79
|
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def read_from_grid key
|
83
|
+
GridFS::GridStore.new(self.class.database, key, 'r')
|
84
|
+
end
|
85
85
|
end
|
86
86
|
end
|
data/lib/grip/has_attachment.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
module Grip
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
2
|
+
module HasAttachment
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
base.instance_eval do
|
7
|
+
many :attachments,
|
8
|
+
:as => :owner,
|
9
|
+
:class_name => "Grip::Attachment",
|
10
|
+
:dependent => :destroy
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
14
|
module ClassMethods
|
15
|
-
|
15
|
+
|
16
16
|
def has_grid_attachment name, opts={}
|
17
17
|
set_callbacks_once
|
18
|
-
|
18
|
+
|
19
19
|
write_inheritable_attribute(:uploaded_file_options, {}) if uploaded_file_options.nil?
|
20
20
|
uploaded_file_options[name] = opts
|
21
21
|
self.send(:include, InstanceMethods)
|
22
|
-
|
22
|
+
|
23
23
|
define_method(name) do
|
24
24
|
attachments.find(:first, :conditions=>{:name => name.to_s})
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
define_method("#{name}=") do |new_file|
|
28
28
|
raise InvalidFile unless (new_file.is_a?(File) || new_file.is_a?(Tempfile))
|
29
29
|
uploaded_files[name] ||= {}
|
@@ -32,62 +32,63 @@ module Grip
|
|
32
32
|
new_attachment = attachments.find_or_create_by_name(name.to_s)
|
33
33
|
update_attachment_attributes!(new_attachment, new_file, opts)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def set_callbacks_once
|
39
39
|
after_save :save_attachments unless after_save.collect(&:method).include?(:save_attachments)
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def uploaded_file_options
|
43
43
|
read_inheritable_attribute(:uploaded_file_options)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
end
|
47
|
-
|
48
|
-
module InstanceMethods
|
49
|
-
def uploaded_files
|
50
|
-
@uploaded_files ||= {}
|
51
|
-
end
|
52
|
-
def update_attachment_attributes! new_attachment, new_file, opts
|
53
|
-
new_attachment.owner_type = self.class.to_s
|
54
|
-
new_attachment.file_name = File.basename(new_file.path)
|
55
|
-
new_attachment.file_size = File.size(new_file.path)
|
56
|
-
new_attachment.content_type = MIME::Types.type_for(new_file.path)
|
57
|
-
new_attachment.file = new_file
|
58
|
-
new_attachment.variants = opts[:variants] || {}
|
59
|
-
new_attachment.save!
|
60
|
-
end
|
61
47
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
48
|
+
module InstanceMethods
|
49
|
+
def uploaded_files
|
50
|
+
@uploaded_files ||= {}
|
51
|
+
end
|
52
|
+
|
53
|
+
def update_attachment_attributes! new_attachment, new_file, opts
|
54
|
+
new_attachment.owner_type = self.class.to_s
|
55
|
+
new_attachment.file_name = File.basename(new_file.path)
|
56
|
+
new_attachment.file_size = File.size(new_file.path)
|
57
|
+
new_attachment.content_type = MIME::Types.type_for(new_file.path)[0].content_type
|
58
|
+
new_attachment.file = new_file
|
59
|
+
new_attachment.variants = opts[:variants] || {}
|
60
|
+
new_attachment.save!
|
61
|
+
end
|
62
|
+
|
63
|
+
def save_attachments
|
64
|
+
attachments.each do |attachment|
|
65
|
+
attachment.variants.each do |variant, dimensions|
|
66
|
+
create_variant(attachment, variant, dimensions)
|
67
67
|
end
|
68
68
|
end
|
69
|
+
end
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
image.crop(dimensions[:width], dimensions[:height]) if dimensions[:crop]
|
77
|
-
image.fit(dimensions[:width], dimensions[:height]) unless dimensions[:crop]
|
71
|
+
def create_variant attachment, variant, dimensions
|
72
|
+
tmp_file = uploaded_files[attachment.name.to_sym][:file]
|
73
|
+
begin
|
74
|
+
tmp = Tempfile.new("#{attachment.name}_#{variant}")
|
75
|
+
image = Miso::Image.new(tmp_file.path)
|
78
76
|
|
79
|
-
|
80
|
-
|
81
|
-
warn "Image was not resized. #{e}"
|
82
|
-
tmp = tmp_file
|
83
|
-
end
|
77
|
+
image.crop(dimensions[:width], dimensions[:height]) if dimensions[:crop]
|
78
|
+
image.fit(dimensions[:width], dimensions[:height]) unless dimensions[:crop]
|
84
79
|
|
85
|
-
|
86
|
-
|
80
|
+
image.write(tmp.path)
|
81
|
+
rescue RuntimeError => e
|
82
|
+
warn "Image was not resized. #{e}"
|
83
|
+
tmp = tmp_file
|
87
84
|
end
|
88
85
|
|
86
|
+
file_hash = {:resized_file => tmp, :uploaded_file => tmp_file}
|
87
|
+
attachment.send("#{variant}=", file_hash)
|
89
88
|
end
|
90
|
-
|
91
|
-
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
|
92
93
|
end
|
93
94
|
end
|
data/test/factories.rb
CHANGED
@@ -10,22 +10,22 @@ class GripAttachmentTest < Test::Unit::TestCase
|
|
10
10
|
@image = File.open("#{@dir}/cthulhu.png", 'r')
|
11
11
|
@file_system = MongoMapper.database['fs.files']
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
teardown do
|
15
|
-
|
15
|
+
#@file_system.drop
|
16
16
|
@image.close
|
17
17
|
end
|
18
18
|
|
19
19
|
should "be an Attachment" do
|
20
20
|
assert @attachment.is_a?(Attachment)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
should "belong to :owner" do
|
24
|
-
name,assoc = Attachment.associations.first
|
24
|
+
name, assoc = Attachment.associations.first
|
25
25
|
#assert_equal(:owner, assoc.name)
|
26
26
|
#assert_equal(:belongs_to, assoc.type)
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
context "with a valid file" do
|
30
30
|
setup do
|
31
31
|
@attachment.file = @image
|
@@ -34,25 +34,25 @@ class GripAttachmentTest < Test::Unit::TestCase
|
|
34
34
|
should "have correct :content_type" do
|
35
35
|
assert_equal("image/png", @attachment.content_type)
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
should "have correct :file_size" do
|
39
39
|
assert_equal(27582, @attachment.file_size)
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
should "have correct :file_name" do
|
43
43
|
assert_equal("cthulhu.png", @attachment.file_name)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
should "read file from grid store" do
|
47
47
|
assert_equal "image/png", @file_system.find_one(:filename => @attachment.grid_key)['contentType']
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
should "return a GridStore" do
|
51
51
|
assert_equal(GridFS::GridStore, @attachment.file.class)
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
context "with an invalid file" do
|
57
57
|
should "raise Grip::InvalidFile" do
|
58
58
|
assert_raise(InvalidFile) { @attachment.file = Hash.new }
|
@@ -60,5 +60,5 @@ class GripAttachmentTest < Test::Unit::TestCase
|
|
60
60
|
end
|
61
61
|
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
end
|
data/test/has_attachment_test.rb
CHANGED
@@ -10,18 +10,18 @@ class HasAttachmentTest < Test::Unit::TestCase
|
|
10
10
|
@image = File.open("#{@dir}/cthulhu.png", 'r')
|
11
11
|
@file_system = MongoMapper.database['fs.files']
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
teardown do
|
15
|
-
|
15
|
+
#@file_system.drop
|
16
16
|
@image.close
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
should "respond to uploaded files" do
|
20
20
|
assert @document.respond_to?(:uploaded_files)
|
21
21
|
end
|
22
22
|
|
23
23
|
should "have many attachments" do
|
24
|
-
name,assoc = Doc.associations.first
|
24
|
+
name, assoc = Doc.associations.first
|
25
25
|
assert_equal(:attachments, assoc.name)
|
26
26
|
assert_equal(:many, assoc.type)
|
27
27
|
end
|
@@ -29,7 +29,7 @@ class HasAttachmentTest < Test::Unit::TestCase
|
|
29
29
|
should "have :after_save callback" do
|
30
30
|
assert_equal(1, Doc.after_save.collect(&:method).count)
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
context "when assigned a file" do
|
34
34
|
setup do
|
35
35
|
@document.image = @image
|
@@ -39,19 +39,24 @@ class HasAttachmentTest < Test::Unit::TestCase
|
|
39
39
|
should "should return an Attachment" do
|
40
40
|
assert_equal(Grip::Attachment, @document.image.class)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
should "read file from grid store" do
|
44
44
|
assert_equal "image/png", @file_system.find_one(:filename => @document.image.grid_key)['contentType']
|
45
|
-
end
|
46
|
-
|
45
|
+
end
|
46
|
+
|
47
47
|
should "have :thumb variant" do
|
48
48
|
assert @document.image.respond_to?( :thumb )
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
|
+
should "have the correct name for each variant" do
|
52
|
+
assert_equal "thumb", @document.image.thumb.name
|
53
|
+
assert_equal "super_thumb", @document.image.super_thumb.name
|
54
|
+
end
|
55
|
+
|
51
56
|
should "have 2 variants" do
|
52
57
|
assert_equal(2, @document.image.attached_variants.count)
|
53
58
|
end
|
54
|
-
|
59
|
+
|
55
60
|
should "be resized" do
|
56
61
|
assert @document.image.file_size > @document.image.thumb.file_size
|
57
62
|
assert @document.image.file_size > @document.image.super_thumb.file_size
|
@@ -60,9 +65,9 @@ class HasAttachmentTest < Test::Unit::TestCase
|
|
60
65
|
should "retrieve variants from grid" do
|
61
66
|
assert_equal "image/png", @file_system.find_one(:filename => @document.image.thumb.grid_key)['contentType']
|
62
67
|
end
|
63
|
-
|
68
|
+
|
64
69
|
end
|
65
|
-
|
70
|
+
|
66
71
|
context "when multiple instances" do
|
67
72
|
setup do
|
68
73
|
@document2 = Doc.new
|
@@ -72,12 +77,12 @@ class HasAttachmentTest < Test::Unit::TestCase
|
|
72
77
|
@document2.image = @image2
|
73
78
|
@document3.image = @image3
|
74
79
|
end
|
75
|
-
|
80
|
+
|
76
81
|
should "not overwrite each other" do
|
77
82
|
assert_not_equal @document2.uploaded_files[:image][:file], @document3.uploaded_files[:image][:file]
|
78
83
|
end
|
79
84
|
end
|
80
|
-
|
85
|
+
|
81
86
|
end
|
82
|
-
|
87
|
+
|
83
88
|
end
|
data/test/models.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Doc
|
2
2
|
include MongoMapper::Document
|
3
3
|
include Grip::HasAttachment
|
4
|
-
has_grid_attachment :image, :variants => {:thumb=>{:width=>50
|
4
|
+
has_grid_attachment :image, :variants => {:thumb=>{:width=>50, :height=>50}, :super_thumb=>{:width=>10, :height=>10}}
|
5
5
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require 'rubygems'
|
3
|
-
require 'grip'
|
4
|
-
require 'growler'
|
5
|
-
%w{test/unit shoulda factory_girl mongo_mapper factories}.each { |lib| require lib }
|
6
2
|
|
3
|
+
require 'grip'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'shoulda'
|
6
|
+
require 'factory_girl'
|
7
|
+
require 'factories'
|
7
8
|
|
8
9
|
TEST_DB = 'test-grip'
|
9
10
|
|
@@ -12,14 +13,14 @@ MongoMapper.database = TEST_DB
|
|
12
13
|
class Test::Unit::TestCase
|
13
14
|
def teardown
|
14
15
|
MongoMapper.database.collections.each do |coll|
|
15
|
-
coll.remove
|
16
|
+
coll.remove
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
20
|
# Make sure that each test case has a teardown
|
20
21
|
# method to clear the db after each test.
|
21
22
|
def inherited(base)
|
22
|
-
base.define_method teardown do
|
23
|
+
base.define_method teardown do
|
23
24
|
super
|
24
25
|
end
|
25
26
|
end
|
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.
|
4
|
+
version: 0.6.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- twoism
|
@@ -13,6 +13,16 @@ cert_chain: []
|
|
13
13
|
date: 2010-01-21 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: mongo_mapper
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.6.10
|
25
|
+
version:
|
16
26
|
- !ruby/object:Gem::Dependency
|
17
27
|
name: rmagick
|
18
28
|
type: :runtime
|
@@ -21,7 +31,7 @@ dependencies:
|
|
21
31
|
requirements:
|
22
32
|
- - ">="
|
23
33
|
- !ruby/object:Gem::Version
|
24
|
-
version:
|
34
|
+
version: 2.12.2
|
25
35
|
version:
|
26
36
|
- !ruby/object:Gem::Dependency
|
27
37
|
name: miso
|
@@ -31,7 +41,27 @@ dependencies:
|
|
31
41
|
requirements:
|
32
42
|
- - ">="
|
33
43
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
44
|
+
version: 0.3.1
|
45
|
+
version:
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: factory_girl
|
48
|
+
type: :development
|
49
|
+
version_requirement:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.2.3
|
55
|
+
version:
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: shoulda
|
58
|
+
type: :development
|
59
|
+
version_requirement:
|
60
|
+
version_requirements: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - "="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 2.10.2
|
35
65
|
version:
|
36
66
|
description: GridFS attachments for MongoMapper
|
37
67
|
email: signalstatic@gmail.com
|
@@ -57,7 +87,6 @@ files:
|
|
57
87
|
- test/fixtures/fennec-fox.jpg
|
58
88
|
- test/fixtures/sample.pdf
|
59
89
|
- test/grip_attachment_test.rb
|
60
|
-
- test/growler.rb
|
61
90
|
- test/has_attachment_test.rb
|
62
91
|
- test/models.rb
|
63
92
|
- test/test_helper.rb
|
@@ -92,7 +121,6 @@ summary: GridFS attachments for MongoMapper
|
|
92
121
|
test_files:
|
93
122
|
- test/factories.rb
|
94
123
|
- test/grip_attachment_test.rb
|
95
|
-
- test/growler.rb
|
96
124
|
- test/has_attachment_test.rb
|
97
125
|
- test/models.rb
|
98
126
|
- test/test_helper.rb
|