dry-operation_generators-test_unit 0.1.0 → 0.2.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +30 -1
- data/CHANGELOG.md +10 -1
- data/CODE_OF_CONDUCT.md +77 -29
- data/LICENSE.txt +1 -1
- data/README.md +8 -18
- data/lib/dry-operation_generators-test_unit/version.rb +5 -0
- data/lib/dry-operation_generators-test_unit.rb +3 -0
- data/lib/{test_unit/generators → generators/test_unit}/operations/schema_generator.rb +5 -1
- metadata +13 -51
- data/lib/test_unit/create_generator.rb +0 -73
- data/lib/test_unit/generators/operations/contract/templates/contract_test.rb.erb +0 -113
- data/lib/test_unit/generators/operations/contract_generator.rb +0 -19
- data/lib/test_unit/generators/operations/operation/templates/operation_test.rb.erb +0 -191
- data/lib/test_unit/generators/operations/operation_generator.rb +0 -19
- data/lib/test_unit/generators/operations/setup/templates/generators.rb.tt +0 -5
- data/lib/test_unit/generators/operations/setup_generator.rb +0 -14
- data/lib/test_unit/templates/template_generator.rb.erb +0 -19
- data/lib/test_unit/templates/template_generator_spec.rb.erb +0 -56
- data/lib/test_unit.rb +0 -15
- data/operation_generators-test_unit.gemspec +0 -41
- data/sig/test_unit_operation_generators.rbs +0 -4
- /data/lib/{test_unit/generators → generators/test_unit}/operations/schema/templates/base/schema_test.rb.erb +0 -0
- /data/lib/{test_unit/generators → generators/test_unit}/operations/schema/templates/schema_test.rb.erb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 223d6c112e5eefdac7a095bc1b8c0677c3f3d8b38a0a09358c29e5a84e8edfde
|
4
|
+
data.tar.gz: 33c6482e25307692a5a91888a11f74c8788f23f8fc3ed2d87867913468cc901b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b511e9302a74ecb4e35aba0a47d41fde3a8dbf3814bfce29b00f2661d2504cb9ac237dc0b17a0997498592e9dd86e904878a472015d7e2c60b65d66b425dd436
|
7
|
+
data.tar.gz: afad6f79c33409742a27c773636fa47fc3ad43245247a020780fb45a3088b88f778e47f143a7207c0c915e8df3179be52e5bda146049c11c6cb83f9ad9ac0c6e
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,11 +1,40 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2024-08-09 13:48:17 UTC using RuboCop version 1.65.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: Severity, Include.
|
11
|
+
# Include: **/*.gemspec
|
12
|
+
Gemspec/RequiredRubyVersion:
|
13
|
+
Exclude:
|
14
|
+
- 'dry-operation_generators-test_unit.gemspec'
|
15
|
+
|
16
|
+
# Offense count: 1
|
17
|
+
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
18
|
+
# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
|
19
|
+
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
|
20
|
+
Naming/FileName:
|
21
|
+
Exclude:
|
22
|
+
- 'Rakefile.rb'
|
23
|
+
- 'lib/dry-operation_generators-test_unit.rb'
|
24
|
+
|
25
|
+
# Offense count: 1
|
26
|
+
RSpec/MessageChain:
|
27
|
+
Exclude:
|
28
|
+
- 'spec/support/pre/rails.rb'
|
29
|
+
|
9
30
|
# Offense count: 3
|
10
31
|
RSpec/MultipleExpectations:
|
11
32
|
Max: 2
|
33
|
+
|
34
|
+
# Offense count: 1
|
35
|
+
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
|
36
|
+
# Include: **/*_spec.rb
|
37
|
+
RSpec/SpecFilePathFormat:
|
38
|
+
Exclude:
|
39
|
+
- '**/spec/routing/**/*'
|
40
|
+
- 'spec/generators/test_unit/operations/schema_generator_spec.rb'
|
data/CHANGELOG.md
CHANGED
data/CODE_OF_CONDUCT.md
CHANGED
@@ -2,83 +2,131 @@
|
|
2
2
|
|
3
3
|
## Our Pledge
|
4
4
|
|
5
|
-
We as members, contributors, and leaders pledge to make participation in our
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
6
11
|
|
7
|
-
We pledge to act and interact in ways that contribute to an open, welcoming,
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
8
14
|
|
9
15
|
## Our Standards
|
10
16
|
|
11
|
-
Examples of behavior that contributes to a positive environment for our
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
12
19
|
|
13
20
|
* Demonstrating empathy and kindness toward other people
|
14
21
|
* Being respectful of differing opinions, viewpoints, and experiences
|
15
22
|
* Giving and gracefully accepting constructive feedback
|
16
|
-
* Accepting responsibility and apologizing to those affected by our mistakes,
|
17
|
-
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
18
27
|
|
19
28
|
Examples of unacceptable behavior include:
|
20
29
|
|
21
|
-
* The use of sexualized language or imagery, and sexual attention or
|
22
|
-
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
23
32
|
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
33
|
* Public or private harassment
|
25
|
-
* Publishing others' private information, such as a physical or email
|
26
|
-
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
27
36
|
* Other conduct which could reasonably be considered inappropriate in a
|
28
37
|
professional setting
|
29
38
|
|
30
39
|
## Enforcement Responsibilities
|
31
40
|
|
32
|
-
Community leaders are responsible for clarifying and enforcing our standards of
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
33
45
|
|
34
|
-
Community leaders have the right and responsibility to remove, edit, or reject
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
35
50
|
|
36
51
|
## Scope
|
37
52
|
|
38
|
-
This Code of Conduct applies within all community spaces, and also applies when
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
39
58
|
|
40
59
|
## Enforcement
|
41
60
|
|
42
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
43
65
|
|
44
|
-
All community leaders are obligated to respect the privacy and security of the
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
45
68
|
|
46
69
|
## Enforcement Guidelines
|
47
70
|
|
48
|
-
Community leaders will follow these Community Impact Guidelines in determining
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
49
73
|
|
50
74
|
### 1. Correction
|
51
75
|
|
52
|
-
**Community Impact**: Use of inappropriate language or other behavior deemed
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
53
78
|
|
54
|
-
**Consequence**: A private, written warning from community leaders, providing
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
55
82
|
|
56
83
|
### 2. Warning
|
57
84
|
|
58
|
-
**Community Impact**: A violation through a single incident or series of
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
59
87
|
|
60
|
-
**Consequence**: A warning with consequences for continued behavior. No
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
61
94
|
|
62
95
|
### 3. Temporary Ban
|
63
96
|
|
64
|
-
**Community Impact**: A serious violation of community standards, including
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
65
99
|
|
66
|
-
**Consequence**: A temporary ban from any sort of interaction or public
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
67
105
|
|
68
106
|
### 4. Permanent Ban
|
69
107
|
|
70
|
-
**Community Impact**: Demonstrating a pattern of violation of community
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
71
111
|
|
72
|
-
**Consequence**: A permanent ban from any sort of public interaction within the
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
73
114
|
|
74
115
|
## Attribution
|
75
116
|
|
76
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
77
|
-
available at
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
78
120
|
|
79
|
-
Community Impact Guidelines were inspired by
|
80
|
-
|
81
|
-
[homepage]: https://www.contributor-covenant.org
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
82
123
|
|
83
124
|
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
-
https://www.contributor-covenant.org/faq. Translations are available at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,7 @@ This library doesn't make sense without [dry-operation_generators](https://githu
|
|
7
7
|
Generates the counterpart test files:
|
8
8
|
|
9
9
|
```shell
|
10
|
-
test/
|
10
|
+
test/operations/users/create/
|
11
11
|
├── acction_test.rb
|
12
12
|
├── contract_test.rb
|
13
13
|
├── operation_test.rb
|
@@ -46,21 +46,11 @@ rails generate --help
|
|
46
46
|
You should see
|
47
47
|
|
48
48
|
```shell
|
49
|
-
|
50
|
-
|
51
|
-
test_unit:generator
|
52
|
-
test_unit:install
|
53
|
-
test_unit:mailbox
|
54
|
-
test_unit:observer
|
55
|
-
test_unit:operations:setup
|
56
|
-
test_unit:plugin
|
57
|
-
```
|
58
|
-
|
59
|
-
You will need to run the Setup to make the generators available in the Host Application.
|
49
|
+
Operations:
|
50
|
+
operations:schema
|
60
51
|
|
61
|
-
|
62
|
-
|
63
|
-
# => initializer operation_generators-test_unit.rb
|
52
|
+
TestUnit:
|
53
|
+
test_unit:operations:schema
|
64
54
|
```
|
65
55
|
|
66
56
|
Now the Generators should appear:
|
@@ -81,10 +71,10 @@ TestUnit:
|
|
81
71
|
They are automatically call when the generator it's call:
|
82
72
|
|
83
73
|
```shell
|
84
|
-
rails generate operations:contract user create firstname:string
|
74
|
+
rails generate operations:contract user create firstname:string{optional} --test_framework=test_unit
|
85
75
|
invoke test_unit
|
86
|
-
create test/
|
87
|
-
create
|
76
|
+
create test/operations/users/create/contract_test.rb
|
77
|
+
create app/operations/users/create/contract.rb
|
88
78
|
```
|
89
79
|
|
90
80
|
## Development
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "rails/generators"
|
4
|
+
require "operations/base"
|
5
|
+
|
6
|
+
# hook_for :test_framework, as: "operations:schema"
|
7
|
+
# "test_unit:operations:schema" => TestUnit::Generators::Operations::SchemaGenerator
|
4
8
|
|
5
9
|
module TestUnit
|
6
10
|
module Generators
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-operation_generators-test_unit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0.alpha1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Joel
|
7
|
+
- Joel AZEMAR
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: dry-operation_generators-base
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rails
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,21 +24,7 @@ dependencies:
|
|
38
24
|
- - ">="
|
39
25
|
- !ruby/object:Gem::Version
|
40
26
|
version: '0'
|
41
|
-
|
42
|
-
name: zeitwerk
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
description:
|
27
|
+
description: Write a longer description or delete this line.
|
56
28
|
email:
|
57
29
|
- joel.azemar@gmail.com
|
58
30
|
executables: []
|
@@ -67,22 +39,12 @@ files:
|
|
67
39
|
- LICENSE.txt
|
68
40
|
- README.md
|
69
41
|
- Rakefile
|
70
|
-
- lib/test_unit.rb
|
71
|
-
- lib/test_unit/
|
72
|
-
- lib/test_unit/
|
73
|
-
- lib/test_unit/
|
74
|
-
- lib/test_unit/
|
75
|
-
|
76
|
-
- lib/test_unit/generators/operations/schema/templates/base/schema_test.rb.erb
|
77
|
-
- lib/test_unit/generators/operations/schema/templates/schema_test.rb.erb
|
78
|
-
- lib/test_unit/generators/operations/schema_generator.rb
|
79
|
-
- lib/test_unit/generators/operations/setup/templates/generators.rb.tt
|
80
|
-
- lib/test_unit/generators/operations/setup_generator.rb
|
81
|
-
- lib/test_unit/templates/template_generator.rb.erb
|
82
|
-
- lib/test_unit/templates/template_generator_spec.rb.erb
|
83
|
-
- operation_generators-test_unit.gemspec
|
84
|
-
- sig/test_unit_operation_generators.rbs
|
85
|
-
homepage: https://github.com/joel/dry-operation_generators-test_unit
|
42
|
+
- lib/dry-operation_generators-test_unit.rb
|
43
|
+
- lib/dry-operation_generators-test_unit/version.rb
|
44
|
+
- lib/generators/test_unit/operations/schema/templates/base/schema_test.rb.erb
|
45
|
+
- lib/generators/test_unit/operations/schema/templates/schema_test.rb.erb
|
46
|
+
- lib/generators/test_unit/operations/schema_generator.rb
|
47
|
+
homepage: http://mygemserver.com
|
86
48
|
licenses:
|
87
49
|
- MIT
|
88
50
|
metadata:
|
@@ -95,15 +57,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
57
|
requirements:
|
96
58
|
- - ">="
|
97
59
|
- !ruby/object:Gem::Version
|
98
|
-
version: 3.
|
60
|
+
version: 3.0.0
|
99
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
62
|
requirements:
|
101
63
|
- - ">="
|
102
64
|
- !ruby/object:Gem::Version
|
103
65
|
version: '0'
|
104
66
|
requirements: []
|
105
|
-
rubygems_version: 3.5.
|
67
|
+
rubygems_version: 3.5.11
|
106
68
|
signing_key:
|
107
69
|
specification_version: 4
|
108
|
-
summary:
|
70
|
+
summary: Write a short summary, because RubyGems requires one.
|
109
71
|
test_files: []
|
@@ -1,73 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
begin
|
5
|
-
require "thor/group"
|
6
|
-
rescue LoadError
|
7
|
-
puts "Thor is not available.\nIf you ran this command from a git checkout " \
|
8
|
-
"of Rails, please make sure thor is installed,\nand run this command " \
|
9
|
-
"as `ruby #{$PROGRAM_NAME} #{(ARGV | ["--dev"]).join(" ")}`"
|
10
|
-
exit
|
11
|
-
end
|
12
|
-
|
13
|
-
require "active_support/inflector"
|
14
|
-
|
15
|
-
module TestUnit
|
16
|
-
class CreateGenerator < Thor::Group
|
17
|
-
include Thor::Actions
|
18
|
-
|
19
|
-
class << self
|
20
|
-
def exit_on_failure?
|
21
|
-
true
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
desc "Create a new Generator (Generator of generators)"
|
26
|
-
|
27
|
-
source_root File.expand_path(".", __dir__)
|
28
|
-
|
29
|
-
class_option :force, type: :boolean, default: false
|
30
|
-
|
31
|
-
argument :name, type: :string, required: true, desc: "Name of the generator"
|
32
|
-
argument :library, type: :string, required: true, desc: "Name of the library, i.e. Dry::Schema"
|
33
|
-
class_option :dry_run, type: :boolean, default: true
|
34
|
-
|
35
|
-
def plural_name
|
36
|
-
name.pluralize
|
37
|
-
end
|
38
|
-
|
39
|
-
def singular_name
|
40
|
-
name.singularize
|
41
|
-
end
|
42
|
-
|
43
|
-
def class_name
|
44
|
-
singular_name.capitalize
|
45
|
-
end
|
46
|
-
|
47
|
-
def copy_generator_files
|
48
|
-
return if options[:dry_run]
|
49
|
-
|
50
|
-
say "Adding files...", :green
|
51
|
-
|
52
|
-
template "templates/template_generator.rb.erb", "lib/test_unit/generators/operations/#{name}_generator.rb"
|
53
|
-
template "templates/template_generator_spec.rb.erb",
|
54
|
-
"spec/test_unit/generators/operations/#{name}_generator_spec.rb"
|
55
|
-
|
56
|
-
create_file "lib/test_unit/generators/operations/#{name}/templates/#{name}_test.rb.erb" do
|
57
|
-
"This is #{name}.rb.erb"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def update_setup
|
62
|
-
say "Updating setup...", :green
|
63
|
-
|
64
|
-
setup_file = "lib/test_unit/generators/operations/setup/templates/generators.rb"
|
65
|
-
include_text = " \"test_unit/generators/operations/#{name}_generator\" if defined?(#{library})\nrequire"
|
66
|
-
|
67
|
-
insert_into_file setup_file, include_text.to_s, after: Regexp.new(Regexp.escape("require"))
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# ./bin/generator <generator name> --no-dry_run
|
73
|
-
TestUnit::CreateGenerator.start(ARGV)
|
@@ -1,113 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
# Test based on the following contract rules:
|
6
|
-
#
|
7
|
-
# module <%= class_name.pluralize %>
|
8
|
-
# module <%= verb.capitalize %>
|
9
|
-
# class Contract < Base::Contract
|
10
|
-
#
|
11
|
-
# params(Schema)
|
12
|
-
#
|
13
|
-
# rule(:user_id) do
|
14
|
-
# key.failure("must exist") if User.where(id: value).none?
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# end
|
18
|
-
# end
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# Adapt the test to the rules of your contract.
|
22
|
-
#
|
23
|
-
module <%= class_name.pluralize %>
|
24
|
-
module <%= verb.capitalize %>
|
25
|
-
class ContractTest < ActiveSupport::TestCase
|
26
|
-
|
27
|
-
<%- @reference_parsed_fields.each do |field| -%>
|
28
|
-
def <%= field.name %>
|
29
|
-
@<%= field.name %> ||= create(:<%= field.name %>)
|
30
|
-
end
|
31
|
-
|
32
|
-
<%- end -%>
|
33
|
-
def attributes
|
34
|
-
{
|
35
|
-
# TODO: Add attributes here.
|
36
|
-
<%- @reference_parsed_fields.each do |field| -%>
|
37
|
-
<%- case Operations.configuration.primary_key_type -%>
|
38
|
-
<%- when :integer -%>
|
39
|
-
<%= field.foreign_key %>: <%= field.name %>.id,
|
40
|
-
<%- when /string|uuid/ -%>
|
41
|
-
<%= field.foreign_key %>: <%= field.name %>.uuid,
|
42
|
-
<%- end -%>
|
43
|
-
<%- end -%>
|
44
|
-
}
|
45
|
-
skip("Skipping: Please replace with the correct attributes for this test.")
|
46
|
-
end
|
47
|
-
|
48
|
-
def valid_attributes
|
49
|
-
attributes
|
50
|
-
end
|
51
|
-
|
52
|
-
def invalid_attributes
|
53
|
-
attributes.merge(
|
54
|
-
{
|
55
|
-
# TODO: Add attributes here
|
56
|
-
<%- @reference_parsed_fields.each do |field| -%>
|
57
|
-
<%- case Operations.configuration.primary_key_type -%>
|
58
|
-
<%- when :integer -%>
|
59
|
-
<%= field.foreign_key %>: 42,
|
60
|
-
<%- when /string|uuid/ -%>
|
61
|
-
<%= field.foreign_key %>: SecureRandom.uuid_v7,
|
62
|
-
<%- end -%>
|
63
|
-
<%- end -%>
|
64
|
-
}
|
65
|
-
)
|
66
|
-
skip("Skipping: Please replace with the correct attributes for this test.")
|
67
|
-
end
|
68
|
-
|
69
|
-
# <%= verb.capitalize %>Schema Mock
|
70
|
-
# NOTE: All the keys used for the rules need to be present in the schema.
|
71
|
-
Mocked<%= verb.capitalize %>Schema = Dry::Schema.Params do
|
72
|
-
<%- @reference_parsed_fields.each do |field| -%>
|
73
|
-
<%= field.requirement %>(:<%= field.foreign_key %>).filled(:<%= Operations.configuration.primary_key_type %>)
|
74
|
-
<%- end -%>
|
75
|
-
end
|
76
|
-
|
77
|
-
# Safe Mocking of the <%= verb.capitalize %>Contract
|
78
|
-
class Mocked<%= verb.capitalize %>Contract < ::<%= class_name.pluralize %>::<%= verb.capitalize %>::Contract
|
79
|
-
|
80
|
-
params(Mocked<%= verb.capitalize %>Schema)
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
context "validations" do
|
85
|
-
|
86
|
-
subject { Mocked<%= verb.capitalize %>Contract.new }
|
87
|
-
|
88
|
-
context "with the right attributes" do
|
89
|
-
|
90
|
-
should "be successful" do
|
91
|
-
assert subject.call(valid_attributes).success?
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
context "with the wrong attributes" do
|
97
|
-
|
98
|
-
should "be unsuccessful" do
|
99
|
-
result = subject.call(invalid_attributes)
|
100
|
-
assert result.failure?
|
101
|
-
<%- @reference_parsed_fields.each do |field| -%>
|
102
|
-
# assert_equal ["must exist"], result.errors[:<%= field.foreign_key %>]
|
103
|
-
<%- end -%>
|
104
|
-
skip("Skipping: Add the correct error messages here.")
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module TestUnit
|
4
|
-
module Generators
|
5
|
-
module Operations
|
6
|
-
class ContractGenerator < Rails::Generators::NamedBase
|
7
|
-
include ::Operations::Base::Generators::BaseGenerator
|
8
|
-
|
9
|
-
source_root File.expand_path("contract/templates", __dir__)
|
10
|
-
|
11
|
-
def generate_files
|
12
|
-
super
|
13
|
-
|
14
|
-
template "contract_test.rb.erb", "#{root_test_file_path}/operations/#{plural_name}/#{verb}/contract_test.rb"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,191 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
# Test based on the following operations:
|
6
|
-
#
|
7
|
-
# module <%= class_name.pluralize %>
|
8
|
-
# module <%= verb.capitalize %>
|
9
|
-
# class Operation
|
10
|
-
#
|
11
|
-
# include Dry::Transaction(container: Register)
|
12
|
-
#
|
13
|
-
# step :validate_inputs, with: "<%= plural_name %>.<%= verb %>.validation"
|
14
|
-
# step :initialize_record, with: "<%= plural_name %>.<%= verb %>.repository"
|
15
|
-
# step :<%= verb %>_record, with: "<%= plural_name %>.<%= verb %>.action"
|
16
|
-
#
|
17
|
-
# end
|
18
|
-
# end
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# Adapt the test to your operation.
|
22
|
-
#
|
23
|
-
module <%= class_name.pluralize %>
|
24
|
-
module <%= verb.capitalize %>
|
25
|
-
class OperationTest < ActiveSupport::TestCase
|
26
|
-
|
27
|
-
<%- @reference_parsed_fields.each do |field| -%>
|
28
|
-
def <%= field.name %>
|
29
|
-
@<%= field.name %> ||= create(:<%= field.name %>)
|
30
|
-
end
|
31
|
-
|
32
|
-
<%- end -%>
|
33
|
-
<%- if verb =~ /update|destroy|all/ -%>
|
34
|
-
def record
|
35
|
-
@record ||= create(:<%= singular_name %>)
|
36
|
-
end
|
37
|
-
<%- end -%>
|
38
|
-
|
39
|
-
<%- if verb != "destroy" -%>
|
40
|
-
def schema_attributes
|
41
|
-
<%= class_name.pluralize %>::Base::Schema.key_list + <%= class_name.pluralize %>::<%= verb.capitalize %>::Schema.key_list
|
42
|
-
end
|
43
|
-
|
44
|
-
# This method should return attributes with the keys as symbols.
|
45
|
-
# symbolize_keys
|
46
|
-
def model_attributes
|
47
|
-
# attributes_for(:<%= singular_name %>) # More efficient
|
48
|
-
@model_attributes ||= create(:<%= singular_name %>).attributes.symbolize_keys
|
49
|
-
end
|
50
|
-
<%- if verb == "create" -%>
|
51
|
-
alias_method :init_setup!, :model_attributes
|
52
|
-
<%- end -%>
|
53
|
-
|
54
|
-
def attributes
|
55
|
-
model_attributes.slice(*schema_attributes).merge({
|
56
|
-
<%- if verb =~ /update|destroy|all/ -%>
|
57
|
-
id: record.uuid,
|
58
|
-
<%- end -%>
|
59
|
-
# TODO: Add attributes here.
|
60
|
-
<%- @reference_parsed_fields.each do |field| -%>
|
61
|
-
<%- case Operations.configuration.primary_key_type -%>
|
62
|
-
<%- when :integer -%>
|
63
|
-
<%= field.foreign_key %>: <%= field.name %>.id,
|
64
|
-
<%- when /string|uuid/ -%>
|
65
|
-
<%= field.foreign_key %>: <%= field.name %>.uuid,
|
66
|
-
<%- end -%>
|
67
|
-
<%- end -%>
|
68
|
-
<%- @regular_parsed_fields.each do |field| -%>
|
69
|
-
<%= field.name %>: "New <%= field.name.capitalize %>",
|
70
|
-
<%- end -%>
|
71
|
-
})
|
72
|
-
skip("Skipping: Please replace with the correct attributes for this test.")
|
73
|
-
end
|
74
|
-
|
75
|
-
def valid_attributes
|
76
|
-
attributes
|
77
|
-
end
|
78
|
-
<%- else -%>
|
79
|
-
def valid_attributes
|
80
|
-
{ id: record.uuid }
|
81
|
-
end
|
82
|
-
<%- end -%>
|
83
|
-
|
84
|
-
<%- if verb != "destroy" -%>
|
85
|
-
def invalid_attributes
|
86
|
-
attributes.merge(
|
87
|
-
{
|
88
|
-
# TODO: Add attributes here
|
89
|
-
<%- @reference_parsed_fields.each do |field| -%>
|
90
|
-
<%- case Operations.configuration.primary_key_type -%>
|
91
|
-
<%- when :integer -%>
|
92
|
-
<%= field.foreign_key %>: 42,
|
93
|
-
<%- when /string|uuid/ -%>
|
94
|
-
<%= field.foreign_key %>: SecureRandom.uuid_v7,
|
95
|
-
<%- end -%>
|
96
|
-
<%- end -%>
|
97
|
-
<%- @regular_parsed_fields.each do |field| -%>
|
98
|
-
<%= field.name %>: nil,
|
99
|
-
<%- end -%>
|
100
|
-
}
|
101
|
-
)
|
102
|
-
skip("Skipping: Please replace with the correct attributes for this test.")
|
103
|
-
end
|
104
|
-
<%- end -%>
|
105
|
-
|
106
|
-
<%- if verb != "destroy" -%>
|
107
|
-
def <%= verb %>d_resource
|
108
|
-
<%= class_name %>.last
|
109
|
-
end
|
110
|
-
<%- end -%>
|
111
|
-
|
112
|
-
context "#perform" do
|
113
|
-
|
114
|
-
subject { described_class.new }
|
115
|
-
|
116
|
-
context "success" do
|
117
|
-
|
118
|
-
# Arround the action
|
119
|
-
<%- case verb -%>
|
120
|
-
<%- when "create" -%>
|
121
|
-
should "create the resource" do
|
122
|
-
init_setup! # Ensure the record exists
|
123
|
-
assert_difference "<%= class_name %>.count", +1 do
|
124
|
-
subject.call(valid_attributes)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
<%- when "update" -%>
|
128
|
-
should "update the resource" do
|
129
|
-
assert_changes -> {
|
130
|
-
# record.reload.name
|
131
|
-
<%= class_name %>.find_by(uuid: record.uuid).name
|
132
|
-
}, to: "New Name" do
|
133
|
-
subject.call(valid_attributes)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
<%- when "destroy" -%>
|
137
|
-
should "destroy the resource" do
|
138
|
-
record # Ensure the record exists
|
139
|
-
assert_difference "<%= class_name %>.count", -1 do
|
140
|
-
subject.call(valid_attributes)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
<%- end -%>
|
144
|
-
|
145
|
-
<%- if verb != "destroy" -%>
|
146
|
-
context "when the action is done" do
|
147
|
-
|
148
|
-
setup { subject.call(valid_attributes) }
|
149
|
-
|
150
|
-
should "have done whatever it was meant to do!" do
|
151
|
-
<%- @reference_parsed_fields.each do |field| -%>
|
152
|
-
# assert_equal <%= verb %>d_resource.<%= field.name %>, <%= field.name %>
|
153
|
-
<%- end -%>
|
154
|
-
skip("Skipping: Please replace with the correct assertions for this test.")
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|
158
|
-
<%- end -%>
|
159
|
-
|
160
|
-
end
|
161
|
-
|
162
|
-
<%- if verb != "destroy" -%>
|
163
|
-
context "failure" do
|
164
|
-
|
165
|
-
setup { @operation = -> { subject.call(invalid_attributes) } }
|
166
|
-
|
167
|
-
should "return an unsuccessful result" do
|
168
|
-
result = @operation.call
|
169
|
-
|
170
|
-
assert result.failure?
|
171
|
-
<%- @regular_parsed_fields.select { |f| f.requirement == "required" }.each do |field| -%>
|
172
|
-
# assert_equal({:<%= field.name %> => ["must be filled"]}, result.failure.to_h) # rubocop:disable Rails/DeprecatedActiveModelErrorsMethods
|
173
|
-
<%- end -%>
|
174
|
-
skip("Skipping: Add the correct error messages here.")
|
175
|
-
end
|
176
|
-
|
177
|
-
should "not perform the operation" do
|
178
|
-
# assert_no_changes -> { # whatever } do
|
179
|
-
# @operation.call
|
180
|
-
# end
|
181
|
-
skip("Skipping: Add the correct check here.")
|
182
|
-
end
|
183
|
-
|
184
|
-
end
|
185
|
-
<%- end -%>
|
186
|
-
|
187
|
-
end
|
188
|
-
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module TestUnit
|
4
|
-
module Generators
|
5
|
-
module Operations
|
6
|
-
class OperationGenerator < Rails::Generators::NamedBase
|
7
|
-
include ::Operations::Base::Generators::BaseGenerator
|
8
|
-
|
9
|
-
source_root File.expand_path("operation/templates", __dir__)
|
10
|
-
|
11
|
-
def generate_files
|
12
|
-
super
|
13
|
-
|
14
|
-
template "operation_test.rb.erb", "#{root_test_file_path}/operations/#{plural_name}/#{verb}/operation_test.rb"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,5 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_unit/generators/operations/schema_generator" if defined?(Dry::Schema)
|
4
|
-
require "test_unit/generators/operations/operation_generator" if defined?(Dry::Transaction)
|
5
|
-
require "test_unit/generators/operations/contract_generator" if defined?(Dry::Validation)
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module TestUnit
|
4
|
-
module Generators
|
5
|
-
module Operations
|
6
|
-
class SetupGenerator < ::Rails::Generators::Base
|
7
|
-
def copy_initializer_file
|
8
|
-
initializer "operation_generators-test_unit.rb",
|
9
|
-
File.read(File.expand_path("setup/templates/generators.rb.tt", __dir__))
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module TestUnit
|
4
|
-
module Generators
|
5
|
-
module Operations
|
6
|
-
class <%= class_name %>Generator < Rails::Generators::NamedBase
|
7
|
-
include ::Operations::Base::Generators::BaseGenerator
|
8
|
-
|
9
|
-
source_root File.expand_path("<%= singular_name %>/templates", __dir__)
|
10
|
-
|
11
|
-
def generate_files
|
12
|
-
super
|
13
|
-
|
14
|
-
template "<%= singular_name %>_test.rb.erb", "#{root_test_file_path}/operations/#{plural_name}/#{verb}/<%= singular_name %>_test.rb"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module TestUnit
|
4
|
-
module Generators
|
5
|
-
module Operations
|
6
|
-
RSpec.describe <%= class_name %>Generator, type: :generator do
|
7
|
-
setup_default_destination
|
8
|
-
|
9
|
-
tests described_class
|
10
|
-
|
11
|
-
let(:<%= singular_name %>_test_path) { "test/operations/users/create/<%= singular_name %>_test.rb" }
|
12
|
-
|
13
|
-
subject(:<%= singular_name %>_generator) do
|
14
|
-
run_generator(
|
15
|
-
%w[
|
16
|
-
user
|
17
|
-
create
|
18
|
-
]
|
19
|
-
)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "copy templates" do
|
23
|
-
<%= singular_name %>_generator
|
24
|
-
|
25
|
-
expect(File).to exist("#{destination_root}/#{<%= singular_name %>_test_path}")
|
26
|
-
end
|
27
|
-
|
28
|
-
it "uses the expected template files" do
|
29
|
-
<%= singular_name %>_generator
|
30
|
-
|
31
|
-
expect(content_for(<%= singular_name %>_test_path)).to match(/This is <%= singular_name %>.rb.erb/)
|
32
|
-
end
|
33
|
-
|
34
|
-
context "with component option" do
|
35
|
-
let(:<%= singular_name %>_test_path) { "test/components/identity/operations/users/create/<%= singular_name %>_test.rb" }
|
36
|
-
|
37
|
-
subject(:<%= singular_name %>_generator) do
|
38
|
-
run_generator(
|
39
|
-
%w[
|
40
|
-
user
|
41
|
-
create
|
42
|
-
--component identity/users
|
43
|
-
]
|
44
|
-
)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "copy templates" do
|
48
|
-
<%= singular_name %>_generator
|
49
|
-
|
50
|
-
expect(File).to exist("#{destination_root}/#{<%= singular_name %>_test_path}")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
data/lib/test_unit.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "zeitwerk"
|
4
|
-
loader = Zeitwerk::Loader.for_gem
|
5
|
-
loader.setup
|
6
|
-
|
7
|
-
require "rails/generators"
|
8
|
-
|
9
|
-
require "test_unit/generators/operations/setup_generator"
|
10
|
-
|
11
|
-
require "operations/base"
|
12
|
-
|
13
|
-
module TestUnit
|
14
|
-
class Error < StandardError; end
|
15
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
Gem::Specification.new do |spec|
|
4
|
-
spec.name = "dry-operation_generators-test_unit"
|
5
|
-
spec.version = "0.1.0"
|
6
|
-
spec.authors = ["Joel Azemar"]
|
7
|
-
spec.email = ["joel.azemar@gmail.com"]
|
8
|
-
|
9
|
-
spec.summary = "Add the test files of Business Logic actions with Dry Rb ecosystem"
|
10
|
-
spec.homepage = "https://github.com/joel/dry-operation_generators-test_unit"
|
11
|
-
spec.license = "MIT"
|
12
|
-
spec.required_ruby_version = ">= 3.2.2"
|
13
|
-
|
14
|
-
# spec.metadata["allowed_push_host"] = "Set to your gem server 'https://example.com'"
|
15
|
-
|
16
|
-
# spec.metadata["homepage_uri"] = spec.homepage
|
17
|
-
# spec.metadata["source_code_uri"] = "Put your gem's public repo URL here."
|
18
|
-
# spec.metadata["changelog_uri"] = "Put your gem's CHANGELOG.md URL here."
|
19
|
-
|
20
|
-
# Specify which files should be added to the gem when it is released.
|
21
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
-
spec.files = Dir.chdir(__dir__) do
|
23
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
-
(File.expand_path(f) == __FILE__) ||
|
25
|
-
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
26
|
-
end
|
27
|
-
end
|
28
|
-
spec.bindir = "exe"
|
29
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
-
spec.require_paths = ["lib"]
|
31
|
-
|
32
|
-
# Uncomment to register a new dependency of your gem
|
33
|
-
|
34
|
-
spec.add_dependency "dry-operation_generators-base"
|
35
|
-
spec.add_dependency "rails"
|
36
|
-
spec.add_dependency "zeitwerk"
|
37
|
-
|
38
|
-
# For more information and examples about making a new gem, check out our
|
39
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
40
|
-
spec.metadata["rubygems_mfa_required"] = "true"
|
41
|
-
end
|
File without changes
|
File without changes
|