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
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::Localtower::Generators::ServiceObjects::InsertIndexes do
|
4
|
+
let(:service) { described_class.new(attributes) }
|
5
|
+
|
6
|
+
let(:attributes) {
|
7
|
+
[
|
8
|
+
{ 'first' =>
|
9
|
+
{
|
10
|
+
'using' => 'gin',
|
11
|
+
'algorithm' => 'concurrently',
|
12
|
+
}
|
13
|
+
},
|
14
|
+
{ 'third' =>
|
15
|
+
{
|
16
|
+
'using' => 'gist',
|
17
|
+
'unique' => true,
|
18
|
+
}
|
19
|
+
},
|
20
|
+
{ 'fourth' =>
|
21
|
+
{
|
22
|
+
'using' => 'default',
|
23
|
+
'algorithm' => 'concurrently',
|
24
|
+
}
|
25
|
+
},
|
26
|
+
{ 'fifth' =>
|
27
|
+
{
|
28
|
+
'using' => 'default',
|
29
|
+
'unique' => true,
|
30
|
+
}
|
31
|
+
}
|
32
|
+
]
|
33
|
+
}
|
34
|
+
|
35
|
+
let(:base_file_content) {
|
36
|
+
<<-MIGRATION.strip_heredoc
|
37
|
+
class CreateTests < ActiveRecord::Migration[7.0]
|
38
|
+
def change
|
39
|
+
create_table :tests do |t|
|
40
|
+
t.string :zero
|
41
|
+
t.string :first
|
42
|
+
t.string :third
|
43
|
+
t.string :fourth
|
44
|
+
t.integer :fifth
|
45
|
+
|
46
|
+
t.timestamps
|
47
|
+
end
|
48
|
+
add_index :tests, :first
|
49
|
+
add_index :tests, :third
|
50
|
+
add_index :tests, :fourth
|
51
|
+
add_index :tests, :fifth
|
52
|
+
end
|
53
|
+
end
|
54
|
+
MIGRATION
|
55
|
+
}
|
56
|
+
|
57
|
+
let(:expected_file_content) {
|
58
|
+
<<-MIGRATION.strip_heredoc
|
59
|
+
class CreateTests < ActiveRecord::Migration[7.0]
|
60
|
+
disable_ddl_transaction!
|
61
|
+
|
62
|
+
def change
|
63
|
+
create_table :tests do |t|
|
64
|
+
t.string :zero
|
65
|
+
t.string :first
|
66
|
+
t.string :third
|
67
|
+
t.string :fourth
|
68
|
+
t.integer :fifth
|
69
|
+
|
70
|
+
t.timestamps
|
71
|
+
end
|
72
|
+
add_index :tests, :first, using: :gin, algorithm: :concurrently
|
73
|
+
add_index :tests, :third, using: :gist, unique: true
|
74
|
+
add_index :tests, :fourth, algorithm: :concurrently
|
75
|
+
add_index :tests, :fifth, unique: true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
MIGRATION
|
79
|
+
}
|
80
|
+
|
81
|
+
before do
|
82
|
+
File.open("#{Rails.root}/db/migrate/0_migration_name_.rb", 'w') { |f| f.write(base_file_content) }
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'works' do
|
86
|
+
service.call
|
87
|
+
|
88
|
+
expect(File.read(last_migration)).to eq(expected_file_content)
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::Localtower::Generators::ServiceObjects::InsertNullable do
|
4
|
+
let(:service) { described_class.new(attributes) }
|
5
|
+
|
6
|
+
let(:attributes) {
|
7
|
+
[
|
8
|
+
'first',
|
9
|
+
'third',
|
10
|
+
'fourth'
|
11
|
+
]
|
12
|
+
}
|
13
|
+
|
14
|
+
let(:base_file_content) {
|
15
|
+
<<-MIGRATION.strip_heredoc
|
16
|
+
class CreateTests < ActiveRecord::Migration[7.0]
|
17
|
+
def change
|
18
|
+
create_table :tests do |t|
|
19
|
+
t.string :first
|
20
|
+
t.integer :second
|
21
|
+
t.string :third
|
22
|
+
t.string :fourth, default: 'foo'
|
23
|
+
t.integer :fifth
|
24
|
+
|
25
|
+
t.timestamps
|
26
|
+
end
|
27
|
+
add_index :tests, :first
|
28
|
+
end
|
29
|
+
end
|
30
|
+
MIGRATION
|
31
|
+
}
|
32
|
+
|
33
|
+
let(:expected_file_content) {
|
34
|
+
<<-MIGRATION.strip_heredoc
|
35
|
+
class CreateTests < ActiveRecord::Migration[7.0]
|
36
|
+
def change
|
37
|
+
create_table :tests do |t|
|
38
|
+
t.string :first, null: false
|
39
|
+
t.integer :second
|
40
|
+
t.string :third, null: false
|
41
|
+
t.string :fourth, null: false, default: 'foo'
|
42
|
+
t.integer :fifth
|
43
|
+
|
44
|
+
t.timestamps
|
45
|
+
end
|
46
|
+
add_index :tests, :first
|
47
|
+
end
|
48
|
+
end
|
49
|
+
MIGRATION
|
50
|
+
}
|
51
|
+
|
52
|
+
before do
|
53
|
+
File.open("#{Rails.root}/db/migrate/0_migration_name_.rb", 'w') { |f| f.write(base_file_content) }
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'works' do
|
57
|
+
service.call
|
58
|
+
|
59
|
+
expect(File.read(last_migration)).to eq(expected_file_content)
|
60
|
+
end
|
61
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -16,7 +16,9 @@ end
|
|
16
16
|
f.write(content_schema)
|
17
17
|
end
|
18
18
|
|
19
|
-
Dir["#{Rails.root}/app/models/**/*.*"]
|
19
|
+
Dir["#{Rails.root}/app/models/**/*.*"]
|
20
|
+
.reject { |file_name| file_name['application_record.rb']}
|
21
|
+
.each { |model_file| File.delete(model_file) }
|
20
22
|
end
|
21
23
|
|
22
24
|
def migration_files
|
@@ -27,6 +29,10 @@ def last_migration
|
|
27
29
|
migration_files.sort.last
|
28
30
|
end
|
29
31
|
|
32
|
+
def word_in_file?(file, word_or_exp)
|
33
|
+
File.readlines(file).grep(word_or_exp).size > 0
|
34
|
+
end
|
35
|
+
|
30
36
|
#============================
|
31
37
|
ENV['RAILS_ENV'] = 'test'
|
32
38
|
|
@@ -45,13 +51,12 @@ RSpec.configure do |config|
|
|
45
51
|
config.infer_base_class_for_anonymous_controllers = true
|
46
52
|
|
47
53
|
config.order = 123
|
48
|
-
# config.order = 'random'
|
49
54
|
|
50
55
|
config.before(:suite) do
|
51
56
|
FactoryBot.find_definitions
|
52
57
|
end
|
53
58
|
|
54
|
-
config.before(:
|
59
|
+
config.before(:each) do
|
55
60
|
clean_files
|
56
61
|
end
|
57
62
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: localtower
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damian Le Nouaille Diez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -107,16 +107,20 @@ files:
|
|
107
107
|
- app/controllers/localtower/pages_controller.rb
|
108
108
|
- app/helpers/localtower/application_helper.rb
|
109
109
|
- app/views/layouts/localtower/application.html.erb
|
110
|
-
- app/views/localtower/pages/
|
110
|
+
- app/views/localtower/pages/_alert_no_models.html.erb
|
111
111
|
- app/views/localtower/pages/migrations.html.erb
|
112
112
|
- app/views/localtower/pages/models.html.erb
|
113
|
-
- app/views/localtower/pages/
|
113
|
+
- app/views/localtower/pages/new_migration.html.erb
|
114
|
+
- app/views/localtower/pages/new_model.html.erb
|
114
115
|
- config/routes.rb
|
115
116
|
- lib/localtower.rb
|
116
117
|
- lib/localtower/engine.rb
|
117
118
|
- lib/localtower/generators/migration.rb
|
118
119
|
- lib/localtower/generators/model.rb
|
120
|
+
- lib/localtower/generators/service_objects/insert_array.rb
|
119
121
|
- lib/localtower/generators/service_objects/insert_defaults.rb
|
122
|
+
- lib/localtower/generators/service_objects/insert_indexes.rb
|
123
|
+
- lib/localtower/generators/service_objects/insert_nullable.rb
|
120
124
|
- lib/localtower/status.rb
|
121
125
|
- lib/localtower/tools.rb
|
122
126
|
- lib/localtower/version.rb
|
@@ -172,6 +176,10 @@ files:
|
|
172
176
|
- public/screenshots/v0.1.6/3_relations.png
|
173
177
|
- public/screenshots/v0.1.6/4_migrations.png
|
174
178
|
- public/screenshots/v0.1.6/5_capture.png
|
179
|
+
- public/screenshots/v1.0.0/migrations.png
|
180
|
+
- public/screenshots/v1.0.0/models.png
|
181
|
+
- public/screenshots/v1.0.0/new_migration.png
|
182
|
+
- public/screenshots/v1.0.0/new_model.png
|
175
183
|
- public/vendor/font-awesome.min.css
|
176
184
|
- public/vendor/highlight-js-default.min.css
|
177
185
|
- public/vendor/highlight.min.js
|
@@ -192,6 +200,7 @@ files:
|
|
192
200
|
- spec/dummy/app/jobs/application_job.rb
|
193
201
|
- spec/dummy/app/mailers/application_mailer.rb
|
194
202
|
- spec/dummy/app/models/application_record.rb
|
203
|
+
- spec/dummy/app/models/post.rb
|
195
204
|
- spec/dummy/app/models/user.rb
|
196
205
|
- spec/dummy/app/views/layouts/application.html.erb
|
197
206
|
- spec/dummy/app/views/layouts/mailer.html.erb
|
@@ -227,15 +236,15 @@ files:
|
|
227
236
|
- spec/dummy/config/routes.rb
|
228
237
|
- spec/dummy/config/secrets.yml
|
229
238
|
- spec/dummy/config/spring.rb
|
230
|
-
- spec/dummy/db/migrate/
|
231
|
-
- spec/dummy/db/migrate/
|
232
|
-
- spec/dummy/db/migrate/
|
233
|
-
- spec/dummy/db/migrate/
|
234
|
-
- spec/dummy/db/migrate/20221115193637_change_users_at1668540996.rb
|
235
|
-
- spec/dummy/db/migrate/20221115193642_change_users_at1668541001.rb
|
239
|
+
- spec/dummy/db/migrate/20230119221452_create_users.rb
|
240
|
+
- spec/dummy/db/migrate/20230119221751_change_users_at1674166670.rb
|
241
|
+
- spec/dummy/db/migrate/20230119222054_create_posts.rb
|
242
|
+
- spec/dummy/db/migrate/20230119222106_change_posts_at1674166865.rb
|
236
243
|
- spec/dummy/db/schema.rb
|
237
244
|
- spec/dummy/log/development.log
|
238
245
|
- spec/dummy/log/localtower.log
|
246
|
+
- spec/dummy/log/test.log
|
247
|
+
- spec/dummy/test/index.html
|
239
248
|
- spec/dummy/tmp/cache/assets/sprockets/v4.0.0/-Y/-YOiiBKqc2UODHFjctm8xc7xFoZaL7zOjWQj6qQ2wyE.cache
|
240
249
|
- spec/dummy/tmp/cache/assets/sprockets/v4.0.0/-d/-dwueM4vmPt8L51S3jeSyg_AjGDcj0GUN6pDpCA1gCg.cache
|
241
250
|
- spec/dummy/tmp/cache/assets/sprockets/v4.0.0/0g/0gaJnJQdtd2ACbihXxn8OnjLWlDjnQ_WxfgOpbiLzhg.cache
|
@@ -303,13 +312,16 @@ files:
|
|
303
312
|
- spec/dummy/tmp/cache/assets/sprockets/v4.0.0/yH/yHZ-a1J23ZCf2n5mEHINMz23Iec2cLGTKauW7k4yGTE.cache
|
304
313
|
- spec/dummy/tmp/cache/assets/sprockets/v4.0.0/z7/z7KfUWYoSaGq8tQ5mbHwyfXyT3Pa4FWKJswHcIdJuds.cache
|
305
314
|
- spec/dummy/tmp/cache/assets/sprockets/v4.0.0/zu/zuExWc5WHxeOUPZUKHl9a9ZRmN50g7jMOD28macn6M0.cache
|
315
|
+
- spec/dummy/tmp/pids/server.pid
|
306
316
|
- spec/dummy/tmp/restart.txt
|
307
317
|
- spec/factories/migration.rb
|
308
318
|
- spec/factories/model.rb
|
309
319
|
- spec/lib/localtower/generators/migration_spec.rb
|
310
320
|
- spec/lib/localtower/generators/model_spec.rb
|
311
|
-
- spec/lib/localtower/generators/
|
321
|
+
- spec/lib/localtower/generators/service_objects/insert_array_spec.rb
|
312
322
|
- spec/lib/localtower/generators/service_objects/insert_defaults_spec.rb
|
323
|
+
- spec/lib/localtower/generators/service_objects/insert_indexes_spec.rb
|
324
|
+
- spec/lib/localtower/generators/service_objects/insert_nullable_spec.rb
|
313
325
|
- spec/lib/localtower/tools_spec.rb
|
314
326
|
- spec/spec_helper.rb
|
315
327
|
homepage: https://github.com/damln/localtower
|
@@ -338,6 +350,7 @@ test_files:
|
|
338
350
|
- spec/spec_helper.rb
|
339
351
|
- spec/dummy/app/mailers/application_mailer.rb
|
340
352
|
- spec/dummy/app/models/application_record.rb
|
353
|
+
- spec/dummy/app/models/post.rb
|
341
354
|
- spec/dummy/app/models/user.rb
|
342
355
|
- spec/dummy/app/jobs/application_job.rb
|
343
356
|
- spec/dummy/app/controllers/application_controller.rb
|
@@ -353,6 +366,7 @@ test_files:
|
|
353
366
|
- spec/dummy/app/helpers/application_helper.rb
|
354
367
|
- spec/dummy/app/channels/application_cable/connection.rb
|
355
368
|
- spec/dummy/app/channels/application_cable/channel.rb
|
369
|
+
- spec/dummy/test/index.html
|
356
370
|
- spec/dummy/bin/update
|
357
371
|
- spec/dummy/bin/rake
|
358
372
|
- spec/dummy/bin/setup
|
@@ -386,16 +400,16 @@ test_files:
|
|
386
400
|
- spec/dummy/README.md
|
387
401
|
- spec/dummy/Rakefile
|
388
402
|
- spec/dummy/db/schema.rb
|
389
|
-
- spec/dummy/db/migrate/
|
390
|
-
- spec/dummy/db/migrate/
|
391
|
-
- spec/dummy/db/migrate/
|
392
|
-
- spec/dummy/db/migrate/
|
393
|
-
- spec/dummy/db/migrate/20221115193642_change_users_at1668541001.rb
|
394
|
-
- spec/dummy/db/migrate/20221115190039_create_users.rb
|
403
|
+
- spec/dummy/db/migrate/20230119221751_change_users_at1674166670.rb
|
404
|
+
- spec/dummy/db/migrate/20230119221452_create_users.rb
|
405
|
+
- spec/dummy/db/migrate/20230119222054_create_posts.rb
|
406
|
+
- spec/dummy/db/migrate/20230119222106_change_posts_at1674166865.rb
|
395
407
|
- spec/dummy/Gemfile
|
396
408
|
- spec/dummy/log/localtower.log
|
409
|
+
- spec/dummy/log/test.log
|
397
410
|
- spec/dummy/log/development.log
|
398
411
|
- spec/dummy/Gemfile.lock
|
412
|
+
- spec/dummy/tmp/pids/server.pid
|
399
413
|
- spec/dummy/tmp/cache/assets/sprockets/v4.0.0/3W/3WBmqd-2V6q5N-jvbyp-tlcfn3aHYMwBppbOUm7x4qg.cache
|
400
414
|
- spec/dummy/tmp/cache/assets/sprockets/v4.0.0/pv/pv6tV3CDkIAmLXdU8EPLlNEkXAKJPufVD4VP30o4fWo.cache
|
401
415
|
- spec/dummy/tmp/cache/assets/sprockets/v4.0.0/sY/sYvTb1uPWWmnHJNXKuW_xSco-aUb-rN2f0J35zSIzuc.cache
|
@@ -469,5 +483,7 @@ test_files:
|
|
469
483
|
- spec/lib/localtower/tools_spec.rb
|
470
484
|
- spec/lib/localtower/generators/migration_spec.rb
|
471
485
|
- spec/lib/localtower/generators/service_objects/insert_defaults_spec.rb
|
486
|
+
- spec/lib/localtower/generators/service_objects/insert_array_spec.rb
|
487
|
+
- spec/lib/localtower/generators/service_objects/insert_nullable_spec.rb
|
488
|
+
- spec/lib/localtower/generators/service_objects/insert_indexes_spec.rb
|
472
489
|
- spec/lib/localtower/generators/model_spec.rb
|
473
|
-
- spec/lib/localtower/generators/relation_spec.rb
|
@@ -1,57 +0,0 @@
|
|
1
|
-
<div class="card">
|
2
|
-
<div class="header">
|
3
|
-
<div class="container-fluid">
|
4
|
-
<div class="row">
|
5
|
-
<div class="col-md-6"><h4 class="title">Pending migrations</h4></div>
|
6
|
-
<div class="col-md-6">
|
7
|
-
<div class="pull-right">
|
8
|
-
<% if migrations.any? %>
|
9
|
-
<%= form_tag actions_path, class: "form" do %>
|
10
|
-
<button name="cmd" type="submit" value="rails db:migrate" class="btn btn-warning" data-selector="submit">
|
11
|
-
Run Pending Migrations (<code>bundle exec rails db:migrate</code>)
|
12
|
-
</button>
|
13
|
-
<% end %>
|
14
|
-
<% end %>
|
15
|
-
</div>
|
16
|
-
</div>
|
17
|
-
</div>
|
18
|
-
</div>
|
19
|
-
</div>
|
20
|
-
|
21
|
-
<div class="content">
|
22
|
-
<% if migrations.any? %>
|
23
|
-
<% migrations.each do |entry| %>
|
24
|
-
<div class="container-fluid">
|
25
|
-
<div class="row">
|
26
|
-
<div class="col-md-8">
|
27
|
-
<h5 style="color: <%= entry['status'] == :todo ? 'red' : 'green' %>;">
|
28
|
-
<% if entry['status'] == :todo %>
|
29
|
-
<button type="button" class="btn btn-danger btn-xs">PENDING</button>
|
30
|
-
<% end %>
|
31
|
-
|
32
|
-
<a href="<%= file_link(entry['file_full_path']) %>"><%= entry['name'] %></a>
|
33
|
-
</h5>
|
34
|
-
</div>
|
35
|
-
</div>
|
36
|
-
|
37
|
-
<div class="row">
|
38
|
-
<div class="col-md-12">
|
39
|
-
<% if entry['status'] == :todo %>
|
40
|
-
<pre><code class="language-ruby"><%= entry['content'] %></code></pre>
|
41
|
-
<% end %>
|
42
|
-
</div>
|
43
|
-
</div>
|
44
|
-
</div>
|
45
|
-
<% end %>
|
46
|
-
|
47
|
-
<% else %>
|
48
|
-
<div class="container-fluid">
|
49
|
-
<div class="row">
|
50
|
-
<div class="col-md-8">
|
51
|
-
No pending migrations.
|
52
|
-
</div>
|
53
|
-
</div>
|
54
|
-
</div>
|
55
|
-
<% end %>
|
56
|
-
</div>
|
57
|
-
</div>
|
@@ -1,67 +0,0 @@
|
|
1
|
-
<% content_for :title do %>Schema<% end %>
|
2
|
-
|
3
|
-
<div class="row">
|
4
|
-
<div class="col-md-12">
|
5
|
-
<div class="content">
|
6
|
-
<div class="">
|
7
|
-
|
8
|
-
<div class="grid">
|
9
|
-
<div class="grid-sizer"></div>
|
10
|
-
|
11
|
-
<% ::Localtower::Tools.models_presented.each do |model| %>
|
12
|
-
|
13
|
-
<div class="grid-item text-small card">
|
14
|
-
<div class="text-center">
|
15
|
-
<h5><%= model[:name] %></h5>
|
16
|
-
</div>
|
17
|
-
|
18
|
-
<table class="table table-hover table-striped table-condensed">
|
19
|
-
<thead>
|
20
|
-
<th>Field</th>
|
21
|
-
<th>Type</th>
|
22
|
-
<th>Belongs To</th>
|
23
|
-
<th>Index?</th>
|
24
|
-
</thead>
|
25
|
-
|
26
|
-
<tbody>
|
27
|
-
<% model[:attributes_list].each do |attribute_data| %>
|
28
|
-
|
29
|
-
<tr>
|
30
|
-
<td>
|
31
|
-
<code>
|
32
|
-
<%= attribute_data["name"] %>
|
33
|
-
</code>
|
34
|
-
</td>
|
35
|
-
|
36
|
-
<td>
|
37
|
-
<%= attribute_data["type_clean"] %>
|
38
|
-
</td>
|
39
|
-
|
40
|
-
<td>
|
41
|
-
<% if attribute_data["belongs_to"] %>
|
42
|
-
<span class="label label-primary">
|
43
|
-
<%= attribute_data["belongs_to"] %>
|
44
|
-
</span>
|
45
|
-
<% end %>
|
46
|
-
</td>
|
47
|
-
|
48
|
-
<td>
|
49
|
-
<% if attribute_data["index"].any? %>
|
50
|
-
<span class="label label-success">Yes</span>
|
51
|
-
<% else %>
|
52
|
-
<span class="label label-default">No</span>
|
53
|
-
<% end %>
|
54
|
-
</td>
|
55
|
-
</tr>
|
56
|
-
<% end %>
|
57
|
-
</tbody>
|
58
|
-
</table>
|
59
|
-
</div>
|
60
|
-
<% end %>
|
61
|
-
<div class="clearfix"></div>
|
62
|
-
</div>
|
63
|
-
|
64
|
-
</div>
|
65
|
-
</div>
|
66
|
-
</div>
|
67
|
-
</div>
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Localtower
|
4
|
-
module Generators
|
5
|
-
describe Relation do
|
6
|
-
before(:all) do
|
7
|
-
clean_files
|
8
|
-
end
|
9
|
-
|
10
|
-
after(:all) do
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'belongs_to' do
|
14
|
-
data1 = attributes_for(:post_one)
|
15
|
-
data1["run_migrate"] = true
|
16
|
-
::Localtower::Generators::Model.new(data1).run
|
17
|
-
|
18
|
-
data2 = attributes_for(:user_one)
|
19
|
-
data2["run_migrate"] = true
|
20
|
-
::Localtower::Generators::Model.new(data2).run
|
21
|
-
|
22
|
-
data = attributes_for(:belongs_to)
|
23
|
-
data["run_migrate"] = true
|
24
|
-
|
25
|
-
generator = ::Localtower::Generators::Migration.new(data).run
|
26
|
-
|
27
|
-
expect(::Localtower::Tools.word_in_file?(last_migration, /add_reference :posts, :user, foreign_key: true, index: true/)).to eq(true)
|
28
|
-
expect(File.exist?("#{Rails.root}/app/models/post.rb")).to eq(true)
|
29
|
-
expect(File.exist?("#{Rails.root}/app/models/user.rb")).to eq(true)
|
30
|
-
expect(::Localtower::Tools.word_in_file?("#{Rails.root}/app/models/post.rb", /class Post/)).to eq(true)
|
31
|
-
expect(::Localtower::Tools.word_in_file?("#{Rails.root}/app/models/post.rb", /belongs_to/)).to eq(true)
|
32
|
-
expect(::Localtower::Tools.word_in_file?("#{Rails.root}/app/models/user.rb", /class User/)).to eq(true)
|
33
|
-
expect(::Localtower::Tools.word_in_file?("#{Rails.root}/app/models/user.rb", /has_many/)).to eq(true)
|
34
|
-
|
35
|
-
Dir["#{Rails.root}/app/models/**/*.*"].each { |model_file| File.delete(model_file) }
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'create a relation' do
|
39
|
-
clean_files
|
40
|
-
|
41
|
-
::Localtower::Generators::Model.new(attributes_for(:post_one)).run
|
42
|
-
::Localtower::Generators::Model.new(attributes_for(:user_one)).run
|
43
|
-
|
44
|
-
::Localtower::Generators::Relation.new(attributes_for(:relation_one)).run
|
45
|
-
|
46
|
-
expect(File.exist?("#{Rails.root}/app/models/user_post.rb")).to eq(true)
|
47
|
-
|
48
|
-
expect(::Localtower::Tools.word_in_file?("#{Rails.root}/app/models/user_post.rb", /class UserPost/)).to eq(true)
|
49
|
-
expect(::Localtower::Tools.word_in_file?("#{Rails.root}/db/schema.rb", /create_table "user_posts"/)).to eq(true)
|
50
|
-
|
51
|
-
user_id = ::Localtower::Tools.word_in_file?("#{Rails.root}/db/schema.rb", /t.integer(.*)"user_id"/) || ::Localtower::Tools.word_in_file?("#{Rails.root}/db/schema.rb", /t.bigint(.*)"user_id"/)
|
52
|
-
post_id = ::Localtower::Tools.word_in_file?("#{Rails.root}/db/schema.rb", /t.integer(.*)"post_id"/) || ::Localtower::Tools.word_in_file?("#{Rails.root}/db/schema.rb", /t.bigint(.*)"post_id"/)
|
53
|
-
|
54
|
-
expect(user_id).to eq(true)
|
55
|
-
expect(post_id).to eq(true)
|
56
|
-
|
57
|
-
expect(::Localtower::Tools.word_in_file?("#{Rails.root}/app/models/user.rb", /has_many :posts, through: :user_posts/)).to eq(true)
|
58
|
-
expect(::Localtower::Tools.word_in_file?("#{Rails.root}/app/models/user.rb", /has_many :posts/)).to eq(true)
|
59
|
-
|
60
|
-
expect(::Localtower::Tools.word_in_file?("#{Rails.root}/app/models/post.rb", /has_many :users/)).to eq(true)
|
61
|
-
expect(::Localtower::Tools.word_in_file?("#{Rails.root}/app/models/post.rb", /has_many :users, through: :user_posts/)).to eq(true)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|