activerecord_views 0.0.4 → 0.0.5
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b51b3b3424c22f7b7eba5af6e221abdea9adcb77
|
4
|
+
data.tar.gz: 9847c0226785c69c854488bb8a0dd607ef5c8b70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f1e2b8e83b4bb47686d9dcecfb82dae020f21a6993dbf75c71d20022c8b90c37295000044d2bebc509c0c8078a3d5c40d763ddb2ee70e15099bf2c9fb764a42
|
7
|
+
data.tar.gz: 9407222259bcf7c5f2e2ee375de1a859a39f072cde39df1ffaa3b66fc56df003d9414adb3886117ebb04d62f0084c6829b6a1e257d4711f07e02973e98f300a2
|
@@ -9,7 +9,12 @@ module ActiveRecordViews
|
|
9
9
|
table_exists = @connection.table_exists?('active_record_views')
|
10
10
|
|
11
11
|
if table_exists && !@connection.column_exists?('active_record_views', 'class_name')
|
12
|
-
@connection.
|
12
|
+
@connection.transaction :requires_new => true do
|
13
|
+
@connection.select_values('SELECT name FROM active_record_views;').each do |view_name|
|
14
|
+
@connection.execute "DROP VIEW IF EXISTS #{view_name} CASCADE;"
|
15
|
+
end
|
16
|
+
@connection.execute 'DROP TABLE active_record_views;'
|
17
|
+
end
|
13
18
|
table_exists = false
|
14
19
|
end
|
15
20
|
|
@@ -30,15 +30,29 @@ describe ActiveRecordViews::ChecksumCache do
|
|
30
30
|
context 'with old table' do
|
31
31
|
before do
|
32
32
|
connection.execute 'CREATE TABLE active_record_views(name text PRIMARY KEY, checksum text NOT NULL);'
|
33
|
+
|
34
|
+
connection.execute 'CREATE VIEW test_view AS SELECT 42 AS id;'
|
35
|
+
connection.execute "INSERT INTO active_record_views VALUES ('test_view', 'dummy');"
|
36
|
+
|
37
|
+
connection.execute 'CREATE VIEW other_view AS SELECT 123 AS id;'
|
33
38
|
end
|
34
39
|
|
35
|
-
it 'recreates the table' do
|
36
|
-
expect(ActiveRecord::Base.connection).to receive(:execute).with(/\
|
40
|
+
it 'drops existing managed views recreates the table' do
|
41
|
+
expect(ActiveRecord::Base.connection).to receive(:execute).with(/\ABEGIN\z/).once.and_call_original
|
42
|
+
expect(ActiveRecord::Base.connection).to receive(:execute).with(/\ADROP VIEW IF EXISTS test_view CASCADE;\z/).once.and_call_original
|
43
|
+
expect(ActiveRecord::Base.connection).to receive(:execute).with(/\ADROP TABLE active_record_views;\z/).once.and_call_original
|
37
44
|
expect(ActiveRecord::Base.connection).to receive(:execute).with(/\ACREATE TABLE active_record_views/).once.and_call_original
|
45
|
+
expect(ActiveRecord::Base.connection).to receive(:execute).with(/\ACOMMIT\z/).once.and_call_original
|
38
46
|
|
39
47
|
expect(connection.column_exists?('active_record_views', 'class_name')).to eq false
|
48
|
+
expect(ActiveRecordViews.view_exists?(connection, 'test_view')).to eq true
|
49
|
+
expect(ActiveRecordViews.view_exists?(connection, 'other_view')).to eq true
|
50
|
+
|
40
51
|
ActiveRecordViews::ChecksumCache.new(connection)
|
52
|
+
|
41
53
|
expect(connection.column_exists?('active_record_views', 'class_name')).to eq true
|
54
|
+
expect(ActiveRecordViews.view_exists?(connection, 'test_view')).to eq false
|
55
|
+
expect(ActiveRecordViews.view_exists?(connection, 'other_view')).to eq true
|
42
56
|
end
|
43
57
|
end
|
44
58
|
end
|