carrierwave-datamapper 0.2.0 → 0.2.1
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/README.rdoc +15 -5
- data/carrierwave-datamapper.gemspec +9 -7
- data/lib/carrierwave/datamapper.rb +10 -4
- data/lib/carrierwave/datamapper/property/uploader.rb +4 -1
- data/lib/carrierwave/datamapper/version.rb +1 -1
- data/spec/integration/datamapper_spec.rb +207 -0
- data/spec/spec_helper.rb +5 -1
- data/spec/unit/carrier_wave/data_mapper/mount_uploader_spec.rb +80 -0
- metadata +79 -110
- data/spec/datamapper_spec.rb +0 -169
data/README.rdoc
CHANGED
@@ -3,18 +3,28 @@
|
|
3
3
|
This gem adds support for DataMapper to CarrierWave, see the CarrierWave
|
4
4
|
documentation for more detailed usage instructions.
|
5
5
|
|
6
|
-
|
6
|
+
= Installation
|
7
7
|
|
8
8
|
gem install carrierwave-datamapper
|
9
9
|
|
10
|
-
|
10
|
+
Using bundler:
|
11
|
+
|
12
|
+
gem 'carrierwave-datamapper', :require => 'carrierwave/datamapper'
|
13
|
+
|
14
|
+
= Usage
|
11
15
|
|
12
16
|
require 'carrierwave/datamapper'
|
13
17
|
|
14
|
-
|
18
|
+
class ImageUploader < CarrierWave::Uploader::Base
|
19
|
+
include CarrierWave::MiniMagick
|
20
|
+
end
|
15
21
|
|
16
|
-
|
22
|
+
class Image
|
23
|
+
include DataMapper::Resource
|
17
24
|
|
18
|
-
|
25
|
+
property :id, Serial
|
26
|
+
|
27
|
+
mount_uploader :source, ImageUploader
|
28
|
+
end
|
19
29
|
|
20
30
|
This used to be part of CarrierWave but has been extracted.
|
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "carrierwave-datamapper"
|
7
7
|
s.version = Carrierwave::Datamapper::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Jonas Nicklas", "Trevor Turk"]
|
9
|
+
s.authors = ["Jonas Nicklas", "Trevor Turk", "Piotr Solnica"]
|
10
10
|
s.email = ["jonas.nicklas@gmail.com"]
|
11
11
|
s.homepage = "https://github.com/jnicklas/carrierwave-datamapper"
|
12
12
|
s.summary = %q{Datamapper support for CarrierWave}
|
@@ -19,10 +19,12 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.add_dependency "dm-core", ["~> 1.
|
23
|
-
s.add_dependency "carrierwave", ["~> 0.
|
24
|
-
|
25
|
-
s.add_development_dependency "
|
26
|
-
s.add_development_dependency "
|
27
|
-
s.add_development_dependency "dm-
|
22
|
+
s.add_dependency "dm-core", ["~> 1.1"]
|
23
|
+
s.add_dependency "carrierwave", ["~> 0.6.0"]
|
24
|
+
|
25
|
+
s.add_development_dependency "rake", ["~> 0.9.2"]
|
26
|
+
s.add_development_dependency "rspec", ["~> 2.8"]
|
27
|
+
s.add_development_dependency "dm-validations", ["~> 1.1"]
|
28
|
+
s.add_development_dependency "dm-migrations", ["~> 1.1"]
|
29
|
+
s.add_development_dependency "dm-sqlite-adapter", ["~> 1.1"]
|
28
30
|
end
|
@@ -18,14 +18,18 @@ module CarrierWave
|
|
18
18
|
properties.delete(properties[column])
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
uploader_property = if options[:mount_on]
|
22
|
+
properties[options[:mount_on]]
|
23
|
+
else
|
24
|
+
property column, Property::Uploader
|
25
|
+
end
|
22
26
|
|
23
27
|
super
|
24
28
|
|
25
29
|
alias_method :read_uploader, :attribute_get
|
26
30
|
alias_method :write_uploader, :attribute_set
|
27
31
|
|
28
|
-
pre_hook = ::DataMapper.const_defined?(:
|
32
|
+
pre_hook = ::DataMapper.const_defined?(:Validations) ? :valid? : :save
|
29
33
|
|
30
34
|
before pre_hook, "write_#{column}_identifier".to_sym
|
31
35
|
after :save, "store_#{column}!".to_sym
|
@@ -37,14 +41,16 @@ module CarrierWave
|
|
37
41
|
class_eval <<-RUBY
|
38
42
|
def remove_#{column}=(value)
|
39
43
|
_mounter(:#{column}).remove = value
|
40
|
-
attribute_set(:#{
|
44
|
+
attribute_set(:#{uploader_property.name}, '') if _mounter(:#{column}).remove?
|
41
45
|
end
|
42
46
|
|
43
47
|
def #{column}=(value)
|
44
|
-
attribute_set(:#{
|
48
|
+
attribute_set(:#{uploader_property.name}, value)
|
45
49
|
super(value)
|
46
50
|
end
|
47
51
|
RUBY
|
52
|
+
|
53
|
+
uploader_property
|
48
54
|
end
|
49
55
|
|
50
56
|
end # DataMapper
|
@@ -2,12 +2,15 @@ module CarrierWave
|
|
2
2
|
module DataMapper
|
3
3
|
module Property
|
4
4
|
class Uploader < ::DataMapper::Property::String
|
5
|
+
|
6
|
+
length 255
|
7
|
+
|
5
8
|
def custom?
|
6
9
|
true
|
7
10
|
end
|
8
11
|
|
9
12
|
def initialize(model, name, options = {})
|
10
|
-
if ::DataMapper.const_defined?(:
|
13
|
+
if ::DataMapper.const_defined?(:Validations)
|
11
14
|
options[:auto_validation] = false
|
12
15
|
end
|
13
16
|
|
@@ -0,0 +1,207 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe CarrierWave::DataMapper do
|
6
|
+
let(:uploader) { Class.new(CarrierWave::Uploader::Base) }
|
7
|
+
let(:uploader_name) { :image }
|
8
|
+
let(:file) { stub_file('test.jpeg') }
|
9
|
+
|
10
|
+
|
11
|
+
let(:described_class) do
|
12
|
+
klass = Class.new do
|
13
|
+
include DataMapper::Resource
|
14
|
+
|
15
|
+
storage_names[:default] = 'events'
|
16
|
+
|
17
|
+
property :id, DataMapper::Property::Serial
|
18
|
+
|
19
|
+
def self.name; :event; end
|
20
|
+
end
|
21
|
+
|
22
|
+
klass.mount_uploader uploader_name, uploader
|
23
|
+
klass
|
24
|
+
end
|
25
|
+
|
26
|
+
before do
|
27
|
+
DataMapper.finalize.auto_migrate!
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:object) { described_class.new }
|
31
|
+
|
32
|
+
describe '#image' do
|
33
|
+
subject { object.image }
|
34
|
+
|
35
|
+
context 'with a new resource' do
|
36
|
+
context 'when nothing has been assigned' do
|
37
|
+
let(:object) { described_class.new }
|
38
|
+
|
39
|
+
it { should be_blank }
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when file name is set' do
|
43
|
+
before do
|
44
|
+
object.attribute_set(:image, 'test.jpeg')
|
45
|
+
object.save
|
46
|
+
object.reload
|
47
|
+
end
|
48
|
+
|
49
|
+
its(:current_path) { should == public_path('uploads/test.jpeg') }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'with a persisted resource' do
|
54
|
+
let(:object) { described_class.first }
|
55
|
+
|
56
|
+
context 'when an empty string has been assigned' do
|
57
|
+
before do
|
58
|
+
repository(:default).adapter.execute("INSERT INTO events (image) VALUES ('')")
|
59
|
+
end
|
60
|
+
|
61
|
+
it { should be_blank }
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when a value is stored in the database' do
|
65
|
+
before do
|
66
|
+
repository(:default).adapter.execute("INSERT INTO events (image) VALUES ('test.jpg')")
|
67
|
+
end
|
68
|
+
|
69
|
+
it { should be_an_instance_of(uploader) }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#image=' do
|
75
|
+
context 'when a file is assigned' do
|
76
|
+
before do
|
77
|
+
object.image = file
|
78
|
+
end
|
79
|
+
|
80
|
+
it "caches a file" do
|
81
|
+
object.image.should be_an_instance_of(uploader)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "copies a file into into the cache directory" do
|
85
|
+
object.image.current_path.should =~ %r[^#{public_path('uploads/tmp')}]
|
86
|
+
end
|
87
|
+
|
88
|
+
context "with a saved resource" do
|
89
|
+
before do
|
90
|
+
object.save
|
91
|
+
object.image = stub_file('test.jpeg')
|
92
|
+
end
|
93
|
+
|
94
|
+
it "marks the resource as dirty" do
|
95
|
+
object.dirty?.should be(true)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'when nil is assigned' do
|
101
|
+
before do
|
102
|
+
object.image = nil
|
103
|
+
end
|
104
|
+
|
105
|
+
it "does nothing" do
|
106
|
+
object.image.should be_blank
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'when nil is assigned' do
|
111
|
+
before do
|
112
|
+
object.image = 'nil'
|
113
|
+
end
|
114
|
+
|
115
|
+
it "does nothing" do
|
116
|
+
object.image.should be_blank
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should write nothing to the database, to prevent overriden filenames to fail because of unassigned attributes" do
|
121
|
+
object.attribute_get(:image).should be_nil
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '#save' do
|
126
|
+
context 'when no file has been assigned' do
|
127
|
+
before do
|
128
|
+
object.save
|
129
|
+
end
|
130
|
+
|
131
|
+
it "does nothing" do
|
132
|
+
object.image.should be_blank
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'when a file has been assigned' do
|
137
|
+
before do
|
138
|
+
object.image = file
|
139
|
+
object.save
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'without validations' do
|
143
|
+
it "copies the file to the upload directory" do
|
144
|
+
object.image.should be_an_instance_of(uploader)
|
145
|
+
object.image.current_path.should == public_path('uploads/test.jpeg')
|
146
|
+
end
|
147
|
+
|
148
|
+
it "assigns the filename to the database" do
|
149
|
+
object.reload
|
150
|
+
object.attribute_get(:image).should == 'test.jpeg'
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'when remove_image? returns true' do
|
154
|
+
before do
|
155
|
+
object.remove_image = true
|
156
|
+
object.save
|
157
|
+
object.reload
|
158
|
+
end
|
159
|
+
|
160
|
+
it "removes the image" do
|
161
|
+
object.image.should be_blank
|
162
|
+
object.attribute_get(:image).should == ''
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context "with validations" do
|
168
|
+
before(:all) do
|
169
|
+
described_class.validates_with_block(:textfile) { [false, "FAIL!"] }
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should do nothing when a validation fails" do
|
173
|
+
object.image.should be_an_instance_of(uploader)
|
174
|
+
object.image.current_path.should =~ %r[^#{public_path('uploads/tmp')}]
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should assign the filename before validation" do
|
178
|
+
object.reload
|
179
|
+
object.attribute_get(:image).should == 'test.jpeg'
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe '#destroy' do
|
186
|
+
context 'when no file has been assigned' do
|
187
|
+
it "does nothing when no file has been assigned" do
|
188
|
+
object.destroy
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'when a file has been assigned' do
|
193
|
+
before do
|
194
|
+
object.image = file
|
195
|
+
object.save.should be_true
|
196
|
+
File.exist?(public_path('uploads/test.jpeg')).should be_true
|
197
|
+
object.image.should be_an_instance_of(uploader)
|
198
|
+
object.image.current_path.should == public_path('uploads/test.jpeg')
|
199
|
+
object.destroy
|
200
|
+
end
|
201
|
+
|
202
|
+
it "removes the file from the filesystem" do
|
203
|
+
File.exist?(public_path('uploads/test.jpeg')).should be_false
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,9 +2,13 @@ require 'rubygems'
|
|
2
2
|
require 'bundler/setup'
|
3
3
|
require 'rspec'
|
4
4
|
|
5
|
-
require 'carrierwave'
|
6
5
|
require 'carrierwave/datamapper'
|
7
6
|
|
7
|
+
require 'dm-validations'
|
8
|
+
require 'dm-migrations'
|
9
|
+
|
10
|
+
DataMapper.setup(:default, 'sqlite3::memory:')
|
11
|
+
|
8
12
|
def file_path( *paths )
|
9
13
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', *paths))
|
10
14
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CarrierWave::DataMapper, '.mount_uploader' do
|
4
|
+
let(:described_class) do
|
5
|
+
Class.new do
|
6
|
+
include DataMapper::Resource
|
7
|
+
property :id, DataMapper::Property::Serial
|
8
|
+
|
9
|
+
def self.name; :spec_model; end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:uploader_name) { :image }
|
14
|
+
let(:uploader) { Class.new(CarrierWave::Uploader::Base) }
|
15
|
+
|
16
|
+
before do
|
17
|
+
DataMapper.finalize
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'Model' do
|
21
|
+
specify { described_class.should respond_to(:mount_uploader) }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'after mounting an uploader' do
|
25
|
+
let!(:uploader_property) do
|
26
|
+
described_class.mount_uploader(uploader_name, uploader)
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'Uploader Property' do
|
30
|
+
subject { uploader_property }
|
31
|
+
|
32
|
+
it { should be_instance_of(CarrierWave::DataMapper::Property::Uploader) }
|
33
|
+
|
34
|
+
its(:name) { should == uploader_name }
|
35
|
+
its(:custom?) { should be(true) }
|
36
|
+
|
37
|
+
specify 'has auto-validation turned off' do
|
38
|
+
subject.options[:auto_validation].should be(false)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'Resource' do
|
43
|
+
subject { described_class.new }
|
44
|
+
|
45
|
+
it { should respond_to("remove_#{uploader_name}=") }
|
46
|
+
it { should respond_to("#{uploader_name}=") }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when using the :mount_on option" do
|
51
|
+
let(:uploader_column) { :image_file_name }
|
52
|
+
|
53
|
+
let(:described_class) do
|
54
|
+
Class.new do
|
55
|
+
include DataMapper::Resource
|
56
|
+
|
57
|
+
property :id, DataMapper::Property::Serial
|
58
|
+
|
59
|
+
property :image_file_name, String
|
60
|
+
|
61
|
+
def self.name; :spec_model; end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
let!(:uploader_property) do
|
66
|
+
described_class.mount_uploader uploader_name, uploader,
|
67
|
+
:mount_on => :image_file_name
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not define a new uploader property" do
|
71
|
+
described_class.properties.should_not be_named(:image)
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'Uploader Property' do
|
75
|
+
subject { uploader_property }
|
76
|
+
|
77
|
+
its(:name) { should == uploader_column }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
CHANGED
@@ -1,125 +1,102 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-datamapper
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
version: 0.2.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Jonas Nicklas
|
14
9
|
- Trevor Turk
|
10
|
+
- Piotr Solnica
|
15
11
|
autorequire:
|
16
12
|
bindir: bin
|
17
13
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
dependencies:
|
22
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
date: 2012-04-25 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
23
17
|
name: dm-core
|
24
|
-
|
25
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirement: &70257289127860 !ruby/object:Gem::Requirement
|
26
19
|
none: false
|
27
|
-
requirements:
|
20
|
+
requirements:
|
28
21
|
- - ~>
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
|
31
|
-
segments:
|
32
|
-
- 1
|
33
|
-
- 0
|
34
|
-
version: "1.0"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '1.1'
|
35
24
|
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: carrierwave
|
39
25
|
prerelease: false
|
40
|
-
|
26
|
+
version_requirements: *70257289127860
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: carrierwave
|
29
|
+
requirement: &70257289124900 !ruby/object:Gem::Requirement
|
41
30
|
none: false
|
42
|
-
requirements:
|
31
|
+
requirements:
|
43
32
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
- 5
|
49
|
-
- 6
|
50
|
-
version: 0.5.6
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.6.0
|
51
35
|
type: :runtime
|
52
|
-
version_requirements: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: rspec
|
55
36
|
prerelease: false
|
56
|
-
|
37
|
+
version_requirements: *70257289124900
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rake
|
40
|
+
requirement: &70257289122560 !ruby/object:Gem::Requirement
|
57
41
|
none: false
|
58
|
-
requirements:
|
42
|
+
requirements:
|
59
43
|
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
62
|
-
segments:
|
63
|
-
- 2
|
64
|
-
- 0
|
65
|
-
version: "2.0"
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.9.2
|
66
46
|
type: :development
|
67
|
-
version_requirements: *id003
|
68
|
-
- !ruby/object:Gem::Dependency
|
69
|
-
name: dm-validations
|
70
47
|
prerelease: false
|
71
|
-
|
48
|
+
version_requirements: *70257289122560
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rspec
|
51
|
+
requirement: &70257289120980 !ruby/object:Gem::Requirement
|
72
52
|
none: false
|
73
|
-
requirements:
|
53
|
+
requirements:
|
74
54
|
- - ~>
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '2.8'
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *70257289120980
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: dm-validations
|
62
|
+
requirement: &70257289119660 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.1'
|
81
68
|
type: :development
|
82
|
-
version_requirements: *id004
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: dm-migrations
|
85
69
|
prerelease: false
|
86
|
-
|
70
|
+
version_requirements: *70257289119660
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: dm-migrations
|
73
|
+
requirement: &70257289118460 !ruby/object:Gem::Requirement
|
87
74
|
none: false
|
88
|
-
requirements:
|
75
|
+
requirements:
|
89
76
|
- - ~>
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
|
92
|
-
segments:
|
93
|
-
- 1
|
94
|
-
- 0
|
95
|
-
version: "1.0"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '1.1'
|
96
79
|
type: :development
|
97
|
-
version_requirements: *id005
|
98
|
-
- !ruby/object:Gem::Dependency
|
99
|
-
name: dm-sqlite-adapter
|
100
80
|
prerelease: false
|
101
|
-
|
81
|
+
version_requirements: *70257289118460
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: dm-sqlite-adapter
|
84
|
+
requirement: &70257289117680 !ruby/object:Gem::Requirement
|
102
85
|
none: false
|
103
|
-
requirements:
|
86
|
+
requirements:
|
104
87
|
- - ~>
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
|
107
|
-
segments:
|
108
|
-
- 1
|
109
|
-
- 0
|
110
|
-
version: "1.0"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.1'
|
111
90
|
type: :development
|
112
|
-
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: *70257289117680
|
113
93
|
description: Datamapper support for CarrierWave
|
114
|
-
email:
|
94
|
+
email:
|
115
95
|
- jonas.nicklas@gmail.com
|
116
96
|
executables: []
|
117
|
-
|
118
97
|
extensions: []
|
119
|
-
|
120
98
|
extra_rdoc_files: []
|
121
|
-
|
122
|
-
files:
|
99
|
+
files:
|
123
100
|
- .gitignore
|
124
101
|
- Gemfile
|
125
102
|
- README.rdoc
|
@@ -128,44 +105,36 @@ files:
|
|
128
105
|
- lib/carrierwave/datamapper.rb
|
129
106
|
- lib/carrierwave/datamapper/property/uploader.rb
|
130
107
|
- lib/carrierwave/datamapper/version.rb
|
131
|
-
- spec/datamapper_spec.rb
|
132
108
|
- spec/fixtures/test.jpeg
|
109
|
+
- spec/integration/datamapper_spec.rb
|
133
110
|
- spec/spec_helper.rb
|
134
|
-
|
111
|
+
- spec/unit/carrier_wave/data_mapper/mount_uploader_spec.rb
|
135
112
|
homepage: https://github.com/jnicklas/carrierwave-datamapper
|
136
113
|
licenses: []
|
137
|
-
|
138
114
|
post_install_message:
|
139
115
|
rdoc_options: []
|
140
|
-
|
141
|
-
require_paths:
|
116
|
+
require_paths:
|
142
117
|
- lib
|
143
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
119
|
none: false
|
145
|
-
requirements:
|
146
|
-
- -
|
147
|
-
- !ruby/object:Gem::Version
|
148
|
-
|
149
|
-
|
150
|
-
- 0
|
151
|
-
version: "0"
|
152
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
125
|
none: false
|
154
|
-
requirements:
|
155
|
-
- -
|
156
|
-
- !ruby/object:Gem::Version
|
157
|
-
|
158
|
-
segments:
|
159
|
-
- 0
|
160
|
-
version: "0"
|
126
|
+
requirements:
|
127
|
+
- - ! '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
161
130
|
requirements: []
|
162
|
-
|
163
131
|
rubyforge_project: carrierwave-datamapper
|
164
|
-
rubygems_version: 1.
|
132
|
+
rubygems_version: 1.8.15
|
165
133
|
signing_key:
|
166
134
|
specification_version: 3
|
167
135
|
summary: Datamapper support for CarrierWave
|
168
|
-
test_files:
|
169
|
-
- spec/datamapper_spec.rb
|
136
|
+
test_files:
|
170
137
|
- spec/fixtures/test.jpeg
|
138
|
+
- spec/integration/datamapper_spec.rb
|
171
139
|
- spec/spec_helper.rb
|
140
|
+
- spec/unit/carrier_wave/data_mapper/mount_uploader_spec.rb
|
data/spec/datamapper_spec.rb
DELETED
@@ -1,169 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
require 'dm-core'
|
6
|
-
require 'dm-validations'
|
7
|
-
require 'dm-migrations'
|
8
|
-
|
9
|
-
DataMapper.setup(:default, 'sqlite3::memory:')
|
10
|
-
|
11
|
-
describe CarrierWave::DataMapper do
|
12
|
-
|
13
|
-
before do
|
14
|
-
uploader = Class.new(CarrierWave::Uploader::Base)
|
15
|
-
|
16
|
-
@class = Class.new
|
17
|
-
@class.class_eval do
|
18
|
-
include DataMapper::Resource
|
19
|
-
|
20
|
-
storage_names[:default] = 'events'
|
21
|
-
|
22
|
-
property :id, DataMapper::Property::Serial
|
23
|
-
mount_uploader :image, uploader
|
24
|
-
end
|
25
|
-
|
26
|
-
@class.auto_migrate!
|
27
|
-
|
28
|
-
@uploader = uploader
|
29
|
-
|
30
|
-
@event = @class.new
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#image' do
|
34
|
-
|
35
|
-
it "should return blank uploader when nothing has been assigned" do
|
36
|
-
@event.image.should be_blank
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should return blank uploader when an empty string has been assigned" do
|
40
|
-
repository(:default).adapter.execute("INSERT INTO events (image) VALUES ('')")
|
41
|
-
@event = @class.first
|
42
|
-
|
43
|
-
@event.image.should be_blank
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should retrieve a file from the storage if a value is stored in the database" do
|
47
|
-
repository(:default).adapter.execute("INSERT INTO events (image) VALUES ('test.jpg')")
|
48
|
-
@event = @class.first
|
49
|
-
|
50
|
-
@event.save
|
51
|
-
@event.reload
|
52
|
-
@event.image.should be_an_instance_of(@uploader)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should set the path to the store dir" do
|
56
|
-
@event.attribute_set(:image, 'test.jpeg')
|
57
|
-
@event.save
|
58
|
-
@event.reload
|
59
|
-
@event.image.current_path.should == public_path('uploads/test.jpeg')
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#image=' do
|
65
|
-
|
66
|
-
it "should cache a file" do
|
67
|
-
@event.image = stub_file('test.jpeg')
|
68
|
-
@event.image.should be_an_instance_of(@uploader)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should write nothing to the database, to prevent overriden filenames to fail because of unassigned attributes" do
|
72
|
-
@event.attribute_get(:image).should be_nil
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should copy a file into into the cache directory" do
|
76
|
-
@event.image = stub_file('test.jpeg')
|
77
|
-
@event.image.current_path.should =~ /^#{public_path('uploads/tmp')}/
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should do nothing when nil is assigned" do
|
81
|
-
@event.image = nil
|
82
|
-
@event.image.should be_blank
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should do nothing when an empty string is assigned" do
|
86
|
-
@event.image = ''
|
87
|
-
@event.image.should be_blank
|
88
|
-
end
|
89
|
-
|
90
|
-
context "with a saved resource" do
|
91
|
-
it "should mark the resource as dirty" do
|
92
|
-
@event.image = stub_file('test.jpeg')
|
93
|
-
@event.save
|
94
|
-
@event.image = stub_file('test.jpeg')
|
95
|
-
@event.dirty?.should be(true)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe '#save' do
|
101
|
-
|
102
|
-
it "should do nothing when no file has been assigned" do
|
103
|
-
@event.save
|
104
|
-
@event.image.should be_blank
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should copy the file to the upload directory when a file has been assigned" do
|
108
|
-
@event.image = stub_file('test.jpeg')
|
109
|
-
@event.save
|
110
|
-
@event.image.should be_an_instance_of(@uploader)
|
111
|
-
@event.image.current_path.should == public_path('uploads/test.jpeg')
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should assign the filename to the database" do
|
115
|
-
@event.image = stub_file('test.jpeg')
|
116
|
-
@event.save
|
117
|
-
@event.reload
|
118
|
-
@event.attribute_get(:image).should == 'test.jpeg'
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should remove the image if remove_image? returns true" do
|
122
|
-
@event.image = stub_file('test.jpeg')
|
123
|
-
@event.save
|
124
|
-
@event.remove_image = true
|
125
|
-
@event.save
|
126
|
-
@event.reload
|
127
|
-
@event.image.should be_blank
|
128
|
-
@event.attribute_get(:image).should == ''
|
129
|
-
end
|
130
|
-
|
131
|
-
describe "with validations" do
|
132
|
-
it "should do nothing when a validation fails" do
|
133
|
-
@class.validates_with_block(:textfile) { [false, "FAIL!"] }
|
134
|
-
@event.image = stub_file('test.jpeg')
|
135
|
-
@event.save
|
136
|
-
@event.image.should be_an_instance_of(@uploader)
|
137
|
-
@event.image.current_path.should =~ /^#{public_path('uploads/tmp')}/
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should assign the filename before validation" do
|
141
|
-
@class.validates_with_block(:image) { [false, "FAIL!"] if self.image.nil? }
|
142
|
-
@event.image = stub_file('test.jpeg')
|
143
|
-
@event.save
|
144
|
-
@event.reload
|
145
|
-
@event.attribute_get(:image).should == 'test.jpeg'
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
describe '#destroy' do
|
152
|
-
|
153
|
-
it "should do nothing when no file has been assigned" do
|
154
|
-
@event.destroy
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should remove the file from the filesystem" do
|
158
|
-
@event.image = stub_file('test.jpeg')
|
159
|
-
@event.save.should be_true
|
160
|
-
File.exist?(public_path('uploads/test.jpeg')).should be_true
|
161
|
-
@event.image.should be_an_instance_of(@uploader)
|
162
|
-
@event.image.current_path.should == public_path('uploads/test.jpeg')
|
163
|
-
@event.destroy
|
164
|
-
File.exist?(public_path('uploads/test.jpeg')).should be_false
|
165
|
-
end
|
166
|
-
|
167
|
-
end
|
168
|
-
|
169
|
-
end
|