Skip to content

Commit

Permalink
fixup! fixup! fixup! Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VladislavSokov committed Jul 5, 2024
1 parent 8404a76 commit b7c52f8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
43 changes: 33 additions & 10 deletions test/controllers/actual_db_schema/migrations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def setup
Rails.logger = Logger.new($stdout)
ActionController::Base.view_paths = [File.expand_path("../../../app/views/", __dir__)]
active_record_setup
@utils.cleanup
@utils.prepare_phantom_migrations
@utils.cleanup(TestingState.db_config)
@utils.prepare_phantom_migrations(TestingState.db_config)
end

def routes_setup
Expand All @@ -27,9 +27,8 @@ def routes_setup
end

def active_record_setup
ActiveRecord::Base.configurations = { "test" => TestingState.db_config["primary"] }
ActiveRecord::Tasks::DatabaseTasks.database_configuration = { "test" => TestingState.db_config["primary"] }
ActiveRecord::Base.establish_connection(**TestingState.db_config["primary"])
ActiveRecord::Base.configurations = { "test" => TestingState.db_config }
ActiveRecord::Tasks::DatabaseTasks.database_configuration = { "test" => TestingState.db_config }
end

test "GET #index returns a successful response" do
Expand All @@ -40,12 +39,30 @@ def active_record_setup
assert_select "tr" do
assert_select "td", text: "up"
assert_select "td", text: "20130906111511"
assert_select "td", text: "First"
assert_select "td", text: "FirstPrimary"
assert_select "td", text: @utils.branch_for("20130906111511")
assert_select "td", text: "tmp/primary.sqlite3"
end
assert_select "tr" do
assert_select "td", text: "up"
assert_select "td", text: "20130906111512"
assert_select "td", text: "Second"
assert_select "td", text: "SecondPrimary"
assert_select "td", text: @utils.branch_for("20130906111512")
assert_select "td", text: "tmp/primary.sqlite3"
end
assert_select "tr" do
assert_select "td", text: "up"
assert_select "td", text: "20130906111514"
assert_select "td", text: "FirstSecondary"
assert_select "td", text: @utils.branch_for("20130906111514")
assert_select "td", text: "tmp/secondary.sqlite3"
end
assert_select "tr" do
assert_select "td", text: "up"
assert_select "td", text: "20130906111515"
assert_select "td", text: "SecondSecondary"
assert_select "td", text: @utils.branch_for("20130906111515")
assert_select "td", text: "tmp/secondary.sqlite3"
end
end
end
Expand All @@ -54,7 +71,7 @@ def active_record_setup
test "GET #show returns a successful response" do
get :show, params: { id: "20130906111511", database: "tmp/primary.sqlite3" }
assert_response :success
assert_select "h2", text: "Migration First Details"
assert_select "h2", text: "Migration FirstPrimary Details"
assert_select "table" do
assert_select "tr" do
assert_select "th", text: "Status"
Expand All @@ -68,6 +85,10 @@ def active_record_setup
assert_select "th", text: "Database"
assert_select "td", text: "tmp/primary.sqlite3"
end
assert_select "tr" do
assert_select "th", text: "Branch"
assert_select "td", text: @utils.branch_for("20130906111511")
end
end
end

Expand All @@ -80,12 +101,14 @@ def active_record_setup
assert_select "tr" do
assert_select "td", text: "down"
assert_select "td", text: "20130906111511"
assert_select "td", text: "First"
assert_select "td", text: "FirstPrimary"
assert_select "td", text: @utils.branch_for("20130906111511")
end
assert_select "tr" do
assert_select "td", text: "up"
assert_select "td", text: "20130906111512"
assert_select "td", text: "Second"
assert_select "td", text: "SecondPrimary"
assert_select "td", text: @utils.branch_for("20130906111512")
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions test/support/test_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ def migrated_files(db_config = nil)
end
end

def branch_for(version)
metadata.fetch(version.to_s, {})[:branch]
end

private

def cleanup_call(prefix_name = nil)
Expand Down Expand Up @@ -189,4 +193,8 @@ def applied_migrations_call
def run_sql(sql)
ActiveRecord::Base.connection.execute(sql)
end

def metadata
ActualDbSchema::Store.instance.read
end
end

0 comments on commit b7c52f8

Please sign in to comment.