activerecord_views 0.0.20 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.tool-versions +1 -0
- data/Appraisals +10 -0
- data/README.markdown +28 -14
- data/activerecord_views.gemspec +3 -1
- data/gemfiles/rails4_2.gemfile +1 -0
- data/gemfiles/rails5_0.gemfile +1 -0
- data/gemfiles/rails6_0.gemfile +7 -0
- data/gemfiles/rails6_1.gemfile +7 -0
- data/lib/active_record_views/checksum_cache.rb +9 -5
- data/lib/active_record_views/extension.rb +10 -13
- data/lib/active_record_views/railtie.rb +13 -4
- data/lib/active_record_views/registered_view.rb +7 -2
- data/lib/active_record_views/version.rb +1 -1
- data/lib/active_record_views.rb +35 -6
- data/lib/tasks/active_record_views.rake +70 -16
- data/spec/active_record_views_checksum_cache_spec.rb +10 -6
- data/spec/active_record_views_extension_spec.rb +149 -68
- data/spec/active_record_views_spec.rb +55 -0
- data/spec/internal/Rakefile +5 -0
- data/spec/internal/app/models/erb_test_model.rb +4 -0
- data/spec/internal/app/models/erb_test_model.sql.erb +1 -1
- data/spec/internal/config/database.yml +1 -0
- data/spec/internal/config/routes.rb +3 -0
- data/spec/spec_helper.rb +47 -13
- data/spec/support/silence_warnings.rb +23 -0
- data/spec/tasks_spec.rb +53 -11
- metadata +44 -12
- data/spec/internal/app/models/missing_file_test_model.rb +0 -5
data/spec/tasks_spec.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'rake tasks' do
|
4
|
-
def rake(task_name,
|
5
|
-
system(*%W[
|
4
|
+
def rake(task_name, env: {})
|
5
|
+
system(env, *%W[
|
6
6
|
rake
|
7
7
|
-f spec/internal/Rakefile
|
8
8
|
#{task_name}
|
9
|
-
RAILS_ENV=#{production ? 'production' : 'development'}
|
10
9
|
])
|
11
10
|
raise unless $?.success?
|
12
11
|
end
|
@@ -28,10 +27,16 @@ describe 'rake tasks' do
|
|
28
27
|
|
29
28
|
it 'creates database views in production mode' do
|
30
29
|
expect(view_names).to be_empty
|
31
|
-
rake 'db:migrate',
|
30
|
+
rake 'db:migrate', env: {'RAILS_ENV' => 'production'}
|
32
31
|
expect(view_names).to_not be_empty
|
33
32
|
end
|
34
33
|
|
34
|
+
it 'does nothing in production mode without models' do
|
35
|
+
expect(view_names).to be_empty
|
36
|
+
rake 'db:migrate', env: {'RAILS_ENV' => 'production', 'SKIP_MODEL_EAGER_LOAD' => 'true'}
|
37
|
+
expect(view_names).to be_empty
|
38
|
+
end
|
39
|
+
|
35
40
|
context 'with unregistered view' do
|
36
41
|
before do
|
37
42
|
ActiveRecordViews.create_view ActiveRecord::Base.connection, 'old_view', 'OldView', 'SELECT 42 AS id'
|
@@ -45,24 +50,61 @@ describe 'rake tasks' do
|
|
45
50
|
|
46
51
|
it 'drops unregistered views in production mode' do
|
47
52
|
expect(view_names).to include 'old_view'
|
48
|
-
rake 'db:migrate',
|
53
|
+
rake 'db:migrate', env: {'RAILS_ENV' => 'production'}
|
49
54
|
expect(view_names).to_not include 'old_view'
|
50
55
|
end
|
51
56
|
end
|
52
57
|
end
|
53
58
|
|
54
|
-
|
55
|
-
|
59
|
+
schema_rake_task = Gem::Version.new(Rails.version) >= Gem::Version.new("6.1") ? 'db:schema:dump' : 'db:structure:dump'
|
60
|
+
describe schema_rake_task do
|
61
|
+
before do
|
62
|
+
FileUtils.rm_f 'spec/internal/db/schema.rb'
|
63
|
+
FileUtils.rm_f 'spec/internal/db/structure.sql'
|
64
|
+
|
56
65
|
ActiveRecordViews.create_view ActiveRecord::Base.connection, 'test_view', 'TestView', 'SELECT 1'
|
66
|
+
end
|
57
67
|
|
68
|
+
after do
|
69
|
+
FileUtils.rm_f 'spec/internal/db/schema.rb'
|
58
70
|
FileUtils.rm_f 'spec/internal/db/structure.sql'
|
59
|
-
rake 'db:structure:dump'
|
60
71
|
|
72
|
+
File.write 'spec/internal/db/schema.rb', ''
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'copies over activerecord_views data' do
|
76
|
+
rake schema_rake_task
|
77
|
+
|
78
|
+
expect(File.exist?('spec/internal/db/schema.rb')).to eq false
|
61
79
|
sql = File.read('spec/internal/db/structure.sql')
|
62
|
-
|
80
|
+
expect(sql).to match(/CREATE TABLE public\.schema_migrations/)
|
81
|
+
expect(sql).to match(/CREATE VIEW public\.test_view/)
|
82
|
+
expect(sql).to match(/COPY public\.active_record_views.+test_view\tTestView\t.*\t.*\t\\N$/m)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'clears refreshed_at values' do
|
86
|
+
ActiveRecord::Base.connection.execute "UPDATE active_record_views SET refreshed_at = current_timestamp AT TIME ZONE 'UTC' WHERE name = 'test_view';"
|
87
|
+
|
88
|
+
rake schema_rake_task
|
89
|
+
|
90
|
+
ActiveRecord::Base.clear_all_connections!
|
91
|
+
|
92
|
+
system 'dropdb activerecord_views_test'
|
93
|
+
raise unless $?.success?
|
94
|
+
system 'createdb activerecord_views_test'
|
95
|
+
raise unless $?.success?
|
96
|
+
system 'psql -X -q -o /dev/null -f spec/internal/db/structure.sql activerecord_views_test'
|
97
|
+
raise unless $?.success?
|
98
|
+
|
99
|
+
refreshed_ats = ActiveRecord::Base.connection.select_values("SELECT refreshed_at FROM active_record_views WHERE name = 'test_view'")
|
100
|
+
expect(refreshed_ats).to eq [nil]
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'does not write structure.sql when `schema_format = :ruby`', if: schema_rake_task != 'db:structure:dump' do
|
104
|
+
rake schema_rake_task, env: {'SCHEMA_FORMAT' => 'ruby'}
|
63
105
|
|
64
|
-
expect(
|
65
|
-
expect(sql).to
|
106
|
+
expect(File.exist?('spec/internal/db/schema.rb')).to eq true
|
107
|
+
expect(File.exist?('spec/internal/db/structure.sql')).to eq false
|
66
108
|
end
|
67
109
|
end
|
68
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord_views
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Weathered
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '4.2'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '6.2'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '4.2'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '6.2'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: appraisal
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '2.14'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: super_diff
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: combustion
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,7 +100,21 @@ dependencies:
|
|
86
100
|
- - ">="
|
87
101
|
- !ruby/object:Gem::Version
|
88
102
|
version: '0'
|
89
|
-
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: warning
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
description:
|
90
118
|
email:
|
91
119
|
- jason@jasoncodes.com
|
92
120
|
executables: []
|
@@ -95,6 +123,7 @@ extra_rdoc_files: []
|
|
95
123
|
files:
|
96
124
|
- ".gitignore"
|
97
125
|
- ".rspec"
|
126
|
+
- ".tool-versions"
|
98
127
|
- Appraisals
|
99
128
|
- Gemfile
|
100
129
|
- LICENSE.txt
|
@@ -105,6 +134,8 @@ files:
|
|
105
134
|
- gemfiles/rails5_0.gemfile
|
106
135
|
- gemfiles/rails5_1.gemfile
|
107
136
|
- gemfiles/rails5_2.gemfile
|
137
|
+
- gemfiles/rails6_0.gemfile
|
138
|
+
- gemfiles/rails6_1.gemfile
|
108
139
|
- lib/active_record_views.rb
|
109
140
|
- lib/active_record_views/checksum_cache.rb
|
110
141
|
- lib/active_record_views/database_cleaner/truncation_extension.rb
|
@@ -126,19 +157,20 @@ files:
|
|
126
157
|
- spec/internal/app/models/external_file_test_model.rb
|
127
158
|
- spec/internal/app/models/external_file_test_model.sql
|
128
159
|
- spec/internal/app/models/heredoc_test_model.rb
|
129
|
-
- spec/internal/app/models/missing_file_test_model.rb
|
130
160
|
- spec/internal/app/models/modified_a.rb
|
131
161
|
- spec/internal/app/models/modified_b.rb
|
132
162
|
- spec/internal/app/models/namespace/test_model.rb
|
133
163
|
- spec/internal/app/models/namespace/test_model.sql
|
134
164
|
- spec/internal/config/database.yml
|
165
|
+
- spec/internal/config/routes.rb
|
135
166
|
- spec/spec_helper.rb
|
167
|
+
- spec/support/silence_warnings.rb
|
136
168
|
- spec/tasks_spec.rb
|
137
169
|
homepage: http://github.com/jasoncodes/activerecord_views
|
138
170
|
licenses:
|
139
171
|
- MIT
|
140
172
|
metadata: {}
|
141
|
-
post_install_message:
|
173
|
+
post_install_message:
|
142
174
|
rdoc_options: []
|
143
175
|
require_paths:
|
144
176
|
- lib
|
@@ -153,9 +185,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
185
|
- !ruby/object:Gem::Version
|
154
186
|
version: '0'
|
155
187
|
requirements: []
|
156
|
-
|
157
|
-
|
158
|
-
signing_key:
|
188
|
+
rubygems_version: 3.1.6
|
189
|
+
signing_key:
|
159
190
|
specification_version: 4
|
160
191
|
summary: Automatic database view creation for ActiveRecord
|
161
192
|
test_files:
|
@@ -171,11 +202,12 @@ test_files:
|
|
171
202
|
- spec/internal/app/models/external_file_test_model.rb
|
172
203
|
- spec/internal/app/models/external_file_test_model.sql
|
173
204
|
- spec/internal/app/models/heredoc_test_model.rb
|
174
|
-
- spec/internal/app/models/missing_file_test_model.rb
|
175
205
|
- spec/internal/app/models/modified_a.rb
|
176
206
|
- spec/internal/app/models/modified_b.rb
|
177
207
|
- spec/internal/app/models/namespace/test_model.rb
|
178
208
|
- spec/internal/app/models/namespace/test_model.sql
|
179
209
|
- spec/internal/config/database.yml
|
210
|
+
- spec/internal/config/routes.rb
|
180
211
|
- spec/spec_helper.rb
|
212
|
+
- spec/support/silence_warnings.rb
|
181
213
|
- spec/tasks_spec.rb
|