Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix `spec/console` and show nice SQL output

  • Loading branch information...
commit dfc304401245abf0aee55c4b34e00a2bacdcd413 1 parent c764e8b
Mislav Marohnić authored
9 spec/console
View
@@ -1,8 +1,9 @@
#!/usr/bin/env ruby
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
-libs = []
+libs = %w[rubygems irb/completion console_fixtures]
-libs << 'irb/completion'
-libs << 'console_fixtures'
+args = libs.map { |lib| ['-r', lib] }.flatten
+args << '--simple-prompt'
-exec "#{irb} -Ilib:spec#{libs.map{ |l| " -r #{l}" }.join} --simple-prompt"
+ENV['RUBYLIB'] = 'lib:spec'
+exec irb, *args
23 spec/console_fixtures.rb
View
@@ -1,8 +1,29 @@
+require 'bundler'
+Bundler.setup
+
require 'will_paginate/finders/active_record'
require 'finders/activerecord_test_connector'
+
ActiverecordTestConnector.setup
+windows = RUBY_PLATFORM =~ /(:?mswin|mingw)/
+# used just for the `color` method
+log_subscriber = ActiveSupport::LogSubscriber.log_subscribers.first
+
+IGNORE_SQL = /\b(sqlite_master|sqlite_version)\b|^CREATE TABLE/
+
+ActiveSupport::Notifications.subscribe(/^sql\./) do |*args|
+ data = args.last
+ unless data[:name] =~ /^Fixture/ or data[:sql] =~ IGNORE_SQL
+ if windows
+ puts data[:sql]
+ else
+ puts log_subscriber.send(:color, data[:sql], :cyan)
+ end
+ end
+end
+
# load all fixtures
Fixtures.create_fixtures(ActiverecordTestConnector::FIXTURES_PATH, ActiveRecord::Base.connection.tables)
-ActiverecordTestConnector.show_sql
+WillPaginate::Finders::ActiveRecord.enable!
8 spec/finders/activerecord_test_connector.rb
View
@@ -41,7 +41,7 @@ def self.setup_connection
raise "no configuration for '#{db}'" unless configurations.key? db
configuration = configurations[db]
- ActiveRecord::Base.logger = Logger.new(STDOUT) if $0 == 'irb'
+ # ActiveRecord::Base.logger = Logger.new(STDOUT) if $0 == 'irb'
puts "using #{configuration['adapter']} adapter"
ActiveRecord::Base.configurations = { db => configuration }
@@ -72,12 +72,6 @@ def execute_with_counting(sql, name = nil, &block)
end
end
- def self.show_sql
- ActiveSupport::Notifications.subscribe('active_record.sql') do |*args|
- puts args.last[:sql]
- end
- end
-
module FixtureSetup
def fixtures(*tables)
table_names = tables.map { |t| t.to_s }
Please sign in to comment.
Something went wrong with that request. Please try again.