gnuside-carrierwave-mongoid 0.6.6
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.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +19 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +63 -0
- data/LICENSE +20 -0
- data/README.md +219 -0
- data/Rakefile +12 -0
- data/gemfiles/carrierwave-0.8.gemfile +5 -0
- data/gemfiles/carrierwave-master.gemfile +5 -0
- data/gemfiles/mongoid-4.0.gemfile +6 -0
- data/gnuside-carrierwave-mongoid.gemspec +29 -0
- data/lib/carrierwave/mongoid.rb +118 -0
- data/lib/carrierwave/mongoid/version.rb +5 -0
- data/lib/carrierwave/storage/grid_fs.rb +114 -0
- data/lib/glebtv-carrierwave-mongoid.rb +1 -0
- data/spec/fixtures/new.jpeg +1 -0
- data/spec/fixtures/new.txt +1 -0
- data/spec/fixtures/old.jpeg +1 -0
- data/spec/fixtures/old.txt +1 -0
- data/spec/fixtures/portrait.jpg +0 -0
- data/spec/fixtures/test.jpeg +1 -0
- data/spec/fixtures/test.jpg +1 -0
- data/spec/mongoid_spec.rb +879 -0
- data/spec/spec_helper.rb +74 -0
- data/spec/storage/grid_fs_spec.rb +184 -0
- metadata +210 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'rspec'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
require 'carrierwave'
|
8
|
+
require 'carrierwave/mongoid'
|
9
|
+
|
10
|
+
Mongoid.configure do |config|
|
11
|
+
config.connect_to('carrierwave_test')
|
12
|
+
end
|
13
|
+
|
14
|
+
def file_path( *paths )
|
15
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', *paths))
|
16
|
+
end
|
17
|
+
|
18
|
+
def public_path( *paths )
|
19
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'public', *paths))
|
20
|
+
end
|
21
|
+
|
22
|
+
CarrierWave.root = public_path
|
23
|
+
|
24
|
+
module CarrierWave
|
25
|
+
module Test
|
26
|
+
module MockFiles
|
27
|
+
def stub_file(filename, mime_type=nil, fake_name=nil)
|
28
|
+
f = File.open(file_path(filename))
|
29
|
+
return f
|
30
|
+
end
|
31
|
+
|
32
|
+
def stub_tempfile(filename, mime_type=nil, fake_name=nil)
|
33
|
+
raise "#{path} file does not exist" unless File.exist?(file_path(filename))
|
34
|
+
|
35
|
+
t = Tempfile.new(filename)
|
36
|
+
FileUtils.copy_file(file_path(filename), t.path)
|
37
|
+
|
38
|
+
t.stub(:local_path => "",
|
39
|
+
:original_filename => filename || fake_name,
|
40
|
+
:content_type => mime_type)
|
41
|
+
|
42
|
+
return t
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
module I18nHelpers
|
47
|
+
def change_locale_and_store_translations(locale, translations, &block)
|
48
|
+
current_locale = I18n.locale
|
49
|
+
begin
|
50
|
+
I18n.backend.store_translations locale, translations
|
51
|
+
I18n.locale = locale
|
52
|
+
yield
|
53
|
+
ensure
|
54
|
+
I18n.reload!
|
55
|
+
I18n.locale = current_locale
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class SIO < StringIO
|
63
|
+
attr_accessor :filename
|
64
|
+
|
65
|
+
def initialize(filename, *args, &block)
|
66
|
+
@filename = filename
|
67
|
+
super(*args, &block)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
RSpec.configure do |config|
|
72
|
+
config.include CarrierWave::Test::MockFiles
|
73
|
+
config.include CarrierWave::Test::I18nHelpers
|
74
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
|
7
|
+
shared_examples_for "a GridFS connection" do
|
8
|
+
describe '#store!' do
|
9
|
+
before do
|
10
|
+
@uploader.stub(:store_path).and_return('uploads/bar.txt')
|
11
|
+
@grid_fs_file = @storage.store!(@file)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should upload the file to gridfs" do
|
15
|
+
@grid['uploads/bar.txt'].data.should == 'this is stuff'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should upload the file to gridfs" do
|
19
|
+
@grid['uploads/bar.txt'].data.should == 'this is stuff'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should have the same path that it was stored as" do
|
23
|
+
@grid_fs_file.path.should == 'uploads/bar.txt'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should read the contents of the file" do
|
27
|
+
@grid_fs_file.read.should == "this is stuff"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should not have a URL" do
|
31
|
+
@grid_fs_file.url.should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be deletable" do
|
35
|
+
@grid_fs_file.delete
|
36
|
+
@grid['uploads/bar.txt'].should be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should store the content type on GridFS" do
|
40
|
+
@grid_fs_file.content_type.should == 'text/plain'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should have a file length" do
|
44
|
+
@grid_fs_file.file_length.should == 13
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#retrieve!' do
|
49
|
+
before do
|
50
|
+
@grid.clear
|
51
|
+
@grid['uploads/bar.txt'] = StringIO.new('A test, 1234')
|
52
|
+
@uploader.stub(:store_path).with('bar.txt').and_return('uploads/bar.txt')
|
53
|
+
@grid_fs_file = @storage.retrieve!('bar.txt')
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should retrieve the file contents from gridfs" do
|
57
|
+
@grid_fs_file.read.chomp.should == "A test, 1234"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should have the same path that it was stored as" do
|
61
|
+
@grid_fs_file.path.should == 'uploads/bar.txt'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not have a URL unless access_url is set" do
|
65
|
+
@grid_fs_file.url.should be_nil
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should return a relative URL path if access_url is set to the root path" do
|
69
|
+
@uploader.stub(:grid_fs_access_url).and_return("/")
|
70
|
+
@grid_fs_file.url.should == "/uploads/bar.txt"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should return a URL path if access_url is set to a file path" do
|
74
|
+
@uploader.stub(:grid_fs_access_url).and_return("/image/show")
|
75
|
+
@grid_fs_file.url.should == "/image/show/uploads/bar.txt"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return an absolute URL if access_url is set to an absolute URL" do
|
79
|
+
@uploader.stub(:grid_fs_access_url).and_return("http://example.com/images/")
|
80
|
+
@grid_fs_file.url.should == "http://example.com/images/uploads/bar.txt"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should be deletable" do
|
84
|
+
@grid_fs_file.delete
|
85
|
+
@grid['uploads/bar.txt'].should be_nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#retrieve! on a store_dir with leading slash' do
|
90
|
+
before do
|
91
|
+
@uploader.stub(:store_path).with('bar.txt').and_return('/uploads/bar.txt')
|
92
|
+
@grid_fs_file = @storage.retrieve!('bar.txt')
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should return a relative URL path if access_url is set to the root path" do
|
96
|
+
@uploader.stub(:grid_fs_access_url).and_return("/")
|
97
|
+
@grid_fs_file.url.should == "/uploads/bar.txt"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
if defined?(Mongoid::GridFs)
|
104
|
+
describe CarrierWave::Storage::GridFS do
|
105
|
+
|
106
|
+
before do
|
107
|
+
@uploader = mock('an uploader')
|
108
|
+
@uploader.stub!(:grid_fs_access_url).and_return(nil)
|
109
|
+
end
|
110
|
+
|
111
|
+
context "when reusing an existing connection manually" do
|
112
|
+
before do
|
113
|
+
@uploader.stub!(:grid_fs_connection).and_return(@database)
|
114
|
+
|
115
|
+
@grid = ::Mongoid::GridFs
|
116
|
+
|
117
|
+
@storage = CarrierWave::Storage::GridFS.new(@uploader)
|
118
|
+
@file = stub_tempfile('test.jpg', 'application/xml')
|
119
|
+
end
|
120
|
+
|
121
|
+
it_should_behave_like "a GridFS connection"
|
122
|
+
|
123
|
+
# Calling #recreate_versions! on uploaders has been known to fail on
|
124
|
+
# remotely hosted files. This is due to a variety of issues, but this test
|
125
|
+
# makes sure that there's no unnecessary errors during the process
|
126
|
+
describe "#recreate_versions!" do
|
127
|
+
before do
|
128
|
+
@uploader_class = Class.new(CarrierWave::Uploader::Base)
|
129
|
+
@uploader_class.class_eval{
|
130
|
+
include CarrierWave::MiniMagick
|
131
|
+
storage :grid_fs
|
132
|
+
|
133
|
+
process :resize_to_fit => [10, 10]
|
134
|
+
}
|
135
|
+
|
136
|
+
@versioned = @uploader_class.new
|
137
|
+
|
138
|
+
@versioned.store! File.open(file_path('portrait.jpg'))
|
139
|
+
end
|
140
|
+
|
141
|
+
after do
|
142
|
+
FileUtils.rm_rf(public_path)
|
143
|
+
end
|
144
|
+
|
145
|
+
it "recreates versions stored remotely without error" do
|
146
|
+
lambda {
|
147
|
+
@versioned.recreate_versions!
|
148
|
+
}.should_not raise_error
|
149
|
+
|
150
|
+
@versioned.should be_present
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "resize_to_fill" do
|
155
|
+
before do
|
156
|
+
@uploader_class = Class.new(CarrierWave::Uploader::Base)
|
157
|
+
@uploader_class.class_eval{
|
158
|
+
include CarrierWave::MiniMagick
|
159
|
+
storage :grid_fs
|
160
|
+
}
|
161
|
+
|
162
|
+
@versioned = @uploader_class.new
|
163
|
+
|
164
|
+
@versioned.store! File.open(file_path('portrait.jpg'))
|
165
|
+
end
|
166
|
+
|
167
|
+
after do
|
168
|
+
FileUtils.rm_rf(public_path)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "resizes the file with out error" do
|
172
|
+
lambda {
|
173
|
+
@versioned.resize_to_fill(200, 200)
|
174
|
+
}.should_not raise_error
|
175
|
+
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
after do
|
181
|
+
@grid.clear
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
metadata
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gnuside-carrierwave-mongoid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- GlebTv
|
8
|
+
- Jonas Nicklas
|
9
|
+
- Trevor Turk
|
10
|
+
- Roland Laurès
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2013-12-13 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: mongoid
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.0'
|
23
|
+
- - "<"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '5.0'
|
26
|
+
type: :runtime
|
27
|
+
prerelease: false
|
28
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.0'
|
33
|
+
- - "<"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '5.0'
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: carrierwave
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 0.8.0
|
43
|
+
- - "<"
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.10.0
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 0.8.0
|
53
|
+
- - "<"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.10.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: mongoid
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 4.0.0
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 4.0.0
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: mongoid-grid_fs
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.9'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.9'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '2.14'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '2.14'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rake
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '10.0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '10.0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: mini_magick
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: pry
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
description: This fork is made to be compatible with rails 4
|
141
|
+
email:
|
142
|
+
- jonas.nicklas@gmail.com
|
143
|
+
- roland.laures@gnuside.com
|
144
|
+
executables: []
|
145
|
+
extensions: []
|
146
|
+
extra_rdoc_files: []
|
147
|
+
files:
|
148
|
+
- ".gitignore"
|
149
|
+
- ".ruby-gemset"
|
150
|
+
- ".ruby-version"
|
151
|
+
- ".travis.yml"
|
152
|
+
- Gemfile
|
153
|
+
- Gemfile.lock
|
154
|
+
- LICENSE
|
155
|
+
- README.md
|
156
|
+
- Rakefile
|
157
|
+
- gemfiles/carrierwave-0.8.gemfile
|
158
|
+
- gemfiles/carrierwave-master.gemfile
|
159
|
+
- gemfiles/mongoid-4.0.gemfile
|
160
|
+
- gnuside-carrierwave-mongoid.gemspec
|
161
|
+
- lib/carrierwave/mongoid.rb
|
162
|
+
- lib/carrierwave/mongoid/version.rb
|
163
|
+
- lib/carrierwave/storage/grid_fs.rb
|
164
|
+
- lib/glebtv-carrierwave-mongoid.rb
|
165
|
+
- log/.gitkeep
|
166
|
+
- spec/fixtures/new.jpeg
|
167
|
+
- spec/fixtures/new.txt
|
168
|
+
- spec/fixtures/old.jpeg
|
169
|
+
- spec/fixtures/old.txt
|
170
|
+
- spec/fixtures/portrait.jpg
|
171
|
+
- spec/fixtures/test.jpeg
|
172
|
+
- spec/fixtures/test.jpg
|
173
|
+
- spec/mongoid_spec.rb
|
174
|
+
- spec/spec_helper.rb
|
175
|
+
- spec/storage/grid_fs_spec.rb
|
176
|
+
homepage: https://github.com/Gnuside/carrierwave-mongoid
|
177
|
+
licenses:
|
178
|
+
- MIT
|
179
|
+
metadata: {}
|
180
|
+
post_install_message:
|
181
|
+
rdoc_options: []
|
182
|
+
require_paths:
|
183
|
+
- lib
|
184
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
requirements: []
|
195
|
+
rubyforge_project:
|
196
|
+
rubygems_version: 2.0.3
|
197
|
+
signing_key:
|
198
|
+
specification_version: 4
|
199
|
+
summary: This fork is made to be compatible with rails 4
|
200
|
+
test_files:
|
201
|
+
- spec/fixtures/new.jpeg
|
202
|
+
- spec/fixtures/new.txt
|
203
|
+
- spec/fixtures/old.jpeg
|
204
|
+
- spec/fixtures/old.txt
|
205
|
+
- spec/fixtures/portrait.jpg
|
206
|
+
- spec/fixtures/test.jpeg
|
207
|
+
- spec/fixtures/test.jpg
|
208
|
+
- spec/mongoid_spec.rb
|
209
|
+
- spec/spec_helper.rb
|
210
|
+
- spec/storage/grid_fs_spec.rb
|