Commits

Michael Granger committed 994bad8

Write specs for the fallback_application_name addition.

  • Participants
  • Parent commits ee5c4f8

Comments (0)

Files changed (2)

lib/pg/connection.rb

 		# This will be swapped soon for code that makes options like those required for
 		# PQconnectdbParams()/PQconnectStartParams(). For now, stick to an options string for
 		# PQconnectdb()/PQconnectStart().
-		connopts = ["fallback_application_name=#{quote_connstr($0)}"]
+
+		appname = PG::Connection.quote_connstr( $0 )
+		connopts = ["fallback_application_name=#{appname}"]
 
 		# Handle an options hash first
 		if args.last.is_a?( Hash )
 			end
 		end
 
+		$stderr.puts "Connecting with options: %p" % [ connopts.join(' ') ]
 		return connopts.join(' ')
 	end
 

spec/pg/connection_spec.rb

 		optstring.should =~ /(^|\s)host='pgsql.example.com'/
 		optstring.should =~ /(^|\s)dbname='sales'/
 		optstring.should =~ /(^|\s)options='-c geqo=off'/
-		
+
 		optstring.should_not =~ /port=/
 		optstring.should_not =~ /tty=/
 	end
 	end
 
 	it "escapes single quotes and backslashes in connection parameters" do
-		described_class.parse_connect_args( "DB 'browser' \\" ).should == "host='DB \\'browser\\' \\\\'"
+		described_class.parse_connect_args( "DB 'browser' \\" ).
+			should =~ /host='DB \\'browser\\' \\\\'/
 
 	end
 
 		expect { conn.finish }.to raise_error( PG::Error, /connection is closed/i )
 	end
 
+	it "sets the fallback_application_name on new connections" do
+		PG::Connection.parse_connect_args( 'dbname=test' ).should include( $0 )
+	end
+
 
 	context "under PostgreSQL 9", :postgresql_90 do