carrierwave-mongoid 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -48,17 +48,36 @@ CarrierWave.configure do |config|
48
48
  end
49
49
  ```
50
50
 
51
- ## Changes from earlier versions of CarrierWave with Mongoid support built in
51
+ ## Version differences
52
52
 
53
- This version supports ONLY version of mongoid ~> 2.1
53
+ ### 0.2.0
54
54
 
55
- You can use `upload_identifier` to retrieve the original name of the uploaded file.
55
+ carrierwave-mongoid ~> 0.2.0 is only compatible with Rails 3.2 or higher.
56
+
57
+ ### 0.1.x
58
+
59
+ carrierwave-mongoid ~> 0.1.1 depends on carrierwave ~> 0.5.7. This version of
60
+ carrierwave is only compatible with Rails 3.1 or earlier.
56
61
 
57
- In the earlier version, the mount_uploader-method for mongoid had been defined in lib/carrierwave/orm/mongoid. This code has been moved to carrierwave/mongoid. If you update from earlier versions, don't forget to adjust your require accordingly in your carrierwave-initializer.
62
+ ### Changes from earlier versions of CarrierWave <= 0.5.6
63
+
64
+ CarrierWave used to have built-in Mongoid support. This gem replaces that
65
+ support and only only supports Mongoid ~> 2.1
66
+
67
+ You can use `upload_identifier` to retrieve the original name of the uploaded file.
58
68
 
59
- The default mount column used to be the name of the upload column plus `_filename`. Now it is simply the name of the column. Most of the time, the column was called `upload`, so it would have been mounted to `upload_filename`.
60
- If you'd like to avoid a database migration, simply use the `:mount_on` option to specify
61
- the field name explicitly. Therefore, you only have to add a `_filename` to your column name. For example, if your column is called `:upload`:
69
+ In the earlier version, the mount_uploader-method for mongoid had been defined
70
+ in lib/carrierwave/orm/mongoid. This code has been moved to
71
+ carrierwave/mongoid. If you update from earlier versions, don't forget to adjust
72
+ your require accordingly in your carrierwave-initializer.
73
+
74
+ The default mount column used to be the name of the upload column plus
75
+ `_filename`. Now it is simply the name of the column. Most of the time, the
76
+ column was called `upload`, so it would have been mounted to `upload_filename`.
77
+ If you'd like to avoid a database migration, simply use the `:mount_on` option
78
+ to specify the field name explicitly. Therefore, you only have to add a
79
+ `_filename` to your column name. For example, if your column is called
80
+ `:upload`:
62
81
 
63
82
  ```ruby
64
83
  class Dokument
@@ -19,7 +19,7 @@ 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 "carrierwave", ["~> 0.5.6"]
22
+ s.add_dependency "carrierwave", ["~> 0.6.1"]
23
23
  s.add_dependency "mongoid", ["~> 2.1"]
24
24
  s.add_development_dependency "rspec", ["~> 2.6"]
25
25
  s.add_development_dependency "bson_ext", ["~> 1.3"]
@@ -59,9 +59,36 @@ module CarrierWave
59
59
  self.class.find(to_key.first)
60
60
  end
61
61
  end
62
+
63
+ def serializable_hash(options=nil)
64
+ hash = {}
65
+ self.class.uploaders.each do |column, uploader|
66
+ hash[column.to_s] = _mounter(:#{column}).uploader.serializable_hash
67
+ end
68
+ super(options).merge(hash)
69
+ end
62
70
  RUBY
63
71
  end
64
72
  end # Mongoid
65
73
  end # CarrierWave
66
74
 
75
+ CarrierWave::Storage.autoload :GridFS, 'carrierwave/storage/grid_fs'
76
+
77
+ class CarrierWave::Uploader::Base
78
+ add_config :grid_fs_connection
79
+ add_config :grid_fs_database
80
+ add_config :grid_fs_host
81
+ add_config :grid_fs_port
82
+ add_config :grid_fs_username
83
+ add_config :grid_fs_password
84
+ add_config :grid_fs_access_url
85
+
86
+ configure do |config|
87
+ config.storage_engines[:grid_fs] = "CarrierWave::Storage::GridFS"
88
+ config.grid_fs_database = "carrierwave"
89
+ config.grid_fs_host = "localhost"
90
+ config.grid_fs_port = 27017
91
+ end
92
+ end
93
+
67
94
  Mongoid::Document::ClassMethods.send(:include, CarrierWave::Mongoid)
@@ -1,5 +1,5 @@
1
1
  module Carrierwave
2
2
  module Mongoid
3
- VERSION = "0.1.7"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/spec/mongoid_spec.rb CHANGED
@@ -97,6 +97,31 @@ describe CarrierWave::Mongoid do
97
97
  @doc.image.current_path.should == public_path('uploads/test.jpg')
98
98
  end
99
99
 
100
+ it "should return valid JSON when to_json is called when image is nil" do
101
+ @doc[:image] = nil
102
+ hash = JSON.parse(@doc.to_json)
103
+ hash.keys.should include("image")
104
+ hash["image"].keys.should include("url")
105
+ hash["image"]["url"].should be_nil
106
+ end
107
+
108
+ it "should return valid JSON when to_json is called when image is present" do
109
+ @doc[:image] = 'test.jpeg'
110
+ @doc.save!
111
+ @doc.reload
112
+
113
+ JSON.parse(@doc.to_json)["image"].should == {"url" => "/uploads/test.jpeg"}
114
+ end
115
+
116
+ it "should return valid JSON when to_json is called on a collection containing uploader from a model" do
117
+ @doc[:image] = 'test.jpeg'
118
+ @doc.save!
119
+ @doc.reload
120
+
121
+ JSON.parse({:data => @doc.image}.to_json).should == {"data"=>{"image"=>{"url"=>"/uploads/test.jpeg"}}}
122
+ end
123
+
124
+
100
125
  end
101
126
 
102
127
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,22 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-08 00:00:00.000000000 Z
13
+ date: 2012-04-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: carrierwave
17
- requirement: &70216819494840 !ruby/object:Gem::Requirement
17
+ requirement: &70329431625080 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: 0.5.6
22
+ version: 0.6.1
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70216819494840
25
+ version_requirements: *70329431625080
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: mongoid
28
- requirement: &70216819480940 !ruby/object:Gem::Requirement
28
+ requirement: &70329431624400 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '2.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70216819480940
36
+ version_requirements: *70329431624400
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &70216819480100 !ruby/object:Gem::Requirement
39
+ requirement: &70329431623900 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '2.6'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70216819480100
47
+ version_requirements: *70329431623900
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: bson_ext
50
- requirement: &70216819479460 !ruby/object:Gem::Requirement
50
+ requirement: &70329431623420 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '1.3'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70216819479460
58
+ version_requirements: *70329431623420
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rake
61
- requirement: &70216819478840 !ruby/object:Gem::Requirement
61
+ requirement: &70329431622880 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0.9'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70216819478840
69
+ version_requirements: *70329431622880
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: mini_magick
72
- requirement: &70216819478440 !ruby/object:Gem::Requirement
72
+ requirement: &70329431622380 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70216819478440
80
+ version_requirements: *70329431622380
81
81
  description: Mongoid support for CarrierWave
82
82
  email:
83
83
  - jonas.nicklas@gmail.com
@@ -119,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  segments:
121
121
  - 0
122
- hash: -3626845613401080446
122
+ hash: 1522479817545957250
123
123
  required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  none: false
125
125
  requirements:
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  segments:
130
130
  - 0
131
- hash: -3626845613401080446
131
+ hash: 1522479817545957250
132
132
  requirements: []
133
133
  rubyforge_project: carrierwave-mongoid
134
134
  rubygems_version: 1.8.11