upgrow 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 +4 -4
- data/lib/generators/test_unit/input/input_generator.rb +22 -0
- data/lib/generators/test_unit/input/templates/input_test.rb.tt +8 -0
- data/lib/generators/test_unit/install/install_generator.rb +48 -0
- data/lib/generators/test_unit/record/record_generator.rb +22 -0
- data/lib/generators/test_unit/record/templates/record_test.rb.tt +8 -0
- data/lib/generators/test_unit/repository/repository_generator.rb +23 -0
- data/lib/generators/test_unit/repository/templates/repository_test.rb.tt +8 -0
- data/lib/generators/upgrow.rb +54 -0
- data/lib/generators/upgrow/action/USAGE +13 -0
- data/lib/generators/upgrow/action/action_generator.rb +24 -0
- data/lib/generators/upgrow/action/templates/action.rb.tt +9 -0
- data/lib/generators/upgrow/input/USAGE +10 -0
- data/lib/generators/upgrow/input/input_generator.rb +26 -0
- data/lib/generators/upgrow/input/templates/input.rb.tt +6 -0
- data/lib/generators/upgrow/install/USAGE +25 -0
- data/lib/generators/upgrow/install/install_generator.rb +56 -0
- data/lib/generators/upgrow/install/templates/app/actions/application_action.rb.tt +4 -0
- data/lib/generators/upgrow/install/templates/app/inputs/application_input.rb.tt +4 -0
- data/lib/generators/upgrow/install/templates/app/models/application_model.rb.tt +4 -0
- data/lib/generators/upgrow/install/templates/app/repositories/application_repository.rb.tt +4 -0
- data/lib/generators/upgrow/model/USAGE +10 -0
- data/lib/generators/upgrow/model/model_generator.rb +24 -0
- data/lib/generators/upgrow/model/templates/model.rb.tt +6 -0
- data/lib/generators/upgrow/record/record_generator.rb +34 -0
- data/lib/generators/upgrow/record/templates/record.rb.tt +6 -0
- data/lib/generators/upgrow/repository/USAGE +10 -0
- data/lib/generators/upgrow/repository/repository_generator.rb +27 -0
- data/lib/generators/upgrow/repository/templates/repository.rb.tt +6 -0
- data/lib/upgrow.rb +3 -0
- data/lib/upgrow/active_record_conversion.rb +2 -3
- data/lib/upgrow/active_record_queries.rb +1 -2
- data/lib/upgrow/active_record_schema.rb +1 -3
- data/lib/upgrow/basic_model.rb +11 -0
- data/lib/upgrow/model.rb +2 -1
- data/lib/upgrow/naming.rb +40 -0
- data/lib/upgrow/railtie.rb +9 -0
- data/lib/upgrow/record.rb +121 -0
- data/test/dummy/app/records/application_record.rb +2 -0
- data/test/dummy/app/records/article_record.rb +2 -3
- data/test/dummy/app/records/comment_record.rb +2 -3
- data/test/dummy/app/records/user_record.rb +2 -4
- data/test/dummy/app/repositories/article_repository.rb +3 -3
- data/test/test_unit/generators/input_generator_test.rb +56 -0
- data/test/test_unit/generators/install_generator_test.rb +138 -0
- data/test/test_unit/generators/record_generator_test.rb +56 -0
- data/test/test_unit/generators/repository_generator_test.rb +57 -0
- data/test/upgrow/active_record_conversion_test.rb +2 -2
- data/test/upgrow/active_record_schema_test.rb +1 -1
- data/test/upgrow/basic_model_test.rb +85 -0
- data/test/upgrow/generators/action_generator_test.rb +59 -0
- data/test/upgrow/generators/helper_test.rb +86 -0
- data/test/upgrow/generators/input_generator_test.rb +65 -0
- data/test/upgrow/generators/install_generator_test.rb +158 -0
- data/test/upgrow/generators/model_generator_test.rb +39 -0
- data/test/upgrow/generators/record_generator_test.rb +65 -0
- data/test/upgrow/generators/repository_generator_test.rb +50 -0
- data/test/upgrow/naming_test.rb +22 -0
- data/test/upgrow/record_test.rb +176 -0
- metadata +60 -3
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'rails/generators/test_case'
|
5
|
+
require 'generators/upgrow'
|
6
|
+
|
7
|
+
module Upgrow
|
8
|
+
module Generators
|
9
|
+
class GeneratorHelperTest < Rails::Generators::TestCase
|
10
|
+
class SampleGenerator < Rails::Generators::Base
|
11
|
+
include Helper
|
12
|
+
|
13
|
+
attr_accessor :file_name, :class_path, :output_buffer
|
14
|
+
|
15
|
+
def do_all_the_things
|
16
|
+
move_file(
|
17
|
+
'app/models/article.rb', 'app/models/articles/my_article.rb'
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
tests SampleGenerator
|
23
|
+
destination File.expand_path('../../../tmp', __dir__)
|
24
|
+
setup :prepare_destination
|
25
|
+
|
26
|
+
test '#move_file moves the original path to destination' do
|
27
|
+
create_file 'app/models/article.rb', <<~RUBY
|
28
|
+
class Article < ApplicationModel
|
29
|
+
end
|
30
|
+
RUBY
|
31
|
+
|
32
|
+
run_generator
|
33
|
+
|
34
|
+
assert_file 'app/models/articles/my_article.rb', <<~RUBY
|
35
|
+
class Article < ApplicationModel
|
36
|
+
end
|
37
|
+
RUBY
|
38
|
+
|
39
|
+
assert_no_file 'app/models/article.rb'
|
40
|
+
end
|
41
|
+
|
42
|
+
test '.base_root is the generators directory' do
|
43
|
+
expected = File.expand_path('lib/generators')
|
44
|
+
assert_equal expected, SampleGenerator.base_root
|
45
|
+
end
|
46
|
+
|
47
|
+
test '#class_name is the camelized file name' do
|
48
|
+
generator.file_name = 'my_file_name'
|
49
|
+
assert_equal 'MyFileName', generator.class_name
|
50
|
+
end
|
51
|
+
|
52
|
+
test '#module_namespacing outputs the given block when class path is empty' do
|
53
|
+
generator.output_buffer = String.new
|
54
|
+
generator.class_path = []
|
55
|
+
|
56
|
+
generator.module_namespacing { generator.send(:concat, 'hello') }
|
57
|
+
assert_equal('hello', generator.output_buffer)
|
58
|
+
end
|
59
|
+
|
60
|
+
test '#module_namespacing namespaces the given block with the class path' do
|
61
|
+
generator.output_buffer = String.new
|
62
|
+
generator.class_path = ['posts', 'tags']
|
63
|
+
|
64
|
+
generator.module_namespacing { generator.send(:concat, 'hello') }
|
65
|
+
|
66
|
+
expected = <<~RUBY
|
67
|
+
module Posts
|
68
|
+
module Tags
|
69
|
+
hello
|
70
|
+
end
|
71
|
+
end
|
72
|
+
RUBY
|
73
|
+
|
74
|
+
assert_equal(expected, generator.output_buffer)
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def create_file(name, content)
|
80
|
+
mkdir_p(File.expand_path(File.dirname(name), destination_root))
|
81
|
+
path = File.expand_path(name, destination_root)
|
82
|
+
File.write(path, content)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'rails/generators/test_case'
|
5
|
+
require 'generators/upgrow/input/input_generator'
|
6
|
+
|
7
|
+
module Upgrow
|
8
|
+
module Generators
|
9
|
+
class InputGeneratorTest < Rails::Generators::TestCase
|
10
|
+
tests InputGenerator
|
11
|
+
destination File.expand_path('tmp')
|
12
|
+
setup :prepare_destination
|
13
|
+
|
14
|
+
test 'generate Input file' do
|
15
|
+
run_generator(['article'])
|
16
|
+
|
17
|
+
assert_file 'app/inputs/article_input.rb', <<~RUBY
|
18
|
+
# frozen_string_literal: true
|
19
|
+
|
20
|
+
class ArticleInput < ApplicationInput
|
21
|
+
end
|
22
|
+
RUBY
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'generate Input when suffix is specified' do
|
26
|
+
run_generator(['ArticleInput'])
|
27
|
+
|
28
|
+
assert_file 'app/inputs/article_input.rb', <<~RUBY
|
29
|
+
# frozen_string_literal: true
|
30
|
+
|
31
|
+
class ArticleInput < ApplicationInput
|
32
|
+
end
|
33
|
+
RUBY
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'generate namespaced Input file' do
|
37
|
+
run_generator(['articles/article'])
|
38
|
+
|
39
|
+
assert_file 'app/inputs/articles/article_input.rb', <<~RUBY
|
40
|
+
# frozen_string_literal: true
|
41
|
+
|
42
|
+
module Articles
|
43
|
+
class ArticleInput < ApplicationInput
|
44
|
+
end
|
45
|
+
end
|
46
|
+
RUBY
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'generate namespaced Input file with many layers' do
|
50
|
+
run_generator(['users/articles/article'])
|
51
|
+
|
52
|
+
assert_file 'app/inputs/users/articles/article_input.rb', <<~RUBY
|
53
|
+
# frozen_string_literal: true
|
54
|
+
|
55
|
+
module Users
|
56
|
+
module Articles
|
57
|
+
class ArticleInput < ApplicationInput
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
RUBY
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'rails/generators/test_case'
|
5
|
+
require 'generators/upgrow/install/install_generator'
|
6
|
+
|
7
|
+
module Upgrow
|
8
|
+
module Generators
|
9
|
+
class InstallGeneratorTest < Rails::Generators::TestCase
|
10
|
+
tests InstallGenerator
|
11
|
+
destination File.expand_path('tmp')
|
12
|
+
setup :prepare_destination
|
13
|
+
|
14
|
+
test 'generate directories and base classes' do
|
15
|
+
run_generator
|
16
|
+
|
17
|
+
assert_file 'app/actions/application_action.rb', <<~RUBY
|
18
|
+
# frozen_string_literal: true
|
19
|
+
|
20
|
+
class ApplicationAction < Upgrow::Action
|
21
|
+
end
|
22
|
+
RUBY
|
23
|
+
|
24
|
+
assert_file 'app/inputs/application_input.rb', <<~RUBY
|
25
|
+
# frozen_string_literal: true
|
26
|
+
|
27
|
+
class ApplicationInput < Upgrow::Input
|
28
|
+
end
|
29
|
+
RUBY
|
30
|
+
|
31
|
+
assert_file 'app/models/application_model.rb', <<~RUBY
|
32
|
+
# frozen_string_literal: true
|
33
|
+
|
34
|
+
class ApplicationModel < Upgrow::Model
|
35
|
+
end
|
36
|
+
RUBY
|
37
|
+
|
38
|
+
assert_file 'app/repositories/application_repository.rb', <<~RUBY
|
39
|
+
# frozen_string_literal: true
|
40
|
+
|
41
|
+
class ApplicationRepository < Upgrow::Repository
|
42
|
+
end
|
43
|
+
RUBY
|
44
|
+
end
|
45
|
+
|
46
|
+
test 'transform existing Models into Records' do
|
47
|
+
create_file 'app/models/application_record.rb', <<~RUBY
|
48
|
+
# frozen_string_literal: true
|
49
|
+
|
50
|
+
class ApplicationRecord < ActiveRecord::Base
|
51
|
+
end
|
52
|
+
RUBY
|
53
|
+
|
54
|
+
create_file 'app/models/article.rb', <<~RUBY
|
55
|
+
# frozen_string_literal: true
|
56
|
+
|
57
|
+
class Article < ApplicationRecord
|
58
|
+
end
|
59
|
+
RUBY
|
60
|
+
|
61
|
+
create_file 'app/models/users/user.rb', <<~RUBY
|
62
|
+
# frozen_string_literal: true
|
63
|
+
|
64
|
+
module Users
|
65
|
+
class User < ApplicationRecord
|
66
|
+
end
|
67
|
+
end
|
68
|
+
RUBY
|
69
|
+
|
70
|
+
Thor::LineEditor.stub(:readline, 'yes') { run_generator }
|
71
|
+
|
72
|
+
assert_file 'app/records/application_record.rb', <<~RUBY
|
73
|
+
# frozen_string_literal: true
|
74
|
+
|
75
|
+
class ApplicationRecord < ActiveRecord::Base
|
76
|
+
include Upgrow::Record
|
77
|
+
end
|
78
|
+
RUBY
|
79
|
+
|
80
|
+
assert_file 'app/records/article_record.rb', <<~RUBY
|
81
|
+
# frozen_string_literal: true
|
82
|
+
|
83
|
+
class ArticleRecord < ApplicationRecord
|
84
|
+
end
|
85
|
+
RUBY
|
86
|
+
|
87
|
+
assert_file 'app/records/users/user_record.rb', <<~RUBY
|
88
|
+
# frozen_string_literal: true
|
89
|
+
|
90
|
+
module Users
|
91
|
+
class UserRecord < ApplicationRecord
|
92
|
+
end
|
93
|
+
end
|
94
|
+
RUBY
|
95
|
+
|
96
|
+
assert_no_file 'app/models/application_record.rb'
|
97
|
+
assert_no_file 'app/models/article.rb'
|
98
|
+
assert_no_file 'app/models/users/user.rb'
|
99
|
+
|
100
|
+
assert_file 'app/models/application_model.rb', <<~RUBY
|
101
|
+
# frozen_string_literal: true
|
102
|
+
|
103
|
+
class ApplicationModel < Upgrow::Model
|
104
|
+
end
|
105
|
+
RUBY
|
106
|
+
end
|
107
|
+
|
108
|
+
test 'does not transform existing Models into Records when user answers no' do
|
109
|
+
create_file 'app/models/application_record.rb', <<~RUBY
|
110
|
+
# frozen_string_literal: true
|
111
|
+
|
112
|
+
class ApplicationRecord < ActiveRecord::Base
|
113
|
+
end
|
114
|
+
RUBY
|
115
|
+
|
116
|
+
create_file 'app/models/article.rb', <<~RUBY
|
117
|
+
# frozen_string_literal: true
|
118
|
+
|
119
|
+
class Article < ApplicationRecord
|
120
|
+
end
|
121
|
+
RUBY
|
122
|
+
|
123
|
+
Thor::LineEditor.stub(:readline, 'no') { run_generator }
|
124
|
+
|
125
|
+
assert_file 'app/models/application_record.rb', <<~RUBY
|
126
|
+
# frozen_string_literal: true
|
127
|
+
|
128
|
+
class ApplicationRecord < ActiveRecord::Base
|
129
|
+
end
|
130
|
+
RUBY
|
131
|
+
|
132
|
+
assert_file 'app/models/article.rb', <<~RUBY
|
133
|
+
# frozen_string_literal: true
|
134
|
+
|
135
|
+
class Article < ApplicationRecord
|
136
|
+
end
|
137
|
+
RUBY
|
138
|
+
|
139
|
+
assert_file 'app/models/application_model.rb', <<~RUBY
|
140
|
+
# frozen_string_literal: true
|
141
|
+
|
142
|
+
class ApplicationModel < Upgrow::Model
|
143
|
+
end
|
144
|
+
RUBY
|
145
|
+
|
146
|
+
assert_no_directory 'app/records'
|
147
|
+
end
|
148
|
+
|
149
|
+
private
|
150
|
+
|
151
|
+
def create_file(name, content)
|
152
|
+
path = File.expand_path(name, destination_root)
|
153
|
+
mkdir_p(File.dirname(path))
|
154
|
+
File.write(path, content)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'rails/generators/test_case'
|
5
|
+
require 'generators/upgrow/model/model_generator'
|
6
|
+
|
7
|
+
module Upgrow
|
8
|
+
module Generators
|
9
|
+
class ModelGeneratorTest < Rails::Generators::TestCase
|
10
|
+
tests ModelGenerator
|
11
|
+
destination File.expand_path('tmp')
|
12
|
+
setup :prepare_destination
|
13
|
+
|
14
|
+
test 'generate Model file' do
|
15
|
+
run_generator(['article'])
|
16
|
+
|
17
|
+
assert_file 'app/models/article.rb', <<~RUBY
|
18
|
+
# frozen_string_literal: true
|
19
|
+
|
20
|
+
class Article < ApplicationModel
|
21
|
+
end
|
22
|
+
RUBY
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'generate namespaced Model file' do
|
26
|
+
run_generator(['articles/article'])
|
27
|
+
|
28
|
+
assert_file 'app/models/articles/article.rb', <<~RUBY
|
29
|
+
# frozen_string_literal: true
|
30
|
+
|
31
|
+
module Articles
|
32
|
+
class Article < ApplicationModel
|
33
|
+
end
|
34
|
+
end
|
35
|
+
RUBY
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'rails/generators/test_case'
|
5
|
+
require 'generators/upgrow/record/record_generator'
|
6
|
+
|
7
|
+
module Upgrow
|
8
|
+
module Generators
|
9
|
+
class RecordGeneratorTest < Rails::Generators::TestCase
|
10
|
+
tests RecordGenerator
|
11
|
+
destination File.expand_path('tmp')
|
12
|
+
setup :prepare_destination
|
13
|
+
|
14
|
+
test 'generate Record file' do
|
15
|
+
run_generator(['article'])
|
16
|
+
|
17
|
+
assert_file 'app/records/article_record.rb', <<~RUBY
|
18
|
+
# frozen_string_literal: true
|
19
|
+
|
20
|
+
class ArticleRecord < ApplicationRecord
|
21
|
+
end
|
22
|
+
RUBY
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'generate Record when suffix is specified' do
|
26
|
+
run_generator(['ArticleRecord'])
|
27
|
+
|
28
|
+
assert_file 'app/records/article_record.rb', <<~RUBY
|
29
|
+
# frozen_string_literal: true
|
30
|
+
|
31
|
+
class ArticleRecord < ApplicationRecord
|
32
|
+
end
|
33
|
+
RUBY
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'generate namespaced Record file' do
|
37
|
+
run_generator(['articles/article'])
|
38
|
+
|
39
|
+
assert_file 'app/records/articles/article_record.rb', <<~RUBY
|
40
|
+
# frozen_string_literal: true
|
41
|
+
|
42
|
+
module Articles
|
43
|
+
class ArticleRecord < ApplicationRecord
|
44
|
+
end
|
45
|
+
end
|
46
|
+
RUBY
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'generate namespaced Record file with many layers' do
|
50
|
+
run_generator(['users/articles/article'])
|
51
|
+
|
52
|
+
assert_file 'app/records/users/articles/article_record.rb', <<~RUBY
|
53
|
+
# frozen_string_literal: true
|
54
|
+
|
55
|
+
module Users
|
56
|
+
module Articles
|
57
|
+
class ArticleRecord < ApplicationRecord
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
RUBY
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'rails/generators/test_case'
|
5
|
+
require 'generators/upgrow/repository/repository_generator'
|
6
|
+
|
7
|
+
module Upgrow
|
8
|
+
module Generators
|
9
|
+
class RepositoryGeneratorTest < Rails::Generators::TestCase
|
10
|
+
tests RepositoryGenerator
|
11
|
+
destination File.expand_path('tmp')
|
12
|
+
setup :prepare_destination
|
13
|
+
|
14
|
+
test 'generate Repository file' do
|
15
|
+
run_generator(['article'])
|
16
|
+
|
17
|
+
assert_file 'app/repositories/article_repository.rb', <<~RUBY
|
18
|
+
# frozen_string_literal: true
|
19
|
+
|
20
|
+
class ArticleRepository < ApplicationRepository
|
21
|
+
end
|
22
|
+
RUBY
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'generate Repository when suffix is specified' do
|
26
|
+
run_generator(['ArticleRepository'])
|
27
|
+
|
28
|
+
assert_file 'app/repositories/article_repository.rb', <<~RUBY
|
29
|
+
# frozen_string_literal: true
|
30
|
+
|
31
|
+
class ArticleRepository < ApplicationRepository
|
32
|
+
end
|
33
|
+
RUBY
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'generate namespaced Repository file' do
|
37
|
+
run_generator(['articles/article'])
|
38
|
+
|
39
|
+
assert_file 'app/repositories/articles/article_repository.rb', <<~RUBY
|
40
|
+
# frozen_string_literal: true
|
41
|
+
|
42
|
+
module Articles
|
43
|
+
class ArticleRepository < ApplicationRepository
|
44
|
+
end
|
45
|
+
end
|
46
|
+
RUBY
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|