torque-postgresql 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fcb69118c9cca1afe5ef21a9ed9b4cf98e9036108b739707a1e7f65058aaaf84
4
- data.tar.gz: d7ca85705f802c0d15c0aabca99a9ec17b8403e60e912724b609d8b93cd7bd86
3
+ metadata.gz: 573548a4177e130f445da5816cf833bb21508a2612c71fd3f8fc6a78c7ce04fc
4
+ data.tar.gz: 509acb45a89a55c30a626117c61a5fc23b9a635f041b1ff6549fed4d221a7571
5
5
  SHA512:
6
- metadata.gz: 0a48ed549030276f9a3e4c845454eb89cf97b8d0bf3d00cd5431abd85a7317f6031e4f997e86ae3657012ca9d4578598d612a14c531247575f1d0496bc629f6e
7
- data.tar.gz: 50a1817ef37c0c8d98a71b92500a73b420f5dc27cf9d19afc6aeb8492e3d4582b69ee9ada91b281699987cc4bb33a9d1df584219073d432299ebad53a4a29513
6
+ metadata.gz: 2267add7a9e17636f0f8ee274d5263d065390998e34b513bede849b7f39292a9742432a6ac41a27930c6cbb49216adccdfb09322497177887267452513494c1f
7
+ data.tar.gz: 5c3c5174170a4f3eb988f6c1c62c56465da91371a3f3d216ba85ba02e1721dce1c99f93e1964bd7f8b9ebd600beed512d4a713349e2435fd686c8bdaa2f0d6d3
@@ -6,6 +6,8 @@ module Torque
6
6
  module Quoting
7
7
 
8
8
  Name = ActiveRecord::ConnectionAdapters::PostgreSQL::Name
9
+ Column = ActiveRecord::ConnectionAdapters::PostgreSQL::Column
10
+ ColumnDefinition = ActiveRecord::ConnectionAdapters::ColumnDefinition
9
11
 
10
12
  # Quotes type names for use in SQL queries.
11
13
  def quote_type_name(string, schema = nil)
@@ -20,11 +22,12 @@ module Torque
20
22
  end
21
23
 
22
24
  def quote_default_expression(value, column)
23
- if column.options.try(:[], :array) && value.class <= Array
24
- quote(value) + '::' + column.sql_type
25
- else
26
- super
27
- end
25
+ return super unless value.class <= Array &&
26
+ ((column.is_a?(ColumnDefinition) && column.dig(:options, :array)) ||
27
+ (column.is_a?(Column) && column.array?))
28
+
29
+ type = column.is_a?(Column) ? column.sql_type_metadata.sql_type : column.sql_type
30
+ quote(value) + '::' + type
28
31
  end
29
32
 
30
33
  private
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Torque
4
4
  module PostgreSQL
5
- VERSION = '2.2.1'
5
+ VERSION = '2.2.2'
6
6
  end
7
7
  end
@@ -55,6 +55,12 @@ RSpec.describe 'Arel' do
55
55
  after(:context) { Torque::PostgreSQL.config.use_extended_defaults = false }
56
56
  after { Author.reset_column_information }
57
57
 
58
+ it 'does not break the change column default value method' do
59
+ connection.add_column(:authors, :enabled, :boolean)
60
+ expect { connection.change_column_default(:authors, :enabled, { from: nil, to: true }) }.not_to raise_error
61
+ expect(Author.columns_hash['enabled'].default).to eq('true')
62
+ end
63
+
58
64
  it 'does not break jsonb' do
59
65
  expect { connection.add_column(:authors, :profile, :jsonb, default: []) }.not_to raise_error
60
66
  expect(Author.columns_hash['profile'].default).to eq('[]')
@@ -76,6 +82,13 @@ RSpec.describe 'Arel' do
76
82
  expect { connection.add_column(:authors, :tag_ids, :string, array: true, default: value) }.not_to raise_error
77
83
  expect(Author.columns_hash['tag_ids'].default).to eq(value)
78
84
  end
85
+
86
+ it 'works with change column default value' do
87
+ value = ['2', '3']
88
+ connection.add_column(:authors, :tag_ids, :string, array: true)
89
+ expect { connection.change_column_default(:authors, :tag_ids, { from: nil, to: value }) }.not_to raise_error
90
+ expect(Author.columns_hash['tag_ids'].default).to eq(value)
91
+ end
79
92
  end
80
93
 
81
94
  context 'on cast' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torque-postgresql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Silva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-25 00:00:00.000000000 Z
11
+ date: 2021-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails