pattern_generator 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/base_generator.rb +59 -0
- data/lib/generators/form/form_generator.rb +9 -0
- data/lib/generators/form/templates/form.rb +5 -0
- data/lib/generators/form/templates/form_spec.rb +5 -0
- data/lib/generators/form/templates/form_test.rb +7 -0
- data/lib/generators/policy/policy_generator.rb +3 -18
- data/lib/generators/policy/templates/policy.rb +1 -5
- data/lib/generators/policy/templates/policy_spec.rb +2 -6
- data/lib/generators/policy/templates/policy_test.rb +1 -1
- data/lib/generators/poro/poro_generator.rb +9 -16
- data/lib/generators/service/service_generator.rb +3 -18
- data/lib/generators/service/templates/service.rb +1 -5
- data/lib/generators/service/templates/service_spec.rb +2 -6
- data/lib/generators/service/templates/service_test.rb +1 -1
- data/lib/pattern_generator.rb +6 -0
- data/lib/pattern_generator/version.rb +1 -1
- data/test/dummy/config/application.rb +0 -1
- data/test/generators/form_generator_test.rb +53 -0
- data/test/generators/policy_generator_test.rb +15 -2
- data/test/generators/poro_generator_test.rb +1 -2
- data/test/generators/service_generator_test.rb +17 -4
- data/test/test_helper.rb +6 -2
- metadata +10 -29
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/app/assets/javascripts/application.js +0 -13
- data/test/dummy/app/assets/stylesheets/application.css +0 -15
- data/test/dummy/app/controllers/application_controller.rb +0 -5
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +0 -0
- data/test/dummy/log/test.log +0 -2107
- data/test/dummy/public/404.html +0 -67
- data/test/dummy/public/422.html +0 -67
- data/test/dummy/public/500.html +0 -66
- data/test/dummy/public/favicon.ico +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ea1fb8d728c10d64b9cb86e82ce3b1a983148ed
|
4
|
+
data.tar.gz: 8ee5f1ebe85f20c7db9314c2904eb26eb8d23e79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54b325aa4025cb188bbf13b2d4824e2ff404c2551cb5c08c17f0b4b8d1e68d28a3c057bbdad0b01b6aad459e718d03d70811a3f63f5580b2a58ed05b53d63d02
|
7
|
+
data.tar.gz: 500ad4871f906f37a3ca41bf7ed0b9e35ac5cb87779a32dd871ca6c145e53a914fcc60e2356a653d029af873ccdbea26f9b416922ac5b8f0d33ab4bc6bde1a24
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "active_support/inflector"
|
2
|
+
|
3
|
+
# Base class for all generators to come. If you want to override some behaviour, all you
|
4
|
+
# got to do is override a method in the child class.
|
5
|
+
class BaseGenerator < Rails::Generators::NamedBase
|
6
|
+
class_option :rspec, type: :boolean, desc: 'DEFAULT: Define rspec as your test framework.'
|
7
|
+
class_option :minitest, type: :boolean, desc: 'Test framework to generate test. (rspec or minitest)'
|
8
|
+
class_option :no_suffix, type: :boolean, desc: "If you don't want any pattern suffix. Ex: AuthenticationService. Service is the suffix."
|
9
|
+
|
10
|
+
# Creates the file for the requested pattern based on a template file.
|
11
|
+
def copy_pattern_file
|
12
|
+
template "#{pattern_name}.rb", generated_file_path
|
13
|
+
end
|
14
|
+
|
15
|
+
# Creates the test file for the request pattern based on a template file.
|
16
|
+
def copy_pattern_test_file
|
17
|
+
template "#{pattern_name}_#{test_suite_identifier}.rb", generated_test_file_path
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# Determines the class name based on the file name given by the user.
|
23
|
+
def class_name
|
24
|
+
file_name.classify + suffix.classify
|
25
|
+
end
|
26
|
+
|
27
|
+
# This method must be overrided in the child classes.
|
28
|
+
def pattern_name
|
29
|
+
raise NotImplementedError
|
30
|
+
end
|
31
|
+
|
32
|
+
def folder_name
|
33
|
+
pattern_name.pluralize
|
34
|
+
end
|
35
|
+
|
36
|
+
# Generates the pattern suffix.
|
37
|
+
# Ex: _service
|
38
|
+
def suffix
|
39
|
+
options.no_suffix? ? "" : "_#{pattern_name}"
|
40
|
+
end
|
41
|
+
|
42
|
+
# Generates the file path.
|
43
|
+
# Ex: app/services/authentication.rb
|
44
|
+
def generated_file_path
|
45
|
+
"app/#{folder_name}/#{file_name}#{suffix}.rb"
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_suite_identifier
|
49
|
+
identifier = "spec"
|
50
|
+
identifier = "test" if options.minitest?
|
51
|
+
identifier
|
52
|
+
end
|
53
|
+
|
54
|
+
# Generates the test file path.
|
55
|
+
# Ex: spec/services/authentication_spec.rb
|
56
|
+
def generated_test_file_path
|
57
|
+
"#{test_suite_identifier}/#{folder_name}/#{file_name}#{suffix}_#{test_suite_identifier}.rb"
|
58
|
+
end
|
59
|
+
end
|
@@ -1,24 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class PolicyGenerator < Rails::Generators::NamedBase
|
1
|
+
class PolicyGenerator < BaseGenerator
|
4
2
|
source_root File.expand_path('../templates', __FILE__)
|
5
|
-
class_option :test_suite, type: :string, default: 'rspec', desc: 'Test framework to generate test. (rspec or minitest)'
|
6
|
-
|
7
|
-
def generate_template
|
8
|
-
template 'policy.rb', "app/policies/#{file_name}_policy.rb"
|
9
|
-
end
|
10
|
-
|
11
|
-
def generate_test
|
12
|
-
if options.test_suite == 'rspec'
|
13
|
-
template 'policy_spec.rb', "spec/policies/#{file_name}_policy_spec.rb"
|
14
|
-
elsif options.test_suite == 'minitest'
|
15
|
-
template 'policy_test.rb', "test/policies/#{file_name}_policy_test.rb"
|
16
|
-
end
|
17
|
-
end
|
18
3
|
|
19
4
|
private
|
20
5
|
|
21
|
-
def
|
22
|
-
|
6
|
+
def pattern_name
|
7
|
+
"policy"
|
23
8
|
end
|
24
9
|
end
|
@@ -1,24 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class PoroGenerator < Rails::Generators::NamedBase
|
1
|
+
class PoroGenerator < BaseGenerator
|
4
2
|
source_root File.expand_path('../templates', __FILE__)
|
5
|
-
class_option :test_suite, type: :string, default: 'rspec', desc: 'Test framework to generate test. (rspec or minitest)'
|
6
3
|
|
7
|
-
|
8
|
-
template 'poro.rb', "app/models/#{file_name}.rb"
|
9
|
-
end
|
4
|
+
private
|
10
5
|
|
11
|
-
def
|
12
|
-
|
13
|
-
template 'poro_spec.rb', "spec/models/#{file_name}_spec.rb"
|
14
|
-
elsif options.test_suite == 'minitest'
|
15
|
-
template 'poro_test.rb', "test/models/#{file_name}_test.rb"
|
16
|
-
end
|
6
|
+
def folder_name
|
7
|
+
"models"
|
17
8
|
end
|
18
9
|
|
19
|
-
|
10
|
+
def pattern_name
|
11
|
+
"poro"
|
12
|
+
end
|
20
13
|
|
21
|
-
def
|
22
|
-
|
14
|
+
def suffix
|
15
|
+
""
|
23
16
|
end
|
24
17
|
end
|
@@ -1,24 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class ServiceGenerator < Rails::Generators::NamedBase
|
1
|
+
class ServiceGenerator < BaseGenerator
|
4
2
|
source_root File.expand_path('../templates', __FILE__)
|
5
|
-
class_option :test_suite, type: :string, default: 'rspec', desc: 'Test framework to generate test. (rspec or minitest)'
|
6
|
-
|
7
|
-
def copy_service_file
|
8
|
-
template 'service.rb', "app/services/#{file_name}_service.rb"
|
9
|
-
end
|
10
|
-
|
11
|
-
def copy_service_test_file
|
12
|
-
if options.test_suite == 'rspec'
|
13
|
-
template 'service_spec.rb', "spec/services/#{file_name}_service_spec.rb"
|
14
|
-
elsif options.test_suite == 'minitest'
|
15
|
-
template 'service_test.rb', "test/services/#{file_name}_service_test.rb"
|
16
|
-
end
|
17
|
-
end
|
18
3
|
|
19
4
|
private
|
20
5
|
|
21
|
-
def
|
22
|
-
|
6
|
+
def pattern_name
|
7
|
+
"service"
|
23
8
|
end
|
24
9
|
end
|
data/lib/pattern_generator.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FormGeneratorTest < Rails::Generators::TestCase
|
4
|
+
tests FormGenerator
|
5
|
+
|
6
|
+
destination File.join(Rails.root)
|
7
|
+
teardown :cleanup
|
8
|
+
|
9
|
+
def cleanup
|
10
|
+
FileUtils.rm_rf(File.join(Rails.root, 'app/forms'))
|
11
|
+
FileUtils.rm_rf(File.join(Rails.root, 'spec/forms'))
|
12
|
+
FileUtils.rm_rf(File.join(Rails.root, 'test/forms'))
|
13
|
+
end
|
14
|
+
|
15
|
+
test 'correct file is generated' do
|
16
|
+
run_generator %w(registration)
|
17
|
+
|
18
|
+
assert_file 'app/forms/registration_form.rb' do |content|
|
19
|
+
assert_match /RegistrationForm/, content
|
20
|
+
assert_match /def initialize/, content
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'correct spec file is generated' do
|
25
|
+
run_generator %w(registration)
|
26
|
+
|
27
|
+
assert_file 'spec/forms/registration_form_spec.rb' do |content|
|
28
|
+
assert_match /RSpec.describe RegistrationForm, type: :form/, content
|
29
|
+
assert_match /pending/, content
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'generates minitest file if --minitest options is passed' do
|
34
|
+
run_generator %w(registration --minitest)
|
35
|
+
|
36
|
+
assert_file 'test/forms/registration_form_test.rb' do |content|
|
37
|
+
assert_match /class RegistrationFormTest < Minitest::Test/, content
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'generates files with no suffixes if --no-sufix option is passed' do
|
42
|
+
run_generator %w(registration --no-suffix)
|
43
|
+
|
44
|
+
assert_file 'app/forms/registration.rb' do |content|
|
45
|
+
assert_match /Registration/, content
|
46
|
+
assert_match /def initialize/, content
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_file 'spec/forms/registration_spec.rb' do |content|
|
50
|
+
assert_match /RSpec.describe Registration, type: :form/, content
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'generators/policy/policy_generator'
|
3
2
|
|
4
3
|
class PolicyGeneratorTest < Rails::Generators::TestCase
|
5
4
|
tests PolicyGenerator
|
@@ -19,6 +18,7 @@ class PolicyGeneratorTest < Rails::Generators::TestCase
|
|
19
18
|
|
20
19
|
assert_file 'app/policies/active_user_policy.rb' do |content|
|
21
20
|
assert_match /class ActiveUserPolicy/, content
|
21
|
+
assert_match /def initialize/, content
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -27,15 +27,28 @@ class PolicyGeneratorTest < Rails::Generators::TestCase
|
|
27
27
|
|
28
28
|
assert_file 'spec/policies/active_user_policy_spec.rb' do |content|
|
29
29
|
assert_match /RSpec.describe ActiveUserPolicy, type: :policy do/, content
|
30
|
+
assert_match /pending/, content
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
34
|
test "if minitest is specified, minitest file is generated" do
|
34
|
-
run_generator %w(active_user --
|
35
|
+
run_generator %w(active_user --minitest)
|
35
36
|
|
36
37
|
assert_file 'test/policies/active_user_policy_test.rb' do |content|
|
37
38
|
assert_match /class ActiveUserPolicyTest < Minitest::Test/, content
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
42
|
+
test 'generates files with no suffixes if --no-sufix option is passed' do
|
43
|
+
run_generator %w(active_user --no-suffix)
|
44
|
+
|
45
|
+
assert_file 'app/policies/active_user.rb' do |content|
|
46
|
+
assert_match /ActiveUser/, content
|
47
|
+
assert_match /def initialize/, content
|
48
|
+
end
|
49
|
+
|
50
|
+
assert_file 'spec/policies/active_user_spec.rb' do |content|
|
51
|
+
assert_match /RSpec.describe ActiveUser, type: :policy/, content
|
52
|
+
end
|
53
|
+
end
|
41
54
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'generators/poro/poro_generator'
|
3
2
|
|
4
3
|
class PoroGeneratorTest < Rails::Generators::TestCase
|
5
4
|
tests PoroGenerator
|
@@ -31,7 +30,7 @@ class PoroGeneratorTest < Rails::Generators::TestCase
|
|
31
30
|
end
|
32
31
|
|
33
32
|
test 'minitest file is generated when test-suite is minitest' do
|
34
|
-
run_generator %w(grade --
|
33
|
+
run_generator %w(grade --minitest)
|
35
34
|
|
36
35
|
assert_file 'test/models/grade_test.rb' do |content|
|
37
36
|
assert_match /class GradeTest < MiniTest::Test/, content
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'generators/service/service_generator'
|
3
2
|
|
4
3
|
class ServiceGeneratorTest < Rails::Generators::TestCase
|
5
4
|
tests ServiceGenerator
|
@@ -17,8 +16,8 @@ class ServiceGeneratorTest < Rails::Generators::TestCase
|
|
17
16
|
run_generator %w(find_match)
|
18
17
|
|
19
18
|
assert_file 'app/services/find_match_service.rb' do |content|
|
20
|
-
assert_match /FindMatchService/, content
|
21
|
-
assert_match /def
|
19
|
+
assert_match /class FindMatchService/, content
|
20
|
+
assert_match /def initialize/, content
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
@@ -27,14 +26,28 @@ class ServiceGeneratorTest < Rails::Generators::TestCase
|
|
27
26
|
|
28
27
|
assert_file 'spec/services/find_match_service_spec.rb' do |content|
|
29
28
|
assert_match /RSpec.describe FindMatchService, type: :service/, content
|
29
|
+
assert_match /pending/, content
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
test 'generates minitest file if test-framework is minitest' do
|
34
|
-
run_generator %w(find_match --
|
34
|
+
run_generator %w(find_match --minitest)
|
35
35
|
|
36
36
|
assert_file 'test/services/find_match_service_test.rb' do |content|
|
37
37
|
assert_match /class FindMatchServiceTest < Minitest::Test/, content
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
test 'generates files with no suffixes if --no-sufix option is passed' do
|
42
|
+
run_generator %w(find_match --no-suffix)
|
43
|
+
|
44
|
+
assert_file 'app/services/find_match.rb' do |content|
|
45
|
+
assert_match /FindMatch/, content
|
46
|
+
assert_match /def initialize/, content
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_file 'spec/services/find_match_spec.rb' do |content|
|
50
|
+
assert_match /RSpec.describe FindMatch, type: :service/, content
|
51
|
+
end
|
52
|
+
end
|
40
53
|
end
|