activerecord_views 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be3aa1741d6dced3c4afcf32a941d3821ec0eafc
4
- data.tar.gz: f29929115236d12395bad521420b03a4f799f382
3
+ metadata.gz: b51b3b3424c22f7b7eba5af6e221abdea9adcb77
4
+ data.tar.gz: 9847c0226785c69c854488bb8a0dd607ef5c8b70
5
5
  SHA512:
6
- metadata.gz: 6c623e3dec891c353d1bb3d2b4a6466a2ea4ea520d5c4082007a3303c358982b6e832d251e9127b37ce0ba1b366cb866547eaa0ae57173fb868d0c4683582e4f
7
- data.tar.gz: 7cde80415bc90e545f7cdcc6f987525c7c53050e59a2e26b8a83838f40c0f9e9cbbeae29ad15568e4a4e886a028b3bfce359167453d56f7af0d80a89111e3d3d
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.execute 'DROP TABLE active_record_views;'
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
 
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordViews
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -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(/\ADROP TABLE active_record_views/).once.and_call_original
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_views
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Weathered