|
| 1 | +# frozen_string_literal: true |
| 2 | + |
1 | 3 | RSpec.describe ROM::SQL::Associations::ManyToMany, helpers: true do
|
2 | 4 | include_context 'users and tasks'
|
3 | 5 |
|
|
41 | 43 | it 'prepares joined relations' do
|
42 | 44 | relation = assoc.()
|
43 | 45 |
|
44 |
| - expect(relation.schema.map(&:to_sql_name)). |
45 |
| - to eql([Sequel.qualify(:tags, :id), |
46 |
| - Sequel.qualify(:tags, :name), |
47 |
| - Sequel.qualify(:task_tags, :task_id)]) |
| 46 | + expect(relation.schema.map(&:to_sql_name)).to eql([ |
| 47 | + Sequel.qualify(:tags, :id), |
| 48 | + Sequel.qualify(:tags, :name), |
| 49 | + Sequel.qualify(:task_tags, :task_id) |
| 50 | + ]) |
48 | 51 | expect(relation.to_a).to eql([id: 1, name: 'important', task_id: 1])
|
49 | 52 | end
|
50 | 53 | end
|
|
57 | 60 | it 'prepares joined relations through other association' do
|
58 | 61 | relation = assoc.()
|
59 | 62 |
|
60 |
| - expect(relation.schema.map(&:to_sql_name)). |
61 |
| - to eql([Sequel.qualify(:tags, :id), |
62 |
| - Sequel.qualify(:tags, :name), |
63 |
| - Sequel.qualify(:tasks, :user_id)]) |
| 63 | + expect(relation.schema.map(&:to_sql_name)).to eql([ |
| 64 | + Sequel.qualify(:tags, :id), |
| 65 | + Sequel.qualify(:tags, :name), |
| 66 | + Sequel.qualify(:tasks, :user_id) |
| 67 | + ]) |
64 | 68 | expect(relation.to_a).to eql([id: 1, name: 'important', user_id: 2])
|
65 | 69 | end
|
66 | 70 | end
|
|
73 | 77 | end
|
74 | 78 |
|
75 | 79 | it 'maintains original relation' do
|
76 |
| - relation = tags. |
77 |
| - select_append(tags[:name].as(:tag)). |
78 |
| - eager_load(assoc).call(tasks.call) |
| 80 | + relation = tags |
| 81 | + .select_append(tags[:name].as(:tag)) |
| 82 | + .eager_load(assoc).call(tasks.call) |
79 | 83 |
|
80 | 84 | expect(relation.to_a).to eql([id: 1, tag: 'important', name: 'important', task_id: 1])
|
81 | 85 | end
|
|
84 | 88 | conn[:tags].insert id: 2, name: 'boring'
|
85 | 89 | conn[:task_tags].insert(tag_id: 2, task_id: 1)
|
86 | 90 |
|
87 |
| - relation = tags. |
88 |
| - order(tags[:name].qualified). |
89 |
| - eager_load(assoc).call(tasks.call) |
| 91 | + relation = tags |
| 92 | + .order(tags[:name].qualified) |
| 93 | + .eager_load(assoc).call(tasks.call) |
90 | 94 |
|
91 |
| - expect(relation.to_a). |
92 |
| - to eql([ |
93 |
| - { id: 2, name: 'boring', task_id: 1 }, |
94 |
| - { id: 1, name: 'important', task_id: 1 } |
95 |
| - ]) |
| 95 | + expect(relation.to_a).to eql([ |
| 96 | + { id: 2, name: 'boring', task_id: 1 }, |
| 97 | + { id: 1, name: 'important', task_id: 1 } |
| 98 | + ]) |
96 | 99 | end
|
97 | 100 | end
|
98 | 101 | end
|
99 | 102 |
|
100 | 103 | context 'with two associations pointing to the same target relation' do
|
101 | 104 | before do
|
102 |
| - inferrable_relations.concat %i(users_tasks) |
| 105 | + inferrable_relations.push(:users_tasks) |
103 | 106 | end
|
104 | 107 |
|
105 | 108 | before do
|
|
0 commit comments