activerecord-sqlserver-adapter 4.2.4 → 4.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/CODE_OF_CONDUCT.md +31 -0
  4. data/Gemfile +7 -4
  5. data/README.md +4 -3
  6. data/RUNNING_UNIT_TESTS.md +14 -5
  7. data/activerecord-sqlserver-adapter.gemspec +3 -2
  8. data/appveyor.yml +30 -0
  9. data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +16 -0
  10. data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +5 -2
  11. data/lib/active_record/connection_adapters/sqlserver/type.rb +0 -2
  12. data/lib/active_record/connection_adapters/sqlserver/type/boolean.rb +0 -1
  13. data/lib/active_record/connection_adapters/sqlserver/type/date.rb +0 -2
  14. data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +0 -2
  15. data/lib/active_record/connection_adapters/sqlserver/type/decimal.rb +0 -1
  16. data/lib/active_record/connection_adapters/sqlserver/type/float.rb +0 -2
  17. data/lib/active_record/connection_adapters/sqlserver/type/integer.rb +0 -1
  18. data/lib/active_record/connection_adapters/sqlserver/type/real.rb +0 -2
  19. data/lib/active_record/connection_adapters/sqlserver/type/smalldatetime.rb +0 -2
  20. data/lib/active_record/connection_adapters/sqlserver/type/time.rb +0 -3
  21. data/lib/active_record/connection_adapters/sqlserver/version.rb +1 -1
  22. data/lib/active_record/connection_adapters/sqlserver_column.rb +8 -0
  23. data/test/appveyor/dbsetup.ps1 +27 -0
  24. data/test/appveyor/dbsetup.sql +11 -0
  25. data/test/cases/coerced_tests.rb +30 -38
  26. data/test/cases/column_test_sqlserver.rb +6 -6
  27. data/test/cases/helper_sqlserver.rb +2 -3
  28. data/test/cases/rake_test_sqlserver.rb +4 -0
  29. data/test/cases/schema_dumper_test_sqlserver.rb +8 -2
  30. data/test/cases/specific_schema_test_sqlserver.rb +6 -0
  31. data/test/config.yml +4 -1
  32. data/test/models/sqlserver/object_default.rb +3 -0
  33. data/test/schema/sqlserver_specific_schema.rb +8 -0
  34. metadata +15 -8
  35. data/lib/active_record/connection_adapters/sqlserver/type/castable.rb +0 -15
  36. data/lib/active_record/connection_adapters/sqlserver/type/core_ext/value.rb +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66376e3352f343f00ed459b35bd3ea825209cd66
4
- data.tar.gz: 4b8ee4f3981be083fc8e6be1733e182bef5b3b83
3
+ metadata.gz: 54dab2a4b34d04529678804457e654cdf3c436b9
4
+ data.tar.gz: 1719214a6ddc266cd8fad7dec68005cabd6ad9e8
5
5
  SHA512:
6
- metadata.gz: 35ce29a0a1666f992f6335d0d106a4317abca6891dc758f00a838292db8ddc82e318e0dbe16f6852c1c25a82bdacb44e0bf99598b321c0b4cf86664e49d6b465
7
- data.tar.gz: 2d7490d9c29f9cc571e35daab9b5daee3fa6ba910a287b84c5dff9c906f8f9bfb595a730aa90bba4600db63ae8f553ee9df68cba4e56af8a59072b09e750ec69
6
+ metadata.gz: 3ffd8586472a4bdbbd6a113919085029268a134b4eecc5b924c129e151518aa61a287f7e5120f5c755e28addb73a4a546136952b18d35265a78df8f775bce015
7
+ data.tar.gz: 2ca086d538c72d86cd508e55cac63ebad56261dcc71eb4f13ae2bd8dd94cb4835b20a7e32acfe9ab551297b201d3af6eaa033fafe139ac1a7a6765d015662e6b
@@ -1,12 +1,30 @@
1
1
 
2
+ ## v4.2.5
3
+
4
+ #### Removed
5
+
6
+ * Remove Type::Castable hacks for core type objects to force trust the DB. Allows Rails 5 attributes.
7
+
8
+ #### Fixed
9
+
10
+ * Tests for decimal scale. See Rails commit. http://git.io/vGotB
11
+ * Improve case comparision performace per column. Fixes #414
12
+ * DB rollback when reversable add_column has several options. Fixes #359
13
+ * Better column definitions for default objects. Fixes #412
14
+
15
+
2
16
  ## v4.2.4
3
17
 
18
+ #### Fixed
19
+
4
20
  * Compatible with Rails 4.2.1.
5
21
  * Fix schema limit reflection for char/varchar. Fixes #394.
6
22
 
7
23
 
8
24
  ## v4.2.3
9
25
 
26
+ #### Fixed
27
+
10
28
  * Fix SET defaults when using Azure.
11
29
  * Test insert 4-byte unicode chars.
12
30
  * Make rollback transaction transcount aware for implicit error rollbacks. Fixes #390
@@ -0,0 +1,31 @@
1
+ Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all
4
+ people who contribute through reporting issues, posting feature requests,
5
+ updating documentation, submitting pull requests or patches, and other
6
+ activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, or religion.
12
+
13
+ Examples of unacceptable behavior by participants include the use of sexual
14
+ language or imagery, derogatory comments or personal attacks, trolling, public
15
+ or private harassment, insults, or other unprofessional conduct.
16
+
17
+ Project maintainers have the right and responsibility to remove, edit, or
18
+ reject comments, commits, code, wiki edits, issues, and other contributions
19
+ that are not aligned to this Code of Conduct. Project maintainers who do not
20
+ follow the Code of Conduct may be removed from the project team.
21
+
22
+ This code of conduct applies both within project spaces and in public spaces
23
+ when an individual is representing the project or its community.
24
+
25
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
26
+ reported by opening an issue or contacting one or more of the project
27
+ maintainers.
28
+
29
+ This Code of Conduct is adapted from the Contributor Covenant
30
+ (http://contributor-covenant.org), version 1.1.0, available at
31
+ http://contributor-covenant.org/version/1/1/0/
data/Gemfile CHANGED
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  gem 'bcrypt'
5
+ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
5
6
 
6
7
  if RbConfig::CONFIG["host_os"] =~ /darwin/
7
8
  gem 'terminal-notifier-guard'
@@ -17,8 +18,11 @@ else
17
18
  spec = eval(File.read('activerecord-sqlserver-adapter.gemspec'))
18
19
  version = spec.dependencies.detect{ |d|d.name == 'activerecord' }.requirement.requirements.first.last.version
19
20
  major, minor, tiny = version.split('.')
20
- uri = URI.parse "http://rubygems.org/api/v1/versions/activerecord.yaml"
21
- YAML.load(Net::HTTP.get(uri)).select do |data|
21
+ uri = URI.parse "https://rubygems.org/api/v1/versions/activerecord.yaml"
22
+ http = Net::HTTP.new(uri.host, uri.port)
23
+ http.use_ssl = true
24
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
25
+ YAML.load(http.request(Net::HTTP::Get.new(uri.request_uri)).body).select do |data|
22
26
  a, b, c = data['number'].split('.')
23
27
  !data['prerelease'] && major == a && (minor.nil? || minor == b)
24
28
  end.first['number']
@@ -34,8 +38,7 @@ group :tinytds do
34
38
  if ENV['TINYTDS_SOURCE']
35
39
  gem 'tiny_tds', path: ENV['TINYTDS_SOURCE']
36
40
  else
37
- # TODO: [Rails4] Change back... segfault caused by tiny_tds 0.6.1
38
- gem 'tiny_tds', git:"https://github.com/rails-sqlserver/tiny_tds.git"
41
+ gem 'tiny_tds'
39
42
  end
40
43
  end
41
44
 
data/README.md CHANGED
@@ -1,14 +1,15 @@
1
1
 
2
2
  # ActiveRecord SQL Server Adapter. For SQL Server 2012 And Higher.
3
3
 
4
- [![Gem Version](http://img.shields.io/gem/v/activerecord-sqlserver-adapter.svg?style=flat)](https://rubygems.org/gems/activerecord-sqlserver-adapter)
5
- [![Gitter chat](https://img.shields.io/badge/%E2%8A%AA%20GITTER%20-JOIN%20CHAT%20%E2%86%92-brightgreen.svg?style=flat)](https://gitter.im/rails-sqlserver/activerecord-sqlserver-adapter)
4
+ [![Build status](https://ci.appveyor.com/api/projects/status/mtgbx8f57vr7k2qa/branch/master?svg=true)](https://ci.appveyor.com/project/rails-sqlserver/activerecord-sqlserver-adapter/branch/master) [![Gem Version](http://img.shields.io/gem/v/activerecord-sqlserver-adapter.svg?style=flat)](https://rubygems.org/gems/activerecord-sqlserver-adapter) [![Gitter chat](https://img.shields.io/badge/%E2%8A%AA%20GITTER%20-JOIN%20CHAT%20%E2%86%92-brightgreen.svg?style=flat)](https://gitter.im/rails-sqlserver/activerecord-sqlserver-adapter)
6
5
 
7
6
  ![kantishna-wide](https://cloud.githubusercontent.com/assets/2381/5895051/aa6a57e0-a4e1-11e4-95b9-23627af5876a.jpg)
8
7
 
9
8
  ## Code Name Kantishna
10
9
 
11
- The SQL Server adapter for ActiveRecord v4.2 using SQL Server 2012 or higher. If you need the adapter for SQL Server 2008 or 2005, you are still in the right spot. Just install the latest 3.2.x to 4.1.x version of the adapter. We follow a rational versioning policy that tracks ActiveRecord. That means that our 4.2.x version of the adapter is only for the latest 4.2 version of Rails. We also have stable branches for each major/minor release of ActiveRecord.
10
+ The SQL Server adapter for ActiveRecord v4.2 using SQL Server 2012 or higher.
11
+
12
+ Interested in older versions? We follow a rational versioning policy that tracks Rails. That means that our 4.2.x version of the adapter is only for the latest 4.2 version of Rails. If you need the adapter for SQL Server 2008 or 2005, you are still in the right spot. Just install the latest 3.2.x to 4.1.x version of the adapter that matches your Rails version. We also have stable branches for each major/minor release of ActiveRecord.
12
13
 
13
14
 
14
15
  #### Executing Stored Procedures
@@ -9,11 +9,7 @@ This process is much easier than it has been before!
9
9
  Default testing uses DBLIB with TinyTDS.
10
10
 
11
11
  * Setup two databases in SQL Server, [activerecord_unittest] and [activerecord_unittest2]
12
- * Create a [rails] user with an empty password and give it a [db_owner] role to both DBs. Some tests require a server role of [sysadmin] too.
13
- - http://twitpic.com/9bsiyp/full
14
- - http://twitpic.com/9bsj7z/full
15
- - http://twitpic.com/9bsjdx/full
16
- - http://twitpic.com/9bsjl7/full
12
+ * Create a [rails] user with an empty password and give it a [db_owner] role to both DBs. Some tests require a server role of [sysadmin] too. More details below with DDL SQL examples.
17
13
  * $ bundle install
18
14
  * $ bundle exec rake test ACTIVERECORD_UNITTEST_HOST='my.db.net'
19
15
 
@@ -34,6 +30,19 @@ The default names for the test databases are `activerecord_unittest` and `active
34
30
 
35
31
  The connection files make certain assumptions. For instance, the ODBC connection assumes you have a DSN setup that matches the name of the default database names. Remember too you have to set an environment variable for the DSN of the adapter, see the connection.rb file that matches your connection mode for details.
36
32
 
33
+ ```sql
34
+ CREATE DATABASE [activerecord_unittest];
35
+ CREATE DATABASE [activerecord_unittest2];
36
+ GO
37
+ CREATE LOGIN [rails] WITH PASSWORD = '', CHECK_POLICY = OFF, DEFAULT_DATABASE = [activerecord_unittest];
38
+ GO
39
+ USE [activerecord_unittest];
40
+ CREATE USER [rails] FOR LOGIN [rails];
41
+ GO
42
+ EXEC sp_addrolemember N'db_owner', N'rails';
43
+ EXEC master..sp_addsrvrolemember @loginame = N'rails', @rolename = N'sysadmin'
44
+ GO
45
+ ```
37
46
 
38
47
  ## Cloning The Repos
39
48
 
@@ -6,11 +6,12 @@ Gem::Specification.new do |spec|
6
6
  spec.name = 'activerecord-sqlserver-adapter'
7
7
  spec.version = ActiveRecord::ConnectionAdapters::SQLServer::Version::VERSION
8
8
  spec.platform = Gem::Platform::RUBY
9
+ spec.license = 'MIT'
9
10
  spec.authors = ['Ken Collins', 'Anna Carey', 'Will Bond', 'Murray Steele', 'Shawn Balestracci', 'Joe Rafaniello', 'Tom Ward']
10
11
  spec.email = ['ken@metaskills.net', 'will@wbond.net']
11
12
  spec.homepage = 'http://github.com/rails-sqlserver/activerecord-sqlserver-adapter'
12
13
  spec.summary = 'ActiveRecord SQL Server Adapter.'
13
- spec.description = spec.summary
14
+ spec.description = 'ActiveRecord SQL Server Adapter. SQL Server 2012 and upward.'
14
15
  spec.files = `git ls-files -z`.split("\x0")
15
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
@@ -24,6 +25,6 @@ Gem::Specification.new do |spec|
24
25
  spec.add_development_dependency 'minitest-spec-rails'
25
26
  spec.add_development_dependency 'mocha'
26
27
  spec.add_development_dependency 'nokogiri'
27
- spec.add_development_dependency 'pry'
28
+ spec.add_development_dependency 'byebug'
28
29
  spec.add_development_dependency 'rake'
29
30
  end
@@ -0,0 +1,30 @@
1
+ version: 4.2.5.{build}
2
+ init:
3
+ - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
4
+ - SET PATH=C:\MinGW\msys\1.0\bin;%PATH%
5
+ - SET RAKEOPT=-rdevkit
6
+ clone_depth: 5
7
+ skip_tags: true
8
+ matrix:
9
+ fast_finish: true
10
+ install:
11
+ - ruby --version
12
+ - gem --version
13
+ - bundle install --without odbc
14
+ build: off
15
+ test_script:
16
+ - powershell -File "%APPVEYOR_BUILD_FOLDER%\test\appveyor\dbsetup.ps1"
17
+ - timeout /t 4 /nobreak > NUL
18
+ - ps: Start-Service 'MSSQL$SQL2014'
19
+ - timeout /t 4 /nobreak > NUL
20
+ - sqlcmd -S ".\SQL2014" -U sa -P Password12! -i %APPVEYOR_BUILD_FOLDER%\test\appveyor\dbsetup.sql
21
+ - bundle exec rake test ACTIVERECORD_UNITTEST_DATASERVER="localhost\SQL2014"
22
+ - ps: Stop-Service 'MSSQL$SQL2014'
23
+ - ps: Start-Service 'MSSQL$SQL2012SP1'
24
+ - timeout /t 4 /nobreak > NUL
25
+ - sqlcmd -S ".\SQL2012SP1" -U sa -P Password12! -i %APPVEYOR_BUILD_FOLDER%\test\appveyor\dbsetup.sql
26
+ - bundle exec rake test ACTIVERECORD_UNITTEST_DATASERVER="localhost\SQL2012SP1"
27
+ environment:
28
+ matrix:
29
+ - ruby_version: "200-x64"
30
+ - ruby_version: "21-x64"
@@ -87,6 +87,22 @@ module ActiveRecord
87
87
  Arel::Nodes::Bin.new(node)
88
88
  end
89
89
 
90
+ def case_sensitive_comparison(table, attribute, column, value)
91
+ if column.case_sensitive?
92
+ table[attribute].eq(value)
93
+ else
94
+ super
95
+ end
96
+ end
97
+
98
+ def case_insensitive_comparison(table, attribute, column, value)
99
+ if column.case_sensitive?
100
+ super
101
+ else
102
+ table[attribute].eq(value)
103
+ end
104
+ end
105
+
90
106
  # === SQLServer Specific ======================================== #
91
107
 
92
108
  def execute_procedure(proc_name, *variables)
@@ -45,7 +45,7 @@ module ActiveRecord
45
45
  def columns(table_name, _name = nil)
46
46
  return [] if table_name.blank?
47
47
  column_definitions(table_name).map do |ci|
48
- sqlserver_options = ci.slice :ordinal_position, :is_primary, :is_identity, :default_function, :table_name
48
+ sqlserver_options = ci.slice :ordinal_position, :is_primary, :is_identity, :default_function, :table_name, :collation
49
49
  cast_type = lookup_cast_type(ci[:type])
50
50
  new_column ci[:name], ci[:default_value], cast_type, ci[:type], ci[:null], sqlserver_options
51
51
  end
@@ -60,7 +60,7 @@ module ActiveRecord
60
60
  rename_table_indexes(table_name, new_name)
61
61
  end
62
62
 
63
- def remove_column(table_name, column_name, _type = nil)
63
+ def remove_column(table_name, column_name, type = nil, options = {})
64
64
  raise ArgumentError.new('You must specify at least one column name. Example: remove_column(:people, :first_name)') if column_name.is_a? Array
65
65
  remove_check_constraints(table_name, column_name)
66
66
  remove_default_constraint(table_name, column_name)
@@ -233,6 +233,7 @@ module ActiveRecord
233
233
  columns.NUMERIC_SCALE AS numeric_scale,
234
234
  columns.NUMERIC_PRECISION AS numeric_precision,
235
235
  columns.DATETIME_PRECISION AS datetime_precision,
236
+ columns.COLLATION_NAME AS collation,
236
237
  columns.ordinal_position,
237
238
  CASE
238
239
  WHEN columns.DATA_TYPE IN ('nchar','nvarchar','char','varchar') THEN columns.CHARACTER_MAXIMUM_LENGTH
@@ -311,6 +312,8 @@ module ActiveRecord
311
312
  when /\A\(N'(.*)'\)\Z/m
312
313
  string_literal = SQLServer::Utils.unquote_string(Regexp.last_match[1])
313
314
  [string_literal, nil]
315
+ when /CREATE DEFAULT/mi
316
+ [nil, nil]
314
317
  else
315
318
  type = case ci[:type]
316
319
  when /smallint|int|bigint/ then ci[:_type]
@@ -1,6 +1,4 @@
1
1
  require 'active_record/type'
2
- require 'active_record/connection_adapters/sqlserver/type/core_ext/value.rb'
3
- require 'active_record/connection_adapters/sqlserver/type/castable.rb'
4
2
  require 'active_record/connection_adapters/sqlserver/type/quoter.rb'
5
3
  # Exact Numerics
6
4
  require 'active_record/connection_adapters/sqlserver/type/integer.rb'
@@ -4,7 +4,6 @@ module ActiveRecord
4
4
  module Type
5
5
  class Boolean < ActiveRecord::Type::Boolean
6
6
 
7
- include Castable
8
7
 
9
8
  end
10
9
  end
@@ -4,8 +4,6 @@ module ActiveRecord
4
4
  module Type
5
5
  class Date < ActiveRecord::Type::Date
6
6
 
7
- # When FreeTDS/TinyTDS casts this data type natively.
8
- # include Castable
9
7
 
10
8
  end
11
9
  end
@@ -4,8 +4,6 @@ module ActiveRecord
4
4
  module Type
5
5
  class DateTime < ActiveRecord::Type::DateTime
6
6
 
7
- include Castable
8
-
9
7
  def type_cast_for_schema(value)
10
8
  value.acts_like?(:string) ? "'#{value}'" : super
11
9
  end
@@ -4,7 +4,6 @@ module ActiveRecord
4
4
  module Type
5
5
  class Decimal < ActiveRecord::Type::Decimal
6
6
 
7
- include Castable
8
7
 
9
8
  end
10
9
  end
@@ -4,8 +4,6 @@ module ActiveRecord
4
4
  module Type
5
5
  class Float < ActiveRecord::Type::Float
6
6
 
7
- include Castable
8
-
9
7
  def type
10
8
  :float
11
9
  end
@@ -4,7 +4,6 @@ module ActiveRecord
4
4
  module Type
5
5
  class Integer < ActiveRecord::Type::Integer
6
6
 
7
- include Castable
8
7
 
9
8
  end
10
9
  end
@@ -4,8 +4,6 @@ module ActiveRecord
4
4
  module Type
5
5
  class Real < Float
6
6
 
7
- include Castable
8
-
9
7
  def type
10
8
  :real
11
9
  end
@@ -4,8 +4,6 @@ module ActiveRecord
4
4
  module Type
5
5
  class SmallDateTime < DateTime
6
6
 
7
- include Castable
8
-
9
7
 
10
8
  private
11
9
 
@@ -11,9 +11,6 @@ module ActiveRecord
11
11
  @precision = nil if @precision == 7
12
12
  end
13
13
 
14
- # When FreeTDS/TinyTDS casts this data type natively.
15
- # include Castable
16
-
17
14
  def type_cast_for_database(value)
18
15
  return if value.nil?
19
16
  Quoter.new super, self
@@ -3,7 +3,7 @@ module ActiveRecord
3
3
  module SQLServer
4
4
  module Version
5
5
 
6
- VERSION = '4.2.4'
6
+ VERSION = '4.2.5'
7
7
 
8
8
  end
9
9
  end
@@ -40,6 +40,14 @@ module ActiveRecord
40
40
  @sql_type =~ /real/i
41
41
  end
42
42
 
43
+ def collation
44
+ @sqlserver_options[:collation]
45
+ end
46
+
47
+ def case_sensitive?
48
+ collation && !collation.match(/_CI/)
49
+ end
50
+
43
51
  end
44
52
  end
45
53
  end
@@ -0,0 +1,27 @@
1
+
2
+ Write-Output "Setting up..."
3
+ [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null
4
+ [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement") | Out-Null
5
+
6
+ Write-Output "Setting variables..."
7
+ $serverName = $env:COMPUTERNAME
8
+ $instances = @('SQL2012SP1', 'SQL2014')
9
+ $smo = 'Microsoft.SqlServer.Management.Smo.'
10
+ $wmi = new-object ($smo + 'Wmi.ManagedComputer')
11
+
12
+ Write-Output "Configure Instances..."
13
+ foreach ($instance in $instances) {
14
+ Write-Output "Instance $instance ..."
15
+ Write-Output "Enable TCP/IP and port 1433..."
16
+ $uri = "ManagedComputer[@Name='$serverName']/ServerInstance[@Name='$instance']/ServerProtocol[@Name='Tcp']"
17
+ $tcp = $wmi.GetSmoObject($uri)
18
+ $tcp.IsEnabled = $true
19
+ foreach ($ipAddress in $Tcp.IPAddresses) {
20
+ $ipAddress.IPAddressProperties["TcpDynamicPorts"].Value = ""
21
+ $ipAddress.IPAddressProperties["TcpPort"].Value = "1433"
22
+ }
23
+ $tcp.Alter()
24
+ }
25
+
26
+ Set-Service SQLBrowser -StartupType Manual
27
+ Start-Service SQLBrowser
@@ -0,0 +1,11 @@
1
+ CREATE DATABASE [activerecord_unittest];
2
+ CREATE DATABASE [activerecord_unittest2];
3
+ GO
4
+ CREATE LOGIN [rails] WITH PASSWORD = '', CHECK_POLICY = OFF, DEFAULT_DATABASE = [activerecord_unittest];
5
+ GO
6
+ USE [activerecord_unittest];
7
+ CREATE USER [rails] FOR LOGIN [rails];
8
+ GO
9
+ EXEC sp_addrolemember N'db_owner', N'rails';
10
+ EXEC master..sp_addsrvrolemember @loginame = N'rails', @rolename = N'sysadmin'
11
+ GO
@@ -1,6 +1,24 @@
1
1
  require 'cases/helper_sqlserver'
2
2
 
3
3
 
4
+ # Windows/Appveyor
5
+ if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
6
+ # All of these are due to Time.local(2000).zone. See http://git.io/v3t0o
7
+ class BelongsToAssociationsTest < ActiveRecord::TestCase
8
+ coerce_tests! :test_belongs_to_with_touch_option_on_touch_without_updated_at_attributes
9
+ end
10
+ class BasicsTest < ActiveRecord::TestCase
11
+ coerce_tests! :test_preserving_time_objects_with_local_time_conversion_to_default_timezone_utc
12
+ coerce_tests! :test_preserving_time_objects_with_time_with_zone_conversion_to_default_timezone_local
13
+ coerce_tests! :test_preserving_time_objects_with_utc_time_conversion_to_default_timezone_local
14
+ end
15
+ class DirtyTest < ActiveRecord::TestCase
16
+ coerce_tests! :test_save_always_should_update_timestamps_when_serialized_attributes_are_present
17
+ coerce_tests! :test_previous_changes # Coupled to above test.
18
+ end
19
+ end
20
+
21
+
4
22
  module ActiveRecord
5
23
  class AdapterTest < ActiveRecord::TestCase
6
24
 
@@ -46,15 +64,19 @@ class BasicsTest < ActiveRecord::TestCase
46
64
  assert_equal "[foo'bar]", quoted
47
65
  end
48
66
 
49
- # This test has a few problems. First, it would require that we use
50
- # the `Type::SQLServer::BigInteger.new(limit: 8)` for the `world_population`
51
- # attribute. Second, since we allow the DB to win at casting for TinyTDS,
52
- # it always comes back as a BigDecimal.
67
+ # PENDING: [Rails5.x] Remove coerced tests and use simple symbol types..
68
+ # This test has a few problems. First, it would require that we use the
69
+ # `Type::SQLServer::BigInteger.new(limit: 8)` for the `world_population` attribute.
53
70
  coerce_tests! :test_numeric_fields
71
+ coerce_tests! :test_numeric_fields_with_scale
54
72
 
55
73
  # Just like PostgreSQLAdapter does.
56
74
  coerce_tests! :test_respect_internal_encoding
57
75
 
76
+ # Caused in Rails v4.2.5 by adding `firm_id` column in this http://git.io/vBfMs
77
+ # commit. Trust Rails has this covered.
78
+ coerce_tests! :test_find_keeps_multiple_group_values
79
+
58
80
  end
59
81
 
60
82
 
@@ -388,41 +410,8 @@ class BigNumber < ActiveRecord::Base
388
410
  end
389
411
  class MigrationTest < ActiveRecord::TestCase
390
412
 
413
+ # PENDING: [Rails5.x] Remove coerced tests and use simple symbol types.
391
414
  coerce_tests! :test_add_table_with_decimals
392
- def test_add_table_with_decimals_coerced
393
- Person.connection.drop_table :big_numbers rescue nil
394
- assert !BigNumber.table_exists?
395
- GiveMeBigNumbers.up
396
- assert BigNumber.create(
397
- :bank_balance => 1586.43,
398
- :big_bank_balance => BigDecimal("1000234000567.95"),
399
- :world_population => 6000000000,
400
- :my_house_population => 3,
401
- :value_of_e => BigDecimal("2.7182818284590452353602875")
402
- )
403
- b = BigNumber.first
404
- assert_not_nil b
405
- assert_not_nil b.bank_balance
406
- assert_not_nil b.big_bank_balance
407
- assert_not_nil b.world_population
408
- assert_not_nil b.my_house_population
409
- assert_not_nil b.value_of_e
410
- # SQLServer: We rock and cast during assignment.
411
- assert_kind_of BigDecimal, b.world_population
412
- assert_equal BigDecimal('6000000000'), b.world_population
413
- # TODO: Our trust the DB policy breaks this expectation. Review SQLServer::Type::Castable module.
414
- skip
415
- assert_kind_of Fixnum, b.my_house_population
416
- assert_equal 3, b.my_house_population
417
- assert_kind_of BigDecimal, b.bank_balance
418
- assert_equal BigDecimal("1586.43"), b.bank_balance
419
- assert_kind_of BigDecimal, b.big_bank_balance
420
- assert_equal BigDecimal("1000234000567.95"), b.big_bank_balance
421
- assert_kind_of BigDecimal, b.value_of_e
422
- assert_equal BigDecimal("2.7182818284590452353602875"), b.value_of_e
423
- GiveMeBigNumbers.down
424
- assert_raise(ActiveRecord::StatementInvalid) { BigNumber.first }
425
- end
426
415
 
427
416
  end
428
417
 
@@ -609,6 +598,9 @@ class SchemaDumperTest < ActiveRecord::TestCase
609
598
  # This accidently returns the wrong number because of our tables too.
610
599
  coerce_tests! :test_types_line_up
611
600
 
601
+ # This is a poorly written test and really does not catch the bottom'ness it is meant too. Ours throw it off.
602
+ coerce_tests! :test_foreign_keys_are_dumped_at_the_bottom_to_circumvent_dependency_issues
603
+
612
604
  end
613
605
 
614
606
 
@@ -134,7 +134,7 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
134
134
  type.precision.must_equal 9
135
135
  type.scale.must_equal 2
136
136
  obj.decimal_9_2 = '1234567.8901'
137
- obj.decimal_9_2.must_equal BigDecimal('1234567.8901') # Cast from user one day.
137
+ obj.decimal_9_2.must_equal BigDecimal('1234567.89')
138
138
  obj.save!
139
139
  obj.reload.decimal_9_2.must_equal BigDecimal('1234567.89')
140
140
  end
@@ -149,7 +149,7 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
149
149
  type.precision.must_equal 16
150
150
  type.scale.must_equal 4
151
151
  obj.decimal_16_4 = '1234567.8901001'
152
- obj.decimal_16_4.must_equal BigDecimal('1234567.8901001') # Cast from user one day.
152
+ obj.decimal_16_4.must_equal BigDecimal('1234567.8901')
153
153
  obj.save!
154
154
  obj.reload.decimal_16_4.must_equal BigDecimal('1234567.8901')
155
155
  end
@@ -169,7 +169,7 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
169
169
  type.precision.must_equal 18
170
170
  type.scale.must_equal 0
171
171
  obj.numeric_18_0 = '192.1'
172
- obj.numeric_18_0.must_equal BigDecimal('192.1') # Cast from user one day.
172
+ obj.numeric_18_0.must_equal BigDecimal('192')
173
173
  obj.save!
174
174
  obj.reload.numeric_18_0.must_equal BigDecimal('192')
175
175
  end
@@ -189,7 +189,7 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
189
189
  type.precision.must_equal 36
190
190
  type.scale.must_equal 2
191
191
  obj.numeric_36_2 = '192.123'
192
- obj.numeric_36_2.must_equal BigDecimal('192.123') # Cast from user one day.
192
+ obj.numeric_36_2.must_equal BigDecimal('192.12')
193
193
  obj.save!
194
194
  obj.reload.numeric_36_2.must_equal BigDecimal('192.12')
195
195
  end
@@ -209,7 +209,7 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
209
209
  type.precision.must_equal 19
210
210
  type.scale.must_equal 4
211
211
  obj.money = '922337203685477.58061'
212
- obj.money.must_equal BigDecimal('922337203685477.58061')
212
+ obj.money.must_equal BigDecimal('922337203685477.5806')
213
213
  obj.save!
214
214
  obj.reload.money.must_equal BigDecimal('922337203685477.5806')
215
215
  end
@@ -229,7 +229,7 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
229
229
  type.precision.must_equal 10
230
230
  type.scale.must_equal 4
231
231
  obj.smallmoney = '214748.36461'
232
- obj.smallmoney.must_equal BigDecimal('214748.36461')
232
+ obj.smallmoney.must_equal BigDecimal('214748.3646')
233
233
  obj.save!
234
234
  obj.reload.smallmoney.must_equal BigDecimal('214748.3646')
235
235
  end
@@ -20,14 +20,13 @@ module ActiveRecord
20
20
  def connection_mode_dblib? ; ActiveRecord::Base.connection.instance_variable_get(:@connection_options)[:mode] == :dblib ; end
21
21
  def connection_mode_odbc? ; ActiveRecord::Base.connection.instance_variable_get(:@connection_options)[:mode] == :odbc ; end
22
22
  def sqlserver_azure? ; ActiveRecord::Base.connection.sqlserver_azure? ; end
23
+ def host_windows? ; RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ; end
23
24
  end
24
25
 
25
-
26
- private
27
-
28
26
  def connection_mode_dblib? ; self.class.connection_mode_dblib? ; end
29
27
  def connection_mode_odbc? ; self.class.connection_mode_odbc? ; end
30
28
  def sqlserver_azure? ; self.class.sqlserver_azure? ; end
29
+ def host_windows? ; self.class.host_windows? ; end
31
30
 
32
31
  def connection
33
32
  ActiveRecord::Base.connection
@@ -120,6 +120,8 @@ class SQLServerRakeStructureDumpLoadTest < SQLServerRakeTest
120
120
  end
121
121
 
122
122
  it 'dumps structure and accounts for defncopy oddities' do
123
+ # CHANGED: [TinyTDS] When utilities are available http://git.io/v3tBk
124
+ skip if host_windows?
123
125
  db_tasks.structure_dump configuration, filename
124
126
  filedata.wont_match %r{\AUSE.*\z}
125
127
  filedata.wont_match %r{\AGO.*\z}
@@ -129,6 +131,8 @@ class SQLServerRakeStructureDumpLoadTest < SQLServerRakeTest
129
131
  end
130
132
 
131
133
  it 'can load dumped structure' do
134
+ # CHANGED: [TinyTDS] When utilities are available http://git.io/v3tBk
135
+ skip if host_windows?
132
136
  db_tasks.structure_dump configuration, filename
133
137
  filedata.must_match %r{CREATE TABLE dbo\.users}
134
138
  db_tasks.purge(configuration)
@@ -100,12 +100,12 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
100
100
  assert_line :binary_basic_col, type: 'binary_basic', limit: '1', precision: nil, scale: nil, default: nil
101
101
  assert_line :varbinary_col, type: 'varbinary', limit: '8000', precision: nil, scale: nil, default: nil
102
102
  assert_line :uuid_col, type: 'uuid', limit: nil, precision: nil, scale: nil, default: nil
103
- assert_line :sstimestamp_col, type: 'ss_timestamp', limit: nil, precision: nil, scale: nil, default: nil
103
+ assert_line :sstimestamp_col, type: 'ss_timestamp', limit: nil, precision: nil, scale: nil, default: nil
104
104
  end
105
105
 
106
106
  # Special Cases
107
107
 
108
- it 'primary_key' do
108
+ it 'honor nonstandard primary keys' do
109
109
  generate_schema_for_table('movies') do |output|
110
110
  match = output.match(%r{create_table "movies"(.*)do})
111
111
  assert_not_nil(match, "nonstandardpk table not found")
@@ -113,6 +113,12 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
113
113
  end
114
114
  end
115
115
 
116
+ it 'no id with model driven primary key' do
117
+ output = generate_schema_for_table 'sst_no_pk_data'
118
+ output.must_match %r{create_table "sst_no_pk_data".*id:\sfalse.*do}
119
+ assert_line :name, type: 'string', limit: '4000'
120
+ end
121
+
116
122
 
117
123
  private
118
124
 
@@ -62,6 +62,12 @@ class SpecificSchemaTestSQLServer < ActiveRecord::TestCase
62
62
  assert_equal '(NULL)', default.string_with_pretend_null_four
63
63
  end
64
64
 
65
+ it 'default objects work' do
66
+ obj = SSTestObjectDefault.create! name: 'MetaSkills'
67
+ obj.date.must_be_nil 'since this is set on insert'
68
+ obj.reload.date.must_be_instance_of Date
69
+ end
70
+
65
71
  # Natural primary keys.
66
72
 
67
73
  it 'work with identity inserts' do
@@ -8,7 +8,6 @@ default_connection_info: &default_connection_info
8
8
  database: activerecord_unittest
9
9
  username: <%= ENV['ACTIVERECORD_UNITTEST_USER'] || 'rails' %>
10
10
  password: <%= ENV['ACTIVERECORD_UNITTEST_PASS'] || '' %>
11
- azure: <%= !ENV['ACTIVERECORD_UNITTEST_AZURE'].nil? %>
12
11
  collation: <%= ENV['ACTIVERECORD_UNITTEST_COLLATION'] || nil %>
13
12
  encoding: utf8
14
13
 
@@ -19,11 +18,15 @@ connections:
19
18
  <<: *default_connection_info
20
19
  appname: SQLServerAdptrUnit
21
20
  dataserver: <%= ENV['ACTIVERECORD_UNITTEST_DATASERVER'] %>
21
+ tds_version: <%= ENV['ACTIVERECORD_UNITTEST_TDSVERSION'] %>
22
+ azure: <%= !ENV['ACTIVERECORD_UNITTEST_AZURE'].nil? %>
22
23
  arunit2:
23
24
  <<: *default_connection_info
24
25
  database: activerecord_unittest2
25
26
  appname: SQLServerAdptrUnit2
26
27
  dataserver: <%= ENV['ACTIVERECORD_UNITTEST_DATASERVER'] %>
28
+ tds_version: <%= ENV['ACTIVERECORD_UNITTEST_TDSVERSION'] %>
29
+ azure: <%= !ENV['ACTIVERECORD_UNITTEST_AZURE'].nil? %>
27
30
 
28
31
  odbc:
29
32
  arunit:
@@ -0,0 +1,3 @@
1
+ class SSTestObjectDefault < ActiveRecord::Base
2
+ self.table_name = 'sst_defaultobjects'
3
+ end
@@ -109,6 +109,14 @@ ActiveRecord::Schema.define do
109
109
  )
110
110
  TINYITPKTABLE
111
111
 
112
+ execute "DROP DEFAULT [sst_getdateobject];" rescue nil
113
+ execute "CREATE DEFAULT [sst_getdateobject] AS getdate();" rescue nil
114
+ create_table 'sst_defaultobjects', force: true do |t|
115
+ t.string :name
116
+ t.date :date
117
+ end
118
+ execute "sp_bindefault 'sst_getdateobject', 'sst_defaultobjects.date'"
119
+
112
120
  # Constraints
113
121
 
114
122
  create_table(:sst_has_fks, force: true) { |t| t.column(:fk_id, :integer, null: false) }
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: 4.2.4
4
+ version: 4.2.5
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: 2015-03-20 00:00:00.000000000 Z
17
+ date: 2015-11-22 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activerecord
@@ -143,7 +143,7 @@ dependencies:
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  - !ruby/object:Gem::Dependency
146
- name: pry
146
+ name: byebug
147
147
  requirement: !ruby/object:Gem::Requirement
148
148
  requirements:
149
149
  - - ">="
@@ -170,7 +170,7 @@ dependencies:
170
170
  - - ">="
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
- description: ActiveRecord SQL Server Adapter.
173
+ description: ActiveRecord SQL Server Adapter. SQL Server 2012 and upward.
174
174
  email:
175
175
  - ken@metaskills.net
176
176
  - will@wbond.net
@@ -180,6 +180,7 @@ extra_rdoc_files: []
180
180
  files:
181
181
  - ".gitignore"
182
182
  - CHANGELOG.md
183
+ - CODE_OF_CONDUCT.md
183
184
  - Gemfile
184
185
  - Guardfile
185
186
  - MIT-LICENSE
@@ -187,6 +188,7 @@ files:
187
188
  - RUNNING_UNIT_TESTS.md
188
189
  - Rakefile
189
190
  - activerecord-sqlserver-adapter.gemspec
191
+ - appveyor.yml
190
192
  - lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb
191
193
  - lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb
192
194
  - lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb
@@ -209,9 +211,7 @@ files:
209
211
  - lib/active_record/connection_adapters/sqlserver/type/big_integer.rb
210
212
  - lib/active_record/connection_adapters/sqlserver/type/binary.rb
211
213
  - lib/active_record/connection_adapters/sqlserver/type/boolean.rb
212
- - lib/active_record/connection_adapters/sqlserver/type/castable.rb
213
214
  - lib/active_record/connection_adapters/sqlserver/type/char.rb
214
- - lib/active_record/connection_adapters/sqlserver/type/core_ext/value.rb
215
215
  - lib/active_record/connection_adapters/sqlserver/type/date.rb
216
216
  - lib/active_record/connection_adapters/sqlserver/type/datetime.rb
217
217
  - lib/active_record/connection_adapters/sqlserver/type/decimal.rb
@@ -247,6 +247,8 @@ files:
247
247
  - lib/activerecord-sqlserver-adapter.rb
248
248
  - lib/arel/visitors/sqlserver.rb
249
249
  - lib/arel_sqlserver.rb
250
+ - test/appveyor/dbsetup.ps1
251
+ - test/appveyor/dbsetup.sql
250
252
  - test/cases/adapter_test_sqlserver.rb
251
253
  - test/cases/coerced_tests.rb
252
254
  - test/cases/column_test_sqlserver.rb
@@ -280,6 +282,7 @@ files:
280
282
  - test/models/sqlserver/natural_pk_data.rb
281
283
  - test/models/sqlserver/natural_pk_int_data.rb
282
284
  - test/models/sqlserver/no_pk_data.rb
285
+ - test/models/sqlserver/object_default.rb
283
286
  - test/models/sqlserver/quoted_table.rb
284
287
  - test/models/sqlserver/quoted_view_1.rb
285
288
  - test/models/sqlserver/quoted_view_2.rb
@@ -299,7 +302,8 @@ files:
299
302
  - test/support/rake_helpers.rb
300
303
  - test/support/sql_counter_sqlserver.rb
301
304
  homepage: http://github.com/rails-sqlserver/activerecord-sqlserver-adapter
302
- licenses: []
305
+ licenses:
306
+ - MIT
303
307
  metadata: {}
304
308
  post_install_message:
305
309
  rdoc_options: []
@@ -317,11 +321,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
317
321
  version: '0'
318
322
  requirements: []
319
323
  rubyforge_project:
320
- rubygems_version: 2.4.2
324
+ rubygems_version: 2.4.8
321
325
  signing_key:
322
326
  specification_version: 4
323
327
  summary: ActiveRecord SQL Server Adapter.
324
328
  test_files:
329
+ - test/appveyor/dbsetup.ps1
330
+ - test/appveyor/dbsetup.sql
325
331
  - test/cases/adapter_test_sqlserver.rb
326
332
  - test/cases/coerced_tests.rb
327
333
  - test/cases/column_test_sqlserver.rb
@@ -355,6 +361,7 @@ test_files:
355
361
  - test/models/sqlserver/natural_pk_data.rb
356
362
  - test/models/sqlserver/natural_pk_int_data.rb
357
363
  - test/models/sqlserver/no_pk_data.rb
364
+ - test/models/sqlserver/object_default.rb
358
365
  - test/models/sqlserver/quoted_table.rb
359
366
  - test/models/sqlserver/quoted_view_1.rb
360
367
  - test/models/sqlserver/quoted_view_2.rb
@@ -1,15 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module SQLServer
4
- module Type
5
- module Castable
6
-
7
- def type_cast_from_database(value)
8
- type_cast_from_ss_database? ? super : value
9
- end
10
-
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,39 +0,0 @@
1
- module ActiveRecord
2
- module Type
3
- class Value
4
-
5
- module SQLServerBehavior
6
-
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- self.type_cast_from_ss_database = false
11
- end
12
-
13
- module ClassMethods
14
-
15
- def type_cast_from_ss_database
16
- @@type_cast_from_ss_database
17
- end
18
-
19
- def type_cast_from_ss_database=(boolean)
20
- @@type_cast_from_ss_database = !!boolean
21
- end
22
-
23
- end
24
-
25
- def type_cast_from_ss_database?
26
- self.class.type_cast_from_ss_database
27
- end
28
-
29
- def type_cast_from_database(value)
30
- type_cast_from_ss_database? ? super : value
31
- end
32
-
33
- end
34
-
35
- include SQLServerBehavior
36
-
37
- end
38
- end
39
- end