localtower 0.5.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -17
- data/app/controllers/localtower/pages_controller.rb +27 -12
- data/app/views/layouts/localtower/application.html.erb +16 -33
- data/app/views/localtower/pages/_alert_no_models.html.erb +3 -0
- data/app/views/localtower/pages/migrations.html.erb +52 -83
- data/app/views/localtower/pages/models.html.erb +53 -70
- data/app/views/localtower/pages/new_migration.html.erb +103 -0
- data/app/views/localtower/pages/new_model.html.erb +87 -0
- data/config/routes.rb +4 -4
- data/lib/localtower/generators/migration.rb +51 -120
- data/lib/localtower/generators/model.rb +52 -28
- data/lib/localtower/generators/service_objects/insert_array.rb +23 -0
- data/lib/localtower/generators/service_objects/insert_defaults.rb +15 -43
- data/lib/localtower/generators/service_objects/insert_indexes.rb +80 -0
- data/lib/localtower/generators/service_objects/insert_nullable.rb +23 -0
- data/lib/localtower/status.rb +1 -1
- data/lib/localtower/tools.rb +13 -16
- data/lib/localtower/version.rb +1 -1
- data/public/css/app.css +0 -49
- data/public/js/app.js +215 -70
- data/public/screenshots/v1.0.0/migrations.png +0 -0
- data/public/screenshots/v1.0.0/models.png +0 -0
- data/public/screenshots/v1.0.0/new_migration.png +0 -0
- data/public/screenshots/v1.0.0/new_model.png +0 -0
- data/spec/dummy/Gemfile +0 -2
- data/spec/dummy/Gemfile.lock +1 -10
- data/spec/dummy/app/models/post.rb +3 -0
- data/spec/dummy/app/models/user.rb +1 -0
- data/spec/dummy/config/environments/development.rb +1 -0
- data/spec/dummy/config/puma.rb +1 -1
- data/spec/dummy/db/migrate/20230119221452_create_users.rb +14 -0
- data/spec/dummy/db/migrate/20230119221751_change_users_at1674166670.rb +7 -0
- data/spec/dummy/db/migrate/20230119222054_create_posts.rb +11 -0
- data/spec/dummy/db/migrate/20230119222106_change_posts_at1674166865.rb +5 -0
- data/spec/dummy/db/schema.rb +20 -8
- data/spec/dummy/log/development.log +15281 -3345
- data/spec/dummy/log/localtower.log +1897 -132
- data/spec/dummy/log/test.log +0 -0
- data/spec/dummy/test/index.html +38 -0
- data/spec/dummy/tmp/pids/server.pid +1 -0
- data/spec/factories/migration.rb +25 -41
- data/spec/factories/model.rb +39 -25
- data/spec/lib/localtower/generators/migration_spec.rb +36 -63
- data/spec/lib/localtower/generators/model_spec.rb +43 -34
- data/spec/lib/localtower/generators/service_objects/insert_array_spec.rb +47 -0
- data/spec/lib/localtower/generators/service_objects/insert_defaults_spec.rb +30 -35
- data/spec/lib/localtower/generators/service_objects/insert_indexes_spec.rb +90 -0
- data/spec/lib/localtower/generators/service_objects/insert_nullable_spec.rb +61 -0
- data/spec/lib/localtower/tools_spec.rb +1 -11
- data/spec/spec_helper.rb +8 -3
- metadata +34 -18
- data/app/views/localtower/pages/_migrations.html.erb +0 -57
- data/app/views/localtower/pages/schema.html.erb +0 -67
- data/spec/dummy/db/migrate/20221115190039_create_users.rb +0 -13
- data/spec/dummy/db/migrate/20221115193020_change_users.rb +0 -8
- data/spec/dummy/db/migrate/20221115193532_change_users_at1668540931.rb +0 -5
- data/spec/dummy/db/migrate/20221115193605_change_users_at1668540964.rb +0 -5
- data/spec/dummy/db/migrate/20221115193637_change_users_at1668540996.rb +0 -5
- data/spec/dummy/db/migrate/20221115193642_change_users_at1668541001.rb +0 -5
- data/spec/lib/localtower/generators/relation_spec.rb +0 -65
File without changes
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<script src="https://cdn.tailwindcss.com"></script>
|
7
|
+
<script>
|
8
|
+
tailwind.config = {
|
9
|
+
theme: {
|
10
|
+
extend: {
|
11
|
+
colors: {
|
12
|
+
clifford: '#da373d',
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
</script>
|
18
|
+
<style type="text/tailwindcss">
|
19
|
+
@layer utilities {
|
20
|
+
.content-auto {
|
21
|
+
content-visibility: auto;
|
22
|
+
}
|
23
|
+
|
24
|
+
.nude {
|
25
|
+
@apply text-green-500;
|
26
|
+
|
27
|
+
}
|
28
|
+
}
|
29
|
+
</style>
|
30
|
+
</head>
|
31
|
+
<body>
|
32
|
+
<div class="container mx-auto">
|
33
|
+
<h1 class="nude text-3xl font-bold underline">
|
34
|
+
Hello world!
|
35
|
+
</h1>
|
36
|
+
</div>
|
37
|
+
</body>
|
38
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
67242
|
data/spec/factories/migration.rb
CHANGED
@@ -1,28 +1,4 @@
|
|
1
1
|
FactoryBot.define do
|
2
|
-
factory :create_table, class: "Hash" do
|
3
|
-
migration_name { "Post" }
|
4
|
-
migrations do
|
5
|
-
[
|
6
|
-
{
|
7
|
-
action: "create_table",
|
8
|
-
table_name: "posts"
|
9
|
-
}
|
10
|
-
]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
factory :create_table_two, class: "Hash" do
|
15
|
-
migration_name { "User" }
|
16
|
-
migrations do
|
17
|
-
[
|
18
|
-
{
|
19
|
-
action: "create_table",
|
20
|
-
table_name: "users"
|
21
|
-
}
|
22
|
-
]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
2
|
factory :add_column, class: "Hash" do
|
27
3
|
migration_name { "Post" }
|
28
4
|
migrations do
|
@@ -32,7 +8,6 @@ FactoryBot.define do
|
|
32
8
|
table_name: "posts",
|
33
9
|
column: "title",
|
34
10
|
column_type: "string",
|
35
|
-
index: true,
|
36
11
|
nullable: true,
|
37
12
|
},
|
38
13
|
{
|
@@ -40,7 +15,6 @@ FactoryBot.define do
|
|
40
15
|
table_name: "posts",
|
41
16
|
column: "content",
|
42
17
|
column_type: "text",
|
43
|
-
index: false,
|
44
18
|
nullable: true,
|
45
19
|
},
|
46
20
|
{
|
@@ -64,20 +38,6 @@ FactoryBot.define do
|
|
64
38
|
end
|
65
39
|
end
|
66
40
|
|
67
|
-
factory :add_column_fail, class: "Hash" do
|
68
|
-
migration_name { "Post" }
|
69
|
-
migrations do
|
70
|
-
[
|
71
|
-
{
|
72
|
-
action: "add_column",
|
73
|
-
table_name: "posts",
|
74
|
-
column: "title",
|
75
|
-
# column_type: "string",
|
76
|
-
}
|
77
|
-
]
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
41
|
factory :rename_column, class: "Hash" do
|
82
42
|
migration_name { "Post" }
|
83
43
|
migrations do
|
@@ -134,10 +94,34 @@ FactoryBot.define do
|
|
134
94
|
migration_name { "Post" }
|
135
95
|
migrations do
|
136
96
|
[
|
97
|
+
{
|
98
|
+
action: "add_column",
|
99
|
+
table_name: "posts",
|
100
|
+
column: "content",
|
101
|
+
column_type: "text",
|
102
|
+
},
|
137
103
|
{
|
138
104
|
action: "add_index_to_column",
|
139
105
|
table_name: "posts",
|
140
|
-
column: "
|
106
|
+
column: "content",
|
107
|
+
},
|
108
|
+
{
|
109
|
+
action: "add_index_to_column",
|
110
|
+
table_name: "posts",
|
111
|
+
column: "content_second",
|
112
|
+
index: {
|
113
|
+
using: 'default',
|
114
|
+
unique: true,
|
115
|
+
}
|
116
|
+
},
|
117
|
+
{
|
118
|
+
action: "add_index_to_column",
|
119
|
+
table_name: "posts",
|
120
|
+
column: "content_third",
|
121
|
+
index: {
|
122
|
+
using: 'gin',
|
123
|
+
algorithm: 'concurrently',
|
124
|
+
}
|
141
125
|
}
|
142
126
|
]
|
143
127
|
end
|
data/spec/factories/model.rb
CHANGED
@@ -1,40 +1,54 @@
|
|
1
1
|
FactoryBot.define do
|
2
|
-
factory :post_one, class:
|
3
|
-
model_name {
|
2
|
+
factory :post_one, class: Hash do
|
3
|
+
model_name { 'Post' }
|
4
4
|
attributes do
|
5
5
|
[
|
6
6
|
{
|
7
|
-
attribute_name
|
8
|
-
attribute_type
|
9
|
-
index
|
7
|
+
'attribute_name' => 'title',
|
8
|
+
'attribute_type' => 'string',
|
9
|
+
'index' => {
|
10
|
+
'using' => 'default',
|
11
|
+
'unique' => true,
|
12
|
+
'algorithm' => 'default',
|
13
|
+
}
|
10
14
|
},
|
11
15
|
{
|
12
|
-
attribute_name
|
13
|
-
attribute_type
|
16
|
+
'attribute_name' => 'tags',
|
17
|
+
'attribute_type' => 'array',
|
18
|
+
'nullable' => false,
|
19
|
+
'default' => '[]',
|
20
|
+
'index' => {
|
21
|
+
'using' => 'gin',
|
22
|
+
'unique' => true,
|
23
|
+
'algorithm' => 'concurrently',
|
24
|
+
}
|
14
25
|
},
|
15
|
-
]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
factory :user_one, class: "Hash" do
|
20
|
-
model_name { "User" }
|
21
|
-
attributes do
|
22
|
-
[
|
23
26
|
{
|
24
|
-
attribute_name
|
25
|
-
attribute_type
|
26
|
-
|
27
|
+
'attribute_name' => 'content',
|
28
|
+
'attribute_type' => 'text',
|
29
|
+
'nullable' => false,
|
30
|
+
'index' => {
|
31
|
+
'using' => 'gist',
|
32
|
+
'algorithm' => 'default',
|
33
|
+
}
|
27
34
|
},
|
28
35
|
{
|
29
|
-
attribute_name
|
30
|
-
attribute_type
|
36
|
+
'attribute_name' => 'likes_count',
|
37
|
+
'attribute_type' => 'integer',
|
38
|
+
'nullable' => true,
|
39
|
+
'default' => '0',
|
40
|
+
},
|
41
|
+
{
|
42
|
+
'attribute_name' => 'score',
|
43
|
+
'attribute_type' => 'float',
|
44
|
+
},
|
45
|
+
{
|
46
|
+
'attribute_name' => 'metadata',
|
47
|
+
'attribute_type' => 'jsonb',
|
48
|
+
'nullable' => false,
|
49
|
+
'default' => '{}',
|
31
50
|
},
|
32
51
|
]
|
33
52
|
end
|
34
53
|
end
|
35
|
-
|
36
|
-
factory :relation_one, class: "Hash" do
|
37
|
-
model_one_name { "User" }
|
38
|
-
model_two_name { "Post" }
|
39
|
-
end
|
40
54
|
end
|
@@ -3,111 +3,84 @@ require 'spec_helper'
|
|
3
3
|
module Localtower
|
4
4
|
module Generators
|
5
5
|
describe Migration do
|
6
|
-
before(:all) do
|
7
|
-
clean_files
|
8
|
-
end
|
9
|
-
|
10
|
-
after(:all) do
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'create_table' do
|
14
|
-
data = attributes_for(:create_table)
|
15
|
-
data["run_migrate"] = true
|
16
|
-
|
17
|
-
generator = ::Localtower::Generators::Migration.new(data).run
|
18
|
-
|
19
|
-
expect(::Localtower::Tools.word_in_file?(last_migration, /create_table :posts/)).to eq(true)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'create_table_two' do
|
23
|
-
data = attributes_for(:create_table_two)
|
24
|
-
data["run_migrate"] = true
|
25
|
-
|
26
|
-
generator = ::Localtower::Generators::Migration.new(data).run
|
27
|
-
|
28
|
-
expect(::Localtower::Tools.word_in_file?(last_migration, /create_table :users/)).to eq(true)
|
29
|
-
end
|
30
|
-
|
31
6
|
it 'add_column' do
|
32
|
-
data = attributes_for(:add_column)
|
33
|
-
data["run_migrate"] = true
|
7
|
+
data = attributes_for(:add_column)[:migrations]
|
34
8
|
|
35
9
|
generator = ::Localtower::Generators::Migration.new(data).run
|
36
10
|
|
37
|
-
expect(
|
38
|
-
expect(
|
39
|
-
expect(
|
40
|
-
expect(
|
41
|
-
expect(::Localtower::Tools.word_in_file?(last_migration, /add_column :posts, :title, :string, index: true/)).to eq(true)
|
11
|
+
expect(word_in_file?(last_migration, /add_column :posts, :tags, :string, default: \[\], array: true/)).to eq(true)
|
12
|
+
expect(word_in_file?(last_migration, /add_column :posts, :views, :integer, default: 0, null: false/)).to eq(true)
|
13
|
+
expect(word_in_file?(last_migration, /add_column :posts, :content, :text/)).to eq(true)
|
14
|
+
expect(word_in_file?(last_migration, /add_column :posts, :title, :string/)).to eq(true)
|
42
15
|
end
|
43
16
|
|
44
|
-
it '
|
45
|
-
data = attributes_for(:
|
46
|
-
data["run_migrate"] = true
|
17
|
+
it 'remove_column' do
|
18
|
+
data = attributes_for(:remove_column)[:migrations]
|
47
19
|
|
48
20
|
generator = ::Localtower::Generators::Migration.new(data).run
|
49
21
|
|
50
|
-
expect(
|
51
|
-
expect(
|
52
|
-
expect(::Localtower::Tools.word_in_file?(last_migration, /add_column :posts, :views, :integer, default: 0, null: false, index: true/)).to eq(false)
|
53
|
-
expect(::Localtower::Tools.word_in_file?(last_migration, /add_column :posts, :content, :text/)).to eq(false)
|
54
|
-
expect(::Localtower::Tools.word_in_file?(last_migration, /add_column :posts, :title, :string, index: true/)).to eq(false)
|
22
|
+
expect(word_in_file?(last_migration, /remove_column :posts, :title/)).to eq(true)
|
23
|
+
expect(word_in_file?(last_migration, /rename_column :posts, :views, :views_by_users/)).to eq(true)
|
55
24
|
end
|
56
25
|
|
57
26
|
it 'rename_column' do
|
58
|
-
data = attributes_for(:rename_column)
|
59
|
-
data["run_migrate"] = true
|
27
|
+
data = attributes_for(:rename_column)[:migrations]
|
60
28
|
|
61
29
|
generator = ::Localtower::Generators::Migration.new(data).run
|
62
30
|
|
63
|
-
expect(
|
31
|
+
expect(word_in_file?(last_migration, /rename_column :posts, :content, :content_new/)).to eq(true)
|
64
32
|
end
|
65
33
|
|
66
|
-
it '
|
67
|
-
data = attributes_for(:
|
68
|
-
data["run_migrate"] = true
|
34
|
+
it 'change_column_type' do
|
35
|
+
data = attributes_for(:change_column_type)[:migrations]
|
69
36
|
|
70
37
|
generator = ::Localtower::Generators::Migration.new(data).run
|
71
38
|
|
72
|
-
expect(
|
73
|
-
expect(
|
39
|
+
expect(word_in_file?(last_migration, /add_index :posts, :views_by_users/)).to eq(true)
|
40
|
+
expect(word_in_file?(last_migration, /change_column :posts, :content_new, :string/)).to eq(true)
|
74
41
|
end
|
75
42
|
|
76
|
-
it '
|
77
|
-
data = attributes_for(:
|
78
|
-
data["run_migrate"] = true
|
43
|
+
it 'add_index_to_column' do
|
44
|
+
data = attributes_for(:add_index_to_column)[:migrations]
|
79
45
|
|
80
46
|
generator = ::Localtower::Generators::Migration.new(data).run
|
81
47
|
|
82
|
-
expect(
|
83
|
-
expect(
|
48
|
+
expect(word_in_file?(last_migration, /disable_ddl_transaction!/)).to eq(true)
|
49
|
+
expect(word_in_file?(last_migration, /add_index :posts, :content/)).to eq(true)
|
50
|
+
expect(word_in_file?(last_migration, /add_index :posts, :content_second, unique: true/)).to eq(true)
|
51
|
+
expect(word_in_file?(last_migration, /add_index :posts, :content_third, using: :gin, algorithm: :concurrently/)).to eq(true)
|
84
52
|
end
|
85
53
|
|
86
|
-
it '
|
87
|
-
data = attributes_for(:
|
88
|
-
|
54
|
+
it 'belongs_to' do
|
55
|
+
data = attributes_for(:belongs_to)[:migrations]
|
56
|
+
|
57
|
+
model_post = "#{Rails.root}/app/models/post.rb"
|
58
|
+
model_user = "#{Rails.root}/app/models/user.rb"
|
59
|
+
|
60
|
+
File.open(model_post, 'w') { |f| f.write("class Post < ApplicationRecord\nend")}
|
61
|
+
File.open(model_user, 'w') { |f| f.write("class User < ApplicationRecord\nend")}
|
89
62
|
|
90
63
|
generator = ::Localtower::Generators::Migration.new(data).run
|
91
64
|
|
92
|
-
expect(
|
65
|
+
expect(word_in_file?(model_post, /# belongs_to :user/)).to eq(true)
|
66
|
+
expect(word_in_file?(model_user, /# has_many :posts/)).to eq(true)
|
67
|
+
expect(word_in_file?(last_migration, /add_reference :posts, :user, foreign_key: true, index: true/)).to eq(true)
|
93
68
|
end
|
94
69
|
|
95
70
|
it 'remove_index_to_column' do
|
96
|
-
data = attributes_for(:remove_index_to_column)
|
97
|
-
data["run_migrate"] = true
|
71
|
+
data = attributes_for(:remove_index_to_column)[:migrations]
|
98
72
|
|
99
73
|
generator = ::Localtower::Generators::Migration.new(data).run
|
100
74
|
|
101
|
-
expect(
|
75
|
+
expect(word_in_file?(last_migration, /remove_index :posts, :views_by_users/)).to eq(true)
|
102
76
|
end
|
103
77
|
|
104
78
|
it 'drop_table' do
|
105
|
-
data = attributes_for(:drop_table)
|
106
|
-
data["run_migrate"] = true
|
79
|
+
data = attributes_for(:drop_table)[:migrations]
|
107
80
|
|
108
81
|
generator = ::Localtower::Generators::Migration.new(data).run
|
109
82
|
|
110
|
-
expect(
|
83
|
+
expect(word_in_file?(last_migration, /drop_table :posts/)).to eq(true)
|
111
84
|
end
|
112
85
|
end
|
113
86
|
end
|
@@ -3,40 +3,49 @@ require 'spec_helper'
|
|
3
3
|
module Localtower
|
4
4
|
module Generators
|
5
5
|
describe Model do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
6
|
+
context 'model 1' do
|
7
|
+
let(:expected_migration) do
|
8
|
+
<<-TEXT_MULTILINE.strip_heredoc
|
9
|
+
class CreatePosts < ActiveRecord::Migration[5.2]
|
10
|
+
disable_ddl_transaction!
|
11
|
+
|
12
|
+
def change
|
13
|
+
create_table :posts do |t|
|
14
|
+
t.string :title
|
15
|
+
t.string :tags, array: true, default: [], null: false
|
16
|
+
t.text :content, null: false
|
17
|
+
t.integer :likes_count, default: 0
|
18
|
+
t.float :score
|
19
|
+
t.jsonb :metadata, default: {}, null: false
|
20
|
+
|
21
|
+
t.timestamps
|
22
|
+
end
|
23
|
+
add_index :posts, :title, unique: true
|
24
|
+
add_index :posts, :tags, using: :gin, unique: true, algorithm: :concurrently
|
25
|
+
add_index :posts, :content, using: :gist
|
26
|
+
add_index :posts, :likes_count
|
27
|
+
add_index :posts, :score
|
28
|
+
add_index :posts, :metadata
|
29
|
+
end
|
30
|
+
end
|
31
|
+
TEXT_MULTILINE
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:expected_model) do
|
35
|
+
<<-TEXT_MULTILINE.strip_heredoc
|
36
|
+
class Post < ApplicationRecord
|
37
|
+
end
|
38
|
+
TEXT_MULTILINE
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:attributes) { attributes_for(:post_one).deep_stringify_keys }
|
42
|
+
|
43
|
+
it 'create a post' do
|
44
|
+
::Localtower::Generators::Model.new(attributes).run
|
45
|
+
|
46
|
+
expect(File.read("#{Rails.root}/app/models/post.rb")).to eq(expected_model)
|
47
|
+
expect(File.read(last_migration)).to eq(expected_migration)
|
48
|
+
end
|
40
49
|
end
|
41
50
|
end
|
42
51
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::Localtower::Generators::ServiceObjects::InsertArray do
|
4
|
+
let(:service) { described_class.new(attributes) }
|
5
|
+
|
6
|
+
let(:attributes) {
|
7
|
+
['tags']
|
8
|
+
}
|
9
|
+
|
10
|
+
let(:base_file_content) {
|
11
|
+
<<-MIGRATION.strip_heredoc
|
12
|
+
class CreateTests < ActiveRecord::Migration[7.0]
|
13
|
+
def change
|
14
|
+
create_table :tests do |t|
|
15
|
+
t.string :tags
|
16
|
+
|
17
|
+
t.timestamps
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
MIGRATION
|
22
|
+
}
|
23
|
+
|
24
|
+
let(:expected_file_content) {
|
25
|
+
<<-MIGRATION.strip_heredoc
|
26
|
+
class CreateTests < ActiveRecord::Migration[7.0]
|
27
|
+
def change
|
28
|
+
create_table :tests do |t|
|
29
|
+
t.string :tags, array: true
|
30
|
+
|
31
|
+
t.timestamps
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
MIGRATION
|
36
|
+
}
|
37
|
+
|
38
|
+
before do
|
39
|
+
File.open("#{Rails.root}/db/migrate/0_migration_name_.rb", 'w') { |f| f.write(base_file_content) }
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'works' do
|
43
|
+
service.call
|
44
|
+
|
45
|
+
expect(File.read(last_migration)).to eq(expected_file_content)
|
46
|
+
end
|
47
|
+
end
|
@@ -1,32 +1,28 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ::Localtower::Generators::ServiceObjects::InsertDefaults do
|
4
|
-
|
5
|
-
let(:latest_migration) do
|
6
|
-
Tempfile.new('foo').tap do |file|
|
7
|
-
file.puts base_file_content
|
8
|
-
file.rewind
|
9
|
-
end
|
10
|
-
end
|
4
|
+
let(:service) { described_class.new(attributes) }
|
11
5
|
|
12
6
|
let(:attributes) {
|
13
7
|
[
|
14
|
-
{ 'first' => "true"
|
15
|
-
{ 'third' => "nil"
|
8
|
+
{ 'first' => "true" },
|
9
|
+
{ 'third' => "nil" },
|
16
10
|
{ 'fourth' => "false" },
|
17
|
-
{ '
|
11
|
+
{ 'foo' => "{}" },
|
12
|
+
{ 'fifth' => "0" }
|
18
13
|
]
|
19
14
|
}
|
20
15
|
|
21
16
|
let(:base_file_content) {
|
22
17
|
<<-MIGRATION.strip_heredoc
|
23
|
-
class CreateTests < ActiveRecord::Migration[
|
18
|
+
class CreateTests < ActiveRecord::Migration[7.0]
|
24
19
|
def change
|
25
20
|
create_table :tests do |t|
|
26
21
|
t.string :first
|
27
22
|
t.integer :second
|
28
23
|
t.string :third
|
29
24
|
t.string :fourth
|
25
|
+
t.jsonb :foo
|
30
26
|
t.integer :fifth
|
31
27
|
|
32
28
|
t.timestamps
|
@@ -37,34 +33,33 @@ describe ::Localtower::Generators::ServiceObjects::InsertDefaults do
|
|
37
33
|
MIGRATION
|
38
34
|
}
|
39
35
|
|
40
|
-
let(:
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
" t.timestamps\n",
|
52
|
-
" end\n",
|
53
|
-
" add_index :tests, :first\n",
|
54
|
-
" end\n",
|
55
|
-
"end\n"
|
56
|
-
]
|
57
|
-
}
|
36
|
+
let(:expected_file_content) {
|
37
|
+
<<-MIGRATION.strip_heredoc
|
38
|
+
class CreateTests < ActiveRecord::Migration[7.0]
|
39
|
+
def change
|
40
|
+
create_table :tests do |t|
|
41
|
+
t.string :first, default: true
|
42
|
+
t.integer :second
|
43
|
+
t.string :third, default: nil
|
44
|
+
t.string :fourth, default: false
|
45
|
+
t.jsonb :foo, default: {}
|
46
|
+
t.integer :fifth, default: 0
|
58
47
|
|
59
|
-
|
48
|
+
t.timestamps
|
49
|
+
end
|
50
|
+
add_index :tests, :first
|
51
|
+
end
|
52
|
+
end
|
53
|
+
MIGRATION
|
54
|
+
}
|
60
55
|
|
61
56
|
before do
|
62
|
-
|
63
|
-
service.call
|
57
|
+
File.open("#{Rails.root}/db/migrate/0_migration_name_.rb", 'w') { |f| f.write(base_file_content) }
|
64
58
|
end
|
65
59
|
|
66
|
-
it '
|
67
|
-
|
68
|
-
|
60
|
+
it 'works' do
|
61
|
+
service.call
|
62
|
+
|
63
|
+
expect(File.read(last_migration)).to eq(expected_file_content)
|
69
64
|
end
|
70
65
|
end
|