Skip to content

Commit

Permalink
Merge pull request #1234 from udzura/master
Browse files Browse the repository at this point in the history
Create table migration should be also timestamped if configured
  • Loading branch information
achiurizo committed Apr 8, 2013
2 parents ef453cc + 3ad5d0f commit d85e340
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 4 additions & 4 deletions padrino-gen/lib/padrino-gen/generators/components/actions.rb
Expand Up @@ -33,9 +33,9 @@ def output_model_migration(filename, name, columns, options={})
contents = options[:base].dup.gsub(/\s{4}!UP!\n/m, options[:up]).gsub(/!DOWN!\n/m, options[:down])
contents = contents.gsub(/!NAME!/, model_name.underscore.camelize).gsub(/!TABLE!/, model_name.underscore)
contents = contents.gsub(/!FILENAME!/, filename.underscore).gsub(/!FILECLASS!/, filename.underscore.camelize)
current_migration_number = return_last_migration_number
contents = contents.gsub(/!FIELDS!/, column_declarations).gsub(/!VERSION!/, (current_migration_number + 1).to_s)
migration_filename = "#{format("%03d", current_migration_number+1)}_#{filename.underscore}.rb"
migration_number = current_migration_number
contents = contents.gsub(/!FIELDS!/, column_declarations).gsub(/!VERSION!/, migration_number)
migration_filename = "#{format("%03d", migration_number)}_#{filename.underscore}.rb"
create_file(destination_root('db/migrate/', migration_filename), contents, :skip => true)
end
end
Expand Down Expand Up @@ -98,7 +98,7 @@ def return_last_migration_number
# For migration files
# returns the number of the migration that is being created
# returna timestamp instead if :migration_format: in .components is "timestamp"
#
#
# @api private
def current_migration_number
if fetch_component_choice(:migration_format).to_s == 'timestamp'
Expand Down
11 changes: 10 additions & 1 deletion padrino-gen/test/test_model_generator.rb
Expand Up @@ -67,7 +67,7 @@ def teardown
end

should "generate migration file versions properly" do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
capture_io { generate(:project, 'sample_project', "--migration_format=number", "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
capture_io { generate(:model, 'user', "-r=#{@apptmp}/sample_project") }
capture_io { generate(:model, 'account', "-r=#{@apptmp}/sample_project") }
capture_io { generate(:model, 'bank', "-r=#{@apptmp}/sample_project") }
Expand All @@ -76,6 +76,15 @@ def teardown
assert_file_exists("#{@apptmp}/sample_project/db/migrate/003_create_banks.rb")
end

should "generate migration file versions properly when timestamped" do
capture_io { generate(:project, 'sample_project', "--migration_format=timestamp", "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }

time = stop_time_for_test.utc.strftime("%Y%m%d%H%M%S")

capture_io { generate(:model, 'user', "-r=#{@apptmp}/sample_project") }
assert_file_exists("#{@apptmp}/sample_project/db/migrate/#{time}_create_users.rb")
end

should "generate a default type value for fields" do
current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
Expand Down

0 comments on commit d85e340

Please sign in to comment.