Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled tests for MS SQL Server. #113

Merged
merged 1 commit into from
Jul 2, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions tasks/databases/sqlserver.rake
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions test/connections/native_sqlserver/connection.rb
Original file line number Diff line number Diff line change
@@ -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)
86 changes: 86 additions & 0 deletions test/fixtures/db_definitions/sqlserver.drop.sql
Original file line number Diff line number Diff line change
@@ -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
210 changes: 210 additions & 0 deletions test/fixtures/db_definitions/sqlserver.sql
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion test/test_find.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down