Skip to content

Commit

Permalink
stub git
Browse files Browse the repository at this point in the history
  • Loading branch information
ka8725 committed Jan 14, 2024
1 parent 8e1736b commit 9ef72a9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
3 changes: 2 additions & 1 deletion lib/actual_db_schema.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

require "active_record/migration"
require "CSV"
require "csv"
require_relative "actual_db_schema/git"
require_relative "actual_db_schema/store"
require_relative "actual_db_schema/version"
require_relative "actual_db_schema/patches/migration_proxy"
Expand Down
19 changes: 10 additions & 9 deletions lib/actual_db_schema/commands/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ def preambule
end

def separator_width
(8 + 14 + branch_column_width + 2 + "Migration File".length)
header.map(&:length).sum + (header.size - 1) * 2
end

def header
[
"Status".center(8),
"Migration ID".ljust(14),
"Branch".ljust(branch_column_width),
"Migration File"
]
@header ||=
[
"Status".center(8),
"Migration ID".ljust(14),
"Branch".ljust(branch_column_width),
"Migration File".ljust(16)
]
end

def table
Expand All @@ -51,7 +52,7 @@ def line_for(status, version)
[
status.center(8),
version.to_s.ljust(14),
branch_for(version).ljust(14),
branch_for(version).ljust(branch_column_width),
migration.filename.gsub("#{Rails.root}/", "")
].join(" ")
end
Expand All @@ -70,7 +71,7 @@ def longest_branch_name
end

def branch_column_width
longest_branch_name.length + 2
longest_branch_name.length
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions lib/actual_db_schema/git.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module ActualDbSchema
# Git helper
class Git
def self.current_branch
`git rev-parse --abbrev-ref HEAD`.strip
rescue Errno::ENOENT
"unknown"
end
end
end
8 changes: 1 addition & 7 deletions lib/actual_db_schema/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,11 @@ def record_metadata(filename)
csv << [
version,
Time.current.iso8601,
`git rev-parse --abbrev-ref HEAD`.strip
Git.current_branch
]
end
end

def current_branch
`git rev-parse --abbrev-ref HEAD`.strip
rescue Errno::ENOENT
"unknown"
end

def folder
ActualDbSchema.migrated_folder
end
Expand Down
14 changes: 8 additions & 6 deletions test/rake_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ def run_task
end

it "shows the list of phantom migrations" do
prepare_phantom_migrations
run_task
assert_match(/ Status Migration ID Migration File/, TestingState.output)
assert_match(/--------------------------------------------------/, TestingState.output)
assert_match(%r{ up 20130906111511 tmp/migrated/20130906111511_first.rb}, TestingState.output)
assert_match(%r{ up 20130906111512 tmp/migrated/20130906111512_second.rb}, TestingState.output)
ActualDbSchema::Git.stub(:current_branch, "fix-bug") do
prepare_phantom_migrations
run_task
assert_match(/ Status Migration ID Branch Migration File/, TestingState.output)
assert_match(/---------------------------------------------------/, TestingState.output)
assert_match(%r{ up 20130906111511 fix-bug tmp/migrated/20130906111511_first.rb}, TestingState.output)
assert_match(%r{ up 20130906111512 fix-bug tmp/migrated/20130906111512_second.rb}, TestingState.output)
end
end
end

0 comments on commit 9ef72a9

Please sign in to comment.