Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Test inet data type migrations

  • Loading branch information...
commit 0145940015d1b5f5999d8ef8ab67db17ed4618e5 1 parent 776a8c1
@danmcclain danmcclain authored
View
2  .rspec
@@ -0,0 +1,2 @@
+--format Fivemat
+--colour
View
24 lib/postgres_ext/active_record/connection_adapters/postgres_adapter.rb
@@ -39,7 +39,31 @@ def #{column_type}(*args) # def string(*args)
end # end
EOV
end
+ end
+ class Table
+ EXTENDED_TYPES.keys.map(&:to_s).each do |column_type|
+ class_eval <<-EOV, __FILE__, __LINE__ + 1
+ def #{column_type}(*args) # def string(*args)
+ options = args.extract_options! # options = args.extract_options!
+ column_names = args # column_names = args
+ type = :'#{column_type}' # type = :string
+ column_names.each do |name| # column_names.each do |name|
+ column = ColumnDefinition.new(@base, name.to_s, type) # column = ColumnDefinition.new(@base, name, type)
+ if options[:limit] # if options[:limit]
+ column.limit = options[:limit] # column.limit = options[:limit]
+ elsif native[type].is_a?(Hash) # elsif native[type].is_a?(Hash)
+ column.limit = native[type][:limit] # column.limit = native[type][:limit]
+ end # end
+ column.precision = options[:precision] # column.precision = options[:precision]
+ column.scale = options[:scale] # column.scale = options[:scale]
+ column.default = options[:default] # column.default = options[:default]
+ column.null = options[:null] # column.null = options[:null]
+ @base.add_column(@table_name, name, column.sql_type, options) # @base.add_column(@table_name, name, column.sql_type, options)
+ end # end
+ end # end
+ EOV
+ end
end
NATIVE_DATABASE_TYPES.merge!(EXTENDED_TYPES)
View
1  postgres_ext.gemspec
@@ -24,4 +24,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'factory_girl_rails', '~> 3.2.0'
gem.add_development_dependency 'pg', '~> 0.13.2'
gem.add_development_dependency 'debugger', '~> 1.1.2'
+ gem.add_development_dependency 'fivemat'
end
View
5 spec/dummy/spec/models/person_spec.rb
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe Person do
- pending "add some examples to (or delete) #{__FILE__}"
-end
View
32 spec/migrations/data_types_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+describe 'Native Data Types Migrations' do
+ before do
+ class Testing < ActiveRecord::Base; end
+ end
+
+ describe 'inet type' do
+ it 'creates an inet column' do
+ lambda do
+ Testing.connection.create_table :data_types do |t|
+ t.inet :ip_1
+ t.inet :ip_2, :ip_3
+ end
+ end.should_not raise_exception
+
+ columns = Testing.connection.columns(:data_types)
+ ip_1 = columns.detect { |c| c.name == 'ip_1'}
+ ip_2 = columns.detect { |c| c.name == 'ip_2'}
+ ip_3 = columns.detect { |c| c.name == 'ip_3'}
+
+ ip_1.sql_type.should eq 'inet'
+ ip_2.sql_type.should eq 'inet'
+ ip_3.sql_type.should eq 'inet'
+ ip_1.sql_type.should eq 'inet'
+ end
+ end
+
+ after do
+ Object.send(:remove_const, :Testing)
+ end
+end
View
3  spec/spec_helper.rb
@@ -3,8 +3,6 @@
require File.expand_path('../dummy/config/environment.rb', __FILE__)
require 'rspec/rails'
-require 'capybara/rspec'
-require 'valid_attribute'
require 'factory_girl_rails'
require 'debugger'
require 'bourne'
@@ -18,5 +16,4 @@
RSpec.configure do |config|
config.mock_with :mocha
config.use_transactional_fixtures = true
- config.include Factory::Syntax::Methods
end
Please sign in to comment.
Something went wrong with that request. Please try again.