activerecord_views 0.1.5 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_record_views/database_tasks.rb +91 -0
- data/lib/active_record_views/railtie.rb +0 -4
- data/lib/active_record_views/version.rb +1 -1
- data/lib/active_record_views.rb +2 -0
- metadata +11 -65
- data/.gitignore +0 -8
- data/.rspec +0 -2
- data/.tool-versions +0 -1
- data/Appraisals +0 -15
- data/Gemfile +0 -3
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -14
- data/activerecord_views.gemspec +0 -27
- data/gemfiles/rails5_2.gemfile +0 -7
- data/gemfiles/rails6_0.gemfile +0 -7
- data/gemfiles/rails6_1.gemfile +0 -7
- data/gemfiles/rails7_0.gemfile +0 -7
- data/lib/tasks/active_record_views.rake +0 -106
- data/spec/active_record_views_checksum_cache_spec.rb +0 -112
- data/spec/active_record_views_extension_spec.rb +0 -459
- data/spec/active_record_views_spec.rb +0 -344
- data/spec/internal/Rakefile +0 -24
- data/spec/internal/app/models/dependency_a.rb +0 -3
- data/spec/internal/app/models/dependency_b.rb +0 -3
- data/spec/internal/app/models/dependency_c.rb +0 -3
- data/spec/internal/app/models/erb_test_model.rb +0 -7
- data/spec/internal/app/models/erb_test_model.sql.erb +0 -1
- data/spec/internal/app/models/external_file_test_model.rb +0 -3
- data/spec/internal/app/models/external_file_test_model.sql +0 -1
- data/spec/internal/app/models/heredoc_test_model.rb +0 -5
- data/spec/internal/app/models/modified_a.rb +0 -3
- data/spec/internal/app/models/modified_b.rb +0 -3
- data/spec/internal/app/models/namespace/test_model.rb +0 -3
- data/spec/internal/app/models/namespace/test_model.sql +0 -1
- data/spec/internal/config/database.yml +0 -9
- data/spec/internal/config/routes.rb +0 -3
- data/spec/spec_helper.rb +0 -130
- data/spec/support/silence_warnings.rb +0 -6
- data/spec/tasks_spec.rb +0 -113
data/spec/tasks_spec.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'rake tasks' do
|
4
|
-
def rake(task_name, env: {})
|
5
|
-
system(env, *%W[
|
6
|
-
rake
|
7
|
-
-f spec/internal/Rakefile
|
8
|
-
#{task_name}
|
9
|
-
])
|
10
|
-
raise unless $?.success?
|
11
|
-
end
|
12
|
-
|
13
|
-
describe 'db:migrate' do
|
14
|
-
def view_names
|
15
|
-
ActiveRecord::Base.connection.select_values(<<~SQL.squish)
|
16
|
-
SELECT table_name
|
17
|
-
FROM information_schema.views
|
18
|
-
WHERE table_schema = 'public'
|
19
|
-
SQL
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'does not create any database views' do
|
23
|
-
expect(view_names).to be_empty
|
24
|
-
rake 'db:migrate'
|
25
|
-
expect(view_names).to be_empty
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'creates database views in production mode' do
|
29
|
-
expect(view_names).to be_empty
|
30
|
-
rake 'db:migrate', env: {'RAILS_ENV' => 'production'}
|
31
|
-
expect(view_names).to_not be_empty
|
32
|
-
end
|
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
|
-
|
40
|
-
context 'with unregistered view' do
|
41
|
-
before do
|
42
|
-
ActiveRecordViews.create_view ActiveRecord::Base.connection, 'old_view', 'OldView', 'SELECT 42 AS id'
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'does not drop unregistered views' do
|
46
|
-
expect(view_names).to include 'old_view'
|
47
|
-
rake 'db:migrate'
|
48
|
-
expect(view_names).to include 'old_view'
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'drops unregistered views in production mode' do
|
52
|
-
expect(view_names).to include 'old_view'
|
53
|
-
rake 'db:migrate', env: {'RAILS_ENV' => 'production'}
|
54
|
-
expect(view_names).to_not include 'old_view'
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
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
|
-
|
65
|
-
ActiveRecordViews.create_view ActiveRecord::Base.connection, 'test_view_1', 'TestView1', 'SELECT 1'
|
66
|
-
ActiveRecordViews.create_view ActiveRecord::Base.connection, 'test_view_3', 'TestView3', 'SELECT 3'
|
67
|
-
ActiveRecordViews.create_view ActiveRecord::Base.connection, 'test_view_2', 'TestView2', 'SELECT 2'
|
68
|
-
end
|
69
|
-
|
70
|
-
after do
|
71
|
-
FileUtils.rm_f 'spec/internal/db/schema.rb'
|
72
|
-
FileUtils.rm_f 'spec/internal/db/structure.sql'
|
73
|
-
|
74
|
-
File.write 'spec/internal/db/schema.rb', ''
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'copies over activerecord_views data' do
|
78
|
-
rake schema_rake_task
|
79
|
-
|
80
|
-
expect(File.exist?('spec/internal/db/schema.rb')).to eq false
|
81
|
-
sql = File.read('spec/internal/db/structure.sql')
|
82
|
-
expect(sql).to match(/CREATE TABLE public\.schema_migrations/)
|
83
|
-
expect(sql).to match(/CREATE VIEW public\.test_view/)
|
84
|
-
expect(sql).to match(/COPY public\.active_record_views.+test_view_1\tTestView1\t.*\t.*\t\\N$/m)
|
85
|
-
expect(sql).to match(/^test_view_1.+^test_view_2.+^test_view_3/m)
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'clears refreshed_at values' do
|
89
|
-
ActiveRecord::Base.connection.execute "UPDATE active_record_views SET refreshed_at = current_timestamp AT TIME ZONE 'UTC' WHERE name = 'test_view_1';"
|
90
|
-
|
91
|
-
rake schema_rake_task
|
92
|
-
|
93
|
-
ActiveRecord::Base.clear_all_connections!
|
94
|
-
|
95
|
-
system 'dropdb activerecord_views_test'
|
96
|
-
raise unless $?.success?
|
97
|
-
system 'createdb activerecord_views_test'
|
98
|
-
raise unless $?.success?
|
99
|
-
system 'psql -X -q -o /dev/null -f spec/internal/db/structure.sql activerecord_views_test'
|
100
|
-
raise unless $?.success?
|
101
|
-
|
102
|
-
refreshed_ats = ActiveRecord::Base.connection.select_values("SELECT refreshed_at FROM active_record_views WHERE name = 'test_view_1'")
|
103
|
-
expect(refreshed_ats).to eq [nil]
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'does not write structure.sql when `schema_format = :ruby`', if: schema_rake_task != 'db:structure:dump' do
|
107
|
-
rake schema_rake_task, env: {'SCHEMA_FORMAT' => 'ruby'}
|
108
|
-
|
109
|
-
expect(File.exist?('spec/internal/db/schema.rb')).to eq true
|
110
|
-
expect(File.exist?('spec/internal/db/structure.sql')).to eq false
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|