Skip to content

Commit

Permalink
Adds arel tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan McClain committed Aug 8, 2012
1 parent 14fcb82 commit 9c6c014
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions spec/arel/inet_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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, :array => true
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 'cotained with (<<) operator' do
it 'converts Arel contained_within statemnts 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
end

0 comments on commit 9c6c014

Please sign in to comment.