-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dan McClain
committed
Aug 8, 2012
1 parent
14fcb82
commit 9c6c014
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |