Sha256: 88787bf46109c38c1e0646ef2fee0c0bf55fcc08c02c7fc30f77c7138e818fa9

Contents?: true

Size: 1.11 KB

Versions: 8

Compression:

Stored size: 1.11 KB

Contents

require 'spec_helper'
describe Upsert do
  describe "logger" do
    it "logs where you tell it" do
      begin
        old_logger = Upsert.logger
        io = StringIO.new
        Thread.exclusive do
          Upsert.logger = Logger.new(io)

          Upsert.logger.warn "hello"

          io.rewind
          io.read.chomp.should == 'hello'
        end
      ensure
        Upsert.logger = old_logger
      end
    end

    it "logs queries" do
      begin
        old_logger = Upsert.logger
        io = StringIO.new
        Thread.exclusive do
          Upsert.logger = Logger.new(io)
          
          u = Upsert.new($conn, :pets)
          u.row(name: 'Jerry')

          io.rewind
          log = io.read.chomp
          case u.connection.class.name
          when /sqlite/i
            log.should =~ /insert or ignore/i
          when /mysql/i
            log.should =~ /call upsert_pets_SEL_name/i
          when /p.*g/i
            log.should =~ /select upsert_pets_SEL_name/i
          else
            raise "not sure"
          end
        end
      ensure
        Upsert.logger = old_logger
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
upsert-1.2.0 spec/logger_spec.rb
upsert-1.1.7 spec/logger_spec.rb
upsert-1.1.6 spec/logger_spec.rb
upsert-1.1.5 spec/logger_spec.rb
upsert-1.1.4 spec/logger_spec.rb
upsert-1.1.3 spec/logger_spec.rb
upsert-1.1.1 spec/logger_spec.rb
upsert-1.1.0 spec/logger_spec.rb