mongo_mapper_ext 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/mongo_mapper_ext/carrier_wave.rb +12 -0
- data/lib/mongo_mapper_ext/carrier_wave/fixes.rb +12 -0
- data/lib/mongo_mapper_ext/carrier_wave/micelaneous.rb +26 -0
- data/lib/mongo_mapper_ext/{plugins/carrierwave.rb → carrier_wave/mongo_mapper/plugins/carrier_wave.rb} +0 -19
- data/lib/mongo_mapper_ext/mongo_db.rb +1 -0
- data/lib/{mongo_db_ext/micelaneous.rb → mongo_mapper_ext/mongo_db/upsert.rb} +3 -3
- data/lib/mongo_mapper_ext/mongo_mapper.rb +46 -0
- data/lib/mongo_mapper_ext/{hacks → mongo_mapper}/fixes.rb +0 -0
- data/lib/mongo_mapper_ext/{hacks/active_model.rb → mongo_mapper/hacks.rb} +0 -0
- data/lib/mongo_mapper_ext/mongo_mapper/locales/activemodel/ru.yml +27 -0
- data/lib/mongo_mapper_ext/mongo_mapper/locales/mongo_mapper/en.yml +4 -0
- data/lib/mongo_mapper_ext/mongo_mapper/locales/mongo_mapper/ru.yml +4 -0
- data/lib/mongo_mapper_ext/{logging.rb → mongo_mapper/logging.rb} +1 -1
- data/lib/mongo_mapper_ext/{migration.rb → mongo_mapper/migration.rb} +13 -13
- data/lib/mongo_mapper_ext/{plugins → mongo_mapper/plugins}/attribute_cache.rb +0 -0
- data/lib/mongo_mapper_ext/{plugins → mongo_mapper/plugins}/attribute_convertors.rb +0 -0
- data/lib/mongo_mapper_ext/{plugins → mongo_mapper/plugins}/belongs_to_with_counter_cache.rb +3 -3
- data/lib/mongo_mapper_ext/{plugins → mongo_mapper/plugins}/custom_scope.rb +3 -3
- data/lib/mongo_mapper_ext/{plugins → mongo_mapper/plugins}/db_config.rb +6 -6
- data/lib/mongo_mapper_ext/{plugins → mongo_mapper/plugins}/micelaneous.rb +0 -0
- data/lib/mongo_mapper_ext/{spec.rb → mongo_mapper/spec.rb} +0 -38
- data/lib/mongo_mapper_ext/mongo_mapper/support.rb +13 -0
- data/lib/mongo_mapper_ext/{view_helpers.rb → mongo_mapper/view_helpers.rb} +0 -0
- data/lib/mongo_mapper_ext/rad.rb +4 -0
- data/lib/mongo_mapper_ext/rad/spec.rb +38 -0
- data/readme.md +11 -2
- data/spec/carrier_wave/carrier_wave_spec.rb +61 -0
- data/spec/{carrierwave_spec → carrier_wave/carrier_wave_spec}/plane.jpg +0 -0
- data/spec/carrier_wave/spec_helper.rb +8 -0
- data/spec/mongo_db/spec_helper.rb +4 -0
- data/spec/mongo_db/upsert_spec.rb +20 -0
- data/spec/{attribute_convertors_spec.rb → mongo_mapper/attribute_convertors_spec.rb} +1 -1
- data/spec/mongo_mapper/belongs_to_with_counter_cache_spec.rb +43 -0
- data/spec/{custom_scope_spec.rb → mongo_mapper/custom_scope_spec.rb} +3 -3
- data/spec/mongo_mapper/micelaneous_plugin_spec.rb +39 -0
- data/spec/{micelaneous_spec.rb → mongo_mapper/micelaneous_spec.rb} +1 -20
- data/spec/{migration_spec.rb → mongo_mapper/migration_spec.rb} +3 -3
- data/spec/{mongo_mapper_spec.rb → mongo_mapper/mongo_mapper_spec.rb} +1 -1
- data/spec/mongo_mapper/spec_helper.rb +7 -0
- data/spec/rad/spec_helper.rb +10 -0
- data/spec/{uploading_spec.rb → rad/uploading_spec.rb} +1 -2
- data/spec/{uploading_spec → rad/uploading_spec}/ship.jpg +0 -0
- data/spec/{uploading_spec → rad/uploading_spec}//321/204/320/260/320/270/314/206/320/273 /321/201 /320/277/321/200/320/276/320/261/320/265/320/273/320/260/320/274/320/270.txt +0 -0
- metadata +65 -52
- data/lib/mongo_mapper_ext.rb +0 -49
- data/spec/carrierwave_spec.rb +0 -42
- data/spec/micelaneous_plugin_spec.rb +0 -70
- data/spec/spec_helper.rb +0 -6
data/Rakefile
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'carrierwave'
|
2
|
+
require 'carrierwave/validations/active_model'
|
3
|
+
|
4
|
+
require 'mongo_mapper_ext/mongo_mapper'
|
5
|
+
|
6
|
+
%w(
|
7
|
+
fixes
|
8
|
+
micelaneous
|
9
|
+
mongo_mapper/plugins/carrier_wave
|
10
|
+
).each{|f| require "mongo_mapper_ext/carrier_wave/#{f}"}
|
11
|
+
|
12
|
+
MongoMapper::Document.send :include, MongoMapper::Plugins::CarrierWave
|
@@ -0,0 +1,12 @@
|
|
1
|
+
CarrierWave::SanitizedFile.class_eval do
|
2
|
+
def sanitize_regexp
|
3
|
+
/[^[:word:]\.\-\+\s_]/i
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
CarrierWave::Uploader::Cache.class_eval do
|
8
|
+
def original_filename=(filename)
|
9
|
+
raise CarrierWave::InvalidParameter, "invalid filename" unless filename =~ /\A[[:word:]\.\-\+\s_]+\z/i
|
10
|
+
@original_filename = filename
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# Changing filename format from <version>_<filename_with_extension> to <name>.<version>.<extension>
|
3
|
+
#
|
4
|
+
CarrierWave::Uploader::Versions.class_eval do
|
5
|
+
def full_filename(for_file)
|
6
|
+
name = super
|
7
|
+
if version_name
|
8
|
+
ext = File.extname name
|
9
|
+
base = File.basename name, ext
|
10
|
+
"#{base}.#{version_name}#{ext}"
|
11
|
+
else
|
12
|
+
name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def full_original_filename
|
17
|
+
name = super
|
18
|
+
if version_name
|
19
|
+
ext = File.extname name
|
20
|
+
base = File.basename name, ext
|
21
|
+
"#{base}.#{version_name}#{ext}"
|
22
|
+
else
|
23
|
+
name
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,22 +1,3 @@
|
|
1
|
-
require 'carrierwave/validations/active_model'
|
2
|
-
|
3
|
-
#
|
4
|
-
# Hacks
|
5
|
-
#
|
6
|
-
CarrierWave::SanitizedFile.class_eval do
|
7
|
-
def sanitize_regexp
|
8
|
-
/[^[:word:]\.\-\+\s_]/i
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
CarrierWave::Uploader::Cache.class_eval do
|
13
|
-
def original_filename=(filename)
|
14
|
-
raise CarrierWave::InvalidParameter, "invalid filename" unless filename =~ /\A[[:word:]\.\-\+\s_]+\z/i
|
15
|
-
@original_filename = filename
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
1
|
#
|
21
2
|
# mount_uploader
|
22
3
|
#
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'mongo_mapper_ext/mongo_db/upsert'
|
@@ -3,9 +3,9 @@
|
|
3
3
|
#
|
4
4
|
Mongo::Collection.class_eval do
|
5
5
|
def upsert! query, opt
|
6
|
-
opt.size.must == 1
|
7
|
-
opt.must_be.a Hash
|
8
|
-
opt.values.first.must_be.a Hash
|
6
|
+
# opt.size.must == 1
|
7
|
+
# opt.must_be.a Hash
|
8
|
+
# opt.values.first.must_be.a Hash
|
9
9
|
|
10
10
|
update(query, opt, {upsert: true, safe: true})
|
11
11
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'mongo_mapper_ext/gems'
|
2
|
+
require 'mongo_mapper'
|
3
|
+
|
4
|
+
require 'mongo_mapper_ext/mongo_db'
|
5
|
+
|
6
|
+
%w(
|
7
|
+
fixes
|
8
|
+
hacks
|
9
|
+
support
|
10
|
+
|
11
|
+
migration
|
12
|
+
view_helpers
|
13
|
+
logging
|
14
|
+
|
15
|
+
plugins/attribute_cache
|
16
|
+
plugins/attribute_convertors
|
17
|
+
plugins/belongs_to_with_counter_cache
|
18
|
+
plugins/custom_scope
|
19
|
+
plugins/db_config
|
20
|
+
plugins/micelaneous
|
21
|
+
).each{|file| require "mongo_mapper_ext/mongo_mapper/#{file}"}
|
22
|
+
|
23
|
+
|
24
|
+
#
|
25
|
+
# Default plugins
|
26
|
+
#
|
27
|
+
module MongoMapper::Plugins
|
28
|
+
[CustomScope, AttributeCache, AttributeConvertors, BelongsToWithCounterCache, Micelaneous, DbConfig].each do |plugin|
|
29
|
+
::MongoMapper::Document.send :include, plugin
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
#
|
35
|
+
# Attribute protection
|
36
|
+
#
|
37
|
+
MongoMapper::Document.included do
|
38
|
+
attr_protected :id, :_id, :_type, :created_at, :updated_at
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
#
|
43
|
+
# Locales
|
44
|
+
#
|
45
|
+
dir = __FILE__.dirname
|
46
|
+
I18n.load_path += Dir["#{dir}/mongo_mapper/locales/**/*.{rb,yml}"]
|
File without changes
|
File without changes
|
@@ -0,0 +1,27 @@
|
|
1
|
+
ru:
|
2
|
+
errors:
|
3
|
+
# The default format to use in full error messages.
|
4
|
+
format: "%{attribute} %{message}"
|
5
|
+
|
6
|
+
# The values :model, :attribute and :value are always available for interpolation
|
7
|
+
# The value :count is available when applicable. Can be used for pluralization.
|
8
|
+
messages:
|
9
|
+
inclusion: "недопустимое значение"
|
10
|
+
exclusion: "недопустимо"
|
11
|
+
invalid: "неверно"
|
12
|
+
confirmation: "не совпадает с подтверждением"
|
13
|
+
accepted: "долно быть принято"
|
14
|
+
empty: "не может быть пустым"
|
15
|
+
blank: "не может быть пустым"
|
16
|
+
too_long: "слишком длинно (максимально допустимо %{count})"
|
17
|
+
too_short: "слищком коротко (минимально допустимо %{count})"
|
18
|
+
wrong_length: "неверная длинна (должно быть %{count})"
|
19
|
+
not_a_number: "не номер"
|
20
|
+
not_an_integer: "долно быть целочисленно"
|
21
|
+
greater_than: "должно быть больше чем %{count}"
|
22
|
+
greater_than_or_equal_to: "должно быть больше чем или равно %{count}"
|
23
|
+
equal_to: "должно быть равно %{count}"
|
24
|
+
less_than: "должно быть меньше чем %{count}"
|
25
|
+
less_than_or_equal_to: "должно быть меньше чем или равно %{count}"
|
26
|
+
odd: "должно быть не четно"
|
27
|
+
even: "должно быть четно"
|
@@ -54,7 +54,7 @@ MongoMapper.class_eval do
|
|
54
54
|
|
55
55
|
def self.use_database database_alias
|
56
56
|
database_alias = database_alias.to_s
|
57
|
-
MongoMapper.db_config.
|
57
|
+
raise "unknown database alias :#{database_alias}" unless MongoMapper.db_config.include? database_alias
|
58
58
|
MongoMapper.connection = MongoMapper.connections['default']
|
59
59
|
MongoMapper.database = MongoMapper.db_config['default']['name']
|
60
60
|
end
|
@@ -41,7 +41,7 @@ module MongoMapper::Migration
|
|
41
41
|
def define database_alias, version, &block
|
42
42
|
database_alias = database_alias.to_s
|
43
43
|
|
44
|
-
version.
|
44
|
+
raise "version should be an Integer! (but you provided '#{version}' instad)!" unless version.is_a? Integer
|
45
45
|
definition = MigrationDefinition.new
|
46
46
|
block.call definition
|
47
47
|
definitions[database_alias][version] = definition
|
@@ -51,21 +51,21 @@ module MongoMapper::Migration
|
|
51
51
|
database_alias = database_alias.to_s
|
52
52
|
db = MongoMapper.databases[database_alias]
|
53
53
|
|
54
|
-
if metadata(db)
|
54
|
+
if metadata(db)['version'] == version
|
55
55
|
logger.info "Database '#{database_alias}' already is of #{version} version, no migration needed."
|
56
56
|
return false
|
57
57
|
else
|
58
58
|
logger.info "Migration for '#{database_alias}' Database:"
|
59
59
|
end
|
60
60
|
|
61
|
-
increase_db_version database_alias, db while metadata(db)
|
62
|
-
decrease_db_version database_alias, db while metadata(db)
|
61
|
+
increase_db_version database_alias, db while metadata(db)['version'] < version
|
62
|
+
decrease_db_version database_alias, db while metadata(db)['version'] > version
|
63
63
|
true
|
64
64
|
end
|
65
65
|
|
66
66
|
def metadata db
|
67
67
|
col = db.collection 'db_metadata'
|
68
|
-
|
68
|
+
col.find_one || {'version' => 0}
|
69
69
|
end
|
70
70
|
|
71
71
|
def definitions
|
@@ -75,28 +75,28 @@ module MongoMapper::Migration
|
|
75
75
|
protected
|
76
76
|
def increase_db_version database_alias, db
|
77
77
|
m = metadata(db)
|
78
|
-
migration = definitions[database_alias][m
|
79
|
-
raise "No upgrade for version #{m
|
78
|
+
migration = definitions[database_alias][m['version'] + 1]
|
79
|
+
raise "No upgrade for version #{m['version'] + 1} of '#{database_alias}' Database!" unless migration and migration.up
|
80
80
|
|
81
81
|
migration.up.call db
|
82
82
|
|
83
|
-
m
|
83
|
+
m['version'] += 1
|
84
84
|
update_metadata db, m
|
85
85
|
|
86
|
-
logger.info "Database '#{database_alias}' upgraded to version #{m
|
86
|
+
logger.info "Database '#{database_alias}' upgraded to version #{m['version']}."
|
87
87
|
end
|
88
88
|
|
89
89
|
def decrease_db_version database_alias, db
|
90
90
|
m = metadata(db)
|
91
|
-
migration = definitions[database_alias][m
|
92
|
-
raise "No downgrade for version #{m
|
91
|
+
migration = definitions[database_alias][m['version']]
|
92
|
+
raise "No downgrade for version #{m['version']} of '#{database_alias}' Database!" unless migration and migration.down
|
93
93
|
|
94
94
|
migration.down.call db
|
95
95
|
|
96
|
-
m
|
96
|
+
m['version'] -= 1
|
97
97
|
update_metadata db, m
|
98
98
|
|
99
|
-
logger.info "Database '#{database_alias}' downgraded to version #{m
|
99
|
+
logger.info "Database '#{database_alias}' downgraded to version #{m['version']}."
|
100
100
|
end
|
101
101
|
|
102
102
|
|
File without changes
|
File without changes
|
@@ -9,8 +9,8 @@ module MongoMapper
|
|
9
9
|
# belongs_to :item, counter_cashe: true
|
10
10
|
#
|
11
11
|
def belongs_to association_id, options={}, &extension
|
12
|
-
options.must_not.include :counter_cashe
|
13
|
-
if options.delete(:counter_cache)
|
12
|
+
# options.must_not.include :counter_cashe
|
13
|
+
if options.delete(:counter_cache)
|
14
14
|
association_id = association_id.to_s
|
15
15
|
association_key = "#{association_id}_id"
|
16
16
|
cache_attribute = "#{self.alias.pluralize.underscore}_count"
|
@@ -19,7 +19,7 @@ module MongoMapper
|
|
19
19
|
else
|
20
20
|
association_id.classify.constantize
|
21
21
|
end
|
22
|
-
cache_class.keys.
|
22
|
+
raise "key :#{cache_attribute} not defined on :#{cache_class}!" unless cache_class.keys.include? cache_attribute
|
23
23
|
increase_method_name = "increase_#{cache_class.alias.underscore}_#{self.alias.pluralize.underscore}_counter"
|
24
24
|
decrease_method_name = "decrease_#{cache_class.alias.underscore}_#{self.alias.pluralize.underscore}_counter"
|
25
25
|
|
@@ -21,7 +21,7 @@ module MongoMapper
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def with_exclusive_scope options = {}, &block
|
24
|
-
Thread.current['mm_with_exclusive_scope']
|
24
|
+
raise "exclusive scope already applied, can't apply it twice!" if Thread.current['mm_with_exclusive_scope']
|
25
25
|
|
26
26
|
before = Thread.current['mm_with_exclusive_scope']
|
27
27
|
begin
|
@@ -33,7 +33,7 @@ module MongoMapper
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def with_scope options = {}, &block
|
36
|
-
Thread.current['mm_with_exclusive_scope']
|
36
|
+
raise "exclusive scope already applied, can't apply it twice!" if Thread.current['mm_with_exclusive_scope']
|
37
37
|
|
38
38
|
before = Thread.current['mm_with_scope']
|
39
39
|
begin
|
@@ -47,7 +47,7 @@ module MongoMapper
|
|
47
47
|
|
48
48
|
protected
|
49
49
|
def default_scope options = nil, &block
|
50
|
-
options.
|
50
|
+
raise "invalid option (#{options.inspect})!" if options and !options.is_a?(Hash)
|
51
51
|
self.write_inheritable_attribute(:default_scope, (options || block))
|
52
52
|
end
|
53
53
|
|
@@ -6,7 +6,7 @@ module MongoMapper
|
|
6
6
|
def [](database_alias)
|
7
7
|
database_alias = database_alias.to_s
|
8
8
|
unless connection = super(database_alias)
|
9
|
-
MongoMapper.db_config.
|
9
|
+
raise "unknown database alias :#{database_alias}" unless MongoMapper.db_config.include? database_alias
|
10
10
|
db_options = MongoMapper.db_config[database_alias]
|
11
11
|
connection = Mongo::Connection.new(db_options['host'], db_options['port'], logger: MongoMapper.logger)
|
12
12
|
|
@@ -30,9 +30,11 @@ module MongoMapper
|
|
30
30
|
def [](database_alias)
|
31
31
|
database_alias = database_alias.to_s
|
32
32
|
unless db = super(database_alias)
|
33
|
-
MongoMapper.db_config.
|
33
|
+
raise "unknown database alias :#{database_alias}" unless MongoMapper.db_config.include? database_alias
|
34
34
|
db_options = MongoMapper.db_config[database_alias]
|
35
|
-
|
35
|
+
name = db_options['name']
|
36
|
+
raise "database name should be a string (#{name})!" unless name.is_a?(String)
|
37
|
+
db = MongoMapper.connections[database_alias].db name
|
36
38
|
self[database_alias] = db
|
37
39
|
end
|
38
40
|
return db
|
@@ -70,13 +72,11 @@ module MongoMapper
|
|
70
72
|
# Connect to database_alias specified in config
|
71
73
|
#
|
72
74
|
def use_database database_alias
|
73
|
-
# defer do
|
74
75
|
database_alias = database_alias.to_s
|
75
|
-
MongoMapper.db_config.
|
76
|
+
raise "unknown database alias :#{database_alias}" unless MongoMapper.db_config.include? database_alias
|
76
77
|
|
77
78
|
self.connection MongoMapper.connections[database_alias]
|
78
79
|
set_database_name MongoMapper.db_config[database_alias]['name']
|
79
|
-
# end
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
File without changes
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'mongo_mapper_ext'
|
2
|
-
|
3
1
|
#
|
4
2
|
# disabling :use_database, all tests will use the same :test database.
|
5
3
|
#
|
@@ -64,40 +62,4 @@ if defined? Paperclip
|
|
64
62
|
@logger ||= Logger.new(nil)
|
65
63
|
end
|
66
64
|
end
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
|
-
#
|
71
|
-
# Files
|
72
|
-
#
|
73
|
-
rspec do
|
74
|
-
class << self
|
75
|
-
def with_files
|
76
|
-
path, cache_path = '/tmp/spec_fs', '/tmp/spec_fs_cache'
|
77
|
-
|
78
|
-
before do
|
79
|
-
rad.config.merge!({fs: {path: path, cache_path: cache_path}}, override: true)
|
80
|
-
|
81
|
-
Models::FileUploader.storage :file
|
82
|
-
|
83
|
-
CarrierWave.configure do |config|
|
84
|
-
config.storage = :file
|
85
|
-
config.enable_processing = false
|
86
|
-
|
87
|
-
config.cache_dir = rad.config.fs.cache_path!
|
88
|
-
config.root = rad.config.fs.path!
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
before do
|
93
|
-
path.to_dir.destroy
|
94
|
-
cache_path.to_dir.destroy
|
95
|
-
end
|
96
|
-
|
97
|
-
after do
|
98
|
-
path.to_dir.destroy
|
99
|
-
cache_path.to_dir.destroy
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
65
|
end
|
File without changes
|
data/lib/mongo_mapper_ext/rad.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'mongo_mapper_ext/rad'
|
2
|
+
|
3
|
+
require 'mongo_mapper_ext/mongo_mapper/spec'
|
4
|
+
|
5
|
+
#
|
6
|
+
# Files
|
7
|
+
#
|
8
|
+
rspec do
|
9
|
+
class << self
|
10
|
+
def with_files
|
11
|
+
path, cache_path = '/tmp/spec_fs', '/tmp/spec_fs_cache'
|
12
|
+
|
13
|
+
before do
|
14
|
+
rad.config.merge!({fs: {path: path, cache_path: cache_path}}, override: true)
|
15
|
+
|
16
|
+
Models::FileUploader.storage :file
|
17
|
+
|
18
|
+
CarrierWave.configure do |config|
|
19
|
+
config.storage = :file
|
20
|
+
config.enable_processing = false
|
21
|
+
|
22
|
+
config.cache_dir = rad.config.fs.cache_path!
|
23
|
+
config.root = rad.config.fs.path!
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
before do
|
28
|
+
path.to_dir.destroy
|
29
|
+
cache_path.to_dir.destroy
|
30
|
+
end
|
31
|
+
|
32
|
+
after do
|
33
|
+
path.to_dir.destroy
|
34
|
+
cache_path.to_dir.destroy
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/readme.md
CHANGED
@@ -27,8 +27,8 @@
|
|
27
27
|
m.down{Sample.destroy_all}
|
28
28
|
end
|
29
29
|
|
30
|
-
# Tell it
|
31
|
-
Migration.update(:
|
30
|
+
# Tell it database and version, and it's smart enough to figure out all needed :up or :down
|
31
|
+
Migration.update(:default, 1)
|
32
32
|
|
33
33
|
|
34
34
|
## Custom Scope
|
@@ -70,6 +70,15 @@ File attachments (stored on File System, S3, MongoDB-GridFS)
|
|
70
70
|
|
71
71
|
Attribute Cache, Spec Helpers (auto-clean db before each test).
|
72
72
|
|
73
|
+
# Installation
|
74
|
+
|
75
|
+
gem install 'mongo_mapper_ext'
|
76
|
+
|
77
|
+
require 'mongo_mapper_ext/mongo_mapper'
|
78
|
+
|
79
|
+
# support for CarrierWave is optional
|
80
|
+
# require 'mongo_mapper_ext/carrier_wave'
|
81
|
+
|
73
82
|
# License
|
74
83
|
|
75
84
|
Copyright (c) Alexey Petrushin [http://4ire.net](http://4ire.net), released under the MIT license.
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'carrier_wave/spec_helper'
|
2
|
+
|
3
|
+
describe "MongoMapper & CarrierWave" do
|
4
|
+
with_mongo_mapper
|
5
|
+
with_tmp_spec_dir
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
class PlaneUploader < CarrierWave::Uploader::Base
|
9
|
+
require 'carrierwave/processing/mini_magick'
|
10
|
+
|
11
|
+
include CarrierWave::MiniMagick
|
12
|
+
|
13
|
+
storage :file
|
14
|
+
|
15
|
+
version :icon do
|
16
|
+
process convert: :png
|
17
|
+
process resize_to_fit: [50, 50]
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
attr_accessor :store_dir
|
22
|
+
end
|
23
|
+
|
24
|
+
def store_dir
|
25
|
+
PlaneUploader.store_dir
|
26
|
+
end
|
27
|
+
|
28
|
+
def root
|
29
|
+
PlaneUploader.store_dir
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Plane
|
34
|
+
include MongoMapper::Document
|
35
|
+
|
36
|
+
mount_uploader :image, PlaneUploader
|
37
|
+
end
|
38
|
+
end
|
39
|
+
after(:all){remove_constants :Plane, :PlaneUploader}
|
40
|
+
|
41
|
+
before do
|
42
|
+
PlaneUploader.store_dir = "#{spec_dir}/data"
|
43
|
+
@file = File.new "#{spec_dir}/plane.jpg"
|
44
|
+
end
|
45
|
+
after{@file.close}
|
46
|
+
|
47
|
+
it "basic" do
|
48
|
+
plane = Plane.create! image: @file
|
49
|
+
plane.image.current_path.should =~ /\/plane.jpg/
|
50
|
+
File.should exist("#{spec_dir}/data/plane.jpg")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "path format" do
|
54
|
+
plane = Plane.create! image: @file
|
55
|
+
plane.image.url.should == '/plane.jpg'
|
56
|
+
plane.image.icon.url.should =~ /\/plane\.icon\.jpg/
|
57
|
+
|
58
|
+
plane.image.icon.current_path.should =~ /\/plane\.icon\.jpg/
|
59
|
+
File.should exist("#{spec_dir}/data/plane.icon.jpg")
|
60
|
+
end
|
61
|
+
end
|
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'mongo_db/spec_helper'
|
2
|
+
|
3
|
+
describe "MongoMapper micelaneous" do
|
4
|
+
before do
|
5
|
+
connection = Mongo::Connection.new.db('test')
|
6
|
+
@collection = connection.collection('test')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "upsert should update" do
|
10
|
+
id = @collection.save count: 2
|
11
|
+
@collection.upsert!({_id: id}, :$inc => {count: 1})
|
12
|
+
@collection.find(_id: id).first['count'].should == 3
|
13
|
+
end
|
14
|
+
|
15
|
+
it "upsert should set" do
|
16
|
+
id = @collection.save({})
|
17
|
+
@collection.upsert!({_id: id}, :$inc => {count: 1})
|
18
|
+
@collection.find(_id: id).first['count'].should == 1
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'mongo_mapper/spec_helper'
|
2
|
+
|
3
|
+
describe "BelongsToWithCounterCache" do
|
4
|
+
with_mongo_mapper
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
class ::Post
|
8
|
+
include MongoMapper::Document
|
9
|
+
include MongoMapper::Plugins::Micelaneous
|
10
|
+
|
11
|
+
key :comments_count, Integer, default: 0
|
12
|
+
has_many :comments
|
13
|
+
end
|
14
|
+
|
15
|
+
class ::Comment
|
16
|
+
include MongoMapper::Document
|
17
|
+
include MongoMapper::Plugins::Micelaneous
|
18
|
+
|
19
|
+
key :post_id
|
20
|
+
belongs_to :post, counter_cache: true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
after(:all){remove_constants :Post, :Comment}
|
24
|
+
|
25
|
+
it "should increase count of comments" do
|
26
|
+
post = Post.create!
|
27
|
+
comment = post.comments.create!
|
28
|
+
|
29
|
+
post.reload
|
30
|
+
post.comments_count.should == 1
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should decrease count of comments" do
|
34
|
+
post = Post.create!
|
35
|
+
comment = post.comments.create!
|
36
|
+
post.reload
|
37
|
+
post.comments_count.should == 1
|
38
|
+
|
39
|
+
comment.destroy
|
40
|
+
post.reload
|
41
|
+
post.comments_count.should == 0
|
42
|
+
end
|
43
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'spec_helper'
|
1
|
+
require 'mongo_mapper/spec_helper'
|
2
2
|
|
3
3
|
describe "MongoMapper Default Scope" do
|
4
4
|
with_mongo_mapper
|
@@ -72,13 +72,13 @@ describe "MongoMapper Default Scope" do
|
|
72
72
|
ScopeSample.with_exclusive_scope do
|
73
73
|
ScopeSample.with_exclusive_scope{}
|
74
74
|
end
|
75
|
-
}.should raise_error(
|
75
|
+
}.should raise_error(/exclusive scope already applied/)
|
76
76
|
|
77
77
|
-> {
|
78
78
|
ScopeSample.with_exclusive_scope do
|
79
79
|
ScopeSample.with_scope{}
|
80
80
|
end
|
81
|
-
}.should raise_error(
|
81
|
+
}.should raise_error(/exclusive scope already applied/)
|
82
82
|
end
|
83
83
|
|
84
84
|
it "with_exclusive_scope should clear other scopes" do
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'mongo_mapper/spec_helper'
|
2
|
+
|
3
|
+
describe "Micelaneous" do
|
4
|
+
with_mongo_mapper
|
5
|
+
|
6
|
+
after(:all){remove_constants :Article, :Post, :Namespace}
|
7
|
+
|
8
|
+
describe "model_name" do
|
9
|
+
it "basic" do
|
10
|
+
class Article
|
11
|
+
include MongoMapper::Document
|
12
|
+
include MongoMapper::Plugins::Micelaneous
|
13
|
+
end
|
14
|
+
|
15
|
+
Article.model_name.should == "Article"
|
16
|
+
Article.model_name "SuperArticle"
|
17
|
+
Article.model_name.should == "SuperArticle"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "by default should be initialized from class alias" do
|
21
|
+
class ::Post
|
22
|
+
include MongoMapper::Document
|
23
|
+
include MongoMapper::Plugins::Micelaneous
|
24
|
+
|
25
|
+
self.alias 'PostAlias'
|
26
|
+
end
|
27
|
+
|
28
|
+
module ::Namespace
|
29
|
+
class Post
|
30
|
+
include MongoMapper::Document
|
31
|
+
include MongoMapper::Plugins::Micelaneous
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Post.model_name.should == 'PostAlias'
|
36
|
+
Namespace::Post.model_name.should == 'Post' # not the Namespace::Post
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,29 +1,10 @@
|
|
1
|
-
require 'spec_helper'
|
1
|
+
require 'mongo_mapper/spec_helper'
|
2
2
|
|
3
3
|
describe "MongoMapper micelaneous" do
|
4
4
|
with_mongo_mapper
|
5
5
|
|
6
6
|
after(:all){remove_constants %w(UpsertSample AsStringSample TranslationCheck)}
|
7
7
|
|
8
|
-
describe "Collection extensions" do
|
9
|
-
before do
|
10
|
-
connection = Mongo::Connection.new.db('test')
|
11
|
-
@collection = connection.collection('test')
|
12
|
-
end
|
13
|
-
|
14
|
-
it "upsert should update" do
|
15
|
-
id = @collection.save count: 2
|
16
|
-
@collection.upsert!({_id: id}, :$inc => {count: 1})
|
17
|
-
@collection.find(_id: id).first['count'].should == 3
|
18
|
-
end
|
19
|
-
|
20
|
-
it "upsert should set" do
|
21
|
-
id = @collection.save({})
|
22
|
-
@collection.upsert!({_id: id}, :$inc => {count: 1})
|
23
|
-
@collection.find(_id: id).first['count'].should == 1
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
8
|
describe "i18n" do
|
28
9
|
it "should translate error messages" do
|
29
10
|
class ::TranslationCheck
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'spec_helper'
|
1
|
+
require 'mongo_mapper/spec_helper'
|
2
2
|
|
3
3
|
describe "MongoMapper Migration" do
|
4
4
|
with_mongo_mapper
|
@@ -51,7 +51,7 @@ describe "MongoMapper Migration" do
|
|
51
51
|
|
52
52
|
Migration.update(:global, 1).should be_true
|
53
53
|
Sample.count.should == 1
|
54
|
-
Migration.metadata(MongoMapper.databases[:global])
|
54
|
+
Migration.metadata(MongoMapper.databases[:global])['version'].should == 1
|
55
55
|
end
|
56
56
|
|
57
57
|
it "decrease_db_version" do
|
@@ -64,7 +64,7 @@ describe "MongoMapper Migration" do
|
|
64
64
|
|
65
65
|
Migration.update(:global, 0).should be_true
|
66
66
|
Sample.count.should == 0
|
67
|
-
Migration.metadata(MongoMapper.databases[:global])
|
67
|
+
Migration.metadata(MongoMapper.databases[:global])['version'].should == 0
|
68
68
|
end
|
69
69
|
|
70
70
|
end
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_mapper_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ default_executable:
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mongo_mapper
|
17
|
-
requirement: &
|
17
|
+
requirement: &2795840 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - =
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 0.9.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2795840
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: carrierwave
|
28
|
-
requirement: &
|
28
|
+
requirement: &2795620 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - =
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 0.5.3
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2795620
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: i18n
|
39
|
-
requirement: &
|
39
|
+
requirement: &2795380 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - =
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 0.5.0
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2795380
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: activesupport
|
50
|
-
requirement: &
|
50
|
+
requirement: &2795160 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - =
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 3.0.7
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2795160
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: activemodel
|
61
|
-
requirement: &
|
61
|
+
requirement: &2794940 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - =
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: 3.0.7
|
67
67
|
type: :runtime
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *2794940
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: bson
|
72
|
-
requirement: &
|
72
|
+
requirement: &2794690 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - =
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: 1.3.0
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *2794690
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: bson_ext
|
83
|
-
requirement: &
|
83
|
+
requirement: &2794480 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - =
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: 1.3.0
|
89
89
|
type: :runtime
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *2794480
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: mongo
|
94
|
-
requirement: &
|
94
|
+
requirement: &2794260 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - =
|
@@ -99,10 +99,10 @@ dependencies:
|
|
99
99
|
version: 1.3.0
|
100
100
|
type: :runtime
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *2794260
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: plucky
|
105
|
-
requirement: &
|
105
|
+
requirement: &2794040 !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|
108
108
|
- - =
|
@@ -110,10 +110,10 @@ dependencies:
|
|
110
110
|
version: 0.3.6
|
111
111
|
type: :runtime
|
112
112
|
prerelease: false
|
113
|
-
version_requirements: *
|
113
|
+
version_requirements: *2794040
|
114
114
|
- !ruby/object:Gem::Dependency
|
115
115
|
name: jnunemaker-validatable
|
116
|
-
requirement: &
|
116
|
+
requirement: &2793820 !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
119
119
|
- - =
|
@@ -121,10 +121,10 @@ dependencies:
|
|
121
121
|
version: 1.8.4
|
122
122
|
type: :runtime
|
123
123
|
prerelease: false
|
124
|
-
version_requirements: *
|
124
|
+
version_requirements: *2793820
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: mini_magick
|
127
|
-
requirement: &
|
127
|
+
requirement: &2793610 !ruby/object:Gem::Requirement
|
128
128
|
none: false
|
129
129
|
requirements:
|
130
130
|
- - =
|
@@ -132,10 +132,10 @@ dependencies:
|
|
132
132
|
version: 3.2.1
|
133
133
|
type: :runtime
|
134
134
|
prerelease: false
|
135
|
-
version_requirements: *
|
135
|
+
version_requirements: *2793610
|
136
136
|
- !ruby/object:Gem::Dependency
|
137
137
|
name: subexec
|
138
|
-
requirement: &
|
138
|
+
requirement: &2793400 !ruby/object:Gem::Requirement
|
139
139
|
none: false
|
140
140
|
requirements:
|
141
141
|
- - =
|
@@ -143,7 +143,7 @@ dependencies:
|
|
143
143
|
version: 0.0.4
|
144
144
|
type: :runtime
|
145
145
|
prerelease: false
|
146
|
-
version_requirements: *
|
146
|
+
version_requirements: *2793400
|
147
147
|
description:
|
148
148
|
email:
|
149
149
|
executables: []
|
@@ -152,38 +152,51 @@ extra_rdoc_files: []
|
|
152
152
|
files:
|
153
153
|
- Rakefile
|
154
154
|
- readme.md
|
155
|
-
- lib/
|
155
|
+
- lib/mongo_mapper_ext/carrier_wave/fixes.rb
|
156
|
+
- lib/mongo_mapper_ext/carrier_wave/micelaneous.rb
|
157
|
+
- lib/mongo_mapper_ext/carrier_wave/mongo_mapper/plugins/carrier_wave.rb
|
158
|
+
- lib/mongo_mapper_ext/carrier_wave.rb
|
156
159
|
- lib/mongo_mapper_ext/gems.rb
|
157
|
-
- lib/mongo_mapper_ext/
|
158
|
-
- lib/mongo_mapper_ext/
|
159
|
-
- lib/mongo_mapper_ext/
|
160
|
-
- lib/mongo_mapper_ext/
|
160
|
+
- lib/mongo_mapper_ext/mongo_db/upsert.rb
|
161
|
+
- lib/mongo_mapper_ext/mongo_db.rb
|
162
|
+
- lib/mongo_mapper_ext/mongo_mapper/fixes.rb
|
163
|
+
- lib/mongo_mapper_ext/mongo_mapper/hacks.rb
|
164
|
+
- lib/mongo_mapper_ext/mongo_mapper/locales/activemodel/ru.yml
|
165
|
+
- lib/mongo_mapper_ext/mongo_mapper/locales/mongo_mapper/en.yml
|
166
|
+
- lib/mongo_mapper_ext/mongo_mapper/locales/mongo_mapper/ru.yml
|
167
|
+
- lib/mongo_mapper_ext/mongo_mapper/logging.rb
|
168
|
+
- lib/mongo_mapper_ext/mongo_mapper/migration.rb
|
169
|
+
- lib/mongo_mapper_ext/mongo_mapper/plugins/attribute_cache.rb
|
170
|
+
- lib/mongo_mapper_ext/mongo_mapper/plugins/attribute_convertors.rb
|
171
|
+
- lib/mongo_mapper_ext/mongo_mapper/plugins/belongs_to_with_counter_cache.rb
|
172
|
+
- lib/mongo_mapper_ext/mongo_mapper/plugins/custom_scope.rb
|
173
|
+
- lib/mongo_mapper_ext/mongo_mapper/plugins/db_config.rb
|
174
|
+
- lib/mongo_mapper_ext/mongo_mapper/plugins/micelaneous.rb
|
175
|
+
- lib/mongo_mapper_ext/mongo_mapper/spec.rb
|
176
|
+
- lib/mongo_mapper_ext/mongo_mapper/support.rb
|
177
|
+
- lib/mongo_mapper_ext/mongo_mapper/view_helpers.rb
|
161
178
|
- lib/mongo_mapper_ext/mongo_mapper.rb
|
162
|
-
- lib/mongo_mapper_ext/plugins/attribute_cache.rb
|
163
|
-
- lib/mongo_mapper_ext/plugins/attribute_convertors.rb
|
164
|
-
- lib/mongo_mapper_ext/plugins/belongs_to_with_counter_cache.rb
|
165
|
-
- lib/mongo_mapper_ext/plugins/carrierwave.rb
|
166
|
-
- lib/mongo_mapper_ext/plugins/custom_scope.rb
|
167
|
-
- lib/mongo_mapper_ext/plugins/db_config.rb
|
168
|
-
- lib/mongo_mapper_ext/plugins/micelaneous.rb
|
169
179
|
- lib/mongo_mapper_ext/rad/file_uploader.rb
|
180
|
+
- lib/mongo_mapper_ext/rad/spec.rb
|
170
181
|
- lib/mongo_mapper_ext/rad.rb
|
171
|
-
- lib/mongo_mapper_ext/spec.rb
|
172
182
|
- lib/mongo_mapper_ext/tasks.rb
|
173
|
-
-
|
174
|
-
-
|
175
|
-
- spec/
|
176
|
-
- spec/
|
177
|
-
- spec/
|
178
|
-
- spec/
|
179
|
-
- spec/
|
180
|
-
- spec/
|
181
|
-
- spec/
|
182
|
-
- spec/
|
183
|
-
- spec/
|
184
|
-
- spec/
|
185
|
-
- spec/
|
186
|
-
- spec/
|
183
|
+
- spec/carrier_wave/carrier_wave_spec/plane.jpg
|
184
|
+
- spec/carrier_wave/carrier_wave_spec.rb
|
185
|
+
- spec/carrier_wave/spec_helper.rb
|
186
|
+
- spec/mongo_db/spec_helper.rb
|
187
|
+
- spec/mongo_db/upsert_spec.rb
|
188
|
+
- spec/mongo_mapper/attribute_convertors_spec.rb
|
189
|
+
- spec/mongo_mapper/belongs_to_with_counter_cache_spec.rb
|
190
|
+
- spec/mongo_mapper/custom_scope_spec.rb
|
191
|
+
- spec/mongo_mapper/micelaneous_plugin_spec.rb
|
192
|
+
- spec/mongo_mapper/micelaneous_spec.rb
|
193
|
+
- spec/mongo_mapper/migration_spec.rb
|
194
|
+
- spec/mongo_mapper/mongo_mapper_spec.rb
|
195
|
+
- spec/mongo_mapper/spec_helper.rb
|
196
|
+
- spec/rad/spec_helper.rb
|
197
|
+
- spec/rad/uploading_spec/ship.jpg
|
198
|
+
- spec/rad/uploading_spec/файл с пробелами.txt
|
199
|
+
- spec/rad/uploading_spec.rb
|
187
200
|
has_rdoc: true
|
188
201
|
homepage: http://github.com/alexeypetrushin/mongo_mapper
|
189
202
|
licenses: []
|
data/lib/mongo_mapper_ext.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'mongo_mapper_ext/gems'
|
2
|
-
|
3
|
-
require 'mongo_mapper'
|
4
|
-
require 'carrierwave'
|
5
|
-
|
6
|
-
%w(
|
7
|
-
micelaneous
|
8
|
-
).each{|file| require "mongo_db_ext/#{file}"}
|
9
|
-
|
10
|
-
%w(
|
11
|
-
hacks/fixes
|
12
|
-
hacks/active_model
|
13
|
-
|
14
|
-
migration
|
15
|
-
mongo_mapper
|
16
|
-
view_helpers
|
17
|
-
logging
|
18
|
-
|
19
|
-
plugins/db_config
|
20
|
-
plugins/custom_scope
|
21
|
-
plugins/attribute_cache
|
22
|
-
plugins/carrierwave
|
23
|
-
plugins/attribute_convertors
|
24
|
-
plugins/micelaneous
|
25
|
-
plugins/belongs_to_with_counter_cache
|
26
|
-
).each{|file| require "mongo_mapper_ext/#{file}"}
|
27
|
-
|
28
|
-
#
|
29
|
-
# Default plugins and settings
|
30
|
-
#
|
31
|
-
module MongoMapper::Plugins
|
32
|
-
[CustomScope, AttributeCache, AttributeConvertors, BelongsToWithCounterCache, Micelaneous, CarrierWave, DbConfig].each do |plugin|
|
33
|
-
::MongoMapper::Document.send :include, plugin
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
#
|
38
|
-
# Attribute protection
|
39
|
-
#
|
40
|
-
MongoMapper::Document.included do
|
41
|
-
attr_protected :id, :_id, :_type, :created_at, :updated_at
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
#
|
46
|
-
# Locales
|
47
|
-
#
|
48
|
-
dir = File.expand_path("#{__FILE__}/../..")
|
49
|
-
I18n.load_path += Dir["#{dir}/locales/**/*.{rb,yml}"]
|
data/spec/carrierwave_spec.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "MongoMapper & CarrierWave" do
|
4
|
-
with_mongo_mapper
|
5
|
-
with_tmp_spec_dir
|
6
|
-
|
7
|
-
before :all do
|
8
|
-
class PlaneUploader < CarrierWave::Uploader::Base
|
9
|
-
storage :file
|
10
|
-
|
11
|
-
class << self
|
12
|
-
attr_accessor :store_dir
|
13
|
-
end
|
14
|
-
|
15
|
-
def store_dir
|
16
|
-
self.class.store_dir
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class Plane
|
21
|
-
include MongoMapper::Document
|
22
|
-
|
23
|
-
mount_uploader :image, PlaneUploader
|
24
|
-
end
|
25
|
-
end
|
26
|
-
after(:all){remove_constants :Plane, :PlaneUploader}
|
27
|
-
|
28
|
-
before do
|
29
|
-
PlaneUploader.store_dir = "#{spec_dir}/data"
|
30
|
-
end
|
31
|
-
|
32
|
-
it "basic" do
|
33
|
-
plane = Plane.new
|
34
|
-
File.open "#{spec_dir}/plane.jpg" do |f|
|
35
|
-
plane.image = f
|
36
|
-
plane.save!
|
37
|
-
end
|
38
|
-
|
39
|
-
plane.image.current_path.should == '/tmp/carrierwave_spec/data/plane.jpg'
|
40
|
-
File.should exist("#{spec_dir}/data/plane.jpg")
|
41
|
-
end
|
42
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "MongoMapper Default Scope" do
|
4
|
-
with_mongo_mapper
|
5
|
-
|
6
|
-
before :all do
|
7
|
-
class ::Post
|
8
|
-
include MongoMapper::Document
|
9
|
-
include MongoMapper::Plugins::Micelaneous
|
10
|
-
|
11
|
-
key :comments_count, Integer, default: 0
|
12
|
-
has_many :comments
|
13
|
-
end
|
14
|
-
|
15
|
-
class ::Comment
|
16
|
-
include MongoMapper::Document
|
17
|
-
include MongoMapper::Plugins::Micelaneous
|
18
|
-
|
19
|
-
key :post_id
|
20
|
-
belongs_to :post, counter_cache: true
|
21
|
-
end
|
22
|
-
end
|
23
|
-
after(:all){remove_constants %w{Post Comment Post2 Namespace}}
|
24
|
-
|
25
|
-
it "should increase count of comments" do
|
26
|
-
post = Post.create!
|
27
|
-
comment = post.comments.create!
|
28
|
-
|
29
|
-
post.reload
|
30
|
-
post.comments_count.should == 1
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should decrease count of comments" do
|
34
|
-
post = Post.create!
|
35
|
-
comment = post.comments.create!
|
36
|
-
post.reload
|
37
|
-
post.comments_count.should == 1
|
38
|
-
|
39
|
-
comment.destroy
|
40
|
-
post.reload
|
41
|
-
post.comments_count.should == 0
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "model_name" do
|
45
|
-
it "basic" do
|
46
|
-
Post.model_name.should == "Post"
|
47
|
-
Post.model_name "SuperPost"
|
48
|
-
Post.model_name.should == "SuperPost"
|
49
|
-
end
|
50
|
-
|
51
|
-
it "by default should be initialized from class alias" do
|
52
|
-
class ::Post2
|
53
|
-
include MongoMapper::Document
|
54
|
-
include MongoMapper::Plugins::Micelaneous
|
55
|
-
|
56
|
-
self.alias 'PostAlias'
|
57
|
-
end
|
58
|
-
|
59
|
-
module ::Namespace
|
60
|
-
class Post
|
61
|
-
include MongoMapper::Document
|
62
|
-
include MongoMapper::Plugins::Micelaneous
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
Post2.model_name.should == 'PostAlias'
|
67
|
-
Namespace::Post.model_name.should == 'Post' # not the Namespace::Post
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|