torque-postgresql 3.3.1 → 3.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/torque/postgresql/associations/belongs_to_many_association.rb +2 -2
- data/lib/torque/postgresql/version.rb +1 -1
- data/spec/schema.rb +9 -9
- data/spec/tests/belongs_to_many_spec.rb +42 -1
- data/spec/tests/distinct_on_spec.rb +1 -1
- data/spec/tests/relation_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a40ad54958c3355dabba2edfdf5fb0a833e9f2eeb16eb6aa680e522a93fe5cd
|
4
|
+
data.tar.gz: 32b7d2b052b475996081fedcfd265ed45f75aa115941269e93d26f6b88fe97e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f36f81c4fd169d0e2dd164f17ba28ee6b6efb7e656609b45471216c5ec7119dc1f567e9864616420786a985d1a1630da681b423c7f9bff035fcf347c518dce14
|
7
|
+
data.tar.gz: de52240614a54984891c727edb19811ab67037a30f5f284bf4e5f9ce7e29e0afd19e9cc24897fdd2a1d060f6fc3d3ac466a39a812c3f975ec4c91b7bf51b0ec2
|
@@ -12,9 +12,9 @@ module Torque
|
|
12
12
|
## CUSTOM
|
13
13
|
def ids_reader
|
14
14
|
if loaded?
|
15
|
-
target.pluck(reflection.
|
15
|
+
target.pluck(reflection.active_record_primary_key)
|
16
16
|
elsif !target.empty?
|
17
|
-
load_target.pluck(reflection.
|
17
|
+
load_target.pluck(reflection.active_record_primary_key)
|
18
18
|
else
|
19
19
|
stale_state || column_default_value
|
20
20
|
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 =
|
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",
|
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",
|
84
|
+
t.integer "user_id", null: false
|
85
85
|
t.integer "comment_id"
|
86
86
|
t.integer "video_id"
|
87
|
-
t.text "content",
|
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",
|
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",
|
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",
|
124
|
-
t.enum "role",
|
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",
|
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
|
@@ -400,7 +400,7 @@ RSpec.describe 'BelongsToMany' do
|
|
400
400
|
let(:player) { Class.new(ActiveRecord::Base) }
|
401
401
|
let(:other) { player.create }
|
402
402
|
|
403
|
-
# TODO: Set as a
|
403
|
+
# TODO: Set as a shared example
|
404
404
|
before do
|
405
405
|
connection.create_table(:players, id: :uuid) { |t| t.string :name }
|
406
406
|
connection.create_table(:games, id: :uuid) { |t| t.uuid :player_ids, array: true }
|
@@ -440,4 +440,45 @@ RSpec.describe 'BelongsToMany' do
|
|
440
440
|
expect { query.load }.not_to raise_error
|
441
441
|
end
|
442
442
|
end
|
443
|
+
|
444
|
+
context 'using custom keys' do
|
445
|
+
let(:connection) { ActiveRecord::Base.connection }
|
446
|
+
let(:post) { Post }
|
447
|
+
let(:tag) { Tag }
|
448
|
+
let(:tags) { %w[a b c].map { |id| create(:tag, friendly_id: id) } }
|
449
|
+
|
450
|
+
subject { create(:post) }
|
451
|
+
|
452
|
+
before do
|
453
|
+
connection.add_column(:tags, :friendly_id, :string)
|
454
|
+
connection.add_column(:posts, :friendly_tag_ids, :string, array: true)
|
455
|
+
post.belongs_to_many(:tags, foreign_key: :friendly_tag_ids, primary_key: :friendly_id)
|
456
|
+
post.reset_column_information
|
457
|
+
tag.reset_column_information
|
458
|
+
end
|
459
|
+
|
460
|
+
after do
|
461
|
+
tag.reset_column_information
|
462
|
+
post.reset_column_information
|
463
|
+
post._reflections.delete(:tags)
|
464
|
+
end
|
465
|
+
|
466
|
+
it 'loads associated records' do
|
467
|
+
subject.update(friendly_tag_ids: tags.pluck(:friendly_id))
|
468
|
+
|
469
|
+
expect(subject.tags.to_sql).to be_eql(<<-SQL.squish)
|
470
|
+
SELECT "tags".* FROM "tags" WHERE "tags"."friendly_id" IN ('a', 'b', 'c')
|
471
|
+
SQL
|
472
|
+
|
473
|
+
expect(subject.tags.load).to be_a(ActiveRecord::Associations::CollectionProxy)
|
474
|
+
expect(subject.tags.to_a).to be_eql(tags)
|
475
|
+
end
|
476
|
+
|
477
|
+
it 'can properly assign tags' do
|
478
|
+
expect(subject.friendly_tag_ids).to be_blank
|
479
|
+
|
480
|
+
subject.tags = tags
|
481
|
+
expect(subject.friendly_tag_ids).to be_eql(%w[a b c])
|
482
|
+
end
|
483
|
+
end
|
443
484
|
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(
|
43
|
+
expect { subject.distinct_on(supervisors: :name).to_sql }.to \
|
44
44
|
raise_error(ArgumentError, /Relation for/)
|
45
45
|
end
|
46
46
|
|
data/spec/tests/relation_spec.rb
CHANGED
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: 3.3.
|
4
|
+
version: 3.3.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: 2024-
|
11
|
+
date: 2024-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|