Skip to content

Commit

Permalink
Reworked timestamped_migration config setting
Browse files Browse the repository at this point in the history
  • Loading branch information
dbloete committed Jun 18, 2010
1 parent 1122679 commit 0c56e2c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
Expand Up @@ -55,7 +55,7 @@ def initialize(name)
# If you'd prefer to use numeric prefixes, you can turn timestamped migrations
# off by setting:
#
# config.mongoid.timestamped_migrations = false
# Mongoid.config.timestamped_migrations = false
#
# In environment.rb.
#
Expand Down
8 changes: 6 additions & 2 deletions lib/mongoid_rails_migrations/mongoid_ext/mongoid.rb
@@ -1,8 +1,12 @@
# encoding: utf-8

module Mongoid #:nodoc
class << self
class Config #:nodoc
# Specify whether or not to use timestamps for migration versions
cattr_accessor(:timestamped_migrations , :instance_writer => true) {|timestamped_migrations| timestamped_migrations = true }
attr_accessor :timestamped_migrations

def reset
@timestamped_migrations = true
end
end
end
3 changes: 2 additions & 1 deletion lib/rails/generators/mongoid/mongoid_generator.rb
@@ -1,3 +1,4 @@
require 'rails/generators/named_base'
require 'rails/generators/migration'

module Mongoid #:nodoc:
Expand All @@ -14,7 +15,7 @@ def self.source_root
# Implement the required interface for Rails::Generators::Migration.
def self.next_migration_number(dirname) #:nodoc:
next_migration_number = current_migration_number(dirname) + 1
if Mongoid.timestamped_migrations
if Mongoid.config.timestamped_migrations
[Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
else
"%.3d" % next_migration_number
Expand Down
1 change: 1 addition & 0 deletions test/config.rb
@@ -1,4 +1,5 @@
require File.dirname(__FILE__) + '/../lib/mongoid_rails_migrations'
require File.dirname(__FILE__) + '/../lib/rails/generators/mongoid/mongoid_generator'

Mongoid.configure do |config|
name = "mongoid_test"
Expand Down
8 changes: 7 additions & 1 deletion test/migration_test.rb
Expand Up @@ -116,6 +116,12 @@ def test_migrator_with_missing_version_numbers
Mongoid::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 500)
end
end


def test_turning_off_timestamped_migrations
Mongoid.config.timestamped_migrations = false
next_number = Mongoid::Generators::Base.next_migration_number(MIGRATIONS_ROOT + "/valid")
assert_equal "20100513063903", next_number
end

end
end

0 comments on commit 0c56e2c

Please sign in to comment.