activerecord-sqlserver-adapter 5.1.6 → 5.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.travis.yml +16 -19
  4. data/CHANGELOG.md +6 -46
  5. data/Dockerfile +14 -0
  6. data/Gemfile +1 -2
  7. data/README.md +4 -4
  8. data/VERSION +1 -1
  9. data/activerecord-sqlserver-adapter.gemspec +1 -1
  10. data/circle.yml +8 -6
  11. data/docker-compose.ci.yml +11 -0
  12. data/lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb +11 -18
  13. data/lib/active_record/connection_adapters/sqlserver/database_limits.rb +13 -2
  14. data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +45 -9
  15. data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +2 -1
  16. data/lib/active_record/connection_adapters/sqlserver/schema_dumper.rb +2 -2
  17. data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +33 -14
  18. data/lib/active_record/connection_adapters/sqlserver/transaction.rb +3 -4
  19. data/lib/active_record/connection_adapters/sqlserver/type/json.rb +1 -1
  20. data/lib/active_record/connection_adapters/sqlserver/type/string.rb +7 -0
  21. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +14 -12
  22. data/lib/active_record/tasks/sqlserver_database_tasks.rb +3 -1
  23. data/lib/arel/visitors/sqlserver.rb +1 -1
  24. data/lib/arel_sqlserver.rb +0 -1
  25. data/test/bin/install-freetds.sh +1 -1
  26. data/test/cases/adapter_test_sqlserver.rb +10 -2
  27. data/test/cases/coerced_tests.rb +262 -13
  28. data/test/cases/column_test_sqlserver.rb +6 -0
  29. data/test/cases/helper_sqlserver.rb +2 -1
  30. data/test/cases/migration_test_sqlserver.rb +3 -1
  31. data/test/cases/order_test_sqlserver.rb +19 -19
  32. data/test/schema/sqlserver_specific_schema.rb +9 -1
  33. data/test/support/core_ext/query_cache.rb +29 -0
  34. metadata +11 -9
  35. data/test/bin/.keep +0 -0
@@ -798,6 +798,12 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
798
798
  obj.save!
799
799
  end
800
800
 
801
+ it 'does not mark object as changed after save' do
802
+ obj.save!
803
+ obj.attributes
804
+ obj.changed?.must_equal false
805
+ end
806
+
801
807
  end
802
808
 
803
809
  end
@@ -2,6 +2,7 @@ require 'support/paths_sqlserver'
2
2
  require 'bundler/setup'
3
3
  Bundler.require :default, :development
4
4
  require 'pry'
5
+ require 'support/core_ext/query_cache'
5
6
  require 'support/minitest_sqlserver'
6
7
  require 'support/test_in_memory_oltp'
7
8
  require 'cases/helper'
@@ -9,7 +10,7 @@ require 'support/load_schema_sqlserver'
9
10
  require 'support/coerceable_test_sqlserver'
10
11
  require 'support/sql_counter_sqlserver'
11
12
  require 'support/connection_reflection'
12
- require 'mocha/mini_test'
13
+ require 'mocha/minitest'
13
14
 
14
15
  module ActiveRecord
15
16
  class TestCase < ActiveSupport::TestCase
@@ -20,7 +20,7 @@ class MigrationTestSQLServer < ActiveRecord::TestCase
20
20
  it 'not create a tables if error in migrations' do
21
21
  begin
22
22
  migrations_dir = File.join ARTest::SQLServer.migrations_root, 'transaction_table'
23
- quietly { ActiveRecord::Migrator.up(migrations_dir) }
23
+ quietly { ActiveRecord::MigrationContext.new(migrations_dir).up }
24
24
  rescue Exception => e
25
25
  assert_match %r|this and all later migrations canceled|, e.message
26
26
  end
@@ -41,6 +41,8 @@ class MigrationTestSQLServer < ActiveRecord::TestCase
41
41
  lock_version_column = Person.columns_hash['lock_version']
42
42
  assert_equal :string, lock_version_column.type
43
43
  assert lock_version_column.default.nil?
44
+ assert_nothing_raised { connection.change_column 'people', 'lock_version', :integer }
45
+ Person.reset_column_information
44
46
  end
45
47
 
46
48
  it 'not drop the default contraint if just renaming' do
@@ -44,13 +44,13 @@ class OrderTestSQLServer < ActiveRecord::TestCase
44
44
  it 'support quoted column' do
45
45
  order = "[title]"
46
46
  post1 = Post.create title: 'AAA Post', body: 'Test cased orders.'
47
- assert_equal post1, Post.order(order).first
47
+ assert_equal post1, Post.order(Arel.sql(order)).first
48
48
  end
49
49
 
50
50
  it 'support quoted table and column' do
51
51
  order = "[posts].[title]"
52
52
  post1 = Post.create title: 'AAA Post', body: 'Test cased orders.'
53
- assert_equal post1, Post.order(order).first
53
+ assert_equal post1, Post.order(Arel.sql(order)).first
54
54
  end
55
55
 
56
56
  it 'support primary: column, secondary: column' do
@@ -73,74 +73,74 @@ class OrderTestSQLServer < ActiveRecord::TestCase
73
73
  order = "(CASE WHEN [title] LIKE N'ZZZ%' THEN title ELSE '' END) DESC, body"
74
74
  post1 = Post.create title: 'ZZZ Post', body: 'Test cased orders.'
75
75
  post2 = Post.create title: 'ZZZ Post', body: 'ZZZ Test cased orders.'
76
- assert_equal post1, Post.order(order).first
77
- assert_equal post2, Post.order(order).second
76
+ assert_equal post1, Post.order(Arel.sql(order)).first
77
+ assert_equal post2, Post.order(Arel.sql(order)).second
78
78
  end
79
79
 
80
80
  it 'support primary: quoted table and column, secondary: case expresion' do
81
81
  order = "[posts].[body] DESC, (CASE WHEN [title] LIKE N'ZZZ%' THEN title ELSE '' END) DESC"
82
82
  post1 = Post.create title: 'ZZZ Post', body: 'ZZZ Test cased orders.'
83
83
  post2 = Post.create title: 'ZZY Post', body: 'ZZZ Test cased orders.'
84
- assert_equal post1, Post.order(order).first
85
- assert_equal post2, Post.order(order).second
84
+ assert_equal post1, Post.order(Arel.sql(order)).first
85
+ assert_equal post2, Post.order(Arel.sql(order)).second
86
86
  end
87
87
 
88
88
  it 'support inline function' do
89
89
  order = "LEN(title)"
90
90
  post1 = Post.create title: 'A', body: 'AAA Test cased orders.'
91
- assert_equal post1, Post.order(order).first
91
+ assert_equal post1, Post.order(Arel.sql(order)).first
92
92
  end
93
93
 
94
94
  it 'support inline function with parameters' do
95
95
  order = "SUBSTRING(title, 1, 3)"
96
96
  post1 = Post.create title: 'AAA Post', body: 'Test cased orders.'
97
- assert_equal post1, Post.order(order).first
97
+ assert_equal post1, Post.order(Arel.sql(order)).first
98
98
  end
99
99
 
100
100
  it 'support inline function with parameters DESC' do
101
101
  order = "SUBSTRING(title, 1, 3) DESC"
102
102
  post1 = Post.create title: 'ZZZ Post', body: 'Test cased orders.'
103
- assert_equal post1, Post.order(order).first
103
+ assert_equal post1, Post.order(Arel.sql(order)).first
104
104
  end
105
105
 
106
106
  it 'support primary: inline function, secondary: column' do
107
107
  order = "LEN(title), body"
108
108
  post1 = Post.create title: 'A', body: 'AAA Test cased orders.'
109
109
  post2 = Post.create title: 'A', body: 'Test cased orders.'
110
- assert_equal post1, Post.order(order).first
111
- assert_equal post2, Post.order(order).second
110
+ assert_equal post1, Post.order(Arel.sql(order)).first
111
+ assert_equal post2, Post.order(Arel.sql(order)).second
112
112
  end
113
113
 
114
114
  it 'support primary: inline function, secondary: column with direction' do
115
115
  order = "LEN(title) ASC, body DESC"
116
116
  post1 = Post.create title: 'A', body: 'ZZZ Test cased orders.'
117
117
  post2 = Post.create title: 'A', body: 'Test cased orders.'
118
- assert_equal post1, Post.order(order).first
119
- assert_equal post2, Post.order(order).second
118
+ assert_equal post1, Post.order(Arel.sql(order)).first
119
+ assert_equal post2, Post.order(Arel.sql(order)).second
120
120
  end
121
121
 
122
122
  it 'support primary: column, secondary: inline function' do
123
123
  order = "body DESC, LEN(title)"
124
124
  post1 = Post.create title: 'Post', body: 'ZZZ Test cased orders.'
125
125
  post2 = Post.create title: 'Longer Post', body: 'ZZZ Test cased orders.'
126
- assert_equal post1, Post.order(order).first
127
- assert_equal post2, Post.order(order).second
126
+ assert_equal post1, Post.order(Arel.sql(order)).first
127
+ assert_equal post2, Post.order(Arel.sql(order)).second
128
128
  end
129
129
 
130
130
  it 'support primary: case expression, secondary: inline function' do
131
131
  order = "CASE WHEN [title] LIKE N'ZZZ%' THEN title ELSE '' END DESC, LEN(body) ASC"
132
132
  post1 = Post.create title: 'ZZZ Post', body: 'Z'
133
133
  post2 = Post.create title: 'ZZZ Post', body: 'Test cased orders.'
134
- assert_equal post1, Post.order(order).first
135
- assert_equal post2, Post.order(order).second
134
+ assert_equal post1, Post.order(Arel.sql(order)).first
135
+ assert_equal post2, Post.order(Arel.sql(order)).second
136
136
  end
137
137
 
138
138
  it 'support primary: inline function, secondary: case expression' do
139
139
  order = "LEN(body), CASE WHEN [title] LIKE N'ZZZ%' THEN title ELSE '' END DESC"
140
140
  post1 = Post.create title: 'ZZZ Post', body: 'Z'
141
141
  post2 = Post.create title: 'Post', body: 'Z'
142
- assert_equal post1, Post.order(order).first
143
- assert_equal post2, Post.order(order).second
142
+ assert_equal post1, Post.order(Arel.sql(order)).first
143
+ assert_equal post2, Post.order(Arel.sql(order)).second
144
144
  end
145
145
 
146
146
 
@@ -144,12 +144,20 @@ ActiveRecord::Schema.define do
144
144
 
145
145
  # Constraints
146
146
 
147
- create_table(:sst_has_fks, force: true) { |t| t.column(:fk_id, :bigint, null: false) }
147
+ create_table(:sst_has_fks, force: true) do |t|
148
+ t.column(:fk_id, :bigint, null: false)
149
+ t.column(:fk_id2, :bigint)
150
+ end
151
+
148
152
  create_table(:sst_has_pks, force: true) { }
149
153
  execute <<-ADDFKSQL
150
154
  ALTER TABLE sst_has_fks
151
155
  ADD CONSTRAINT FK__sst_has_fks_id
152
156
  FOREIGN KEY ([fk_id])
157
+ REFERENCES [sst_has_pks] ([id]),
158
+
159
+ CONSTRAINT FK__sst_has_fks_id2
160
+ FOREIGN KEY ([fk_id2])
153
161
  REFERENCES [sst_has_pks] ([id])
154
162
  ADDFKSQL
155
163
 
@@ -0,0 +1,29 @@
1
+ require 'active_record/connection_adapters/sqlserver_adapter'
2
+
3
+ module SqlIgnoredCache
4
+ extend ActiveSupport::Concern
5
+
6
+ IGNORED_SQL = [
7
+ /INFORMATION_SCHEMA\.(TABLES|VIEWS|COLUMNS|KEY_COLUMN_USAGE)/im,
8
+ /SELECT @@version/,
9
+ /SELECT @@TRANCOUNT/,
10
+ /(BEGIN|COMMIT|ROLLBACK|SAVE) TRANSACTION/,
11
+ /SELECT CAST\(.* AS .*\) AS value/,
12
+ /SELECT DATABASEPROPERTYEX/im
13
+ ]
14
+
15
+ # We don't want to coerce every ActiveRecord test that relies on `query_cache`
16
+ # just because we do more queries than the other adapters.
17
+ #
18
+ # Removing internal queries from the cache will make AR tests pass without
19
+ # compromising cache outside tests.
20
+ def cache_sql(sql, name, binds)
21
+ result = super
22
+ @query_cache.delete_if { |k, v| k =~ Regexp.union(IGNORED_SQL) }
23
+ result
24
+ end
25
+ end
26
+
27
+ ActiveSupport.on_load(:active_record) do
28
+ ActiveRecord::ConnectionAdapters::SQLServerAdapter.prepend(SqlIgnoredCache)
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-sqlserver-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.6
4
+ version: 5.2.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Collins
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2018-01-23 00:00:00.000000000 Z
17
+ date: 2019-02-12 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activerecord
@@ -22,14 +22,14 @@ dependencies:
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: 5.1.0
25
+ version: 5.2.0
26
26
  type: :runtime
27
27
  prerelease: false
28
28
  version_requirements: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: 5.1.0
32
+ version: 5.2.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: tiny_tds
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -57,6 +57,7 @@ files:
57
57
  - BACKERS.md
58
58
  - CHANGELOG.md
59
59
  - CODE_OF_CONDUCT.md
60
+ - Dockerfile
60
61
  - Gemfile
61
62
  - Guardfile
62
63
  - MIT-LICENSE
@@ -67,6 +68,7 @@ files:
67
68
  - activerecord-sqlserver-adapter.gemspec
68
69
  - appveyor.yml
69
70
  - circle.yml
71
+ - docker-compose.ci.yml
70
72
  - lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb
71
73
  - lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb
72
74
  - lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb
@@ -132,7 +134,6 @@ files:
132
134
  - lib/arel_sqlserver.rb
133
135
  - test/appveyor/dbsetup.ps1
134
136
  - test/appveyor/dbsetup.sql
135
- - test/bin/.keep
136
137
  - test/bin/install-freetds.sh
137
138
  - test/bin/install-openssl.sh
138
139
  - test/bin/setup.sh
@@ -193,6 +194,7 @@ files:
193
194
  - test/schema/sqlserver_specific_schema.rb
194
195
  - test/support/coerceable_test_sqlserver.rb
195
196
  - test/support/connection_reflection.rb
197
+ - test/support/core_ext/query_cache.rb
196
198
  - test/support/load_schema_sqlserver.rb
197
199
  - test/support/minitest_sqlserver.rb
198
200
  - test/support/paths_sqlserver.rb
@@ -214,19 +216,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
214
216
  version: '0'
215
217
  required_rubygems_version: !ruby/object:Gem::Requirement
216
218
  requirements:
217
- - - ">="
219
+ - - ">"
218
220
  - !ruby/object:Gem::Version
219
- version: '0'
221
+ version: 1.3.1
220
222
  requirements: []
221
223
  rubyforge_project:
222
- rubygems_version: 2.6.8
224
+ rubygems_version: 2.5.2.3
223
225
  signing_key:
224
226
  specification_version: 4
225
227
  summary: ActiveRecord SQL Server Adapter.
226
228
  test_files:
227
229
  - test/appveyor/dbsetup.ps1
228
230
  - test/appveyor/dbsetup.sql
229
- - test/bin/.keep
230
231
  - test/bin/install-freetds.sh
231
232
  - test/bin/install-openssl.sh
232
233
  - test/bin/setup.sh
@@ -287,6 +288,7 @@ test_files:
287
288
  - test/schema/sqlserver_specific_schema.rb
288
289
  - test/support/coerceable_test_sqlserver.rb
289
290
  - test/support/connection_reflection.rb
291
+ - test/support/core_ext/query_cache.rb
290
292
  - test/support/load_schema_sqlserver.rb
291
293
  - test/support/minitest_sqlserver.rb
292
294
  - test/support/paths_sqlserver.rb
File without changes