Skip to content

Commit 0145940

Browse files
author
Dan Seaver
committed
Test inet data type migrations
1 parent 776a8c1 commit 0145940

File tree

6 files changed

+59
-8
lines changed

6 files changed

+59
-8
lines changed

.rspec

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--format Fivemat
2+
--colour

lib/postgres_ext/active_record/connection_adapters/postgres_adapter.rb

+24
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,31 @@ def #{column_type}(*args) # def string(*args)
3939
end # end
4040
EOV
4141
end
42+
end
4243

44+
class Table
45+
EXTENDED_TYPES.keys.map(&:to_s).each do |column_type|
46+
class_eval <<-EOV, __FILE__, __LINE__ + 1
47+
def #{column_type}(*args) # def string(*args)
48+
options = args.extract_options! # options = args.extract_options!
49+
column_names = args # column_names = args
50+
type = :'#{column_type}' # type = :string
51+
column_names.each do |name| # column_names.each do |name|
52+
column = ColumnDefinition.new(@base, name.to_s, type) # column = ColumnDefinition.new(@base, name, type)
53+
if options[:limit] # if options[:limit]
54+
column.limit = options[:limit] # column.limit = options[:limit]
55+
elsif native[type].is_a?(Hash) # elsif native[type].is_a?(Hash)
56+
column.limit = native[type][:limit] # column.limit = native[type][:limit]
57+
end # end
58+
column.precision = options[:precision] # column.precision = options[:precision]
59+
column.scale = options[:scale] # column.scale = options[:scale]
60+
column.default = options[:default] # column.default = options[:default]
61+
column.null = options[:null] # column.null = options[:null]
62+
@base.add_column(@table_name, name, column.sql_type, options) # @base.add_column(@table_name, name, column.sql_type, options)
63+
end # end
64+
end # end
65+
EOV
66+
end
4367
end
4468

4569
NATIVE_DATABASE_TYPES.merge!(EXTENDED_TYPES)

postgres_ext.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ Gem::Specification.new do |gem|
2424
gem.add_development_dependency 'factory_girl_rails', '~> 3.2.0'
2525
gem.add_development_dependency 'pg', '~> 0.13.2'
2626
gem.add_development_dependency 'debugger', '~> 1.1.2'
27+
gem.add_development_dependency 'fivemat'
2728
end

spec/dummy/spec/models/person_spec.rb

-5
This file was deleted.

spec/migrations/data_types_spec.rb

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'spec_helper'
2+
3+
describe 'Native Data Types Migrations' do
4+
before do
5+
class Testing < ActiveRecord::Base; end
6+
end
7+
8+
describe 'inet type' do
9+
it 'creates an inet column' do
10+
lambda do
11+
Testing.connection.create_table :data_types do |t|
12+
t.inet :ip_1
13+
t.inet :ip_2, :ip_3
14+
end
15+
end.should_not raise_exception
16+
17+
columns = Testing.connection.columns(:data_types)
18+
ip_1 = columns.detect { |c| c.name == 'ip_1'}
19+
ip_2 = columns.detect { |c| c.name == 'ip_2'}
20+
ip_3 = columns.detect { |c| c.name == 'ip_3'}
21+
22+
ip_1.sql_type.should eq 'inet'
23+
ip_2.sql_type.should eq 'inet'
24+
ip_3.sql_type.should eq 'inet'
25+
ip_1.sql_type.should eq 'inet'
26+
end
27+
end
28+
29+
after do
30+
Object.send(:remove_const, :Testing)
31+
end
32+
end

spec/spec_helper.rb

-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
require File.expand_path('../dummy/config/environment.rb', __FILE__)
44

55
require 'rspec/rails'
6-
require 'capybara/rspec'
7-
require 'valid_attribute'
86
require 'factory_girl_rails'
97
require 'debugger'
108
require 'bourne'
@@ -18,5 +16,4 @@
1816
RSpec.configure do |config|
1917
config.mock_with :mocha
2018
config.use_transactional_fixtures = true
21-
config.include Factory::Syntax::Methods
2219
end

0 commit comments

Comments
 (0)