@@ -10,6 +10,11 @@ class Model < ActiveRecord::Base
1010 self . table_name = 'sample'
1111 has_many :joins , class_name : 'ModelJoin' , primary_key : 'event_name'
1212 end
13+ class ModelPk < ActiveRecord ::Base
14+ self . table_name = 'sample'
15+ self . primary_key = 'event_name'
16+ end
17+ IS_NEW_CLICKHOUSE_SERVER = Model . connection . server_version . to_f >= 23.4
1318
1419 let ( :date ) { Date . today }
1520
@@ -20,8 +25,10 @@ class Model < ActiveRecord::Base
2025 quietly { ActiveRecord ::MigrationContext . new ( migrations_dir ) . up }
2126 end
2227
23- it 'detect primary key' do
24- expect ( Model . primary_key ) . to eq ( 'event_name' )
28+ if IS_NEW_CLICKHOUSE_SERVER
29+ it "detect primary key" do
30+ expect ( Model . primary_key ) . to eq ( 'event_name' )
31+ end
2532 end
2633
2734 describe '#do_execute' do
@@ -80,7 +87,11 @@ class Model < ActiveRecord::Base
8087
8188 it 'update model with primary key' do
8289 expect {
83- Model . first . update! ( event_value : 2 )
90+ if IS_NEW_CLICKHOUSE_SERVER
91+ Model . first . update! ( event_value : 2 )
92+ else
93+ ModelPk . first . update! ( event_value : 2 )
94+ end
8495 } . to_not raise_error
8596 end
8697 end
@@ -96,7 +107,11 @@ class Model < ActiveRecord::Base
96107
97108 it 'destroy model with primary key' do
98109 expect {
99- Model . first . destroy!
110+ if IS_NEW_CLICKHOUSE_SERVER
111+ Model . first . destroy!
112+ else
113+ ModelPk . first . destroy!
114+ end
100115 } . to_not raise_error
101116 end
102117 end
@@ -117,8 +132,13 @@ class Model < ActiveRecord::Base
117132 it 'select' do
118133 Model . create! ( event_name : 'some event 1' , date : 1 . day . ago )
119134 Model . create! ( event_name : 'some event 2' , date : 2 . day . ago )
120- expect ( Model . all . reverse_order! . to_sql ) . to eq ( 'SELECT sample.* FROM sample ORDER BY sample.event_name DESC' )
121- expect ( Model . all . reverse_order! . map ( &:event_name ) ) . to eq ( [ 'some event 2' , 'some event 1' ] )
135+ if IS_NEW_CLICKHOUSE_SERVER
136+ expect ( Model . all . reverse_order! . to_sql ) . to eq ( 'SELECT sample.* FROM sample ORDER BY sample.event_name DESC' )
137+ expect ( Model . all . reverse_order! . map ( &:event_name ) ) . to eq ( [ 'some event 2' , 'some event 1' ] )
138+ else
139+ expect ( Model . all . reverse_order! . to_sql ) . to eq ( 'SELECT sample.* FROM sample ORDER BY sample.date DESC' )
140+ expect ( Model . all . reverse_order! . map ( &:event_name ) ) . to eq ( [ 'some event 1' , 'some event 2' ] )
141+ end
122142 end
123143 end
124144
0 commit comments