public
Description: All the extra stuff you could want for the Mack Framework.
Homepage: http://www.mackframework.com
Clone URL: git://github.com/markbates/mack-more.git
Working on refactoring out active_record to mack-orm [#87]
markbates (author)
Tue Aug 12 12:14:38 -0700 2008
commit  60733564ab430ecea42a65dc386954ed9edec09f
tree    8188f50ab70fcddb7f34ca4e355674700070d301
parent  80324859b13764c03c7525a6811affbec0667381
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
 
 
39
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
42
43
44
45
46
47
48
 
 
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 
 
 
 
 
 
 
 
 
 
 
 
68
69
70
71
 
72
73
74
...
83
84
85
86
 
87
88
89
...
99
100
101
102
 
103
 
 
 
 
 
 
104
105
106
...
146
147
148
149
150
151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
...
 
 
 
 
 
 
 
1
2
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
 
 
 
 
 
29
30
31
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 
48
49
50
51
...
60
61
62
 
63
64
65
66
...
76
77
78
 
79
80
81
82
83
84
85
86
87
88
89
...
129
130
131
 
 
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
0
@@ -1,74 +1,51 @@
0
-#
0
-# AR db create/drop.
0
-# Currently it supports 3 adapters: sqlite3, postgresql, and mysql
0
-#
0
-# ds - July 2008
0
-#
0
-
0
 module Mack
0
   module Database
0
     
0
-    module Migrator
0
-      def self.version
0
-        ActiveRecord::Migrator.current_version
0
-      end
0
-      
0
-      def self.migrate
0
-        ActiveRecord::Migrator.up(File.join(Mack.root, "db", "migrations"))
0
-      end
0
-      
0
-      def self.rollback(step = 1)
0
-        step = (ENV["STEP"] || step).to_i
0
-        cur_version = version.to_i
0
-        target_version = cur_version - step 
0
-        target_version = 0 if target_version < 0
0
-        
0
-        ActiveRecord::Migrator.down(File.join(Mack.root, "db", "migrations"), target_version)
0
-      end
0
-      
0
-    end
0
-        
0
-    def self.db_settings(env)
0
-      dbs = YAML::load(ERB.new(IO.read(File.join(Mack.root, "config", "database.yml"))).result)
0
-      dbs = dbs[env]
0
-      dbs.symbolize_keys!
0
-      return dbs
0
-    end
0
-    
0
-    def self.establish_connection(env)
0
+    # Sets up and establishes connections to the database based on the specified environment
0
+    # and the settings in the database.yml file.
0
+    def self.establish_connection(env = Mack.env)
0
       dbs = db_settings(env)
0
       ActiveRecord::Base.establish_connection(dbs)
0
+    end # establish_connection
0
+    
0
+    # Creates a database, if it doesn't already exist for the specified environment
0
+    def self.create(env = Mack.env, repis = :default)
0
+      dbs = db_settings(env)
0
+      case dbs[:adapter]
0
+      when "mysql"
0
+        establish_mysql_connection
0
+        create_mysql_db(env, dbs)
0
+      when "postgresql"
0
+        ENV['PGHOST']     = dbs[:host] if dbs[:host]
0
+        ENV['PGPORT']     = dbs[:port].to_s if dbs[:port]
0
+        ENV['PGPASSWORD'] = dbs[:password].to_s if dbs[:password]
0
+        ActiveRecord::Base.clear_active_connections!
0
+        create_postgresql_db(env, dbs)
0
+      when "sqlite3"
0
+        ActiveRecord::Base.clear_active_connections!
0
+      end
0
     end
0
     
0
-    # Perform db create or drop
0
-    # 
0
-    # By default the mode is drop then create, but caller will be able to 
0
-    # call this routine with a specific action (:drop, :create, or :drop_and_create)
0
-    # 
0
-    def self.drop_or_create_database(env, mode = :drop_and_create)
0
+    # Drops a database, if it exists for the specified environment
0
+    def self.drop(env = Mack.env, repis = :default)
0
       dbs = db_settings(env)
0
       case dbs[:adapter]
0
-        when "mysql"
0
-          establish_mysql_connection
0
-          drop_mysql_db(env, dbs) if mode == :drop or mode == :drop_and_create
0
-          create_mysql_db(env, dbs) if mode == :create or mode == :drop_and_create
0
-          
0
-        when "postgresql"
0
-          ENV['PGHOST']     = dbs[:host] if dbs[:host]
0
-          ENV['PGPORT']     = dbs[:port].to_s if dbs[:port]
0
-          ENV['PGPASSWORD'] = dbs[:password].to_s if dbs[:password]
0
-          
0
-          ActiveRecord::Base.clear_active_connections!
0
-          drop_postgresql_db(env, dbs) if mode == :drop or mode == :drop_and_create
0
-          create_postgresql_db(env, dbs) if mode == :create or mode == :drop_and_create
0
-          
0
-        when "sqlite3"
0
-          ActiveRecord::Base.clear_active_connections!
0
-          FileUtils.rm_rf(dbs[:database]) if mode == :drop or mode == :drop_and_create
0
+      when "mysql"
0
+        establish_mysql_connection
0
+        drop_mysql_db(env, dbs)
0
+      when "postgresql"
0
+        ENV['PGHOST']     = dbs[:host] if dbs[:host]
0
+        ENV['PGPORT']     = dbs[:port].to_s if dbs[:port]
0
+        ENV['PGPASSWORD'] = dbs[:password].to_s if dbs[:password]
0
+        ActiveRecord::Base.clear_active_connections!
0
+        drop_postgresql_db(env, dbs)
0
+      when "sqlite3"
0
+        ActiveRecord::Base.clear_active_connections!
0
+        FileUtils.rm_rf(dbs[:database])
0
       end
0
     end
0
     
0
-    def self.load_structure(file, env = Mack.env)
0
+    def self.load_structure(file, env = Mack.env, repis = :default)
0
       Mack::Database.establish_connection(env)
0
       dbs = db_settings(env)
0
       sql = File.read(file)
0
@@ -83,7 +60,7 @@ module Mack
0
       end
0
     end
0
     
0
-    def self.dump_structure(env = Mack.env)
0
+    def self.dump_structure(env = Mack.env, repis = :default)
0
       Mack::Database.establish_connection(env)
0
       dbs = db_settings(env)
0
       structure = ""
0
@@ -99,8 +76,14 @@ module Mack
0
         raise "Task not supported for '#{dbs[:adapter]}'"
0
       end
0
     end
0
-            
0
+    
0
     private
0
+    def self.db_settings(env)
0
+      dbs = YAML::load(ERB.new(IO.read(File.join(Mack.root, "config", "database.yml"))).result)
0
+      dbs = dbs[env]
0
+      dbs.symbolize_keys!
0
+      return dbs
0
+    end
0
     
0
     def self.drop_postgresql_db(env, dbs)
0
       begin
0
@@ -146,5 +129,159 @@ module Mack
0
       puts "Dropping (MySQL): #{dbs[:database]}"
0
       ActiveRecord::Base.connection.execute "DROP DATABASE IF EXISTS `#{dbs[:database]}`"
0
     end
0
-  end
0
-end
0
\ No newline at end of file
0
+    
0
+  end # Database
0
+  
0
+end # Mack
0
+
0
+
0
+# #
0
+# # AR db create/drop.
0
+# # Currently it supports 3 adapters: sqlite3, postgresql, and mysql
0
+# #
0
+# # ds - July 2008
0
+# #
0
+# 
0
+# module Mack
0
+#   module Database
0
+#     
0
+#     module Migrator
0
+#       def self.version
0
+#         ActiveRecord::Migrator.current_version
0
+#       end
0
+#       
0
+#       def self.migrate
0
+#         ActiveRecord::Migrator.up(File.join(Mack.root, "db", "migrations"))
0
+#       end
0
+#       
0
+#       def self.rollback(step = 1)
0
+#         step = (ENV["STEP"] || step).to_i
0
+#         cur_version = version.to_i
0
+#         target_version = cur_version - step 
0
+#         target_version = 0 if target_version < 0
0
+#         
0
+#         ActiveRecord::Migrator.down(File.join(Mack.root, "db", "migrations"), target_version)
0
+#       end
0
+#       
0
+#     end
0
+#         
0
+#     def self.db_settings(env)
0
+#       dbs = YAML::load(ERB.new(IO.read(File.join(Mack.root, "config", "database.yml"))).result)
0
+#       dbs = dbs[env]
0
+#       dbs.symbolize_keys!
0
+#       return dbs
0
+#     end
0
+#     
0
+#     def self.establish_connection(env)
0
+#       dbs = db_settings(env)
0
+#       ActiveRecord::Base.establish_connection(dbs)
0
+#     end
0
+#     
0
+#     # Perform db create or drop
0
+#     # 
0
+#     # By default the mode is drop then create, but caller will be able to 
0
+#     # call this routine with a specific action (:drop, :create, or :drop_and_create)
0
+#     # 
0
+#     def self.drop_or_create_database(env, mode = :drop_and_create)
0
+#       dbs = db_settings(env)
0
+#       case dbs[:adapter]
0
+#         when "mysql"
0
+#           establish_mysql_connection
0
+#           drop_mysql_db(env, dbs) if mode == :drop or mode == :drop_and_create
0
+#           create_mysql_db(env, dbs) if mode == :create or mode == :drop_and_create
0
+#           
0
+#         when "postgresql"
0
+#           ENV['PGHOST']     = dbs[:host] if dbs[:host]
0
+#           ENV['PGPORT']     = dbs[:port].to_s if dbs[:port]
0
+#           ENV['PGPASSWORD'] = dbs[:password].to_s if dbs[:password]
0
+#           
0
+#           ActiveRecord::Base.clear_active_connections!
0
+#           drop_postgresql_db(env, dbs) if mode == :drop or mode == :drop_and_create
0
+#           create_postgresql_db(env, dbs) if mode == :create or mode == :drop_and_create
0
+#           
0
+#         when "sqlite3"
0
+#           ActiveRecord::Base.clear_active_connections!
0
+#           FileUtils.rm_rf(dbs[:database]) if mode == :drop or mode == :drop_and_create
0
+#       end
0
+#     end
0
+#     
0
+#     def self.load_structure(file, env = Mack.env)
0
+#       Mack::Database.establish_connection(env)
0
+#       dbs = db_settings(env)
0
+#       sql = File.read(file)
0
+#       case dbs[:adapter]
0
+#       when "mysql"
0
+#         sql.split(";").each do |s|
0
+#           s.strip! 
0
+#           ActiveRecord::Base.connection.execute(s) unless s.blank?
0
+#         end
0
+#       else
0
+#         ActiveRecord::Base.connection.execute(sql) unless sql.blank?
0
+#       end
0
+#     end
0
+#     
0
+#     def self.dump_structure(env = Mack.env)
0
+#       Mack::Database.establish_connection(env)
0
+#       dbs = db_settings(env)
0
+#       structure = ""
0
+#       output_file = File.join(Mack.root, "db", "#{env}_schema_structure.sql")
0
+#       case dbs[:adapter]
0
+#       when "mysql"
0
+#         File.open(output_file, "w") {|f| f.puts ActiveRecord::Base.connection.structure_dump}
0
+#       when "postgresql"
0
+#         `pg_dump -i -U "#{dbs[:username]}" -s -x -O -n #{ENV["SCHEMA"] ||= "public"} -f #{output_file} #{dbs[:database]}`
0
+#       when "sqlite3"
0
+#         `sqlite3 #{dbs[:database]} .schema > #{output_file}`
0
+#       else
0
+#         raise "Task not supported for '#{dbs[:adapter]}'"
0
+#       end
0
+#     end
0
+#             
0
+#     private
0
+#     
0
+#     def self.drop_postgresql_db(env, dbs)
0
+#       begin
0
+#         puts "Dropping (PostgreSQL): #{dbs[:database]}"
0
+#         `dropdb -U "#{dbs[:username]}" #{dbs[:database]}`
0
+#       rescue Exception => e
0
+#         puts e
0
+#       end
0
+#     end
0
+#     
0
+#     def self.create_postgresql_db(env, dbs)
0
+#       begin
0
+#         enc_option = "-E #{dbs[:encoding]}" if dbs[:encoding]
0
+#         puts "Creating (PostgreSQL): #{dbs[:database]}"
0
+#         `createdb #{enc_option} -U "#{dbs[:username]}" #{dbs[:database]}`
0
+#       rescue Exception => e
0
+#         puts e
0
+#       end
0
+#     end
0
+#     
0
+#     def self.establish_mysql_connection
0
+#       # connect to mysql meta database
0
+#       ActiveRecord::Base.establish_connection(
0
+#         :adapter => "mysql",
0
+#         :host => "localhost",
0
+#         :database => "mysql",
0
+#         :username => ENV["DB_USERNAME"] || "root",
0
+#         :password => ENV["DB_PASSWORD"] || ""
0
+#       )
0
+#     end
0
+#     
0
+#     def self.create_mysql_db(env, dbs)
0
+#       if dbs[:collation]
0
+#         puts "Dropping (MySQL): #{dbs[:database]}"
0
+#         ActiveRecord::Base.connection.execute "CREATE DATABASE `#{dbs[:database]}` DEFAULT CHARACTER SET `#{dbs[:charset] || 'utf8'}` COLLATE `#{dbs[:collation]}`"
0
+#       else
0
+#         puts "Creating (MySQL): #{dbs[:database]}"
0
+#         ActiveRecord::Base.connection.execute "CREATE DATABASE `#{dbs[:database]}` DEFAULT CHARACTER SET `#{dbs[:charset] || 'utf8'}`"
0
+#       end
0
+#     end
0
+#     
0
+#     def self.drop_mysql_db(env, dbs)
0
+#       puts "Dropping (MySQL): #{dbs[:database]}"
0
+#       ActiveRecord::Base.connection.execute "DROP DATABASE IF EXISTS `#{dbs[:database]}`"
0
+#     end
0
+#   end
0
+# end
0
\ No newline at end of file
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
0
@@ -1,52 +1,52 @@
0
-require 'rake'
0
-namespace :db do
0
-    
0
-  task :drop => :environment do
0
-    Mack::Database.drop_or_create_database(Mack.env, :drop)    
0
-  end
0
-  
0
-  namespace :drop do 
0
-    desc "Drop databases for both development and test environemnt"
0
-    task :all => :environment do
0
-      Mack::Database.drop_or_create_database("development", :drop)
0
-      Mack::Database.drop_or_create_database("test", :drop)
0
-    end
0
-  end
0
-  
0
-  task :create do
0
-    puts Mack.env
0
-    Mack::Database.drop_or_create_database(Mack.env, :create)
0
-  end
0
-  
0
-  task :recreate do
0
-    puts Mack.env
0
-    Mack::Database.drop_or_create_database(Mack.env, :drop_and_create)
0
-  end
0
-  
0
-  namespace :create do
0
-    desc "Creates your Full environment. Does NOT create your production database!"
0
-    task :all => :environment do
0
-      abcs = YAML::load(ERB.new(IO.read(File.join(Mack.root, "config", "database.yml"))).result)
0
-      db_settings = abcs[Mack.env]
0
-      
0
-      Mack::Database.drop_or_create_database("development", :create)
0
-      Mack::Database.drop_or_create_database("test", :create)
0
-      ActiveRecord::Base.establish_connection(db_settings)
0
-      Rake::Task["db:migrate"].invoke
0
-    end
0
-  end
0
-  
0
-  namespace :recreate do
0
-    desc "Creates your Full environment. Does NOT create your production database!"
0
-    task :all => :environment do
0
-      abcs = YAML::load(ERB.new(IO.read(File.join(Mack.root, "config", "database.yml"))).result)
0
-      db_settings = abcs[Mack.env]
0
-      
0
-      Mack::Database.drop_or_create_database("development")
0
-      Mack::Database.drop_or_create_database("test")
0
-      ActiveRecord::Base.establish_connection(db_settings)
0
-      Rake::Task["db:migrate"].invoke
0
-    end
0
-  end
0
-    
0
-end
0
+# require 'rake'
0
+# namespace :db do
0
+#     
0
+#   task :drop => :environment do
0
+#     Mack::Database.drop_or_create_database(Mack.env, :drop)    
0
+#   end
0
+#   
0
+#   namespace :drop do 
0
+#     desc "Drop databases for both development and test environemnt"
0
+#     task :all => :environment do
0
+#       Mack::Database.drop_or_create_database("development", :drop)
0
+#       Mack::Database.drop_or_create_database("test", :drop)
0
+#     end
0
+#   end
0
+#   
0
+#   task :create do
0
+#     puts Mack.env
0
+#     Mack::Database.drop_or_create_database(Mack.env, :create)
0
+#   end
0
+#   
0
+#   task :recreate do
0
+#     puts Mack.env
0
+#     Mack::Database.drop_or_create_database(Mack.env, :drop_and_create)
0
+#   end
0
+#   
0
+#   namespace :create do
0
+#     desc "Creates your Full environment. Does NOT create your production database!"
0
+#     task :all => :environment do
0
+#       abcs = YAML::load(ERB.new(IO.read(File.join(Mack.root, "config", "database.yml"))).result)
0
+#       db_settings = abcs[Mack.env]
0
+#       
0
+#       Mack::Database.drop_or_create_database("development", :create)
0
+#       Mack::Database.drop_or_create_database("test", :create)
0
+#       ActiveRecord::Base.establish_connection(db_settings)
0
+#       Rake::Task["db:migrate"].invoke
0
+#     end
0
+#   end
0
+#   
0
+#   namespace :recreate do
0
+#     desc "Creates your Full environment. Does NOT create your production database!"
0
+#     task :all => :environment do
0
+#       abcs = YAML::load(ERB.new(IO.read(File.join(Mack.root, "config", "database.yml"))).result)
0
+#       db_settings = abcs[Mack.env]
0
+#       
0
+#       Mack::Database.drop_or_create_database("development")
0
+#       Mack::Database.drop_or_create_database("test")
0
+#       ActiveRecord::Base.establish_connection(db_settings)
0
+#       Rake::Task["db:migrate"].invoke
0
+#     end
0
+#   end
0
+#     
0
+# end
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
0
@@ -1,21 +1,21 @@
0
-require 'rake'
0
-namespace :db do
0
-  
0
-  desc "Migrate the database through scripts in db/migrations"
0
-  task :migrate => "mack:environment" do
0
-    #ActiveRecord::Migrator.up(File.join(Mack.root, "db", "migrations"))
0
-    Mack::Database::Migrator.migrate
0
-  end # migrate
0
-  
0
-  desc "Rolls the schema back to the previous version. Specify the number of steps with STEP=n"
0
-  task :rollback => ["mack:environment"] do
0
-    Mack::Database::Migrator.rollback
0
-    #ActiveRecord::Migrator.rollback(File.join(Mack.root, "db", "migrations"), (ENV["STEP"] || 1).to_i)
0
-  end # rollback
0
-
0
-  desc "Displays the current schema version of your database"
0
-  task :version => "mack:environment" do
0
-    puts "\nYour database is currently at version: #{Mack::Database::Migrator.version}\n"
0
-  end
0
-  
0
-end # db
0
\ No newline at end of file
0
+# require 'rake'
0
+# namespace :db do
0
+#   
0
+#   desc "Migrate the database through scripts in db/migrations"
0
+#   task :migrate => "mack:environment" do
0
+#     #ActiveRecord::Migrator.up(File.join(Mack.root, "db", "migrations"))
0
+#     Mack::Database::Migrator.migrate
0
+#   end # migrate
0
+#   
0
+#   desc "Rolls the schema back to the previous version. Specify the number of steps with STEP=n"
0
+#   task :rollback => ["mack:environment"] do
0
+#     Mack::Database::Migrator.rollback
0
+#     #ActiveRecord::Migrator.rollback(File.join(Mack.root, "db", "migrations"), (ENV["STEP"] || 1).to_i)
0
+#   end # rollback
0
+# 
0
+#   desc "Displays the current schema version of your database"
0
+#   task :version => "mack:environment" do
0
+#     puts "\nYour database is currently at version: #{Mack::Database::Migrator.version}\n"
0
+#   end
0
+#   
0
+# end # db
0
\ No newline at end of file
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
0
@@ -1,18 +1,18 @@
0
-namespace :test do
0
-  
0
-  task :setup do
0
-    ENV["MACK_ENV"] = "test"
0
-    Mack.reset_logger!
0
-    Rake::Task["db:recreate"].invoke
0
-    Mack::Database.dump_structure("development")
0
-    Mack::Database.load_structure(File.join(Mack.root, "db", "development_schema_structure.sql"))
0
-    
0
-    # auto require factories:
0
-    Dir.glob(File.join(Mack.root, "test", "factories", "**/*.rb")).each do |f|
0
-      require f
0
-    end
0
-    
0
-    run_factories(:init) if respond_to?(:run_factories)
0
-  end
0
-  
0
-end
0
\ No newline at end of file
0
+# namespace :test do
0
+#   
0
+#   task :setup do
0
+#     ENV["MACK_ENV"] = "test"
0
+#     Mack.reset_logger!
0
+#     Rake::Task["db:recreate"].invoke
0
+#     Mack::Database.dump_structure("development")
0
+#     Mack::Database.load_structure(File.join(Mack.root, "db", "development_schema_structure.sql"))
0
+#     
0
+#     # auto require factories:
0
+#     Dir.glob(File.join(Mack.root, "test", "factories", "**/*.rb")).each do |f|
0
+#       require f
0
+#     end
0
+#     
0
+#     run_factories(:init) if respond_to?(:run_factories)
0
+#   end
0
+#   
0
+# end
0
\ No newline at end of file
...
33
34
35
36
 
 
37
38
 
 
39
40
41
...
33
34
35
 
36
37
38
 
39
40
41
42
43
0
@@ -33,9 +33,11 @@ module Spec
0
             # if exists delete the db created by this task
0
             config_db(adapter) do
0
               if db_exists?("foo_development")
0
-                rake_task("db:drop")
0
+                # rake_task("db:drop")
0
+                Mack::Database.drop
0
               elsif db_exists?("foo_test")
0
-                rake_task("db:drop", {"MACK_ENV" => "test"})
0
+                Mack::Database.create("test")
0
+                # rake_task("db:drop", {"MACK_ENV" => "test"})
0
               end
0
             end
0
           rescue Exception => ex
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
0
@@ -1,164 +1,164 @@
0
-require 'pathname'
0
-require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
0
-
0
-describe "rake" do
0
-
0
-  describe "db" do
0
-
0
-    describe "create" do
0
-
0
-      describe "MySQL" do
0
-        include Spec::CreateAndDropTask::Helper::MySQL
0
-        
0
-        before(:each) do
0
-          ENV["MACK_ENV"] = "development"
0
-          clear_connection
0
-        end
0
-        
0
-        after(:all) do 
0
-          cleanup_db
0
-        end
0
-        
0
-        it "should create a MySQL db for the current environment" do
0
-          config_db(:mysql) do
0
-            rake_task("db:recreate")
0
-            db_exists?("foo_development").should == true
0
-          end
0
-        end
0
-        
0
-        it "should drop/create a MySQL db if it already exists for the current environment" do
0
-          config_db(:mysql) do
0
-            rake_task("db:recreate")
0
-            db_exists?("foo_development").should == true
0
-            rake_task("db:drop")
0
-            db_exists?("foo_development").should == false
0
-          end
0
-        end
0
-        
0
-        it "should create a MySQL db for the specified environment" do
0
-          config_db(:mysql) do
0
-            rake_task("db:recreate", {"MACK_ENV" => "test"})
0
-            db_exists?("foo_test").should == true
0
-          end
0
-        end
0
-        
0
-        it "should drop/create a MySQL db if it already exists for the specified environment" do
0
-          config_db(:mysql) do
0
-            rake_task("db:recreate", {"MACK_ENV" => "test"})
0
-            db_exists?("foo_test").should == true
0
-            rake_task("db:recreate", {"MACK_ENV" => "test"})
0
-            db_exists?("foo_test").should == true
0
-          end
0
-        end
0
-      end
0
-
0
-      describe "PostgreSQL" do
0
-        include Spec::CreateAndDropTask::Helper::PostgreSQL
0
-        
0
-        before(:each) do 
0
-          clear_connection
0
-        end
0
-      
0
-        after(:each) do
0
-          cleanup_db
0
-        end
0
-      
0
-        it "should create a PostgreSQL db for the current environment" do
0
-          config_db(:postgresql) do
0
-            rake_task("db:recreate")
0
-            db_exists?("foo_development").should == true
0
-          end
0
-        end
0
-        
0
-        it "should drop a PostgreSQL db for the current environment" do
0
-          config_db(:postgresql) do
0
-            rake_task("db:recreate")
0
-            db_exists?("foo_development").should == true
0
-            rake_task("db:drop")
0
-            db_exists?("foo_development").should == false
0
-          end
0
-        end
0
-      
0
-        it "should create a PostgreSQL db for the specified environment" do
0
-          config_db(:postgresql) do
0
-            rake_task("db:recreate", {"MACK_ENV" => "test"})
0
-            db_exists?("foo_test", "test").should == true
0
-          end
0
-        end
0
-        
0
-        it "should drop a PostgreSQL db for the specified environment" do
0
-          config_db(:postgresql) do
0
-            rake_task("db:recreate", {"MACK_ENV" => "test"})
0
-            db_exists?("foo_test", "test").should == true
0
-            rake_task("db:drop", {"MACK_ENV" => "test"})
0
-            db_exists?("foo_test", "test").should == false
0
-          end
0
-        end
0
-      end
0
-
0
-    end
0
-
0
-    describe "create:all" do
0
-    
0
-      describe "MySQL" do
0
-        include Spec::CreateAndDropTask::Helper::MySQL
0
-        
0
-        before(:all) do
0
-          clear_connection
0
-        end
0
-        
0
-        after(:all) do
0
-          cleanup_db
0
-        end
0
-        
0
-        it "should create a MySQL db for all environments" do
0
-          config_db(:mysql) do
0
-            rake_task("db:recreate:all")
0
-            db_exists?("foo_development").should == true
0
-            db_exists?("foo_test").should == true
0
-          end
0
-        end
0
-        
0
-      end
0
-    
0
-      describe "PostgreSQL" do
0
-        include Spec::CreateAndDropTask::Helper::PostgreSQL
0
-        
0
-        before(:each) do
0
-          clear_connection
0
-        end
0
-        
0
-        after(:each) do
0
-          cleanup_db
0
-        end
0
-        
0
-        it "should create a PostgreSQL db for all environments" do
0
-          config_db(:postgresql) do
0
-            rake_task("db:recreate:all")
0
-            db_exists?("foo_test", "test").should == true
0
-            db_exists?("foo_development").should == true
0
-            
0
-            # running db:recreate again should be successful
0
-            rake_task("db:recreate:all")
0
-            db_exists?("foo_test", "test").should == true
0
-            db_exists?("foo_development").should == true
0
-          end
0
-        end
0
-        
0
-        it "should drop a PostgreSQL db for all environments" do
0
-          config_db(:postgresql) do
0
-            rake_task("db:recreate:all")
0
-            db_exists?("foo_test", "test").should == true
0
-            db_exists?("foo_development").should == true
0
-            rake_task("db:drop:all")
0
-            db_exists?("foo_test", "test").should == false
0
-            db_exists?("foo_development").should == false
0
-          end
0
-        end
0
-        
0
-      end
0
-    end
0
-
0
-  end
0
-
0
-end
0
\ No newline at end of file
0
+# require 'pathname'
0
+# require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
0
+# 
0
+# describe "rake" do
0
+# 
0
+#   describe "db" do
0
+# 
0
+#     describe "create" do
0
+# 
0
+#       describe "MySQL" do
0
+#         include Spec::CreateAndDropTask::Helper::MySQL
0
+#         
0
+#         before(:each) do
0
+#           ENV["MACK_ENV"] = "development"
0
+#           clear_connection
0
+#         end
0
+#         
0
+#         after(:all) do 
0
+#           cleanup_db
0
+#         end
0
+#         
0
+#         it "should create a MySQL db for the current environment" do
0
+#           config_db(:mysql) do
0
+#             rake_task("db:recreate")
0
+#             db_exists?("foo_development").should == true
0
+#           end
0
+#         end
0
+#         
0
+#         it "should drop/create a MySQL db if it already exists for the current environment" do
0
+#           config_db(:mysql) do
0
+#             rake_task("db:recreate")
0
+#             db_exists?("foo_development").should == true
0
+#             rake_task("db:drop")
0
+#             db_exists?("foo_development").should == false
0
+#           end
0
+#         end
0
+#         
0
+#         it "should create a MySQL db for the specified environment" do
0
+#           config_db(:mysql) do
0
+#             rake_task("db:recreate", {"MACK_ENV" => "test"})
0
+#             db_exists?("foo_test").should == true
0
+#           end
0
+#         end
0
+#         
0
+#         it "should drop/create a MySQL db if it already exists for the specified environment" do
0
+#           config_db(:mysql) do
0
+#             rake_task("db:recreate", {"MACK_ENV" => "test"})
0
+#             db_exists?("foo_test").should == true
0
+#             rake_task("db:recreate", {"MACK_ENV" => "test"})
0
+#             db_exists?("foo_test").should == true
0
+#           end
0
+#         end
0
+#       end
0
+# 
0
+#       describe "PostgreSQL" do
0
+#         include Spec::CreateAndDropTask::Helper::PostgreSQL
0
+#         
0
+#         before(:each) do 
0
+#           clear_connection
0
+#         end
0
+#       
0
+#         after(:each) do
0
+#           cleanup_db
0
+#         end
0
+#       
0
+#         it "should create a PostgreSQL db for the current environment" do
0
+#           config_db(:postgresql) do
0
+#             rake_task("db:recreate")
0
+#             db_exists?("foo_development").should == true
0
+#           end
0
+#         end
0
+#         
0
+#         it "should drop a PostgreSQL db for the current environment" do
0
+#           config_db(:postgresql) do
0
+#             rake_task("db:recreate")
0
+#             db_exists?("foo_development").should == true
0
+#             rake_task("db:drop")
0
+#             db_exists?("foo_development").should == false
0
+#           end
0
+#         end
0
+#       
0
+#         it "should create a PostgreSQL db for the specified environment" do
0
+#           config_db(:postgresql) do
0
+#             rake_task("db:recreate", {"MACK_ENV" => "test"})
0
+#             db_exists?("foo_test", "test").should == true
0
+#           end
0
+#         end
0
+#         
0
+#         it "should drop a PostgreSQL db for the specified environment" do
0
+#           config_db(:postgresql) do
0
+#             rake_task("db:recreate", {"MACK_ENV" => "test"})
0
+#             db_exists?("foo_test", "test").should == true
0
+#             rake_task("db:drop", {"MACK_ENV" => "test"})
0
+#             db_exists?("foo_test", "test").should == false
0
+#           end
0
+#         end
0
+#       end
0
+# 
0
+#     end
0
+# 
0
+#     describe "create:all" do
0
+#     
0
+#       describe "MySQL" do
0
+#         include Spec::CreateAndDropTask::Helper::MySQL
0
+#         
0
+#         before(:all) do
0
+#           clear_connection
0
+#         end
0
+#         
0
+#         after(:all) do
0
+#           cleanup_db
0
+#         end
0
+#         
0
+#         it "should create a MySQL db for all environments" do
0
+#           config_db(:mysql) do
0
+#             rake_task("db:recreate:all")
0
+#             db_exists?("foo_development").should == true
0
+#             db_exists?("foo_test").should == true
0
+#           end
0
+#         end
0
+#         
0
+#       end
0
+#     
0
+#       describe "PostgreSQL" do
0
+#         include Spec::CreateAndDropTask::Helper::PostgreSQL
0
+#         
0
+#         before(:each) do
0
+#           clear_connection
0
+#         end
0
+#         
0
+#         after(:each) do
0
+#           cleanup_db
0
+#         end
0
+#         
0
+#         it "should create a PostgreSQL db for all environments" do
0
+#           config_db(:postgresql) do
0
+#             rake_task("db:recreate:all")
0
+#             db_exists?("foo_test", "test").should == true
0
+#             db_exists?("foo_development").should == true
0
+#             
0
+#             # running db:recreate again should be successful
0
+#             rake_task("db:recreate:all")
0
+#             db_exists?("foo_test", "test").should == true
0
+#             db_exists?("foo_development").should == true
0
+#           end
0
+#         end
0
+#         
0
+#         it "should drop a PostgreSQL db for all environments" do
0
+#           config_db(:postgresql) do
0
+#             rake_task("db:recreate:all")
0
+#             db_exists?("foo_test", "test").should == true
0
+#             db_exists?("foo_development").should == true
0
+#             rake_task("db:drop:all")
0
+#             db_exists?("foo_test", "test").should == false
0
+#             db_exists?("foo_development").should == false
0
+#           end
0
+#         end
0
+#         
0
+#       end
0
+#     end
0
+# 
0
+#   end
0
+# 
0
+# end
0
\ No newline at end of file
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
0
@@ -1,132 +1,132 @@
0
-require 'pathname'
0
-require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
0
-
0
-describe "rake" do
0
-
0
-  describe "db" do
0
-  
0
-    describe "migrate" do
0
-      include Spec::CreateAndDropTask::Helper::MySQL
0
-      
0
-      after(:all) do
0
-        cleanup_db
0
-      end
0
-      
0
-      it "should migrate the database with the migrations in the db/migrations folder" do
0
-        config_db(:mysql) do
0
-          db_exists?("foo_development").should_not == true
0
-          rake_task("db:recreate")
0
-          db_exists?("foo_development").should == true
0
-          table_exists?("zoos").should_not == true
0
-          
0
-          # now write one migration file, and see if we can get the table created
0
-          data = fixture("002_create_zoos")
0
-          mig_file = File.join(migrations_directory, "002_create_zoos.rb")
0
-          
0
-          File.open(mig_file, "w") { |f| f.write(data) }
0
-          rake_task("db:migrate")
0
-          table_exists?("zoos").should == true
0
-          
0
-          FileUtils.rm_rf(mig_file)
0
-        end
0
-      end
0
-    
0
-    end
0
-  
0
-    describe "rollback" do
0
-      include Spec::CreateAndDropTask::Helper::MySQL
0
-      
0
-      after(:each) do
0
-        cleanup_db
0
-      end
0
-      
0
-      it "should rollback the database by a default of 1 step" do
0
-        config_db(:mysql) do
0
-          db_exists?("foo_development").should_not == true
0
-          rake_task("db:recreate")
0
-          db_exists?("foo_development").should == true
0
-          table_exists?("zoos").should_not == true
0
-          table_exists?("animals").should_not == true
0
-        
0
-          mig_file1 = File.join(migrations_directory, "002_create_zoos.rb")
0
-          mig_file2 = File.join(migrations_directory, "003_create_animals.rb")
0
-        
0
-          # now write one migration file, and see if we can get the table created
0
-          data = fixture("002_create_zoos")
0
-          File.open(mig_file1, "w") { |f| f.write(data) }
0
-          rake_task("db:migrate")
0
-          table_exists?("zoos").should == true
0
-        
0
-          # now write the second migration file, and see if we can see that table
0
-          data = fixture("003_create_animals")
0
-          File.open(mig_file2, "w") { |f| f.write(data) }
0
-          rake_task("db:migrate")
0
-          table_exists?("animals").should == true
0
-        
0
-          # now rollback 1 step, and we shouldn't see "animals" table anymore
0
-          rake_task("db:rollback")
0
-          table_exists?("animals").should_not == true
0
-
0
-          FileUtils.rm_rf(mig_file1)
0
-          FileUtils.rm_rf(mig_file2)
0
-        end
0
-      end
0
-    
0
-      it "should rollback the database by n steps if ENV['STEP'] is set" do
0
-        config_db(:mysql) do
0
-          db_exists?("foo_development").should_not == true
0
-          rake_task("db:recreate")
0
-          db_exists?("foo_development").should == true
0
-          table_exists?("zoos").should_not == true
0
-          table_exists?("animals").should_not == true
0
-          
0
-          mig_file1 = File.join(migrations_directory, "002_create_zoos.rb")
0
-          mig_file2 = File.join(migrations_directory, "003_create_animals.rb")
0
-                    
0
-          # now write 2 migration files, and we should see the 2 new tables
0
-          data = fixture("002_create_zoos")
0
-          File.open(mig_file1, "w") { |f| f.write(data) }
0
-          
0
-          data = fixture("003_create_animals")
0
-          File.open(mig_file2, "w") { |f| f.write(data) }
0
-          
0
-          rake_task("db:migrate")
0
-          table_exists?("zoos").should == true
0
-          table_exists?("animals").should == true
0
-
0
-          # now set ENV['STEP'] to 2, and we should see those 2 tables go away
0
-          ENV['STEP'] = "2"
0
-          rake_task("db:rollback")
0
-          table_exists?("animals").should_not == true
0
-          table_exists?("zoos").should_not == true
0
-
0
-          FileUtils.rm_rf(mig_file1)
0
-          FileUtils.rm_rf(mig_file2)
0
-        end
0
-      end
0
-    
0
-    end
0
-  
0
-    describe "version" do
0
-      include Spec::CreateAndDropTask::Helper::MySQL
0
-            
0
-      after(:all) do
0
-        cleanup_db
0
-      end
0
-    
0
-      it "should return the current version number of the database" do
0
-        config_db(:mysql) do
0
-          db_exists?("foo_development").should_not == true
0
-          rake_task("db:recreate")
0
-          db_exists?("foo_development").should == true
0
-          
0
-          rake_task("db:migrate")
0
-          Mack::Database::Migrator.version.to_s.should_not == ""
0
-        end
0
-      end
0
-    
0
-    end
0
-  
0
-  end
0
-  
0
-end
0
\ No newline at end of file
0
+# require 'pathname'
0
+# require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
0
+# 
0
+# describe "rake" do
0
+# 
0
+#   describe "db" do
0
+#   
0
+#     describe "migrate" do
0
+#       include Spec::CreateAndDropTask::Helper::MySQL
0
+#       
0
+#       after(:all) do
0
+#         cleanup_db
0
+#       end
0
+#       
0
+#       it "should migrate the database with the migrations in the db/migrations folder" do
0
+#         config_db(:mysql) do
0
+#           db_exists?("foo_development").should_not == true
0
+#           rake_task("db:recreate")
0
+#           db_exists?("foo_development").should == true
0
+#           table_exists?("zoos").should_not == true
0
+#           
0
+#           # now write one migration file, and see if we can get the table created
0
+#           data = fixture("002_create_zoos")
0
+#           mig_file = File.join(migrations_directory, "002_create_zoos.rb")
0
+#           
0
+#           File.open(mig_file, "w") { |f| f.write(data) }
0
+#           rake_task("db:migrate")
0
+#           table_exists?("zoos").should == true
0
+#           
0
+#           FileUtils.rm_rf(mig_file)
0
+#         end
0
+#       end
0
+#     
0
+#     end
0
+#   
0
+#     describe "rollback" do
0
+#       include Spec::CreateAndDropTask::Helper::MySQL
0
+#       
0
+#       after(:each) do
0
+#         cleanup_db
0
+#       end
0
+#       
0
+#       it "should rollback the database by a default of 1 step" do
0
+#         config_db(:mysql) do
0
+#           db_exists?("foo_development").should_not == true
0
+#           rake_task("db:recreate")
0
+#           db_exists?("foo_development").should == true
0
+#           table_exists?("zoos").should_not == true
0
+#           table_exists?("animals").should_not == true
0
+#         
0
+#           mig_file1 = File.join(migrations_directory, "002_create_zoos.rb")
0
+#           mig_file2 = File.join(migrations_directory, "003_create_animals.rb")
0
+#         
0
+#           # now write one migration file, and see if we can get the table created
0
+#           data = fixture("002_create_zoos")
0
+#           File.open(mig_file1, "w") { |f| f.write(data) }
0
+#           rake_task("db:migrate")
0
+#           table_exists?("zoos").should == true
0
+#         
0
+#           # now write the second migration file, and see if we can see that table
0
+#           data = fixture("003_create_animals")
0
+#           File.open(mig_file2, "w") { |f| f.write(data) }
0
+#           rake_task("db:migrate")
0
+#           table_exists?("animals").should == true
0
+#         
0
+#           # now rollback 1 step, and we shouldn't see "animals" table anymore
0
+#           rake_task("db:rollback")
0
+#           table_exists?("animals").should_not == true
0
+# 
0
+#           FileUtils.rm_rf(mig_file1)
0
+#           FileUtils.rm_rf(mig_file2)
0
+#         end
0
+#       end
0
+#     
0
+#       it "should rollback the database by n steps if ENV['STEP'] is set" do
0
+#         config_db(:mysql) do
0
+#           db_exists?("foo_development").should_not == true
0
+#           rake_task("db:recreate")
0
+#           db_exists?("foo_development").should == true
0
+#           table_exists?("zoos").should_not == true
0
+#           table_exists?("animals").should_not == true
0
+#           
0
+#           mig_file1 = File.join(migrations_directory, "002_create_zoos.rb")
0
+#           mig_file2 = File.join(migrations_directory, "003_create_animals.rb")
0
+#                     
0
+#           # now write 2 migration files, and we should see the 2 new tables
0
+#           data = fixture("002_create_zoos")
0
+#           File.open(mig_file1, "w") { |f| f.write(data) }
0
+#           
0
+#           data = fixture("003_create_animals")
0
+#           File.open(mig_file2, "w") { |f| f.write(data) }
0
+#           
0
+#           rake_task("db:migrate")
0
+#           table_exists?("zoos").should == true
0
+#           table_exists?("animals").should == true
0
+# 
0
+#           # now set ENV['STEP'] to 2, and we should see those 2 tables go away
0
+#           ENV['STEP'] = "2"
0
+#           rake_task("db:rollback")
0
+#           table_exists?("animals").should_not == true
0
+#           table_exists?("zoos").should_not == true
0
+# 
0
+#           FileUtils.rm_rf(mig_file1)
0
+#           FileUtils.rm_rf(mig_file2)
0
+#         end
0
+#       end
0
+#     
0
+#     end
0
+#   
0
+#     describe "version" do
0
+#       include Spec::CreateAndDropTask::Helper::MySQL
0
+#             
0
+#       after(:all) do
0
+#         cleanup_db
0
+#       end
0
+#     
0
+#       it "should return the current version number of the database" do
0
+#         config_db(:mysql) do
0
+#           db_exists?("foo_development").should_not == true
0
+#           rake_task("db:recreate")
0
+#           db_exists?("foo_development").should == true
0
+#           
0
+#           rake_task("db:migrate")
0
+#           Mack::Database::Migrator.version.to_s.should_not == ""
0
+#         end
0
+#       end
0
+#     
0
+#     end
0
+#   
0
+#   end
0
+#   
0
+# end
0
\ No newline at end of file
...
27
28
29
30
31
32
33
34
35
 
36
37
38
39
...
27
28
29
 
 
 
 
 
 
30
31
32
33
34
0
@@ -27,12 +27,7 @@ module Mack
0
         end
0
         DataMapper::MigrationRunner.migrations.clear
0
       end
0
-      
0
-      private
0
-      def self.migration_files
0
-        Dir.glob(File.join(Mack.root, "db", "migrations", "*.rb"))
0
-      end
0
-      
0
+            
0
     end # Migrations
0
   end # Database
0
 end # Mack
0
\ No newline at end of file
...
14
15
16
 
 
 
 
17
18
19
20
...
14
15
16
17
18
19
20
21
22
23
24
0
@@ -14,6 +14,10 @@ module Mack
0
         # raise NoMethodError.new(:abort_if_pending_migrations)
0
       end
0
       
0
+      def self.migration_files
0
+        Dir.glob(File.join(Mack.root, "db", "migrations", "*.rb"))
0
+      end
0
+      
0
     end # Migrations
0
   end # Database
0
 end # Mack
0
\ No newline at end of file

Comments