torque-postgresql 2.4.2 → 2.4.4

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: 9185b34c8897975b296b43fe5585a1a62d61d02c30d204f5963bfb2b87cb74ca
4
- data.tar.gz: ca9ec1fc2558f8d24296ac287b592e3d9b10ea41015f8c29b2c8f8a01536606c
3
+ metadata.gz: 3533ab897fec6762e3d3165d9b4795bf3167409724bfc9c77acd845747ee698c
4
+ data.tar.gz: 76e868de2923ff393e4fe8f9a836a4cd258588726e522811515b70bec1f5afbd
5
5
  SHA512:
6
- metadata.gz: a2c30b52f8573c6745735d3625b64f9bebd052e47b51b7ceec3a297977cebcef945d0428dc55830932e3ee6c7cd7b78c8309e090c16b7b66ed7d9559ab753a20
7
- data.tar.gz: cbd8559012bfb7cd112e67f52e9e6fad96528bfb66bdc6e17244e8771f033cde0530a5fb51679ce264eaa7c37cc4b4db36807a93eff53cab45bab0038c20fe11
6
+ metadata.gz: 886466cc45f9581d18e7fabf3a287ad17b318be0a447fe611f33aa403e63e74de25d9f230f5ddf1475c6dc12e3658d54e98378af57ec8c92d7e5d6503e87a033
7
+ data.tar.gz: 0a940cb293cf793e5ca884203b328f346b0276ada4a1ea682ec0677c051d415c31f31abcb27dd2d27c197060335d8117556d87607367f4bc8b81a8a104e95280
@@ -12,9 +12,9 @@ module Torque
12
12
  ## CUSTOM
13
13
  def ids_reader
14
14
  if loaded?
15
- target.pluck(reflection.association_primary_key)
15
+ target.pluck(reflection.active_record_primary_key)
16
16
  elsif !target.empty?
17
- load_target.pluck(reflection.association_primary_key)
17
+ load_target.pluck(reflection.active_record_primary_key)
18
18
  else
19
19
  stale_state || column_default_value
20
20
  end
@@ -25,7 +25,7 @@ module Torque
25
25
  end
26
26
 
27
27
  def foreign_key
28
- @foreign_key ||= options[:foreign_key] || derive_foreign_key.freeze
28
+ @foreign_key ||= options[:foreign_key]&.to_s || derive_foreign_key.freeze
29
29
  end
30
30
 
31
31
  def association_foreign_key
@@ -33,7 +33,7 @@ module Torque
33
33
  end
34
34
 
35
35
  def active_record_primary_key
36
- @active_record_primary_key ||= options[:primary_key] || derive_primary_key
36
+ @active_record_primary_key ||= options[:primary_key]&.to_s || derive_primary_key
37
37
  end
38
38
 
39
39
  def join_primary_key(*)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Torque
4
4
  module PostgreSQL
5
- VERSION = '2.4.2'
5
+ VERSION = '2.4.4'
6
6
  end
7
7
  end
data/spec/schema.rb CHANGED
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- version = 2
13
+ version = 3
14
14
 
15
15
  return if ActiveRecord::Migrator.current_version == version
16
16
  ActiveRecord::Schema.define(version: version) do
@@ -77,14 +77,14 @@ ActiveRecord::Schema.define(version: version) do
77
77
  create_table "texts", force: :cascade do |t|
78
78
  t.integer "user_id"
79
79
  t.string "content"
80
- t.enum "conflict", enum_type: :conflicts
80
+ t.enum "conflict", enum_type: :conflicts
81
81
  end
82
82
 
83
83
  create_table "comments", force: :cascade do |t|
84
- t.integer "user_id", null: false
84
+ t.integer "user_id", null: false
85
85
  t.integer "comment_id"
86
86
  t.integer "video_id"
87
- t.text "content", null: false
87
+ t.text "content", null: false
88
88
  t.string "kind"
89
89
  t.index ["user_id"], name: "index_comments_on_user_id", using: :btree
90
90
  t.index ["comment_id"], name: "index_comments_on_comment_id", using: :btree
@@ -92,7 +92,7 @@ ActiveRecord::Schema.define(version: version) do
92
92
 
93
93
  create_table "courses", force: :cascade do |t|
94
94
  t.integer "category_id"
95
- t.string "title", null: false
95
+ t.string "title", null: false
96
96
  t.interval "duration"
97
97
  t.enum "types", enum_type: :types, array: true
98
98
  t.datetime "created_at", null: false
@@ -108,7 +108,7 @@ ActiveRecord::Schema.define(version: version) do
108
108
  t.integer "activity_id"
109
109
  t.string "title"
110
110
  t.text "content"
111
- t.enum "status", enum_type: :content_status
111
+ t.enum "status", enum_type: :content_status
112
112
  t.index ["author_id"], name: "index_posts_on_author_id", using: :btree
113
113
  end
114
114
 
@@ -120,8 +120,8 @@ ActiveRecord::Schema.define(version: version) do
120
120
  end
121
121
 
122
122
  create_table "users", force: :cascade do |t|
123
- t.string "name", null: false
124
- t.enum "role", enum_type: :roles, default: :visitor
123
+ t.string "name", null: false
124
+ t.enum "role", enum_type: :roles, default: :visitor
125
125
  t.datetime "created_at", null: false
126
126
  t.datetime "updated_at", null: false
127
127
  end
@@ -137,7 +137,7 @@ ActiveRecord::Schema.define(version: version) do
137
137
  t.integer "author_id"
138
138
  t.string "title"
139
139
  t.boolean "active"
140
- t.enum "kind", enum_type: :types
140
+ t.enum "kind", enum_type: :types
141
141
  t.datetime "created_at", null: false
142
142
  t.datetime "updated_at", null: false
143
143
  end
@@ -20,6 +20,14 @@ RSpec.describe 'BelongsToMany' do
20
20
 
21
21
  model.belongs_to_many(:tests)
22
22
  end
23
+
24
+ it 'allows setting up foreign key and primary_key as symbol' do
25
+ model.belongs_to_many(:tests, foreign_key: :test_ids, primary_key: :test_id)
26
+
27
+ reflection = model._reflections['tests']
28
+ expect(reflection.foreign_key).to be_eql('test_ids')
29
+ expect(reflection.active_record_primary_key).to be_eql('test_id')
30
+ end
23
31
  end
24
32
 
25
33
  context 'on association' do
@@ -441,4 +449,45 @@ RSpec.describe 'BelongsToMany' do
441
449
  expect { query.load }.not_to raise_error
442
450
  end
443
451
  end
452
+
453
+ context 'using custom keys' do
454
+ let(:connection) { ActiveRecord::Base.connection }
455
+ let(:post) { Post }
456
+ let(:tag) { Tag }
457
+ let(:tags) { %w[a b c].map { |id| create(:tag, friendly_id: id) } }
458
+
459
+ subject { create(:post) }
460
+
461
+ before do
462
+ connection.add_column(:tags, :friendly_id, :string)
463
+ connection.add_column(:posts, :friendly_tag_ids, :string, array: true)
464
+ post.belongs_to_many(:tags, foreign_key: :friendly_tag_ids, primary_key: :friendly_id)
465
+ post.reset_column_information
466
+ tag.reset_column_information
467
+ end
468
+
469
+ after do
470
+ tag.reset_column_information
471
+ post.reset_column_information
472
+ post._reflections.delete(:tags)
473
+ end
474
+
475
+ it 'loads associated records' do
476
+ subject.update(friendly_tag_ids: tags.pluck(:friendly_id))
477
+
478
+ expect(subject.tags.to_sql).to be_eql(<<-SQL.squish)
479
+ SELECT "tags".* FROM "tags" WHERE "tags"."friendly_id" IN ('a', 'b', 'c')
480
+ SQL
481
+
482
+ expect(subject.tags.load).to be_a(ActiveRecord::Associations::CollectionProxy)
483
+ expect(subject.tags.to_a).to be_eql(tags)
484
+ end
485
+
486
+ it 'can properly assign tags' do
487
+ expect(subject.friendly_tag_ids).to be_blank
488
+
489
+ subject.tags = tags
490
+ expect(subject.friendly_tag_ids).to be_eql(%w[a b c])
491
+ end
492
+ end
444
493
  end
@@ -40,7 +40,7 @@ RSpec.describe 'DistinctOn' do
40
40
  end
41
41
 
42
42
  it 'raises with invalid relation' do
43
- expect { subject.distinct_on(tags: :name).to_sql }.to \
43
+ expect { subject.distinct_on(supervisors: :name).to_sql }.to \
44
44
  raise_error(ArgumentError, /Relation for/)
45
45
  end
46
46
 
@@ -44,7 +44,7 @@ RSpec.describe 'Relation', type: :helper do
44
44
  end
45
45
 
46
46
  it 'raises on relation not present' do
47
- check = [tags: :name]
47
+ check = [supervisors: :name]
48
48
  expect{ subject.call(check) }.to raise_error(ArgumentError, /Relation for/)
49
49
  end
50
50
 
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.4.2
4
+ version: 2.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Silva
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-20 00:00:00.000000000 Z
11
+ date: 2024-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -134,6 +134,9 @@ dependencies:
134
134
  - - ">="
135
135
  - !ruby/object:Gem::Version
136
136
  version: 6.2.1
137
+ - - "<"
138
+ - !ruby/object:Gem::Version
139
+ version: '6.4'
137
140
  type: :development
138
141
  prerelease: false
139
142
  version_requirements: !ruby/object:Gem::Requirement
@@ -144,6 +147,9 @@ dependencies:
144
147
  - - ">="
145
148
  - !ruby/object:Gem::Version
146
149
  version: 6.2.1
150
+ - - "<"
151
+ - !ruby/object:Gem::Version
152
+ version: '6.4'
147
153
  - !ruby/object:Gem::Dependency
148
154
  name: faker
149
155
  requirement: !ruby/object:Gem::Requirement
@@ -299,7 +305,7 @@ licenses:
299
305
  metadata:
300
306
  source_code_uri: https://github.com/crashtech/torque-postgresql
301
307
  bug_tracker_uri: https://github.com/crashtech/torque-postgresql/issues
302
- post_install_message:
308
+ post_install_message:
303
309
  rdoc_options:
304
310
  - "--title"
305
311
  - Torque PostgreSQL
@@ -317,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
317
323
  version: 1.8.11
318
324
  requirements: []
319
325
  rubygems_version: 3.2.15
320
- signing_key:
326
+ signing_key:
321
327
  specification_version: 4
322
328
  summary: ActiveRecord extension to access PostgreSQL advanced resources
323
329
  test_files: