arel-helpers 2.9.1 → 2.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/combustion_test.sqlite
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ ActiveRecord::Schema.define do
4
+ create_table :posts do |t|
5
+ t.column :title, :string
6
+ end
7
+
8
+ create_table :comments do |t|
9
+ t.references :post
10
+ end
11
+
12
+ create_table :authors do |t|
13
+ t.references :comment
14
+ t.references :collab_posts
15
+ end
16
+
17
+ create_table :favorites do |t|
18
+ t.references :post
19
+ end
20
+
21
+ create_table :collab_posts do |t|
22
+ t.references :authors
23
+ end
24
+
25
+ create_table :cards
26
+
27
+ create_table :card_locations do |t|
28
+ t.references :location
29
+ t.references :card, polymorphic: true
30
+ end
31
+
32
+ create_table :locations
33
+ create_table :community_tickets
34
+ end
@@ -0,0 +1,393 @@
1
+  (1.9ms) SELECT sqlite_version(*)
2
+  (0.1ms) SELECT sqlite_version(*)
3
+  (1.5ms) CREATE TABLE "posts" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar)
4
+  (1.3ms) CREATE TABLE "comments" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "post_id" integer)
5
+  (1.3ms) CREATE INDEX "index_comments_on_post_id" ON "comments" ("post_id")
6
+  (1.2ms) CREATE TABLE "authors" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "comment_id" integer, "collab_posts_id" integer)
7
+  (1.3ms) CREATE INDEX "index_authors_on_comment_id" ON "authors" ("comment_id")
8
+  (1.4ms) CREATE INDEX "index_authors_on_collab_posts_id" ON "authors" ("collab_posts_id")
9
+  (1.1ms) CREATE TABLE "favorites" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "post_id" integer)
10
+  (1.1ms) CREATE INDEX "index_favorites_on_post_id" ON "favorites" ("post_id")
11
+  (0.9ms) CREATE TABLE "collab_posts" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "authors_id" integer)
12
+  (1.0ms) CREATE INDEX "index_collab_posts_on_authors_id" ON "collab_posts" ("authors_id")
13
+  (1.0ms) CREATE TABLE "cards" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL)
14
+  (1.0ms) CREATE TABLE "card_locations" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "location_id" integer, "card_type" varchar, "card_id" integer)
15
+  (0.9ms) CREATE INDEX "index_card_locations_on_location_id" ON "card_locations" ("location_id")
16
+  (1.0ms) CREATE INDEX "index_card_locations_on_card" ON "card_locations" ("card_type", "card_id")
17
+  (0.9ms) CREATE TABLE "locations" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL)
18
+  (0.9ms) CREATE TABLE "community_tickets" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL)
19
+  (1.0ms) CREATE TABLE "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL)
20
+ ActiveRecord::InternalMetadata Load (0.1ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", "environment"], ["LIMIT", 1]]
21
+ TRANSACTION (0.0ms) begin transaction
22
+ ActiveRecord::InternalMetadata Create (0.4ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["key", "environment"], ["value", "test"], ["created_at", "2021-08-26 17:33:23.741476"], ["updated_at", "2021-08-26 17:33:23.741476"]]
23
+ TRANSACTION (0.9ms) commit transaction
24
+  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY)
25
+ ActiveRecord::InternalMetadata Load (0.1ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", "environment"], ["LIMIT", 1]]
26
+  (0.1ms) SELECT sqlite_version(*)
27
+  (0.0ms) PRAGMA foreign_keys
28
+  (0.1ms) PRAGMA defer_foreign_keys
29
+  (0.1ms) PRAGMA defer_foreign_keys = ON
30
+  (0.0ms) PRAGMA foreign_keys = OFF
31
+  (1.1ms) DELETE FROM "posts";
32
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
33
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'posts';
34
+  (1.2ms) DELETE FROM "comments";
35
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
36
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'comments';
37
+  (1.1ms) DELETE FROM "authors";
38
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
39
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'authors';
40
+  (1.0ms) DELETE FROM "favorites";
41
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
42
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'favorites';
43
+  (1.0ms) DELETE FROM "collab_posts";
44
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
45
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'collab_posts';
46
+  (0.9ms) DELETE FROM "cards";
47
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
48
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'cards';
49
+  (1.0ms) DELETE FROM "card_locations";
50
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
51
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'card_locations';
52
+  (0.9ms) DELETE FROM "locations";
53
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
54
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'locations';
55
+  (0.8ms) DELETE FROM "community_tickets";
56
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
57
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'community_tickets';
58
+  (0.0ms) PRAGMA defer_foreign_keys = 0
59
+  (0.0ms) PRAGMA foreign_keys = 1
60
+ TRANSACTION (0.0ms) begin transaction
61
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
62
+ Post Create (0.4ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "I'm a little teapot"]]
63
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
64
+ Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = ? [["post_id", 1]]
65
+ TRANSACTION (0.2ms) rollback transaction
66
+ TRANSACTION (0.0ms) begin transaction
67
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
68
+ Post Create (0.4ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "I'm a little teapot"]]
69
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
70
+ TRANSACTION (0.1ms) SAVEPOINT active_record_1
71
+ Comment Create (0.2ms) INSERT INTO "comments" ("post_id") VALUES (?) [["post_id", 1]]
72
+ TRANSACTION (0.1ms) RELEASE SAVEPOINT active_record_1
73
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
74
+ Comment Load (0.0ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = ? [["post_id", 1]]
75
+ TRANSACTION (0.4ms) rollback transaction
76
+ TRANSACTION (0.0ms) begin transaction
77
+ Post Load (0.2ms) SELECT "posts".* FROM "posts"
78
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
79
+ Post Create (0.4ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "foo"]]
80
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
81
+ Post Load (0.0ms) SELECT "posts".* FROM "posts"
82
+ TRANSACTION (0.4ms) rollback transaction
83
+ TRANSACTION (0.1ms) begin transaction
84
+ TRANSACTION (0.0ms) rollback transaction
85
+ TRANSACTION (0.1ms) begin transaction
86
+ TRANSACTION (0.0ms) rollback transaction
87
+ TRANSACTION (0.1ms) begin transaction
88
+ TRANSACTION (0.1ms) rollback transaction
89
+ TRANSACTION (0.1ms) begin transaction
90
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
91
+ Location Create (0.4ms) INSERT INTO "locations" DEFAULT VALUES
92
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
93
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
94
+ CommunityTicket Create (0.1ms) INSERT INTO "community_tickets" DEFAULT VALUES
95
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
96
+ TRANSACTION (0.1ms) SAVEPOINT active_record_1
97
+ CardLocation Create (0.3ms) INSERT INTO "card_locations" ("location_id", "card_type", "card_id") VALUES (?, ?, ?) [["location_id", 1], ["card_type", "CommunityTicket"], ["card_id", 1]]
98
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
99
+  (0.1ms) SELECT COUNT(*) FROM "locations" INNER JOIN "card_locations" ON "card_locations"."card_type" = ? AND "card_locations"."location_id" = "locations"."id" INNER JOIN "community_tickets" ON "community_tickets"."id" = "card_locations"."card_id" [["card_type", "CommunityTicket"]]
100
+ Location Load (0.1ms) SELECT "locations".* FROM "locations" INNER JOIN "card_locations" ON "card_locations"."card_type" = ? AND "card_locations"."location_id" = "locations"."id" INNER JOIN "community_tickets" ON "community_tickets"."id" = "card_locations"."card_id" [["card_type", "CommunityTicket"]]
101
+ TRANSACTION (0.5ms) rollback transaction
102
+ TRANSACTION (0.0ms) begin transaction
103
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
104
+ Post Create (0.4ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "Foobar"]]
105
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
106
+ Post Load (0.0ms) SELECT "posts".* FROM "posts"
107
+ TRANSACTION (0.3ms) rollback transaction
108
+ TRANSACTION (0.1ms) begin transaction
109
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
110
+ Post Create (0.4ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "Foobar"]]
111
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
112
+ Post Load (0.0ms) SELECT "posts".* FROM "posts"
113
+ TRANSACTION (0.4ms) rollback transaction
114
+ TRANSACTION (0.0ms) begin transaction
115
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
116
+ Post Create (0.5ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "Foobar"]]
117
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
118
+ Post Load (0.0ms) SELECT "posts".* FROM "posts"
119
+ TRANSACTION (0.3ms) rollback transaction
120
+ TRANSACTION (0.1ms) begin transaction
121
+  (0.1ms) SELECT COUNT(*) FROM "posts"
122
+ TRANSACTION (0.1ms) rollback transaction
123
+ TRANSACTION (0.1ms) begin transaction
124
+ Post Load (0.2ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" ASC LIMIT ? [["LIMIT", 1]]
125
+ TRANSACTION (0.1ms) rollback transaction
126
+ TRANSACTION (0.1ms) begin transaction
127
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" DESC LIMIT ? [["LIMIT", 1]]
128
+ TRANSACTION (0.0ms) rollback transaction
129
+ TRANSACTION (0.0ms) begin transaction
130
+  (0.1ms) SELECT "posts".* FROM "posts"
131
+ TRANSACTION (0.0ms) rollback transaction
132
+  (1.2ms) SELECT sqlite_version(*)
133
+  (0.1ms) SELECT sqlite_version(*)
134
+  (1.3ms) CREATE TABLE "posts" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar)
135
+  (1.2ms) CREATE TABLE "comments" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "post_id" integer)
136
+  (1.1ms) CREATE INDEX "index_comments_on_post_id" ON "comments" ("post_id")
137
+  (1.1ms) CREATE TABLE "authors" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "comment_id" integer, "collab_posts_id" integer)
138
+  (1.1ms) CREATE INDEX "index_authors_on_comment_id" ON "authors" ("comment_id")
139
+  (1.0ms) CREATE INDEX "index_authors_on_collab_posts_id" ON "authors" ("collab_posts_id")
140
+  (1.0ms) CREATE TABLE "favorites" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "post_id" integer)
141
+  (1.0ms) CREATE INDEX "index_favorites_on_post_id" ON "favorites" ("post_id")
142
+  (1.1ms) CREATE TABLE "collab_posts" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "authors_id" integer)
143
+  (1.1ms) CREATE INDEX "index_collab_posts_on_authors_id" ON "collab_posts" ("authors_id")
144
+  (1.1ms) CREATE TABLE "cards" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL)
145
+  (1.2ms) CREATE TABLE "card_locations" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "location_id" integer, "card_type" varchar, "card_id" integer)
146
+  (1.2ms) CREATE INDEX "index_card_locations_on_location_id" ON "card_locations" ("location_id")
147
+  (1.1ms) CREATE INDEX "index_card_locations_on_card" ON "card_locations" ("card_type", "card_id")
148
+  (1.2ms) CREATE TABLE "locations" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL)
149
+  (1.0ms) CREATE TABLE "community_tickets" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL)
150
+  (1.1ms) CREATE TABLE "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL)
151
+ ActiveRecord::InternalMetadata Load (0.1ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", "environment"], ["LIMIT", 1]]
152
+ TRANSACTION (0.0ms) begin transaction
153
+ ActiveRecord::InternalMetadata Create (0.4ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["key", "environment"], ["value", "test"], ["created_at", "2021-08-26 17:55:10.184260"], ["updated_at", "2021-08-26 17:55:10.184260"]]
154
+ TRANSACTION (1.0ms) commit transaction
155
+  (1.1ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY)
156
+ ActiveRecord::InternalMetadata Load (0.1ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", "environment"], ["LIMIT", 1]]
157
+  (0.1ms) SELECT sqlite_version(*)
158
+  (0.0ms) PRAGMA foreign_keys
159
+  (0.0ms) PRAGMA defer_foreign_keys
160
+  (0.0ms) PRAGMA defer_foreign_keys = ON
161
+  (0.0ms) PRAGMA foreign_keys = OFF
162
+  (1.1ms) DELETE FROM "posts";
163
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
164
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'posts';
165
+  (1.2ms) DELETE FROM "comments";
166
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
167
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'comments';
168
+  (1.1ms) DELETE FROM "authors";
169
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
170
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'authors';
171
+  (1.0ms) DELETE FROM "favorites";
172
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
173
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'favorites';
174
+  (1.1ms) DELETE FROM "collab_posts";
175
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
176
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'collab_posts';
177
+  (1.0ms) DELETE FROM "cards";
178
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
179
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'cards';
180
+  (1.0ms) DELETE FROM "card_locations";
181
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
182
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'card_locations';
183
+  (0.8ms) DELETE FROM "locations";
184
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
185
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'locations';
186
+  (1.0ms) DELETE FROM "community_tickets";
187
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
188
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'community_tickets';
189
+  (0.0ms) PRAGMA defer_foreign_keys = 0
190
+  (0.0ms) PRAGMA foreign_keys = 1
191
+ TRANSACTION (0.0ms) begin transaction
192
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
193
+ Post Create (0.4ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "I'm a little teapot"]]
194
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
195
+ Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = ? [["post_id", 1]]
196
+ TRANSACTION (0.3ms) rollback transaction
197
+ TRANSACTION (0.1ms) begin transaction
198
+ TRANSACTION (0.1ms) SAVEPOINT active_record_1
199
+ Post Create (0.5ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "I'm a little teapot"]]
200
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
201
+ TRANSACTION (0.1ms) SAVEPOINT active_record_1
202
+ Comment Create (0.2ms) INSERT INTO "comments" ("post_id") VALUES (?) [["post_id", 1]]
203
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
204
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
205
+ Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = ? [["post_id", 1]]
206
+ TRANSACTION (0.3ms) rollback transaction
207
+ TRANSACTION (0.0ms) begin transaction
208
+ Post Load (0.1ms) SELECT "posts".* FROM "posts"
209
+ TRANSACTION (0.1ms) SAVEPOINT active_record_1
210
+ Post Create (0.4ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "foo"]]
211
+ TRANSACTION (0.1ms) RELEASE SAVEPOINT active_record_1
212
+ Post Load (0.0ms) SELECT "posts".* FROM "posts"
213
+ TRANSACTION (0.4ms) rollback transaction
214
+ TRANSACTION (0.1ms) begin transaction
215
+ TRANSACTION (0.0ms) rollback transaction
216
+ TRANSACTION (0.0ms) begin transaction
217
+ TRANSACTION (0.1ms) rollback transaction
218
+ TRANSACTION (0.1ms) begin transaction
219
+ TRANSACTION (0.1ms) rollback transaction
220
+ TRANSACTION (0.1ms) begin transaction
221
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
222
+ Location Create (0.4ms) INSERT INTO "locations" DEFAULT VALUES
223
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
224
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
225
+ CommunityTicket Create (0.1ms) INSERT INTO "community_tickets" DEFAULT VALUES
226
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
227
+ TRANSACTION (0.1ms) SAVEPOINT active_record_1
228
+ CardLocation Create (0.2ms) INSERT INTO "card_locations" ("location_id", "card_type", "card_id") VALUES (?, ?, ?) [["location_id", 1], ["card_type", "CommunityTicket"], ["card_id", 1]]
229
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
230
+  (0.1ms) SELECT COUNT(*) FROM "locations" INNER JOIN "card_locations" ON "card_locations"."card_type" = ? AND "card_locations"."location_id" = "locations"."id" INNER JOIN "community_tickets" ON "community_tickets"."id" = "card_locations"."card_id" [["card_type", "CommunityTicket"]]
231
+ Location Load (0.1ms) SELECT "locations".* FROM "locations" INNER JOIN "card_locations" ON "card_locations"."card_type" = ? AND "card_locations"."location_id" = "locations"."id" INNER JOIN "community_tickets" ON "community_tickets"."id" = "card_locations"."card_id" [["card_type", "CommunityTicket"]]
232
+ TRANSACTION (0.4ms) rollback transaction
233
+ TRANSACTION (0.1ms) begin transaction
234
+ TRANSACTION (0.1ms) SAVEPOINT active_record_1
235
+ Post Create (0.5ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "Foobar"]]
236
+ TRANSACTION (0.1ms) RELEASE SAVEPOINT active_record_1
237
+ Post Load (0.1ms) SELECT "posts".* FROM "posts"
238
+ TRANSACTION (0.4ms) rollback transaction
239
+ TRANSACTION (0.1ms) begin transaction
240
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
241
+ Post Create (0.4ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "Foobar"]]
242
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
243
+ Post Load (0.0ms) SELECT "posts".* FROM "posts"
244
+ TRANSACTION (0.3ms) rollback transaction
245
+ TRANSACTION (0.0ms) begin transaction
246
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
247
+ Post Create (0.4ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "Foobar"]]
248
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
249
+ Post Load (0.0ms) SELECT "posts".* FROM "posts"
250
+ TRANSACTION (0.3ms) rollback transaction
251
+ TRANSACTION (0.1ms) begin transaction
252
+  (0.2ms) SELECT COUNT(*) FROM "posts"
253
+ TRANSACTION (0.1ms) rollback transaction
254
+ TRANSACTION (0.0ms) begin transaction
255
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" ASC LIMIT ? [["LIMIT", 1]]
256
+ TRANSACTION (0.0ms) rollback transaction
257
+ TRANSACTION (0.0ms) begin transaction
258
+ Post Load (0.2ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" DESC LIMIT ? [["LIMIT", 1]]
259
+ TRANSACTION (0.0ms) rollback transaction
260
+ TRANSACTION (0.0ms) begin transaction
261
+  (0.1ms) SELECT "posts".* FROM "posts"
262
+ TRANSACTION (0.0ms) rollback transaction
263
+  (1.5ms) SELECT sqlite_version(*)
264
+  (0.1ms) SELECT sqlite_version(*)
265
+  (1.4ms) CREATE TABLE "posts" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar)
266
+  (1.0ms) CREATE TABLE "comments" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "post_id" integer)
267
+  (1.0ms) CREATE INDEX "index_comments_on_post_id" ON "comments" ("post_id")
268
+  (0.9ms) CREATE TABLE "authors" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "comment_id" integer, "collab_posts_id" integer)
269
+  (1.0ms) CREATE INDEX "index_authors_on_comment_id" ON "authors" ("comment_id")
270
+  (1.0ms) CREATE INDEX "index_authors_on_collab_posts_id" ON "authors" ("collab_posts_id")
271
+  (0.9ms) CREATE TABLE "favorites" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "post_id" integer)
272
+  (0.9ms) CREATE INDEX "index_favorites_on_post_id" ON "favorites" ("post_id")
273
+  (1.0ms) CREATE TABLE "collab_posts" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "authors_id" integer)
274
+  (0.9ms) CREATE INDEX "index_collab_posts_on_authors_id" ON "collab_posts" ("authors_id")
275
+  (0.9ms) CREATE TABLE "cards" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL)
276
+  (0.9ms) CREATE TABLE "card_locations" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "location_id" integer, "card_type" varchar, "card_id" integer)
277
+  (0.9ms) CREATE INDEX "index_card_locations_on_location_id" ON "card_locations" ("location_id")
278
+  (0.9ms) CREATE INDEX "index_card_locations_on_card" ON "card_locations" ("card_type", "card_id")
279
+  (0.9ms) CREATE TABLE "locations" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL)
280
+  (1.0ms) CREATE TABLE "community_tickets" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL)
281
+  (1.0ms) CREATE TABLE "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL)
282
+ ActiveRecord::InternalMetadata Load (0.1ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", "environment"], ["LIMIT", 1]]
283
+ TRANSACTION (0.0ms) begin transaction
284
+ ActiveRecord::InternalMetadata Create (0.4ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["key", "environment"], ["value", "test"], ["created_at", "2021-08-26 17:57:07.842116"], ["updated_at", "2021-08-26 17:57:07.842116"]]
285
+ TRANSACTION (0.8ms) commit transaction
286
+  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY)
287
+ ActiveRecord::InternalMetadata Load (0.1ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", "environment"], ["LIMIT", 1]]
288
+  (0.1ms) SELECT sqlite_version(*)
289
+  (0.0ms) PRAGMA foreign_keys
290
+  (0.0ms) PRAGMA defer_foreign_keys
291
+  (0.0ms) PRAGMA defer_foreign_keys = ON
292
+  (0.0ms) PRAGMA foreign_keys = OFF
293
+  (0.9ms) DELETE FROM "posts";
294
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
295
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'posts';
296
+  (0.8ms) DELETE FROM "comments";
297
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
298
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'comments';
299
+  (0.8ms) DELETE FROM "authors";
300
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
301
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'authors';
302
+  (0.8ms) DELETE FROM "favorites";
303
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
304
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'favorites';
305
+  (0.6ms) DELETE FROM "collab_posts";
306
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
307
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'collab_posts';
308
+  (0.8ms) DELETE FROM "cards";
309
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
310
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'cards';
311
+  (1.0ms) DELETE FROM "card_locations";
312
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
313
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'card_locations';
314
+  (0.6ms) DELETE FROM "locations";
315
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
316
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'locations';
317
+  (1.0ms) DELETE FROM "community_tickets";
318
+  (0.1ms) SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
319
+  (0.1ms) DELETE FROM sqlite_sequence where name = 'community_tickets';
320
+  (0.0ms) PRAGMA defer_foreign_keys = 0
321
+  (0.0ms) PRAGMA foreign_keys = 1
322
+ TRANSACTION (0.0ms) begin transaction
323
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
324
+ Post Create (0.3ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "I'm a little teapot"]]
325
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
326
+ Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = ? [["post_id", 1]]
327
+ TRANSACTION (0.3ms) rollback transaction
328
+ TRANSACTION (0.1ms) begin transaction
329
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
330
+ Post Create (0.4ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "I'm a little teapot"]]
331
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
332
+ TRANSACTION (0.1ms) SAVEPOINT active_record_1
333
+ Comment Create (0.2ms) INSERT INTO "comments" ("post_id") VALUES (?) [["post_id", 1]]
334
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
335
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
336
+ Comment Load (0.0ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = ? [["post_id", 1]]
337
+ TRANSACTION (0.4ms) rollback transaction
338
+ TRANSACTION (0.0ms) begin transaction
339
+ Post Load (0.1ms) SELECT "posts".* FROM "posts"
340
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
341
+ Post Create (0.4ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "foo"]]
342
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
343
+ Post Load (0.0ms) SELECT "posts".* FROM "posts"
344
+ TRANSACTION (0.2ms) rollback transaction
345
+ TRANSACTION (0.1ms) begin transaction
346
+ TRANSACTION (0.0ms) rollback transaction
347
+ TRANSACTION (0.1ms) begin transaction
348
+ TRANSACTION (0.0ms) rollback transaction
349
+ TRANSACTION (0.0ms) begin transaction
350
+ TRANSACTION (0.1ms) rollback transaction
351
+ TRANSACTION (0.1ms) begin transaction
352
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
353
+ Location Create (0.4ms) INSERT INTO "locations" DEFAULT VALUES
354
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
355
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
356
+ CommunityTicket Create (0.1ms) INSERT INTO "community_tickets" DEFAULT VALUES
357
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
358
+ TRANSACTION (0.1ms) SAVEPOINT active_record_1
359
+ CardLocation Create (0.3ms) INSERT INTO "card_locations" ("location_id", "card_type", "card_id") VALUES (?, ?, ?) [["location_id", 1], ["card_type", "CommunityTicket"], ["card_id", 1]]
360
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
361
+  (0.1ms) SELECT COUNT(*) FROM "locations" INNER JOIN "card_locations" ON "card_locations"."card_type" = ? AND "card_locations"."location_id" = "locations"."id" INNER JOIN "community_tickets" ON "community_tickets"."id" = "card_locations"."card_id" [["card_type", "CommunityTicket"]]
362
+ Location Load (0.1ms) SELECT "locations".* FROM "locations" INNER JOIN "card_locations" ON "card_locations"."card_type" = ? AND "card_locations"."location_id" = "locations"."id" INNER JOIN "community_tickets" ON "community_tickets"."id" = "card_locations"."card_id" [["card_type", "CommunityTicket"]]
363
+ TRANSACTION (0.4ms) rollback transaction
364
+ TRANSACTION (0.1ms) begin transaction
365
+ TRANSACTION (0.1ms) SAVEPOINT active_record_1
366
+ Post Create (0.5ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "Foobar"]]
367
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
368
+ Post Load (0.0ms) SELECT "posts".* FROM "posts"
369
+ TRANSACTION (0.2ms) rollback transaction
370
+ TRANSACTION (0.0ms) begin transaction
371
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
372
+ Post Create (0.4ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "Foobar"]]
373
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
374
+ Post Load (0.0ms) SELECT "posts".* FROM "posts"
375
+ TRANSACTION (0.3ms) rollback transaction
376
+ TRANSACTION (0.0ms) begin transaction
377
+ TRANSACTION (0.0ms) SAVEPOINT active_record_1
378
+ Post Create (0.4ms) INSERT INTO "posts" ("title") VALUES (?) [["title", "Foobar"]]
379
+ TRANSACTION (0.0ms) RELEASE SAVEPOINT active_record_1
380
+ Post Load (0.0ms) SELECT "posts".* FROM "posts"
381
+ TRANSACTION (0.2ms) rollback transaction
382
+ TRANSACTION (0.1ms) begin transaction
383
+  (0.1ms) SELECT COUNT(*) FROM "posts"
384
+ TRANSACTION (0.0ms) rollback transaction
385
+ TRANSACTION (0.0ms) begin transaction
386
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" ASC LIMIT ? [["LIMIT", 1]]
387
+ TRANSACTION (0.0ms) rollback transaction
388
+ TRANSACTION (0.0ms) begin transaction
389
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" DESC LIMIT ? [["LIMIT", 1]]
390
+ TRANSACTION (0.0ms) rollback transaction
391
+ TRANSACTION (0.0ms) begin transaction
392
+  (0.1ms) SELECT "posts".* FROM "posts"
393
+ TRANSACTION (0.0ms) rollback transaction
@@ -1,94 +1,137 @@
1
- # encoding: UTF-8
2
-
3
1
  require 'spec_helper'
4
2
 
5
3
  describe ArelHelpers do
6
- describe "#join_association" do
7
- it "should work for a directly associated model" do
8
- Post.joins(ArelHelpers.join_association(Post, :comments)).to_sql.should ==
9
- 'SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"'
4
+ describe '#join_association' do
5
+ it 'should work for a directly associated model' do
6
+ expect(Post.joins(ArelHelpers.join_association(Post, :comments)).to_sql).to(
7
+ eq('SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"')
8
+ )
10
9
  end
11
10
 
12
- it "should work with an outer join" do
13
- Post.joins(ArelHelpers.join_association(Post, :comments, Arel::Nodes::OuterJoin)).to_sql.should ==
14
- 'SELECT "posts".* FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id"'
11
+ it 'should work with an outer join' do
12
+ expect(Post.joins(ArelHelpers.join_association(Post, :comments, Arel::Nodes::OuterJoin)).to_sql).to(
13
+ eq('SELECT "posts".* FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id"')
14
+ )
15
15
  end
16
16
 
17
- it "should allow adding additional join conditions" do
18
- Post.joins(ArelHelpers.join_association(Post, :comments) do |assoc_name, join_conditions|
17
+ it 'should allow adding additional join conditions' do
18
+ sql = Post.joins(ArelHelpers.join_association(Post, :comments) do |_assoc_name, join_conditions|
19
19
  join_conditions.and(Comment[:id].eq(10))
20
- end).to_sql.should ==
21
- 'SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" AND "comments"."id" = 10'
20
+ end).to_sql
21
+
22
+ expect(sql).to eq <<-SQL.squish
23
+ SELECT "posts".* FROM "posts"
24
+ INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" AND "comments"."id" = 10
25
+ SQL
22
26
  end
23
27
 
24
- it "should work for two models, one directly associated and the other indirectly" do
25
- Post
26
- .joins(ArelHelpers.join_association(Post, :comments))
27
- .joins(ArelHelpers.join_association(Comment, :author))
28
- .to_sql.should ==
29
- 'SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" INNER JOIN "authors" ON "authors"."id" = "comments"."author_id"'
28
+ it 'should work for two models, one directly associated and the other indirectly' do
29
+ sql = Post
30
+ .joins(ArelHelpers.join_association(Post, :comments))
31
+ .joins(ArelHelpers.join_association(Comment, :author))
32
+ .to_sql
33
+
34
+ expect(sql).to eq <<-SQL.squish
35
+ SELECT "posts".* FROM "posts"
36
+ INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"
37
+ INNER JOIN "authors" ON "authors"."id" = "comments"."author_id"
38
+ SQL
30
39
  end
31
40
 
32
- it "should work for a nested hash of association names" do
33
- Post
34
- .joins(ArelHelpers.join_association(Post, { comments: :author }))
35
- .to_sql.should ==
36
- 'SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" INNER JOIN "authors" ON "authors"."id" = "comments"."author_id"'
41
+ it 'should work for a nested hash of association names' do
42
+ sql = Post
43
+ .joins(ArelHelpers.join_association(Post, { comments: :author }))
44
+ .to_sql
45
+
46
+ expect(sql).to eq <<-SQL.squish
47
+ SELECT "posts".* FROM "posts"
48
+ INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"
49
+ INNER JOIN "authors" ON "authors"."id" = "comments"."author_id"
50
+ SQL
37
51
  end
38
52
 
39
- it "should work with outer joins when given a nested hash of association names" do
40
- Post
41
- .joins(ArelHelpers.join_association(Post, { comments: :author }, Arel::Nodes::OuterJoin))
42
- .to_sql.should ==
43
- 'SELECT "posts".* FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id" LEFT OUTER JOIN "authors" ON "authors"."id" = "comments"."author_id"'
53
+ it 'should work with outer joins when given a nested hash of association names' do
54
+ sql = Post.joins(ArelHelpers.join_association(Post, { comments: :author }, Arel::Nodes::OuterJoin)).to_sql
55
+
56
+ expect(sql).to eq <<-SQL.squish
57
+ SELECT "posts".* FROM "posts"
58
+ LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id"
59
+ LEFT OUTER JOIN "authors" ON "authors"."id" = "comments"."author_id"
60
+ SQL
44
61
  end
45
62
 
46
- it "should be able to handle multiple associations" do
47
- Post.joins(ArelHelpers.join_association(Post, [:comments, :favorites])).to_sql.should ==
48
- 'SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" INNER JOIN "favorites" ON "favorites"."post_id" = "posts"."id"'
63
+ it 'should be able to handle multiple associations' do
64
+ expect(Post.joins(ArelHelpers.join_association(Post, %i[comments favorites])).to_sql).to(
65
+ eq <<-SQL.squish
66
+ SELECT "posts".* FROM "posts"
67
+ INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"
68
+ INNER JOIN "favorites" ON "favorites"."post_id" = "posts"."id"
69
+ SQL
70
+ )
49
71
  end
50
72
 
51
- it "should yield once for each association" do
52
- Post.joins(ArelHelpers.join_association(Post, [:comments, :favorites]) do |assoc_name, join_conditions|
73
+ it 'should yield once for each association' do
74
+ sql = Post.joins(ArelHelpers.join_association(Post, %i[comments favorites]) do |assoc_name, join_conditions|
53
75
  case assoc_name
54
- when :favorites
55
- join_conditions.or(Favorite[:amount].eq("lots"))
56
- when :comments
57
- join_conditions.and(Comment[:text].eq("Awesome post!"))
76
+ when :favorites
77
+ join_conditions.or(Favorite[:amount].eq('lots'))
78
+ when :comments
79
+ join_conditions.and(Comment[:text].eq('Awesome post!'))
58
80
  end
59
- end).to_sql.should ==
60
- 'SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" AND "comments"."text" = \'Awesome post!\' INNER JOIN "favorites" (ON "favorites"."post_id" = "posts"."id" OR "favorites"."amount" = \'lots\')'
81
+ end).to_sql
82
+
83
+ expect(sql).to eq <<-SQL.squish
84
+ SELECT "posts".* FROM "posts"
85
+ INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" AND "comments"."text" = 'Awesome post!'
86
+ INNER JOIN "favorites" (ON "favorites"."post_id" = "posts"."id" OR "favorites"."amount" = 'lots')
87
+ SQL
61
88
  end
62
89
 
63
90
  it 'should be able to handle has_and_belongs_to_many associations' do
64
- CollabPost.joins(ArelHelpers.join_association(CollabPost, :authors)).to_sql.should ==
65
- 'SELECT "collab_posts".* FROM "collab_posts" INNER JOIN "authors_collab_posts" ON "authors_collab_posts"."collab_post_id" = "collab_posts"."id" INNER JOIN "authors" ON "authors"."id" = "authors_collab_posts"."author_id"'
91
+ sql = CollabPost.joins(ArelHelpers.join_association(CollabPost, :authors)).to_sql
92
+
93
+ expect(sql).to eq <<-SQL.squish
94
+ SELECT "collab_posts".* FROM "collab_posts"
95
+ INNER JOIN "authors_collab_posts" ON "authors_collab_posts"."collab_post_id" = "collab_posts"."id"
96
+ INNER JOIN "authors" ON "authors"."id" = "authors_collab_posts"."author_id"
97
+ SQL
66
98
  end
67
99
 
68
- it "allows adding a custom alias to the joined table" do
100
+ it 'allows adding a custom alias to the joined table' do
69
101
  Comment.aliased_as(:foo) do |foo|
70
- Post.joins(ArelHelpers.join_association(Post, :comments, Arel::Nodes::InnerJoin, aliases: [foo])).to_sql.should ==
71
- 'SELECT "posts".* FROM "posts" INNER JOIN "comments" "foo" ON "foo"."post_id" = "posts"."id"'
102
+ sql = Post.joins(
103
+ ArelHelpers.join_association(Post, :comments, Arel::Nodes::InnerJoin, aliases: [foo])
104
+ ).to_sql
105
+
106
+ expect(sql).to eq 'SELECT "posts".* FROM "posts" INNER JOIN "comments" "foo" ON "foo"."post_id" = "posts"."id"'
72
107
  end
73
108
  end
74
109
 
75
- it "allows aliasing multiple associations" do
110
+ it 'allows aliasing multiple associations' do
76
111
  Comment.aliased_as(:foo) do |foo|
77
112
  Favorite.aliased_as(:bar) do |bar|
78
- Post.joins(ArelHelpers.join_association(Post, [:comments, :favorites], Arel::Nodes::InnerJoin, aliases: [foo, bar])).to_sql.should ==
79
- 'SELECT "posts".* FROM "posts" INNER JOIN "comments" "foo" ON "foo"."post_id" = "posts"."id" INNER JOIN "favorites" "bar" ON "bar"."post_id" = "posts"."id"'
113
+ sql = Post.joins(
114
+ ArelHelpers.join_association(Post, %i[comments favorites], Arel::Nodes::InnerJoin, aliases: [foo, bar])
115
+ ).to_sql
116
+
117
+ expect(sql).to eq <<-SQL.squish
118
+ SELECT "posts".* FROM "posts"
119
+ INNER JOIN "comments" "foo" ON "foo"."post_id" = "posts"."id"
120
+ INNER JOIN "favorites" "bar" ON "bar"."post_id" = "posts"."id"
121
+ SQL
80
122
  end
81
123
  end
82
124
  end
83
125
 
84
126
  it 'handles polymorphic through associations' do
85
- relation = Location.joins(
86
- ArelHelpers.join_association(Location, :community_tickets)
87
- )
127
+ location = Location.create!
128
+ ticket = CommunityTicket.create!
129
+ CardLocation.create! card: ticket, location: location
130
+
131
+ relation = Location.joins(ArelHelpers.join_association(Location, :community_tickets))
88
132
 
89
- relation.to_sql.should == 'SELECT "locations".* FROM "locations" ' +
90
- 'INNER JOIN "card_locations" ON "card_locations"."location_id" = "locations"."id" AND "card_locations"."card_type" = \'CommunityTicket\' ' +
91
- 'INNER JOIN "community_tickets" ON "community_tickets"."id" = "card_locations"."card_id"'
133
+ expect(relation.count).to eq 1
134
+ expect(relation.to_a).to include location
92
135
  end
93
136
  end
94
137
  end
@@ -98,8 +141,9 @@ describe ArelHelpers::JoinAssociation do
98
141
  include ArelHelpers::JoinAssociation
99
142
  end
100
143
 
101
- it "should provide the join_association method and use the parent class as the model to join on" do
102
- AssocPost.joins(AssocPost.join_association(:comments)).to_sql.should ==
103
- 'SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"'
144
+ it 'should provide the join_association method and use the parent class as the model to join on' do
145
+ expect(AssocPost.joins(AssocPost.join_association(:comments)).to_sql).to eq <<-SQL.squish
146
+ SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"
147
+ SQL
104
148
  end
105
149
  end