Skip to content

Commit 15e1584

Browse files
committed
Few more base tests passing.
1 parent 6100d23 commit 15e1584

File tree

3 files changed

+19
-121
lines changed

3 files changed

+19
-121
lines changed

lib/active_record/connection_adapters/sqlserver/quoting.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def quote_string(s)
1212
end
1313

1414
def quote_column_name(name)
15-
SQLServer::Utils.extract_identifiers(name).object_quoted
15+
SQLServer::Utils.extract_identifiers(name).quoted
1616
end
1717

1818
def quote_default_value(value, column)

lib/active_record/connection_adapters/sqlserver/schema_cache.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ def view_exists?(table_name)
7979

8080
def view_information(table_name)
8181
name = table_name_key(table_name)
82-
return @view_information[key] if @view_information.key? key
83-
@view_information[key] = connection.send(:view_information, table_name)
82+
return @view_information[name] if @view_information.key? name
83+
@view_information[name] = connection.send(:view_information, table_name)
8484
end
8585

8686

test/cases/adapter_test_sqlserver.rb

Lines changed: 16 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
require 'cases/helper_sqlserver'
22
require 'models/topic'
33
require 'models/task'
4+
require 'models/subscriber'
5+
require 'models/minimalistic'
46

57
# require 'models/reply'
68
# require 'models/joke'
7-
# require 'models/subscriber'
8-
# require 'models/minimalistic'
99
# require 'models/post'
1010
# require 'models/sqlserver/fk_test_has_pk'
1111
# require 'models/sqlserver/fk_test_has_fk'
@@ -144,7 +144,7 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
144144

145145
end
146146

147-
describe 'For identity inserts' do
147+
describe 'identity inserts' do
148148

149149
before do
150150
@identity_insert_sql = "INSERT INTO [funny_jokes] ([id],[name]) VALUES(420,'Knock knock')"
@@ -171,27 +171,18 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
171171
end
172172

173173
it 'find identity column using #identity_column' do
174-
joke_id_column = Joke.columns.find { |c| c.name == 'id' }
175-
assert_equal joke_id_column.name, connection.send(:identity_column,Joke.table_name).name
176-
assert_equal joke_id_column.sql_type, connection.send(:identity_column,Joke.table_name).sql_type
174+
task_id_column = Task.columns_hash['id']
175+
assert_equal task_id_column.name, connection.send(:identity_column, Task.table_name).name
176+
assert_equal task_id_column.sql_type, connection.send(:identity_column, Task.table_name).sql_type
177177
end
178178

179179
it 'return nil when calling #identity_column for a table_name with no identity' do
180-
assert_nil connection.send(:identity_column,Subscriber.table_name)
181-
end unless sqlserver_azure?
182-
183-
it 'be able to disable referential integrity' do
184-
Minimalistic.delete_all
185-
connection.send :set_identity_insert, Minimalistic.table_name, false
186-
connection.execute_procedure :sp_MSforeachtable, 'ALTER TABLE ? CHECK CONSTRAINT ALL'
187-
o = Minimalistic.new
188-
o.id = 420
189-
o.save!
180+
assert_nil connection.send(:identity_column, Subscriber.table_name)
190181
end
191182

192183
end
193184

194-
describe 'For Quoting' do
185+
describe 'quoting' do
195186

196187
it 'return 1 for #quoted_true' do
197188
assert_equal '1', connection.quoted_true
@@ -222,114 +213,21 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
222213
assert_equal '[foo].[bar].[baz]', connection.quote_column_name('foo.bar.baz')
223214
end
224215

225-
describe "#quote" do
226-
227-
describe "string and multibyte values" do
228-
229-
describe "on an activerecord :integer column" do
230-
231-
before do
232-
@column = Post.columns_hash['id']
233-
end
234-
235-
it "return 0 for empty string" do
236-
assert_equal '0', connection.quote('', @column)
237-
end
238-
239-
end
240-
241-
describe "on an activerecord :string column or with any value" do
242-
243-
it "surround it when N'...'" do
244-
assert_equal "N'foo'", connection.quote("foo")
245-
end
246-
247-
it "escape all single quotes by repeating them" do
248-
assert_equal "N'''quotation''s'''", connection.quote("'quotation's'")
249-
end
250-
251-
end
252-
253-
end
254-
216+
it "return 0 for empty string" do
217+
assert_equal '0', connection.quote('', Post.columns_hash['id'])
255218
end
256219

257-
describe "#quoted_datetime" do
258-
259-
before do
260-
@iso_string = '2001-02-03T04:05:06-0700'
261-
@date = Date.parse @iso_string
262-
@time = Time.parse @iso_string
263-
@datetime = DateTime.parse @iso_string
264-
end
265-
266-
describe "with a Date" do
267-
268-
it "return a dd-mm-yyyy date string" do
269-
assert_equal '02-03-2001', connection.quoted_datetime(@date)
270-
end
271-
272-
end
273-
274-
describe "when the ActiveRecord default timezone is UTC" do
275-
276-
before do
277-
@old_activerecord_timezone = ActiveRecord::Base.default_timezone
278-
ActiveRecord::Base.default_timezone = :utc
279-
end
280-
281-
after do
282-
ActiveRecord::Base.default_timezone = @old_activerecord_timezone
283-
@old_activerecord_timezone = nil
284-
end
285-
286-
describe "with a Time" do
287-
288-
it "return an ISO 8601 datetime string" do
289-
assert_equal '2001-02-03T11:05:06.000', connection.quoted_datetime(@time)
290-
end
291-
292-
end
293-
294-
describe "with a DateTime" do
295-
296-
it "return an ISO 8601 datetime string" do
297-
assert_equal '2001-02-03T11:05:06', connection.quoted_datetime(@datetime)
298-
end
299-
300-
end
301-
302-
describe "with an ActiveSupport::TimeWithZone" do
303-
304-
describe "wrapping a datetime" do
305-
306-
it "return an ISO 8601 datetime string with milliseconds" do
307-
Time.use_zone('Eastern Time (US & Canada)') do
308-
assert_equal '2001-02-03T11:05:06.000', connection.quoted_datetime(@datetime.in_time_zone)
309-
end
310-
end
311-
312-
end
313-
314-
describe "wrapping a time" do
315-
316-
it "return an ISO 8601 datetime string with milliseconds" do
317-
Time.use_zone('Eastern Time (US & Canada)') do
318-
assert_equal '2001-02-03T11:05:06.000', connection.quoted_datetime(@time.in_time_zone)
319-
end
320-
end
321-
322-
end
323-
324-
end
325-
326-
end
220+
it "surround string with national prefix" do
221+
assert_equal "N'foo'", connection.quote("foo")
222+
end
327223

224+
it "escape all single quotes by repeating them" do
225+
assert_equal "N'''quotation''s'''", connection.quote("'quotation's'")
328226
end
329227

330228
end
331229

332-
describe 'When disabling referential integrity' do
230+
describe 'disabling referential integrity' do
333231

334232
before do
335233
connection.disable_referential_integrity { FkTestHasPk.delete_all; FkTestHasFk.delete_all }

0 commit comments

Comments
 (0)