rails-ext 0.2.15 → 0.2.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.git/index +0 -0
  2. data/.git/logs/HEAD +2 -0
  3. data/.git/logs/refs/heads/master +2 -0
  4. data/.git/logs/refs/remotes/origin/master +2 -0
  5. data/.git/objects/0d/b63ec7380f5132ca02be93c82f5295e33c10a9 +0 -0
  6. data/.git/objects/1b/83175202b0bdd9e8aac50c186533c1730aa220 +5 -0
  7. data/.git/objects/28/8e20f19c6662b1425e0a0797ae443f7eddcc4a +0 -0
  8. data/.git/objects/3e/f23cf310c5eebac930a19d36a0561dd362d3ee +0 -0
  9. data/.git/objects/47/28fde4426b545c73552bd5e0f79296a2b4be19 +0 -0
  10. data/.git/objects/52/5fcb274029ec36780b264166ea3d487d968997 +0 -0
  11. data/.git/objects/5c/95be85f2a2a984454fed4941a5ae00062634c5 +0 -0
  12. data/.git/objects/67/2396778b142df8b0b7ab212b7564039c48cf39 +0 -0
  13. data/.git/objects/73/667b7ae341d478513ba0bd6ec8af0aa1f62f0d +0 -0
  14. data/.git/objects/85/fd531f7352ad8f5ac030eed2204a662dd10a66 +0 -0
  15. data/.git/objects/8e/a47de58a27dd343b3ecd3dd5e0fab88e268a72 +0 -0
  16. data/.git/objects/a3/84715546f6a11dc7d56a32784dbdd5d7d92e8e +0 -0
  17. data/.git/objects/ab/6b7d6c5c5fee246e184a58448682b73b574d6b +0 -0
  18. data/.git/objects/b5/33c1c1bca9eae5b7e75c639fff8ec2c2f9fea1 +1 -0
  19. data/.git/objects/c5/208dea612df35fb84ceeda0649c103c32e2240 +2 -0
  20. data/.git/objects/c5/3b27c9641ea1c2aed192672b67ba8c4034b2ad +0 -0
  21. data/.git/objects/c6/9db405143490c407206cf8afd7537a49ea30b2 +0 -0
  22. data/.git/objects/ca/a9edd4de82aa3abec99946e92da9225efb83bc +0 -0
  23. data/.git/objects/e6/4d9b4d86a001e4f882a9842a8dd4368001c470 +0 -0
  24. data/.git/objects/f6/0fd8c2582e0f7688877f12f78ddb97a291046c +0 -0
  25. data/.git/objects/f7/b177b2c6b25dd886d23d6be87bcf802af9b513 +0 -0
  26. data/.git/objects/fa/854db299be87a6e6a65d906e7c2f9b122d9980 +0 -0
  27. data/.git/objects/fc/022a0a2ed82b2361292833c0cb90f996aae858 +0 -0
  28. data/.git/objects/fc/bf66b949d823f884d1aff2f3e192943cb195a2 +0 -0
  29. data/.git/refs/heads/master +1 -1
  30. data/.git/refs/remotes/origin/master +1 -1
  31. data/Rakefile +1 -1
  32. data/lib/mongo_mapper_ext/fixes.rb +9 -0
  33. data/lib/mongo_mapper_ext/migration.rb +109 -0
  34. data/lib/mongo_mapper_ext/mongo_mapper.rb +160 -0
  35. data/lib/mongo_mapper_ext/multitenant.rb +8 -0
  36. data/lib/mongo_mapper_ext/object_id.rb +12 -0
  37. data/lib/mongo_mapper_ext/spec_helper.rb +14 -0
  38. data/lib/mongo_mapper_ext/view_helpers.rb +20 -0
  39. data/lib/mongo_mapper_ext.rb +5 -0
  40. data/lib/rails_ext/config_files.rb +1 -1
  41. data/lib/rails_ext.rb +1 -1
  42. data/spec/mongo_mapper_migration_spec.rb +137 -0
  43. metadata +35 -4
  44. data/lib/rails_ext/mongo_mapper.rb +0 -48
  45. data/lib/rails_ext/mongo_mapper_spec_helper.rb +0 -8
data/.git/index CHANGED
Binary file
data/.git/logs/HEAD CHANGED
@@ -29,3 +29,5 @@ fec19d13244f6b439e234e1af2e2e6d1f886b2fb 5f483b0c41645f8882f549c1c6d0274bb592140
29
29
  a0d595c78f280787659a2a4400f5d63578b53dce e7e790ff7c580a636d0de69956834c9b47ad771b alex <alex@amac.local> 1266000303 +0300 commit: upd
30
30
  e7e790ff7c580a636d0de69956834c9b47ad771b a59472e8ecb5d06647adeec11ae931b956508191 alex <alex@amac.local> 1266630067 +0300 commit: upd
31
31
  a59472e8ecb5d06647adeec11ae931b956508191 08f5dafa9123b7f8d1f22a796c4cba4a4063ad0d alex <alex@amac.local> 1266772739 +0300 commit: upd
32
+ 08f5dafa9123b7f8d1f22a796c4cba4a4063ad0d b533c1c1bca9eae5b7e75c639fff8ec2c2f9fea1 alex <alex@amac.local> 1267048597 +0300 commit: refactor mongo connections and add multitenant migration with specs
33
+ b533c1c1bca9eae5b7e75c639fff8ec2c2f9fea1 288e20f19c6662b1425e0a0797ae443f7eddcc4a alex <alex@amac.local> 1267051247 +0300 commit: upd
@@ -29,3 +29,5 @@ fec19d13244f6b439e234e1af2e2e6d1f886b2fb 5f483b0c41645f8882f549c1c6d0274bb592140
29
29
  a0d595c78f280787659a2a4400f5d63578b53dce e7e790ff7c580a636d0de69956834c9b47ad771b alex <alex@amac.local> 1266000303 +0300 commit: upd
30
30
  e7e790ff7c580a636d0de69956834c9b47ad771b a59472e8ecb5d06647adeec11ae931b956508191 alex <alex@amac.local> 1266630067 +0300 commit: upd
31
31
  a59472e8ecb5d06647adeec11ae931b956508191 08f5dafa9123b7f8d1f22a796c4cba4a4063ad0d alex <alex@amac.local> 1266772739 +0300 commit: upd
32
+ 08f5dafa9123b7f8d1f22a796c4cba4a4063ad0d b533c1c1bca9eae5b7e75c639fff8ec2c2f9fea1 alex <alex@amac.local> 1267048597 +0300 commit: refactor mongo connections and add multitenant migration with specs
33
+ b533c1c1bca9eae5b7e75c639fff8ec2c2f9fea1 288e20f19c6662b1425e0a0797ae443f7eddcc4a alex <alex@amac.local> 1267051247 +0300 commit: upd
@@ -27,3 +27,5 @@ fec19d13244f6b439e234e1af2e2e6d1f886b2fb 5f483b0c41645f8882f549c1c6d0274bb592140
27
27
  a0d595c78f280787659a2a4400f5d63578b53dce e7e790ff7c580a636d0de69956834c9b47ad771b alex <alex@amac.local> 1266000307 +0300 update by push
28
28
  e7e790ff7c580a636d0de69956834c9b47ad771b a59472e8ecb5d06647adeec11ae931b956508191 alex <alex@amac.local> 1266630072 +0300 update by push
29
29
  a59472e8ecb5d06647adeec11ae931b956508191 08f5dafa9123b7f8d1f22a796c4cba4a4063ad0d alex <alex@amac.local> 1266772749 +0300 update by push
30
+ 08f5dafa9123b7f8d1f22a796c4cba4a4063ad0d b533c1c1bca9eae5b7e75c639fff8ec2c2f9fea1 alex <alex@amac.local> 1267048616 +0300 update by push
31
+ b533c1c1bca9eae5b7e75c639fff8ec2c2f9fea1 288e20f19c6662b1425e0a0797ae443f7eddcc4a alex <alex@amac.local> 1267051254 +0300 update by push
@@ -0,0 +1,5 @@
1
+ xuRKo�@�ٿb�TXr�*�E�� �j
2
+ n6�f��JD-c"U W���Y2�L���0�����WU���w��X
3
+ &�^�rcK�s��#���Ŝ��Cs�1W�?�B�VkJ���碬`J9��B�nE�$M����&�
4
+ Z�q]�*O�B��
5
+ \����������e4�u>�Lg���C8�#�{\v���C�ӫ��!�t���Nm�|�v_��6|�A���E��"�rJ^���*��D�\�����$�mx{=�\����@��������6 �F���'͉�#IX���?�Gd����R
@@ -0,0 +1 @@
1
+ x��Aj�0E��)f_(cY�%�W���%[�=~������<��^kd<��C��D�ip�� k�͚l�3����7�qh�!���8�e[sHs6k�be��e� q���~v��ˋ_���� �O��_�Wz�y�����7�C3d<?jo�N�[S����!%��}��
@@ -0,0 +1,2 @@
1
+ xM�K
2
+ �@����S�MN!�;4����1���qp�(�^e|E����%�.ֳֻU}�pI��42c +mPQ��#Av4Q"�r�|�FY4}w0�c�r��#�im�`M���4[�}ʵ�,��|��[ql0�Xd�
@@ -1 +1 @@
1
- 08f5dafa9123b7f8d1f22a796c4cba4a4063ad0d
1
+ 288e20f19c6662b1425e0a0797ae443f7eddcc4a
@@ -1 +1 @@
1
- 08f5dafa9123b7f8d1f22a796c4cba4a4063ad0d
1
+ 288e20f19c6662b1425e0a0797ae443f7eddcc4a
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ require 'fileutils'
18
18
 
19
19
  spec = Gem::Specification.new do |s|
20
20
  s.name = "rails-ext"
21
- s.version = "0.2.15"
21
+ s.version = "0.2.16"
22
22
  s.summary = "Set of common Ruby on Rails extensions"
23
23
  s.description = "Set of common Ruby on Rails extensions"
24
24
  s.author = "Alexey Petrushin"
@@ -0,0 +1,9 @@
1
+ MongoMapper::Plugins::Keys::Key.class_eval do
2
+ def get(value)
3
+ if value.nil? && !default_value.nil?
4
+ return default_value.respond_to?(:clone) ? default_value.clone : default_value
5
+ end
6
+
7
+ type.from_mongo(value)
8
+ end
9
+ end
@@ -0,0 +1,109 @@
1
+ module MongoMapper::Migration
2
+ class MigrationDefinition
3
+ def upgrade &block
4
+ if block
5
+ @upgrade = block
6
+ else
7
+ @upgrade
8
+ end
9
+ end
10
+ alias_method :up, :upgrade
11
+
12
+ def downgrade &block
13
+ if block
14
+ @downgrade = block
15
+ else
16
+ @downgrade
17
+ end
18
+ end
19
+ alias_method :down, :downgrade
20
+ end
21
+
22
+ class << self
23
+ def define_migration version, &block
24
+ version.should! :be_a, Integer
25
+ definition = MigrationDefinition.new
26
+ block.call definition
27
+ migration_definitions[version] = definition
28
+ end
29
+
30
+ def define_global_migration version, &block
31
+ version.should! :be_a, Integer
32
+ definition = MigrationDefinition.new
33
+ block.call definition
34
+ global_migration_definitions[version] = definition
35
+ end
36
+
37
+ def update_global_database_to version
38
+ puts "Migration for Global Database:"
39
+ update_database MongoMapper.global_database, global_migration_definitions, version
40
+ end
41
+
42
+ def update_database_to version
43
+ puts "Migration for Accounts Databases:"
44
+ results = {}
45
+ MongoMapper.accounts_names.each do |account_name|
46
+ MongoMapper.account_database account_name do |db|
47
+ result = update_database db, migration_definitions, version
48
+ results[db.name] = result
49
+ end
50
+ end
51
+ results
52
+ end
53
+
54
+ def metadata db
55
+ col = db.collection 'db_metadata'
56
+ metadata = (col.find_one || {:version => 0}).to_openobject
57
+ end
58
+
59
+ def global_migration_definitions; @global_migration_definitions ||= [] end
60
+ def migration_definitions; @migration_definitions ||= [] end
61
+
62
+ protected
63
+ def increase_db_version migration_definitions, db
64
+ m = metadata(db)
65
+ migration = migration_definitions[m.version + 1]
66
+ raise "No upgrade for version #{m.version + 1}" unless migration and migration.up
67
+
68
+ migration.up.call
69
+
70
+ m.version += 1
71
+ update_metadata db, m
72
+
73
+ puts "Database #{db.name} upgraded to version #{m.version}"
74
+ end
75
+
76
+ def decrease_db_version migration_definitions, db
77
+ m = metadata(db)
78
+ migration = migration_definitions[m.version]
79
+ raise "No downgrade for version #{m.version}" unless migration and migration.down
80
+
81
+ migration.down.call
82
+
83
+ m.version -= 1
84
+ update_metadata db, m
85
+
86
+ puts "Database #{db.name} downgraded to version #{m.version}"
87
+ end
88
+
89
+ def update_database db, migrations, version
90
+ if metadata(db).version == version
91
+ puts "Database #{db.name} already is of #{version} version, no migration needed"
92
+ return false
93
+ end
94
+
95
+ increase_db_version migrations, db while metadata(db).version < version
96
+ decrease_db_version migrations, db while metadata(db).version > version
97
+ true
98
+ end
99
+
100
+ def update_metadata db, metadata
101
+ col = db.collection 'db_metadata'
102
+ col.save metadata.to_hash
103
+ end
104
+
105
+ def reset
106
+ [global_migration_definitions, migration_definitions].every.clear
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,160 @@
1
+ MongoMapper.class_eval do
2
+ const_set :ACCOUNT_TOKEN, ':account'
3
+ class << self
4
+ #
5
+ # Config
6
+ #
7
+ attr_accessor :custom_config
8
+
9
+ def config
10
+ unless @config
11
+ @config = if defined?(Rails)
12
+ global_database = DATABASE["#{Rails.env}!"].global_database!
13
+ accounts_database = DATABASE["#{Rails.env}!"].accounts_database!
14
+ config = {
15
+ :global_database => {
16
+ :name => global_database.name!,
17
+ :host => global_database.host(nil),
18
+ :port => global_database.port(nil)
19
+ }.to_openobject,
20
+ :accounts_database => {
21
+ :name => accounts_database.name!,
22
+ :host => accounts_database.host(nil),
23
+ :port => accounts_database.port(nil)
24
+ }.to_openobject
25
+ }.to_openobject
26
+ else
27
+ raise "If you don't using Rails you must override this method and provide your own custom_config!" if custom_config.blank?
28
+ custom_config
29
+ end
30
+
31
+ # Global database should't looks the same as Account database. We need to distinguish it by names!
32
+ db_pattern = accounts_database.name
33
+ re = Regexp.new(db_pattern.gsub(MongoMapper::ACCOUNT_TOKEN, '.+'))
34
+ raise "Global Database Name shouldn't be similar to Account Database Name!" if global_database.name =~ re
35
+ end
36
+ @config
37
+ end
38
+
39
+ #
40
+ # Global Database
41
+ #
42
+ def global_connection
43
+ unless @global_connection
44
+ @global_connection = Mongo::Connection.new(config.global_database.host, config.global_database.port, :logger => logger)
45
+
46
+ if defined?(PhusionPassenger)
47
+ PhusionPassenger.on_event(:starting_worker_process) do |forked|
48
+ @global_connection.connect_to_master if forked
49
+ end
50
+ end
51
+ end
52
+ @global_connection
53
+ end
54
+
55
+ def global_database
56
+ @global_database ||= global_connection.db config.global_database.name
57
+ end
58
+
59
+ def current_global_database
60
+ global_database
61
+ end
62
+
63
+
64
+ #
65
+ # Accounts Database
66
+ #
67
+ def account_connection
68
+ unless @account_connection
69
+ @account_connection = Mongo::Connection.new(config.accounts_database.host, config.accounts_database.port, :logger => logger)
70
+
71
+ if defined?(PhusionPassenger)
72
+ PhusionPassenger.on_event(:starting_worker_process) do |forked|
73
+ @account_connection.connect_to_master if forked
74
+ end
75
+ end
76
+ end
77
+ @account_connection
78
+ end
79
+
80
+ attr_accessor :multitenant_mode
81
+ def multitenant_mode?; !!@multitenant_mode end
82
+
83
+ def account_database_name account_name
84
+ db_name_template = config.accounts_database.name
85
+ db_name_template.should! :include, MongoMapper::ACCOUNT_TOKEN
86
+ db_name = db_name_template.gsub(MongoMapper::ACCOUNT_TOKEN, account_name)
87
+ end
88
+
89
+ def account_database account_name, &block
90
+ self.logger.warn "Previous database #{self.database.name} has note be closed!" if multitenant_mode?
91
+
92
+ db_name = account_database_name account_name
93
+
94
+ begin
95
+ self.connection = account_connection
96
+ self.database = db_name
97
+ self.multitenant_mode = true
98
+ block.call self.database if block
99
+ ensure
100
+ if block
101
+ self.multitenant_mode = false
102
+ self.database = nil
103
+ self.connection = nil
104
+ else
105
+ self.logger.warn "Account Database #{self.database.name} will not be closed automatically!"
106
+ end
107
+ end
108
+ end
109
+
110
+ def current_account_database
111
+ multitenant_mode? ? database : nil
112
+ end
113
+
114
+ def logger
115
+ return @logger ||= Logger.new(nil) if defined?(Spec)
116
+
117
+ @logger ||= ("irb" == $0) ? Logger.new(STDOUT) : (defined?(Rails) ? Rails.logger : Logger.new(STDOUT))
118
+ end
119
+
120
+ def accounts_names
121
+ accounts_names = []
122
+ db_pattern = MongoMapper.config.accounts_database.name
123
+ re = Regexp.new(db_pattern.gsub(MongoMapper::ACCOUNT_TOKEN, '.+'))
124
+
125
+ token_start = db_pattern.index MongoMapper::ACCOUNT_TOKEN
126
+ token_size = MongoMapper::ACCOUNT_TOKEN.size
127
+
128
+ prefix_size = token_start
129
+ postfix_size = db_pattern.size - prefix_size - token_size
130
+
131
+ MongoMapper.account_connection.database_names.each do |name|
132
+ if name =~ re
133
+ account_name = name[prefix_size..-(postfix_size + 1)]
134
+ accounts_names << account_name
135
+ end
136
+ end
137
+ accounts_names
138
+ end
139
+ end
140
+ end
141
+
142
+
143
+ #
144
+ # cache
145
+ #
146
+ MongoMapper::Document::InstanceMethods.class_eval do
147
+ def cache
148
+ @cache ||= {}
149
+ end
150
+
151
+ def clear_cache
152
+ @cache = {}
153
+ end
154
+
155
+ def reload_with_cache
156
+ @cache.clear if @cache
157
+ reload_without_cache
158
+ end
159
+ alias_method_chain :reload, :cache
160
+ end
@@ -0,0 +1,8 @@
1
+ [MongoMapper::EmbeddedDocument::ClassMethods, MongoMapper::Document::ClassMethods].each do |aclass|
2
+ aclass.class_eval do
3
+ def connect_to_global_database!
4
+ self.connection MongoMapper.global_connection
5
+ self.set_database_name MongoMapper.config.global_database.name
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ #
2
+ # ObjectID
3
+ #
4
+ Mongo::ObjectID.class_eval do
5
+ def == other
6
+ self.to_s == other.to_s
7
+ end
8
+
9
+ def to_yaml *args
10
+ to_s.to_yaml *args
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ MongoMapper.account_database 'development'
2
+
3
+ Spec::Runner.configure do |config|
4
+ config.before(:each) do
5
+ dbs = [MongoMapper.current_global_database]
6
+ dbs << MongoMapper.current_account_database unless MongoMapper.current_account_database.blank?
7
+
8
+ dbs.each do |db|
9
+ db.collection_names.each do |name|
10
+ db.collection(name).drop
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ #
2
+ # HTML helpers
3
+ #
4
+ [MongoMapper::EmbeddedDocument::InstanceMethods, MongoMapper::Document::InstanceMethods].each do |aclass|
5
+ aclass.class_eval do
6
+ def original_id; id end
7
+
8
+ def dom_id
9
+ new_record? ? "new_#{self.class.original_class.name.underscore}" : original_id.to_s
10
+ end
11
+
12
+ def to_param; original_id.to_s end
13
+ end
14
+ end
15
+
16
+ [MongoMapper::EmbeddedDocument::ClassMethods, MongoMapper::Document::ClassMethods].each do |aclass|
17
+ aclass.class_eval do
18
+ def original_class; self end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ require 'mongo_mapper'
2
+
3
+ %w{fixes migration mongo_mapper multitenant object_id view_helpers}.each do |file|
4
+ require "#{File.dirname __FILE__}/mongo_mapper_ext/#{file}"
5
+ end
@@ -1,7 +1,7 @@
1
1
  # Converts any non standart fname.yml file in /config folder into FNAME constant with loaded YAML content wrapped into SafeHash.
2
2
  config_dir = "#{RAILS_ROOT}/config/"
3
3
  files = Dir.glob("#{config_dir}*.yml")
4
- ignore = ["asset_packages\\.yml", "database\\.yml", "\\..+\\."].collect{|expr| Regexp.new expr}
4
+ ignore = ["asset_packages\\.yml", "\\..+\\."].collect{|expr| Regexp.new expr}
5
5
  files.delete_if{|fname| ignore.any?{|template| template =~ fname}}
6
6
  files.delete_if{|fname| /^[a-zA-Z0-9_]+\.yml$/ !~ fname.sub(config_dir, '')}
7
7
 
data/lib/rails_ext.rb CHANGED
@@ -6,7 +6,7 @@ require 'rails_ext/active_record'
6
6
 
7
7
  require 'rails_ext/model'
8
8
 
9
- require 'rails_ext/mongo_mapper'
9
+ # require 'rails_ext/mongo_mapper'
10
10
 
11
11
  require 'rails_ext/config_files/safe_hash'
12
12
  require 'rails_ext/config_files'
@@ -0,0 +1,137 @@
1
+ require 'spec'
2
+ require 'ruby_ext'
3
+ require "#{File.dirname __FILE__}/../lib/mongo_mapper_ext"
4
+
5
+ MongoMapper.custom_config = {
6
+ :global_database => {
7
+ :name => 'global_development_test'
8
+ }.to_openobject,
9
+ :accounts_database => {
10
+ :name => "accounts_#{MongoMapper::ACCOUNT_TOKEN}_test"
11
+ }.to_openobject
12
+ }.to_openobject
13
+ require "#{File.dirname __FILE__}/../lib/mongo_mapper_ext/spec_helper"
14
+
15
+
16
+ describe "MongoMapper Migration" do
17
+ Migration = MongoMapper::Migration
18
+
19
+ before :each do
20
+ Migration.send :reset
21
+ end
22
+
23
+ describe "Global Database" do
24
+ before :all do
25
+ class GlobalSample
26
+ include MongoMapper::Document
27
+ connect_to_global_database!
28
+
29
+ key :name, String
30
+ end
31
+ end
32
+
33
+ after :all do
34
+ Object.send :remove_const, :GlobalSample if defined?(GlobalSample)
35
+ end
36
+
37
+ it "Shouldn't update if versions are the same" do
38
+ Migration.update_global_database_to(0).should be_false
39
+ end
40
+
41
+ it "increase_db_version" do
42
+ GlobalSample.count.should == 0
43
+ Migration.define_global_migration 1 do |m|
44
+ m.up{GlobalSample.create :name => 'name'}
45
+ end
46
+
47
+ Migration.update_global_database_to(1).should be_true
48
+ GlobalSample.count.should == 1
49
+ Migration.metadata(MongoMapper.global_database).should == 1
50
+ end
51
+
52
+ it "decrease_db_version" do
53
+ Migration.define_global_migration 1 do |m|
54
+ m.up{GlobalSample.create :name => 'name'}
55
+ m.down{GlobalSample.destroy_all}
56
+ end
57
+ Migration.update_global_database_to(1).should be_true
58
+ GlobalSample.count.should == 1
59
+
60
+ Migration.update_global_database_to(0).should be_true
61
+ GlobalSample.count.should == 0
62
+ Migration.metadata(MongoMapper.global_database).should == 0
63
+ end
64
+ end
65
+
66
+ describe "Acccounts Database" do
67
+ before :all do
68
+ class Sample
69
+ include MongoMapper::Document
70
+
71
+ key :name, String
72
+ end
73
+ end
74
+
75
+ after :all do
76
+ Object.send :remove_const, :Sample if defined?(Sample)
77
+ end
78
+
79
+ before :each do
80
+ @account_db_name = 'accounts_development_test'
81
+ MongoMapper.accounts_names.each do |acccount_name|
82
+ next if acccount_name == 'development'
83
+ MongoMapper.account_connection.drop_database MongoMapper.account_database_name(acccount_name)
84
+ end
85
+ MongoMapper.current_account_database.collection('stub').save('a' => 'b') # Creating empty database
86
+ MongoMapper.accounts_names.should == ['development']
87
+ end
88
+
89
+ after :each do
90
+ MongoMapper.account_database 'development'
91
+ end
92
+
93
+ it "Shouldn't update if versions are the same" do
94
+ results = Migration.update_database_to(0)
95
+ results[@account_db_name].should be_false
96
+ end
97
+
98
+ it "increase_db_version" do
99
+ Sample.count.should == 0
100
+ Migration.define_migration 1 do |m|
101
+ m.up{Sample.create :name => 'name'}
102
+ end
103
+
104
+ results = Migration.update_database_to(1)
105
+ results.size.should == 1
106
+ results[@account_db_name].should be_true
107
+
108
+ MongoMapper.account_database 'development'
109
+ Sample.count.should == 1
110
+ Migration.metadata(MongoMapper.current_account_database).should == 1
111
+ end
112
+
113
+ it "decrease_db_version" do
114
+ Migration.define_migration 1 do |m|
115
+ m.up{Sample.create :name => 'name'}
116
+ m.down{Sample.destroy_all}
117
+ end
118
+
119
+ # Up
120
+ results = Migration.update_database_to(1)
121
+ results.size.should == 1
122
+ results[@account_db_name].should be_true
123
+
124
+ MongoMapper.account_database 'development'
125
+ Sample.count.should == 1
126
+
127
+ # Down
128
+ results = Migration.update_database_to(0)
129
+ results.size.should == 1
130
+ results[@account_db_name].should be_true
131
+
132
+ MongoMapper.account_database 'development'
133
+ Sample.count.should == 0
134
+ Migration.metadata(MongoMapper.database).should == 0
135
+ end
136
+ end
137
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.15
4
+ version: 0.2.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Petrushin
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-21 00:00:00 +03:00
12
+ date: 2010-02-25 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -66,6 +66,7 @@ files:
66
66
  - .git/objects/0b/3b3d1048f25fdc0de3f680cdbbd867a42b5a95
67
67
  - .git/objects/0b/e101a0586410212b4ee5905881ad726b7b4907
68
68
  - .git/objects/0d/aa3468e187093eff222b8094a6e702dea9ba4e
69
+ - .git/objects/0d/b63ec7380f5132ca02be93c82f5295e33c10a9
69
70
  - .git/objects/0f/92cb7ae358323d43d026b83f7d1a4969cf7568
70
71
  - .git/objects/0f/d3ac42b07c2d3102263bd939704f5633db304e
71
72
  - .git/objects/10/1f52d83027dfe5798f87aec1118f02d19e5cf8
@@ -80,6 +81,7 @@ files:
80
81
  - .git/objects/18/77033b90ed3dd55a3034b7e3ca1c5c9f66868d
81
82
  - .git/objects/18/adbbbcd043a3ef3e19854df8476b02d69544d0
82
83
  - .git/objects/19/1f68644a3646d774f2546c4cd49ac7d66f4cc2
84
+ - .git/objects/1b/83175202b0bdd9e8aac50c186533c1730aa220
83
85
  - .git/objects/1c/65c12ac1816d1b56c7c3892acc61512696c673
84
86
  - .git/objects/1c/7fd48742e76d2cd6605e1a569e65e79ddd8f92
85
87
  - .git/objects/1d/d49713de2942dc974e55adc3684f55b2b817e2
@@ -87,6 +89,7 @@ files:
87
89
  - .git/objects/1f/1be5b8e4dce8787367b3a607b0695ca70d4e82
88
90
  - .git/objects/21/e143c036491275aaa7d6e45ed4683f5defdae2
89
91
  - .git/objects/23/926daa53cee50268bd329a8b4cbd853cb3a45b
92
+ - .git/objects/28/8e20f19c6662b1425e0a0797ae443f7eddcc4a
90
93
  - .git/objects/28/c44da9255a78bf7105a1c251e4e1cd643b8f44
91
94
  - .git/objects/29/7a2c413b11f78b69dd8caa4f334c9536088f8a
92
95
  - .git/objects/29/b1f8abaed4aea1da8f8bd5f1bd81c26058c41a
@@ -107,12 +110,14 @@ files:
107
110
  - .git/objects/3a/797683953be7e6d0ffa0e34514f3e8e9c3ceb0
108
111
  - .git/objects/3a/ff2a7bfdf3a677812899ede62d084369c7c5f4
109
112
  - .git/objects/3e/c0da65fe2e572ad31203f9412baa09dfdf49d3
113
+ - .git/objects/3e/f23cf310c5eebac930a19d36a0561dd362d3ee
110
114
  - .git/objects/3f/3db6bb5a5204ae58e303959c4c0da3a70d8b35
111
115
  - .git/objects/3f/8f2086049359d8b2b2500a7145afe3040e9c37
112
116
  - .git/objects/40/215c0554202fc46dc2fca94ed21e2920ce1e84
113
117
  - .git/objects/40/7adfb7f6188b0bb0b88cf9391943e1aaa32374
114
118
  - .git/objects/40/b5d1a81a061ce0e2f315b7e741ec70e0defe1d
115
119
  - .git/objects/46/d12e0420cd6341a2720730cc45703fc835efb6
120
+ - .git/objects/47/28fde4426b545c73552bd5e0f79296a2b4be19
116
121
  - .git/objects/49/66cd792ea3e03d5091aa7a332f2a082e479a76
117
122
  - .git/objects/4a/80705702f499ef1278630257a33c6088238ba3
118
123
  - .git/objects/4a/be35eba6ed159578e3f43f6ffa8ea7541598e2
@@ -124,6 +129,7 @@ files:
124
129
  - .git/objects/4d/f726437dcbd106a583c07863e56076b245e8e3
125
130
  - .git/objects/4f/2c09cf4d187a86ce37983eb76211ebabdb45d0
126
131
  - .git/objects/4f/fa8f1c9b7e3fdbb23ab600722d1011dcb48cec
132
+ - .git/objects/52/5fcb274029ec36780b264166ea3d487d968997
127
133
  - .git/objects/53/8aca7c60ef3cdfde25d4698e8e133ce18e512e
128
134
  - .git/objects/55/6c13b26b6cecd286427a7f16c60c86c7df7885
129
135
  - .git/objects/55/d1f1efc344266d472094b1fd2f247b97de1c8b
@@ -133,6 +139,7 @@ files:
133
139
  - .git/objects/59/0ef6ba9931d75fbddc7a940044dbaaa50efc76
134
140
  - .git/objects/59/7b19d2ba6f1d46f75f702cbacf8828b7b506f9
135
141
  - .git/objects/5a/35fa85474278f3c817aa59d07b725428c41a28
142
+ - .git/objects/5c/95be85f2a2a984454fed4941a5ae00062634c5
136
143
  - .git/objects/5c/d7e89f2b29ed92fd51e2c6b2ee74db376d17d7
137
144
  - .git/objects/5f/483b0c41645f8882f549c1c6d0274bb592140a
138
145
  - .git/objects/60/a681e873ca0ae0b7da3f37dbc5701f6e42b970
@@ -143,6 +150,7 @@ files:
143
150
  - .git/objects/64/96d7c4cc0c824e706bf757f9ec63b5553c9caf
144
151
  - .git/objects/65/51094fa3b996ff25b88d7ddb21d21a811d53fc
145
152
  - .git/objects/66/37f98202acb1895cb347d7c5fb5c414dd9e6db
153
+ - .git/objects/67/2396778b142df8b0b7ab212b7564039c48cf39
146
154
  - .git/objects/67/850cf1ede94d80c9b07ceace074a4d62f15249
147
155
  - .git/objects/68/8ce506ac4f7c160bd6880d8507820761a3b3b7
148
156
  - .git/objects/68/a8fc1e77fc27530430b55046609ee80cd9b2ad
@@ -154,6 +162,7 @@ files:
154
162
  - .git/objects/6d/f725e3519872a75bc763045f00d8844eb890cf
155
163
  - .git/objects/6e/a04c6c0a52b9c7da1de6364b530553dfd78c4a
156
164
  - .git/objects/71/e6b43e9d41f9903992fd86d483b7d3e4dd28cd
165
+ - .git/objects/73/667b7ae341d478513ba0bd6ec8af0aa1f62f0d
157
166
  - .git/objects/74/ce4a58ebf96006e1e9be0980b99ac3b5b820c7
158
167
  - .git/objects/74/d8411c7276b4e1c1f614606af7f69ab4526d30
159
168
  - .git/objects/75/d0b250bcdf241d981313b1d6eb153b96e4b05f
@@ -171,6 +180,7 @@ files:
171
180
  - .git/objects/82/03c2c6cdd29e1e20e88fbb81e63b7ea1ec2899
172
181
  - .git/objects/83/6f33959bcf517b9952aefb3fdfdd7ff3c1f207
173
182
  - .git/objects/85/eee9f4c1a6f710ed87bf28a0531275777f8848
183
+ - .git/objects/85/fd531f7352ad8f5ac030eed2204a662dd10a66
174
184
  - .git/objects/86/b31b604469e9b261f4e5b927932504bca8c402
175
185
  - .git/objects/87/fc827fd223cac6b4e55d823a9ea86bb0726a3b
176
186
  - .git/objects/89/2697494eb70fdccaf26bf547bb8d7428c0e5ff
@@ -179,6 +189,7 @@ files:
179
189
  - .git/objects/8d/4dcde8df4da8f53f5f5313757b907e9aa1af66
180
190
  - .git/objects/8e/3cfb391de711b5fecfbdf2860fa37b019e8036
181
191
  - .git/objects/8e/69b6cf3ec8b49270091b4a206ccf326679dc20
192
+ - .git/objects/8e/a47de58a27dd343b3ecd3dd5e0fab88e268a72
182
193
  - .git/objects/90/ca84ea326afab5fcc92a50469c2052ebc46f11
183
194
  - .git/objects/92/e1c250edfca72ed0932934257ef3cfc7122ec5
184
195
  - .git/objects/92/e1f3936e7c33007d0a466b836804450992a1eb
@@ -194,12 +205,14 @@ files:
194
205
  - .git/objects/a3/4e4e8572d323de26965619321576f903fa7935
195
206
  - .git/objects/a3/5c311b625d863b50d51e2385259d487e277c90
196
207
  - .git/objects/a3/6956ff51b72b69d1ac2c1ad0d78bb9ad1ade75
208
+ - .git/objects/a3/84715546f6a11dc7d56a32784dbdd5d7d92e8e
197
209
  - .git/objects/a5/4db1bec30f7dc8981c4d5ccf9c9a90c1e13662
198
210
  - .git/objects/a5/9472e8ecb5d06647adeec11ae931b956508191
199
211
  - .git/objects/a6/438da91846df9ac940b59f6d11d5019a5580be
200
212
  - .git/objects/a7/6c4944dc009628cb65b4962464a8eb484d6a71
201
213
  - .git/objects/a7/a902aeac4af3f10b474c23c2a3750fde007a02
202
214
  - .git/objects/a9/d2b84a743094002fef87a193e681ee721d76ed
215
+ - .git/objects/ab/6b7d6c5c5fee246e184a58448682b73b574d6b
203
216
  - .git/objects/ab/825cde00e626431c6045e6886d470327c63001
204
217
  - .git/objects/ac/92bcf6c74d23824c3c7ce341f667507592c7f9
205
218
  - .git/objects/ac/a1ad63cec98e0b3dae23fbe088f5a5d2125a7a
@@ -214,6 +227,7 @@ files:
214
227
  - .git/objects/b4/228251babf3a84ac181d462fdd383816bd23b8
215
228
  - .git/objects/b4/eb909dd819bf870d2445bddc0d7f00678b11b6
216
229
  - .git/objects/b5/15828bb32356501aa81bb4e808ea5d7d77f068
230
+ - .git/objects/b5/33c1c1bca9eae5b7e75c639fff8ec2c2f9fea1
217
231
  - .git/objects/b5/edd343ceb8e87d1a73922612aec210b393f839
218
232
  - .git/objects/b7/88e3ac322b164a2a223f80f8a6da0836d9d1dd
219
233
  - .git/objects/ba/67eef0f58a44e4b39af605d45e1e958023588d
@@ -227,9 +241,13 @@ files:
227
241
  - .git/objects/c1/424cadd8817a7e927742e52945f303b38e7222
228
242
  - .git/objects/c3/dd5ae1e005efb09ef758da1ec17781c616ae9d
229
243
  - .git/objects/c4/524d9d99c6072949bfc565f78b7a62577ffa3f
244
+ - .git/objects/c5/208dea612df35fb84ceeda0649c103c32e2240
245
+ - .git/objects/c5/3b27c9641ea1c2aed192672b67ba8c4034b2ad
230
246
  - .git/objects/c5/64ac68ebc8e0db7a6355a45f3299829ef2a825
247
+ - .git/objects/c6/9db405143490c407206cf8afd7537a49ea30b2
231
248
  - .git/objects/c7/a9ce2f4c2230143a30c77952c14ddf6507f511
232
249
  - .git/objects/c8/e50fcfb3ed2c892a6c75e8d703552bb8edd4ca
250
+ - .git/objects/ca/a9edd4de82aa3abec99946e92da9225efb83bc
233
251
  - .git/objects/ca/c13b06411cdb70ac35d51ecf9efb0907645bd1
234
252
  - .git/objects/cd/cf979816bbea77b6000145a1e23921553bf497
235
253
  - .git/objects/d0/ca1129a25def590908081d9dc166d5288fddf0
@@ -259,6 +277,7 @@ files:
259
277
  - .git/objects/e4/1d46e33f52e07b836b966d58677fc2a864a4a4
260
278
  - .git/objects/e4/d7cacac2d7e66df5a7c21eaae71c0a90f1439d
261
279
  - .git/objects/e5/7fa5fd7f10f6f532742b0cc2dc3edaed6c0763
280
+ - .git/objects/e6/4d9b4d86a001e4f882a9842a8dd4368001c470
262
281
  - .git/objects/e6/ed7d272f8c48a28904007d653837bfe761be36
263
282
  - .git/objects/e7/e790ff7c580a636d0de69956834c9b47ad771b
264
283
  - .git/objects/e7/f4b26a3258b7788ffe2665773387e19c01095a
@@ -279,11 +298,16 @@ files:
279
298
  - .git/objects/f3/7784042bc99c16c02fd104dda82aafa42d4c9c
280
299
  - .git/objects/f4/2863a866b6cd3bb09d0482052cbf2da7fb4e5a
281
300
  - .git/objects/f5/91a5c39e03e2102c9101db957b48c8c76e194c
301
+ - .git/objects/f6/0fd8c2582e0f7688877f12f78ddb97a291046c
282
302
  - .git/objects/f6/3ad03a8daa1602df63aab3838947c18fa63797
303
+ - .git/objects/f7/b177b2c6b25dd886d23d6be87bcf802af9b513
283
304
  - .git/objects/f9/8d0f95460a7a3f63ab4c08ad5508fd32d1b5c2
284
305
  - .git/objects/f9/ef6dd08a60dec5d5e4e7a9b08f693ebf76da39
285
306
  - .git/objects/fa/4e345a8b9a12bf1cf7af254b3caa111b04191b
307
+ - .git/objects/fa/854db299be87a6e6a65d906e7c2f9b122d9980
286
308
  - .git/objects/fb/05e1cc9825c59c7edc596c05077a1eed9c321e
309
+ - .git/objects/fc/022a0a2ed82b2361292833c0cb90f996aae858
310
+ - .git/objects/fc/bf66b949d823f884d1aff2f3e192943cb195a2
287
311
  - .git/objects/fd/25e0c8e44fb97a7c7d76280cec51886b51abf6
288
312
  - .git/objects/fe/c19d13244f6b439e234e1af2e2e6d1f886b2fb
289
313
  - .git/objects/fe/ce95626cedcc0682e6fcc20fe019aab60938f2
@@ -298,6 +322,14 @@ files:
298
322
  - lib/asset_packager/asset_packager.rb
299
323
  - lib/asset_packager/jsmin.rb
300
324
  - lib/asset_packager/tasks.rb
325
+ - lib/mongo_mapper_ext/fixes.rb
326
+ - lib/mongo_mapper_ext/migration.rb
327
+ - lib/mongo_mapper_ext/mongo_mapper.rb
328
+ - lib/mongo_mapper_ext/multitenant.rb
329
+ - lib/mongo_mapper_ext/object_id.rb
330
+ - lib/mongo_mapper_ext/spec_helper.rb
331
+ - lib/mongo_mapper_ext/view_helpers.rb
332
+ - lib/mongo_mapper_ext.rb
301
333
  - lib/rails_ext/action_controller.rb
302
334
  - lib/rails_ext/action_controller_ext.rb
303
335
  - lib/rails_ext/action_view.rb
@@ -325,13 +357,12 @@ files:
325
357
  - lib/rails_ext/merge_default_scope.rb
326
358
  - lib/rails_ext/micelaneous.rb
327
359
  - lib/rails_ext/model.rb
328
- - lib/rails_ext/mongo_mapper.rb
329
- - lib/rails_ext/mongo_mapper_spec_helper.rb
330
360
  - lib/rails_ext/persistent_params.rb
331
361
  - lib/rails_ext/redirect_helper.rb
332
362
  - lib/rails_ext/reload_page.rb
333
363
  - lib/rails_ext/user_error.rb
334
364
  - lib/rails_ext.rb
365
+ - spec/mongo_mapper_migration_spec.rb
335
366
  - spec/safe_hash_spec.rb
336
367
  - spec/spec.opts
337
368
  - public/rails_ext/rails_ext.css
@@ -1,48 +0,0 @@
1
- # require 'mm-paginate'
2
-
3
- #
4
- # dom_id
5
- #
6
- # MongoMapper::Document.class_eval do
7
- # def dom_id
8
- # new_record? ? "new_#{self.class.name.underscore}" : "#{id}"
9
- # end
10
- # end
11
-
12
- #
13
- # cache
14
- #
15
- MongoMapper::Document::InstanceMethods.class_eval do
16
- def cache
17
- @cache ||= {}
18
- end
19
-
20
- def clear_cache
21
- @cache = {}
22
- end
23
-
24
- def reload_with_cache
25
- @cache.clear if @cache
26
- reload_without_cache
27
- end
28
- alias_method_chain :reload, :cache
29
- end
30
-
31
- #
32
- # ObjectID
33
- #
34
- Mongo::ObjectID.class_eval do
35
- def == other
36
- self.to_s == other.to_s
37
- end
38
-
39
- def to_yaml *args
40
- to_s.to_yaml *args
41
- end
42
- end
43
-
44
- # String.class_eval do
45
- # def to_mongo_id
46
- # ObjectId.to_mongo self
47
- # end
48
- # end
@@ -1,8 +0,0 @@
1
- Spec::Runner.configure do |config|
2
- config.before(:each) do
3
- db = MongoMapper.database
4
- db.collection_names.each do |name|
5
- db.collection(name).drop
6
- end
7
- end
8
- end