Skip to content

Commit

Permalink
Added controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jan 26, 2021
1 parent 349b565 commit 961e152
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ tmp
*.so
*.o
*.a
mkmf.log
*.log
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ gem "rake"

gem "activerecord", "~> 6.1.0"
gem "activerecord-import"
gem "combustion"
gem "pg"
gem "pg_query"
1 change: 1 addition & 0 deletions gemfiles/activerecord50.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ gem "rake"

gem "activerecord", "~> 5.0.0"
gem "activerecord-import"
gem "combustion"
gem "pg"
gem "pg_query", RUBY_VERSION.to_f < 2.5 ? "< 1.3.0" : nil
1 change: 1 addition & 0 deletions gemfiles/activerecord51.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ gem "rake"

gem "activerecord", "~> 5.1.0"
gem "activerecord-import"
gem "combustion"
gem "pg"
gem "pg_query"
1 change: 1 addition & 0 deletions gemfiles/activerecord52.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ gem "rake"

gem "activerecord", "~> 5.2.0"
gem "activerecord-import"
gem "combustion"
gem "pg"
gem "pg_query"
1 change: 1 addition & 0 deletions gemfiles/activerecord60.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ gem "rake"

gem "activerecord", "~> 6.0.0"
gem "activerecord-import"
gem "combustion"
gem "pg"
gem "pg_query"
69 changes: 69 additions & 0 deletions test/controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require_relative "test_helper"

class ControllerTest < ActionDispatch::IntegrationTest
def test_index
get pg_hero.root_path
assert_response :success
end

def test_space
get pg_hero.space_path
assert_response :success
end

def test_relation_space
get pg_hero.relation_space_path(relation: "users")
assert_response :success
end

def test_index_bloat
get pg_hero.index_bloat_path
assert_response :success
end

def test_live_queries
get pg_hero.live_queries_path
assert_response :success
end

def test_queries
get pg_hero.queries_path
assert_response :success
end

def test_show_query
get pg_hero.show_query_path(query_hash: 123)
assert_response :success
end

def test_system
get pg_hero.system_path
assert_response :success
end

def test_explain
get pg_hero.explain_path
assert_response :success
end

def test_tune
get pg_hero.tune_path
assert_response :success
end

def test_connections
get pg_hero.connections_path
assert_response :success
end

def test_maintenance
get pg_hero.maintenance_path
assert_response :success
end

def test_kill
# prevent warning for now
# post pg_hero.kill_path(pid: 1_000_000_000)
# assert_redirected_to "/"
end
end
Empty file.
3 changes: 3 additions & 0 deletions test/internal/config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test:
adapter: postgresql
database: pghero_test
3 changes: 3 additions & 0 deletions test/internal/config/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Rails.application.routes.draw do
mount PgHero::Engine, at: "/"
end
57 changes: 57 additions & 0 deletions test/internal/db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
ActiveRecord::Schema.define do
enable_extension "pg_stat_statements"
enable_extension "pg_trgm"
enable_extension "ltree"

create_table :pghero_query_stats, force: true do |t|
t.text :database
t.text :user
t.text :query
t.integer :query_hash, limit: 8
t.float :total_time
t.integer :calls, limit: 8
t.timestamp :captured_at
t.index [:database, :captured_at]
end

create_table :pghero_space_stats, force: true do |t|
t.text :database
t.text :schema
t.text :relation
t.integer :size, limit: 8
t.timestamp :captured_at
t.index [:database, :captured_at]
end

create_table :cities, force: true do |t|
t.string :name
end

create_table :states, force: true do |t|
t.string :name
end

create_table :users, force: true do |t|
t.integer :city_id
t.integer :login_attempts
t.string :email
t.string :zip_code
t.boolean :active
t.string :country
t.column :tree_path, :ltree
t.column :range, :int4range
t.column :last_known_ip, :inet
t.column :metadata, :jsonb
t.timestamp :created_at
t.timestamp :updated_at
t.index :id # duplicate index
t.index :updated_at
t.index :login_attempts, using: :hash
t.index "country gist_trgm_ops", using: :gist
t.index :tree_path, using: :gist
t.index :range, using: :gist
t.index :created_at, using: :brin
t.index "last_known_ip inet_ops", using: :gist
t.index :metadata, using: :gin
end
end
Empty file.
57 changes: 0 additions & 57 deletions test/support/migrations.rb

This file was deleted.

11 changes: 6 additions & 5 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require "bundler/setup"
require "combustion"
Bundler.require(:default)
require "minitest/autorun"
require "minitest/pride"
require "pg_query"
require "active_record"
require "activerecord-import"

class Minitest::Test
Expand All @@ -13,11 +13,12 @@ def database
end

logger = ActiveSupport::Logger.new(ENV["VERBOSE"] ? STDERR : nil)
ActiveRecord::Base.logger = logger

ActiveRecord::Base.establish_connection adapter: "postgresql", database: "pghero_test"

require_relative "support/migrations"
Combustion.path = "test/internal"
Combustion.initialize! :active_record, :action_controller do
config.action_controller.logger = logger
config.active_record.logger = logger
end

class City < ActiveRecord::Base
end
Expand Down

0 comments on commit 961e152

Please sign in to comment.