Sha256: 75a0836dd32d3cc2c7a9725209a77ea6bb4669ffdd01374b5de9d480179c86b9

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'
describe Upsert do
  describe 'hstore on pg' do
    it "just works" do
      require 'hstore'
      Pet.connection.execute 'CREATE EXTENSION HSTORE'
      Pet.connection.execute "ALTER TABLE pets ADD COLUMN crazy HSTORE"
      upsert = Upsert.new $conn, :pets

      upsert.row({name: 'Bill'}, crazy: nil)
      row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
      row['crazy'].should == nil

      upsert.row({name: 'Bill'}, crazy: {a: 1})
      row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
      crazy = HStore.parse row['crazy']
      crazy.should == { a: '1' }

      upsert.row({name: 'Bill'}, crazy: nil)
      row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
      row['crazy'].should == nil

      upsert.row({name: 'Bill'}, crazy: {a: 1})
      row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
      crazy = HStore.parse row['crazy']
      crazy.should == { a: '1' }

      upsert.row({name: 'Bill'}, crazy: {whatdat: 'whodat'})
      row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
      crazy = HStore.parse row['crazy']
      crazy.should == { a: '1', whatdat: 'whodat' }

      upsert.row({name: 'Bill'}, crazy: {a: 2})
      row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
      crazy = HStore.parse row['crazy']
      crazy.should == { a: '2', whatdat: 'whodat' }
    end
  end
end if ENV['DB'] == 'postgresql'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
upsert-1.1.3 spec/hstore_spec.rb