Sha256: e178c5adde1c16d2d8c80b0cc43c59ca1ddf8ab293addd66924b9e0e73d6f71a

Contents?: true

Size: 1.82 KB

Versions: 3

Compression:

Stored size: 1.82 KB

Contents

require 'spec_helper'

describe 'INET related AREL functions' do
  let!(:adapter) { ActiveRecord::Base.connection }
  before do
    adapter.create_table :ip_addresses, :force => true do |t|
      t.inet :address
    end

    class IpAddress < ActiveRecord::Base
      attr_accessible :address
    end
  end

  after do
    adapter.drop_table :ip_addresses
    Object.send(:remove_const, :IpAddress)
  end

  describe 'quoting IPAddr in sql statement' do
    it 'properly converts IPAddr to quoted strings when passed as an argument to a where clause' do
      IpAddress.where(:address => IPAddr.new('127.0.0.1')).to_sql.should include("'127.0.0.1/32'")
    end
  end

  describe 'contained with (<<) operator' do
    it 'converts Arel contained_within statements to <<' do
      arel_table = IpAddress.arel_table

      arel_table.where(arel_table[:address].contained_within(IPAddr.new('127.0.0.1/24'))).to_sql.should match /<< '127.0.0.0\/24'/
    end
  end

  describe 'contained within or equals (<<=) operator' do
    it 'converts Arel contained_within_or_equals statements to  <<=' do
      arel_table  = IpAddress.arel_table

      arel_table.where(arel_table[:address].contained_within_or_equals(IPAddr.new('127.0.0.1/24'))).to_sql.should match /<<= '127.0.0.0\/24'/
    end
  end
  describe 'contains (>>) operator' do
    it 'converts Arel contains statements to >>' do
      arel_table = IpAddress.arel_table

      arel_table.where(arel_table[:address].contains(IPAddr.new('127.0.0.1/24'))).to_sql.should match />> '127.0.0.0\/24'/
    end
  end

  describe 'contains or equals (>>=) operator' do
    it 'converts Arel contains_or_equals statements to  >>=' do
      arel_table  = IpAddress.arel_table

      arel_table.where(arel_table[:address].contains_or_equals(IPAddr.new('127.0.0.1/24'))).to_sql.should match />>= '127.0.0.0\/24'/
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
postgres_ext-0.2.2 spec/arel/inet_spec.rb
postgres_ext-0.2.1 spec/arel/inet_spec.rb
postgres_ext-0.2.0 spec/arel/inet_spec.rb