lib/postspec.rb in postspec-0.2.5 vs lib/postspec.rb in postspec-0.4.0

- old
+ new

@@ -32,11 +32,11 @@ # Type of the database. A PgGraph::Type object attr_reader :type # List of table types in the database except tables from hidden schemas (eg. postspec) attr_reader :tables - + # If true and a test case fails, postspec will commit all changes and # ignore any further tests. If rspec is called with the --fail-fast option # the test run will terminate immediately. Default true attr_reader :fail @@ -66,28 +66,30 @@ attr_reader :render # TODO: PgMeta object # # +mode+ can be one of :seed, :empty (TODO :reseed, :keep) - def initialize(conn, reflector: nil, mode: :empty, anchors: [], fail: true, ignore: []) + def initialize(conn, reflector: nil, mode: :empty, anchors: [], fail: true, ignore: [], cache: nil) constrain conn, PgConn constrain reflector, NilClass, String, PgGraph::Reflector constrain mode, lambda { |m| [:empty, :seed].include?(m) } constrain anchors, [Hash], NilClass constrain fail, TrueClass, FalseClass constrain ignore, [String] + constrain cache, String, nil @conn = conn - @meta = PgMeta.new(@conn) + @meta = cache ? PgMeta.cache(@conn, yaml: cache) : PgMeta.new(@conn) # Make sure the postspec schema is not included in the type model. TODO: # Consolidate this into the :ignore option of PgGraph::Type.new as is # done with the prick schema below has_postspec = @meta.schemas.key?("postspec") !has_postspec or (@meta.schemas["postspec"].hidden = true) - @type = PgGraph::Type.new(@meta, reflector, ignore: ["prick"] + ignore) + @type = PgGraph::Type.new(@meta, reflector, ignore: ["prick"] + ignore) + @render = Render.new(self) @tables = type.schemas.map(&:tables).flatten @ignore = ignore @fail = fail @failed = false @@ -174,13 +176,16 @@ # True if this is the primary transaction. A primary transaction is a # Postgres transaction while secondary transactions are savepoints def primary_transaction?() @frames.size == 1 end - # Transactionn timestamp + # Transactionn timestamp without time zone def timestamp() @conn.timestamp end + # Transactionn timestamp with time zone + def timestamptz() @conn.timestamptz end + # True if no tests failed. Default true def success?() @success end # True if Postspec is in failed state. In failed state no new commands can # be issued. Postspec enters a failed state when it encounters an error and @@ -193,11 +198,11 @@ @success = false @failed = true if @fail end def search_path() @search_path end - def search_path=(*paths) + def search_path=(*paths) @search_path = Array(paths).flatten.compact @search_path = %w(public) if @search_path.empty? end # Only called from RSpec::Core::ExampleGroup#set_search_path. FIXME: Why not search_path= @@ -316,10 +321,10 @@ # The content of the fixture as a PgGraph::Data object def fixture() @fixture ||= begin if fox.ast - fox.data + fox.data elsif @foxes.size >= 2 @foxes[-2].data else type.instantiate end