Skip to content
Browse files

start to sanity check with activerecord (which will, however, never b…

…e a dependency)
  • Loading branch information...
1 parent 9134e4e commit ad842489b0c1e6eb7c1547b3808d397228de4a6b @seamusabshere committed Aug 6, 2012
Showing with 16 additions and 0 deletions.
  1. +2 −0 create_table.gemspec
  2. +14 −0 spec/examples_spec.rb
View
2 create_table.gemspec
@@ -19,4 +19,6 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rspec-expectations'
gem.add_development_dependency 'rspec-mocks'
gem.add_development_dependency 'posix-spawn'
+ gem.add_development_dependency 'activerecord'
+ gem.add_development_dependency 'mysql2'
end
View
14 spec/examples_spec.rb
@@ -1,5 +1,10 @@
require 'spec_helper'
require 'yaml'
+require 'active_record'
+
+system %{ mysql -u root -ppassword -e "DROP DATABASE IF EXISTS create_table_test; CREATE DATABASE create_table_test CHARSET utf8" }
+ENV['DATABASE_URL'] ||= 'mysql2://root:password@127.0.0.1/create_table_test'
+ActiveRecord::Base.establish_connection
describe 'Examples' do
Dir[File.expand_path('../examples/*.yml', __FILE__)].each do |path|
@@ -8,9 +13,11 @@
before do
@c = CreateTable.new(e['input'])
end
+
it "generates correct output" do
assert_same_sql @c.to_sql, e['output']
end
+
e.each do |k, ref|
next if ['name', 'input', 'output'].include?(k)
it "checks #{k}" do
@@ -22,6 +29,13 @@
calc.should == ref
end
end
+
+ it "compares favorably with ActiveRecord's interpretation" do
+ conn = ActiveRecord::Base.connection
+ conn.execute e['input']
+ @c.columns.map(&:name).should == conn.columns(e['table_name']).map(&:name)
+ conn.drop_table e['table_name']
+ end
end
end
end

0 comments on commit ad84248

Please sign in to comment.
Something went wrong with that request. Please try again.