Skip to content
This repository

Enabled tests for MS SQL Server. #113

Merged
merged 1 commit into from almost 2 years ago

2 participants

Enderson Tadeu S. Maia Charlie Savage
Enderson Tadeu S. Maia

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
Enderson Tadeu S. Maia 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
Charlie Savage
Owner
cfis commented July 01, 2012

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

Charlie Savage cfis merged commit aa186ef into from July 01, 2012
Charlie Savage cfis closed this July 01, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jun 12, 2012
Enderson Tadeu S. Maia 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
This page is out of date. Refresh to see the latest.
2  Rakefile
@@ -20,7 +20,7 @@ Dir.glob('tasks/**/*.rake').each do |rake_file|
20 20
 end
21 21
 
22 22
 # Set up test tasks for each supported connection adapter
23  
-%w(mysql sqlite3 oracle oracle_enhanced postgresql ibm_db).each do |adapter|
  23
+%w(mysql sqlite3 oracle oracle_enhanced postgresql ibm_db sqlserver).each do |adapter|
24 24
   namespace adapter do
25 25
     desc "Run tests using the #{adapter} adapter"
26 26
     task "test" do
27  tasks/databases/sqlserver.rake
... ...
@@ -0,0 +1,27 @@
  1
+require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
  2
+require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
  3
+
  4
+namespace :sqlserver do
  5
+  desc 'Build the SQL Server test database'
  6
+  task :build_database => :load_connection do
  7
+    options_str = connection_string
  8
+
  9
+    schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'sqlserver.sql')
  10
+    sh %( sqsh #{options_str} -i #{schema} )
  11
+  end
  12
+
  13
+  desc 'Drop the SQL Server test database'
  14
+  task :drop_database => :load_connection do 
  15
+    options_str = connection_string
  16
+    
  17
+    schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'sqlserver.drop.sql')
  18
+    sh %( sqsh #{options_str} -i #{schema} )
  19
+  end
  20
+
  21
+  desc 'Rebuild the SQL Server test database'
  22
+  task :rebuild_database => [:drop_database, :build_database]
  23
+
  24
+  task :load_connection do
  25
+    require File.join(PROJECT_ROOT, "test", "connections", "native_sqlserver", "connection")
  26
+  end
  27
+end
11  test/connections/native_sqlserver/connection.rb
... ...
@@ -0,0 +1,11 @@
  1
+print "Using native SQL Server\n"
  2
+
  3
+require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
  4
+
  5
+def connection_string
  6
+  "-S #{SPEC['host']} -U #{SPEC['username']} -P\"#{SPEC['password']}\""
  7
+end
  8
+
  9
+# Adapter config setup in locals/database_connections.rb
  10
+SPEC = CompositePrimaryKeys::ConnectionSpec['sqlserver']
  11
+ActiveRecord::Base.establish_connection(SPEC)
86  test/fixtures/db_definitions/sqlserver.drop.sql
... ...
@@ -0,0 +1,86 @@
  1
+USE [composite_primary_keys_unittest];
  2
+go
  3
+
  4
+DROP TABLE reference_types;
  5
+go
  6
+
  7
+DROP TABLE reference_codes;
  8
+go
  9
+
  10
+DROP TABLE products;
  11
+go
  12
+
  13
+DROP TABLE tariffs;
  14
+go
  15
+
  16
+DROP TABLE product_tariffs;
  17
+go
  18
+
  19
+DROP TABLE suburbs;
  20
+go
  21
+
  22
+DROP TABLE streets;
  23
+go
  24
+
  25
+DROP TABLE users;
  26
+go
  27
+
  28
+DROP TABLE articles;
  29
+go
  30
+
  31
+DROP TABLE readings;
  32
+go
  33
+
  34
+DROP TABLE groups;
  35
+go
  36
+
  37
+DROP TABLE memberships;
  38
+go
  39
+
  40
+DROP TABLE membership_statuses;
  41
+go
  42
+
  43
+DROP TABLE departments;
  44
+go
  45
+
  46
+DROP TABLE employees;
  47
+go
  48
+
  49
+DROP TABLE comments;
  50
+go
  51
+
  52
+DROP TABLE hacks;
  53
+go
  54
+
  55
+DROP TABLE restaurants;
  56
+go
  57
+
  58
+DROP TABLE restaurants_suburbs;
  59
+go
  60
+
  61
+DROP TABLE dorms;
  62
+go
  63
+
  64
+DROP TABLE rooms;
  65
+go
  66
+
  67
+DROP TABLE room_attributes;
  68
+go
  69
+
  70
+DROP TABLE room_attribute_assignments;
  71
+go
  72
+
  73
+DROP TABLE students;
  74
+go
  75
+
  76
+DROP TABLE room_assignments;
  77
+go
  78
+
  79
+DROP TABLE seats;
  80
+go
  81
+
  82
+DROP TABLE capitols;
  83
+go
  84
+
  85
+DROP TABLE products_restaurants;
  86
+go
210  test/fixtures/db_definitions/sqlserver.sql
... ...
@@ -0,0 +1,210 @@
  1
+USE [composite_primary_keys_unittest];
  2
+go
  3
+
  4
+CREATE TABLE reference_types (
  5
+    reference_type_id [int] IDENTITY(1000,1) NOT NULL,
  6
+    type_label        [varchar](50) NULL,
  7
+    abbreviation      [varchar](50) NULL,
  8
+    description       [varchar](50) NULL
  9
+);
  10
+go
  11
+
  12
+CREATE TABLE reference_codes (
  13
+    reference_type_id [int],
  14
+    reference_code    [int],
  15
+    code_label        [varchar](50) NULL,
  16
+    abbreviation      [varchar](50) NULL,
  17
+    description       [varchar](50) NULL
  18
+);
  19
+go
  20
+
  21
+CREATE TABLE products (
  22
+    id   [int] IDENTITY(1000,1) NOT NULL,
  23
+    name [varchar](50) NULL
  24
+);
  25
+go
  26
+
  27
+CREATE TABLE tariffs (
  28
+    [tariff_id]  [int],
  29
+    [start_date] [date],
  30
+    [amount]     [int] NULL
  31
+    CONSTRAINT [tariffs_pk] PRIMARY KEY 
  32
+        ( [tariff_id], [start_date] )
  33
+);
  34
+go
  35
+
  36
+CREATE TABLE product_tariffs (
  37
+    [product_id]        [int],
  38
+    [tariff_id]         [int],
  39
+    [tariff_start_date] [date]
  40
+    CONSTRAINT [product_tariffs_pk] PRIMARY KEY
  41
+        ( [product_id], [tariff_id], [tariff_start_date] )
  42
+);
  43
+go
  44
+
  45
+CREATE TABLE suburbs (
  46
+    city_id   [int],
  47
+    suburb_id [int],
  48
+    name      varchar(50) not null,
  49
+    CONSTRAINT [suburbs_pk] PRIMARY KEY
  50
+        ( [city_id], [suburb_id] )
  51
+);
  52
+go
  53
+
  54
+CREATE TABLE streets (
  55
+    id        [int] IDENTITY(1000,1) NOT NULL,
  56
+    city_id   [int]   NOT NULL,
  57
+    suburb_id [int]   NOT NULL,
  58
+    name        [varchar](50)      NOT NULL
  59
+);
  60
+go
  61
+
  62
+CREATE TABLE users (
  63
+    id   [int] IDENTITY(1000,1) NOT NULL,
  64
+    name varchar(50) NOT NULL
  65
+);
  66
+go
  67
+
  68
+CREATE TABLE articles (
  69
+    id   [int] IDENTITY(1000,1) NOT NULL,
  70
+    name varchar(50) NOT NULL
  71
+);
  72
+go
  73
+
  74
+CREATE TABLE readings (
  75
+    id         [int] PRIMARY KEY,
  76
+    user_id    [int] NOT NULL,
  77
+    article_id [int] NOT NULL,
  78
+    rating     [int] NOT NULL
  79
+);
  80
+go
  81
+
  82
+CREATE TABLE groups (
  83
+    id   [int] IDENTITY(1000,1) NOT NULL,
  84
+    name [varchar](50) NOT NULL
  85
+);
  86
+go
  87
+
  88
+CREATE TABLE memberships (
  89
+    user_id  [int] NOT NULL,
  90
+    group_id [int] NOT NULL
  91
+    CONSTRAINT [memberships_pk] PRIMARY KEY 
  92
+        ( [user_id], [group_id] )
  93
+);
  94
+go
  95
+
  96
+CREATE TABLE membership_statuses (
  97
+    id       [int] IDENTITY(1,1) NOT NULL,
  98
+    user_id  [int]   not null,
  99
+    group_id [int]   not null,
  100
+    status   varchar(50) not null
  101
+);
  102
+go
  103
+
  104
+CREATE TABLE departments (
  105
+    department_id [int] NOT NULL,
  106
+    location_id   [int] NOT NULL
  107
+    CONSTRAINT [departments_pk] PRIMARY KEY
  108
+        ( [department_id], [location_id] )
  109
+);
  110
+go
  111
+
  112
+CREATE TABLE employees (
  113
+    id            [int] IDENTITY(1000,1) NOT NULL,
  114
+    department_id [int] NULL,
  115
+    location_id   [int] NULL
  116
+);
  117
+go
  118
+
  119
+CREATE TABLE comments (
  120
+    id          [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL,
  121
+    person_id   [int] NULL,
  122
+    person_type varchar(100)      NULL,
  123
+    hack_id     [int] NULL
  124
+);
  125
+go
  126
+
  127
+CREATE TABLE hacks (
  128
+    id   [int]  IDENTITY(1000,1) PRIMARY KEY NOT NULL,
  129
+    name [varchar](50) NOT NULL
  130
+);
  131
+go
  132
+
  133
+CREATE TABLE restaurants (
  134
+    franchise_id [int] NOT NULL,
  135
+    store_id     [int] NOT NULL,
  136
+    name         [varchar](100)
  137
+    CONSTRAINT [restaurants_pk] PRIMARY KEY CLUSTERED 
  138
+        ( [franchise_id], [store_id] )
  139
+);
  140
+go
  141
+
  142
+CREATE TABLE restaurants_suburbs (
  143
+    franchise_id [int] NOT NULL,
  144
+    store_id     [int] NOT NULL,
  145
+    city_id      [int] NOT NULL,
  146
+    suburb_id    [int] NOT NULL
  147
+);
  148
+go
  149
+
  150
+CREATE TABLE dorms (
  151
+    id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL
  152
+);
  153
+go
  154
+
  155
+CREATE TABLE rooms (
  156
+    dorm_id [int] NOT NULL,
  157
+    room_id [int] NOT NULL,
  158
+    CONSTRAINT [rooms_pk] PRIMARY KEY CLUSTERED 
  159
+        ( [dorm_id], [room_id] )
  160
+);
  161
+go
  162
+
  163
+CREATE TABLE room_attributes (
  164
+    id   [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL,
  165
+    name [varchar](50)
  166
+);
  167
+go
  168
+
  169
+CREATE TABLE room_attribute_assignments (
  170
+    dorm_id           [int] NOT NULL,
  171
+    room_id           [int] NOT NULL,
  172
+    room_attribute_id [int] NOT NULL
  173
+);
  174
+go
  175
+
  176
+CREATE TABLE students (
  177
+    id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL
  178
+);
  179
+go
  180
+
  181
+CREATE TABLE room_assignments (
  182
+    student_id [int] NOT NULL,
  183
+    dorm_id    [int] NOT NULL,
  184
+    room_id    [int] NOT NULL
  185
+);
  186
+go
  187
+
  188
+CREATE TABLE seats (
  189
+    flight_number [int] NOT NULL,
  190
+    seat          [int] NOT NULL,
  191
+    customer      [int]
  192
+    CONSTRAINT [seats_pk] PRIMARY KEY
  193
+        ( [flight_number], [seat] )
  194
+);
  195
+go
  196
+
  197
+CREATE TABLE capitols (
  198
+    country varchar(450) NOT NULL,
  199
+    city varchar(450) NOT NULL
  200
+    CONSTRAINT [capitols_pk] PRIMARY KEY 
  201
+        ( [country], [city] )
  202
+);
  203
+go
  204
+
  205
+CREATE TABLE products_restaurants (
  206
+    product_id   [int] NOT NULL,
  207
+    franchise_id [int] NOT NULL,
  208
+    store_id     [int] NOT NULL
  209
+);
  210
+go
7  test/test_find.rb
@@ -54,7 +54,12 @@ def test_not_found
54 54
     connection = ActiveRecord::Base.connection
55 55
     ref_type_quoted = "#{connection.quote_table_name('reference_codes')}.#{connection.quote_column_name('reference_type_id')}"
56 56
     ref_code_quoted = "#{connection.quote_table_name('reference_codes')}.#{connection.quote_column_name('reference_code')}"
57  
-    expected = "Couldn't find ReferenceCode with ID=999,999 WHERE #{ref_type_quoted} = 999 AND #{ref_code_quoted} = 999"
  57
+
  58
+    if current_adapter?(:SQLServerAdapter)
  59
+      expected = "Couldn't find ReferenceCode with ID=999,999 WHERE #{ref_type_quoted} = N'999' AND #{ref_code_quoted} = N'999'"
  60
+    else
  61
+      expected = "Couldn't find ReferenceCode with ID=999,999 WHERE #{ref_type_quoted} = 999 AND #{ref_code_quoted} = 999"
  62
+    end
58 63
 
59 64
     assert_equal(with_quoted_identifiers(expected),
60 65
                  error.message)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.