Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Enabled tests for MS SQL Server. #113

Merged
merged 1 commit into from

2 participants

@endersonmaia

Used sqsh, activerecord-sqlserver-adapter and SQL Sever 2008 R2 Express to
run the tests. I'm sure there's a better solution for the changes at test/test_find.rb. :)

Finished tests in 2.741221s, 42.3169 tests/s, 107.6163 assertions/s.

116 tests, 295 assertions, 0 failures, 0 errors, 0 skips
@endersonmaia endersonmaia Enabled tests for MS SQL Server.
Used sqsh, activerecord-sqlserver-adapter and SQL Sever 2008 R2 Express to
run the tests. I'm sure there's a better solution for the changes at test/test_find.rb. :)
0a59888
@cfis
Owner

Thanks for the patch. For the test find method, maybe just update the test to use a regex comparison?

@cfis cfis merged commit aa186ef into composite-primary-keys:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 12, 2012
  1. @endersonmaia

    Enabled tests for MS SQL Server.

    endersonmaia authored
    Used sqsh, activerecord-sqlserver-adapter and SQL Sever 2008 R2 Express to
    run the tests. I'm sure there's a better solution for the changes at test/test_find.rb. :)
This page is out of date. Refresh to see the latest.
View
2  Rakefile
@@ -20,7 +20,7 @@ Dir.glob('tasks/**/*.rake').each do |rake_file|
end
# Set up test tasks for each supported connection adapter
-%w(mysql sqlite3 oracle oracle_enhanced postgresql ibm_db).each do |adapter|
+%w(mysql sqlite3 oracle oracle_enhanced postgresql ibm_db sqlserver).each do |adapter|
namespace adapter do
desc "Run tests using the #{adapter} adapter"
task "test" do
View
27 tasks/databases/sqlserver.rake
@@ -0,0 +1,27 @@
+require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
+require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
+
+namespace :sqlserver do
+ desc 'Build the SQL Server test database'
+ task :build_database => :load_connection do
+ options_str = connection_string
+
+ schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'sqlserver.sql')
+ sh %( sqsh #{options_str} -i #{schema} )
+ end
+
+ desc 'Drop the SQL Server test database'
+ task :drop_database => :load_connection do
+ options_str = connection_string
+
+ schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'sqlserver.drop.sql')
+ sh %( sqsh #{options_str} -i #{schema} )
+ end
+
+ desc 'Rebuild the SQL Server test database'
+ task :rebuild_database => [:drop_database, :build_database]
+
+ task :load_connection do
+ require File.join(PROJECT_ROOT, "test", "connections", "native_sqlserver", "connection")
+ end
+end
View
11 test/connections/native_sqlserver/connection.rb
@@ -0,0 +1,11 @@
+print "Using native SQL Server\n"
+
+require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
+
+def connection_string
+ "-S #{SPEC['host']} -U #{SPEC['username']} -P\"#{SPEC['password']}\""
+end
+
+# Adapter config setup in locals/database_connections.rb
+SPEC = CompositePrimaryKeys::ConnectionSpec['sqlserver']
+ActiveRecord::Base.establish_connection(SPEC)
View
86 test/fixtures/db_definitions/sqlserver.drop.sql
@@ -0,0 +1,86 @@
+USE [composite_primary_keys_unittest];
+go
+
+DROP TABLE reference_types;
+go
+
+DROP TABLE reference_codes;
+go
+
+DROP TABLE products;
+go
+
+DROP TABLE tariffs;
+go
+
+DROP TABLE product_tariffs;
+go
+
+DROP TABLE suburbs;
+go
+
+DROP TABLE streets;
+go
+
+DROP TABLE users;
+go
+
+DROP TABLE articles;
+go
+
+DROP TABLE readings;
+go
+
+DROP TABLE groups;
+go
+
+DROP TABLE memberships;
+go
+
+DROP TABLE membership_statuses;
+go
+
+DROP TABLE departments;
+go
+
+DROP TABLE employees;
+go
+
+DROP TABLE comments;
+go
+
+DROP TABLE hacks;
+go
+
+DROP TABLE restaurants;
+go
+
+DROP TABLE restaurants_suburbs;
+go
+
+DROP TABLE dorms;
+go
+
+DROP TABLE rooms;
+go
+
+DROP TABLE room_attributes;
+go
+
+DROP TABLE room_attribute_assignments;
+go
+
+DROP TABLE students;
+go
+
+DROP TABLE room_assignments;
+go
+
+DROP TABLE seats;
+go
+
+DROP TABLE capitols;
+go
+
+DROP TABLE products_restaurants;
+go
View
210 test/fixtures/db_definitions/sqlserver.sql
@@ -0,0 +1,210 @@
+USE [composite_primary_keys_unittest];
+go
+
+CREATE TABLE reference_types (
+ reference_type_id [int] IDENTITY(1000,1) NOT NULL,
+ type_label [varchar](50) NULL,
+ abbreviation [varchar](50) NULL,
+ description [varchar](50) NULL
+);
+go
+
+CREATE TABLE reference_codes (
+ reference_type_id [int],
+ reference_code [int],
+ code_label [varchar](50) NULL,
+ abbreviation [varchar](50) NULL,
+ description [varchar](50) NULL
+);
+go
+
+CREATE TABLE products (
+ id [int] IDENTITY(1000,1) NOT NULL,
+ name [varchar](50) NULL
+);
+go
+
+CREATE TABLE tariffs (
+ [tariff_id] [int],
+ [start_date] [date],
+ [amount] [int] NULL
+ CONSTRAINT [tariffs_pk] PRIMARY KEY
+ ( [tariff_id], [start_date] )
+);
+go
+
+CREATE TABLE product_tariffs (
+ [product_id] [int],
+ [tariff_id] [int],
+ [tariff_start_date] [date]
+ CONSTRAINT [product_tariffs_pk] PRIMARY KEY
+ ( [product_id], [tariff_id], [tariff_start_date] )
+);
+go
+
+CREATE TABLE suburbs (
+ city_id [int],
+ suburb_id [int],
+ name varchar(50) not null,
+ CONSTRAINT [suburbs_pk] PRIMARY KEY
+ ( [city_id], [suburb_id] )
+);
+go
+
+CREATE TABLE streets (
+ id [int] IDENTITY(1000,1) NOT NULL,
+ city_id [int] NOT NULL,
+ suburb_id [int] NOT NULL,
+ name [varchar](50) NOT NULL
+);
+go
+
+CREATE TABLE users (
+ id [int] IDENTITY(1000,1) NOT NULL,
+ name varchar(50) NOT NULL
+);
+go
+
+CREATE TABLE articles (
+ id [int] IDENTITY(1000,1) NOT NULL,
+ name varchar(50) NOT NULL
+);
+go
+
+CREATE TABLE readings (
+ id [int] PRIMARY KEY,
+ user_id [int] NOT NULL,
+ article_id [int] NOT NULL,
+ rating [int] NOT NULL
+);
+go
+
+CREATE TABLE groups (
+ id [int] IDENTITY(1000,1) NOT NULL,
+ name [varchar](50) NOT NULL
+);
+go
+
+CREATE TABLE memberships (
+ user_id [int] NOT NULL,
+ group_id [int] NOT NULL
+ CONSTRAINT [memberships_pk] PRIMARY KEY
+ ( [user_id], [group_id] )
+);
+go
+
+CREATE TABLE membership_statuses (
+ id [int] IDENTITY(1,1) NOT NULL,
+ user_id [int] not null,
+ group_id [int] not null,
+ status varchar(50) not null
+);
+go
+
+CREATE TABLE departments (
+ department_id [int] NOT NULL,
+ location_id [int] NOT NULL
+ CONSTRAINT [departments_pk] PRIMARY KEY
+ ( [department_id], [location_id] )
+);
+go
+
+CREATE TABLE employees (
+ id [int] IDENTITY(1000,1) NOT NULL,
+ department_id [int] NULL,
+ location_id [int] NULL
+);
+go
+
+CREATE TABLE comments (
+ id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL,
+ person_id [int] NULL,
+ person_type varchar(100) NULL,
+ hack_id [int] NULL
+);
+go
+
+CREATE TABLE hacks (
+ id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL,
+ name [varchar](50) NOT NULL
+);
+go
+
+CREATE TABLE restaurants (
+ franchise_id [int] NOT NULL,
+ store_id [int] NOT NULL,
+ name [varchar](100)
+ CONSTRAINT [restaurants_pk] PRIMARY KEY CLUSTERED
+ ( [franchise_id], [store_id] )
+);
+go
+
+CREATE TABLE restaurants_suburbs (
+ franchise_id [int] NOT NULL,
+ store_id [int] NOT NULL,
+ city_id [int] NOT NULL,
+ suburb_id [int] NOT NULL
+);
+go
+
+CREATE TABLE dorms (
+ id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL
+);
+go
+
+CREATE TABLE rooms (
+ dorm_id [int] NOT NULL,
+ room_id [int] NOT NULL,
+ CONSTRAINT [rooms_pk] PRIMARY KEY CLUSTERED
+ ( [dorm_id], [room_id] )
+);
+go
+
+CREATE TABLE room_attributes (
+ id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL,
+ name [varchar](50)
+);
+go
+
+CREATE TABLE room_attribute_assignments (
+ dorm_id [int] NOT NULL,
+ room_id [int] NOT NULL,
+ room_attribute_id [int] NOT NULL
+);
+go
+
+CREATE TABLE students (
+ id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL
+);
+go
+
+CREATE TABLE room_assignments (
+ student_id [int] NOT NULL,
+ dorm_id [int] NOT NULL,
+ room_id [int] NOT NULL
+);
+go
+
+CREATE TABLE seats (
+ flight_number [int] NOT NULL,
+ seat [int] NOT NULL,
+ customer [int]
+ CONSTRAINT [seats_pk] PRIMARY KEY
+ ( [flight_number], [seat] )
+);
+go
+
+CREATE TABLE capitols (
+ country varchar(450) NOT NULL,
+ city varchar(450) NOT NULL
+ CONSTRAINT [capitols_pk] PRIMARY KEY
+ ( [country], [city] )
+);
+go
+
+CREATE TABLE products_restaurants (
+ product_id [int] NOT NULL,
+ franchise_id [int] NOT NULL,
+ store_id [int] NOT NULL
+);
+go
View
7 test/test_find.rb
@@ -54,7 +54,12 @@ def test_not_found
connection = ActiveRecord::Base.connection
ref_type_quoted = "#{connection.quote_table_name('reference_codes')}.#{connection.quote_column_name('reference_type_id')}"
ref_code_quoted = "#{connection.quote_table_name('reference_codes')}.#{connection.quote_column_name('reference_code')}"
- expected = "Couldn't find ReferenceCode with ID=999,999 WHERE #{ref_type_quoted} = 999 AND #{ref_code_quoted} = 999"
+
+ if current_adapter?(:SQLServerAdapter)
+ expected = "Couldn't find ReferenceCode with ID=999,999 WHERE #{ref_type_quoted} = N'999' AND #{ref_code_quoted} = N'999'"
+ else
+ expected = "Couldn't find ReferenceCode with ID=999,999 WHERE #{ref_type_quoted} = 999 AND #{ref_code_quoted} = 999"
+ end
assert_equal(with_quoted_identifiers(expected),
error.message)
Something went wrong with that request. Please try again.