Class: PGSpecHelper

Inherits:
Object
  • Object
show all
Includes:
Columns, Connection, EmptyDatabase, Enums, Extensions, ForeignKeys, Functions, IgnoredSchemas, Indexes, MaterializedViews, Models, PrimaryKeys, Reset, Schemas, Tables, TrackChanges, Triggers, UniqueConstraints, Validations
Defined in:
lib/pg_spec_helper.rb,
lib/pg_spec_helper/enums.rb,
lib/pg_spec_helper/reset.rb,
lib/pg_spec_helper/models.rb,
lib/pg_spec_helper/tables.rb,
lib/pg_spec_helper/columns.rb,
lib/pg_spec_helper/indexes.rb,
lib/pg_spec_helper/schemas.rb,
lib/pg_spec_helper/version.rb,
lib/pg_spec_helper/triggers.rb,
lib/pg_spec_helper/functions.rb,
lib/pg_spec_helper/connection.rb,
lib/pg_spec_helper/extensions.rb,
lib/pg_spec_helper/validations.rb,
lib/pg_spec_helper/foreign_keys.rb,
lib/pg_spec_helper/primary_keys.rb,
lib/pg_spec_helper/track_changes.rb,
lib/pg_spec_helper/empty_database.rb,
lib/pg_spec_helper/table_executer.rb,
lib/pg_spec_helper/ignored_schemas.rb,
lib/pg_spec_helper/materialized_views.rb,
lib/pg_spec_helper/unique_constraints.rb

Defined Under Namespace

Modules: Columns, Connection, EmptyDatabase, Enums, Extensions, ForeignKeys, Functions, IgnoredSchemas, Indexes, MaterializedViews, Models, PrimaryKeys, Reset, Schemas, Tables, TrackChanges, Triggers, UniqueConstraints, Validations Classes: MissingRequiredOptionError, TableExecuter

Constant Summary collapse

VERSION =
"1.9.12"

Constants included from TrackChanges

TrackChanges::TRACKED_METHOD_CALLS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TrackChanges

#has_changes?

Methods included from EmptyDatabase

#assert_database_empty!

Methods included from Reset

#reset!

Methods included from MaterializedViews

#refresh_all_materialized_views, #track_materialized_view

Methods included from Models

#create_model

Methods included from Enums

#create_enum, #delete_created_enums, #drop_enum, #get_enum_names

Methods included from Extensions

#create_extension, #drop_extension, #get_extension_names

Methods included from Functions

#create_function, #delete_created_functions, #get_function_names

Methods included from Triggers

#create_trigger, #get_trigger_names

Methods included from Indexes

#create_index, #get_index_names

Methods included from PrimaryKeys

#create_primary_key, #get_primary_key_name

Methods included from UniqueConstraints

#create_unique_constraint, #get_unique_constraint_names

Methods included from ForeignKeys

#create_foreign_key, #get_foreign_key_names

Methods included from Validations

#create_validation, #get_validation_names

Methods included from Columns

#create_column, #get_column_names, #is_column_nullable

Methods included from Tables

#create_table, #delete_tables, #get_table_names

Methods included from Schemas

#create_schema, #delete_all_schemas, #get_schema_names, #schema_exists?

Methods included from IgnoredSchemas

#ignore_schema, #ignored_schemas

Methods included from Connection

#connection

Constructor Details

#initialize(host:, port:, database: nil, dbname: nil, user: nil, username: nil, password: nil) ⇒ PGSpecHelper

Returns a new instance of PGSpecHelper.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/pg_spec_helper.rb', line 56

def initialize host:, port:, database: nil, dbname: nil, user: nil, username: nil, password: nil
  # for simplicity, we accept both `database` and `dbname` as the name of the database
  # and both `user` and `username` as the name of the user
  # this covers the naming conventions from both the PG gem and ActiveRecord
  provided_database = dbname || database
  provided_username = user || username

  # assert that all required options are present
  raise MissingRequiredOptionError, "database is required" if provided_database.nil?
  raise MissingRequiredOptionError, "host is required" if host.nil?
  raise MissingRequiredOptionError, "username is required" if provided_username.nil?

  # record the configuration
  @database = provided_database
  @host = host
  @port = port || 5432
  @username = provided_username
  # password is optional
  @password = password

  # the TrackChanges module is used to track high level changes which are
  # made to the database using this class, this allows us to reach out to the
  # database and reset it only when needed.
  #
  # The `install_trackable_methods` method will override the methods which
  # we are tracking with a new proxy method which will record when the method
  # is called before subsequently calling the original method.
  install_trackable_methods
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



54
55
56
# File 'lib/pg_spec_helper.rb', line 54

def database
  @database
end

#hostObject (readonly)

Returns the value of attribute host.



54
55
56
# File 'lib/pg_spec_helper.rb', line 54

def host
  @host
end

#passwordObject (readonly)

Returns the value of attribute password.



54
55
56
# File 'lib/pg_spec_helper.rb', line 54

def password
  @password
end

#portObject (readonly)

Returns the value of attribute port.



54
55
56
# File 'lib/pg_spec_helper.rb', line 54

def port
  @port
end

#usernameObject (readonly)

Returns the value of attribute username.



54
55
56
# File 'lib/pg_spec_helper.rb', line 54

def username
  @username
end