Permalink
Browse files

Changed add_column and change_column specs to check all supported db …

…adapters
  • Loading branch information...
1 parent cee507c commit acdb0105c025e815b8c47aaed97598caadb9528d @pyromaniac pyromaniac committed Nov 8, 2012
Showing with 61 additions and 66 deletions.
  1. +58 −63 spec/lib/activerecord_spec.rb
  2. +3 −3 spec/support/spec_for_adapter.rb
@@ -1,68 +1,63 @@
require 'spec_helper'
-# describe ActiveRecord::Base do
-# context '.connection' do
-# let!(:connection) { ActiveRecord::Base.connection }
-# let(:table_name) { :test_uuid_field_creation }
-
-# before :each do
-# connection.create_table table_name
-# connection.table_exists?(table_name).should be_true
-# end
-
-# after :each do
-# connection.drop_table table_name
-# end
-
-# context '#add_column' do
-# it 'support adding uuid column' do
-# connection.add_column table_name, :uuid_col, :uuid
-# connection.column_exists?(table_name, :uuid_col).should be_true
-# columns = connection.columns(table_name)
-# col = (columns.select {|c| c.name.to_sym == :uuid_col }).first
-# col.should_not be_nil
-
-# spec_for_adapter do |adapters|
-# adapters.sqlite { col.sql_type.should == 'uuid' }
-# adapters.mysql2 do
-# col.sql_type.should == 'binary(16)'
-# col.type.should == :binary
-# col.respond_to? :string_to_binary
-# end
-# end
-# end
-# end
-
-# context '#change_column' do
-# before :each do
-# connection.add_column table_name, :binary_col, :binary, :limit => 16
-# end
-
-# it 'support changing type from binary to uuid' do
-# col = (connection.columns(table_name).select {|c| c.name.to_sym == :binary_col}).first
-# col.should_not be_nil
-# spec_for_adapter do |adapters|
-# adapters.mysql2 do
-# col.type.should == :binary
-# col.sql_type.should == 'tinyblob'
-# end
-# end
-
-# connection.change_column table_name, :binary_col, :uuid
-
-# col = (connection.columns(table_name).select {|c| c.name.to_sym == :binary_col}).first
-# col.should_not be_nil
-# spec_for_adapter do |adapters|
-# adapters.mysql2 do
-# col.type.should == :binary
-# col.sql_type.should == 'binary(16)'
-# end
-# end
-# end
-# end
-
-# end
-# end
+describe ActiveRecord::Base do
+ context '.connection' do
+ let!(:connection) { ActiveRecord::Base.connection }
+ let(:table_name) { :test_uuid_field_creation }
+
+ before do
+ connection.drop_table(table_name) if connection.table_exists?(table_name)
+ connection.create_table(table_name)
+ end
+
+ after do
+ connection.drop_table table_name
+ end
+
+ specify { connection.table_exists?(table_name).should be_true }
+
+ context '#add_column' do
+ let(:column_name) { :uuid_column }
+ let(:column) { connection.columns(table_name).detect { |c| c.name.to_sym == column_name } }
+
+ before { connection.add_column table_name, column_name, :uuid }
+
+ specify { connection.column_exists?(table_name, column_name).should be_true }
+ specify { column.should_not be_nil }
+
+ it 'should have proper sql type' do
+ spec_for_adapter do |adapters|
+ adapters.sqlite3 { column.sql_type.should == 'binary(16)' }
+ adapters.mysql2 { column.sql_type.should == 'binary(16)' }
+ adapters.postgresql { column.sql_type.should == 'uuid' }
+ end
+ end
+ end
+
+ context '#change_column' do
+ let(:column_name) { :string_col }
+ let(:column) { connection.columns(table_name).detect { |c| c.name.to_sym == column_name } }
+
+ before do
+ connection.add_column table_name, column_name, :string
+ spec_for_adapter do |adapters|
+ adapters.sqlite3 { connection.change_column table_name, column_name, :uuid }
+ adapters.mysql2 { connection.change_column table_name, column_name, :uuid }
+ # adapters.postgresql { connection.change_column table_name, column_name, :uuid }
+ end
+ end
+
+ it 'support changing type from string to uuid' do
+ spec_for_adapter do |adapters|
+ adapters.sqlite3 { column.sql_type.should == 'binary(16)' }
+ adapters.mysql2 { column.sql_type.should == 'binary(16)' }
+ adapters.postgresql { pending('postgresql can`t change column type to uuid') }
+ end
+ end
+ end
+
+ end
+end
describe Article do
let!(:article) { Fabricate :article }
@@ -5,13 +5,13 @@ class SpecForAdapter
def initialize
@specs = {}
end
-
- [:sqlite, :mysql2, :postgres].each do |name|
+
+ [:sqlite3, :mysql2, :postgresql].each do |name|
send :define_method, name do |&block|
@specs[name] = block
end
end
-
+
def run(connection)
name = connection.adapter_name.downcase.to_sym
@specs[name].call() if(@specs.include? name)

0 comments on commit acdb010

Please sign in to comment.