dry-operation_generators-rspec 0.2.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +24 -0
- data/.rubocop_todo.yml +47 -0
- data/CHANGELOG.md +14 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +96 -0
- data/Rakefile +14 -0
- data/lib/dry-operation_generators-rspec/version.rb +5 -0
- data/lib/dry-operation_generators-rspec.rb +3 -0
- data/lib/generators/rspec/operations/schema/templates/base/schema_spec.rb.erb +73 -0
- data/lib/generators/rspec/operations/schema/templates/schema_spec.rb.erb +93 -0
- data/lib/generators/rspec/operations/schema_generator.rb +28 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a8cc055729dfc76da929f79df028240f7f1d06379326f8efb2990c325fddead6
|
4
|
+
data.tar.gz: 1b6436636b53fdd7851c52e4e82e79fb9017cf20467314f35d2c31f77baae537
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c62079fbc3c52597921f0d780ad37b5d4e8189cdeeabcead7d01c55be1047525a8b13a0fe391a3d476759815dc30f26f2b6691ff9773413ceeb3c4ad3a142fb2
|
7
|
+
data.tar.gz: cd4ac8a2d5b1cca41b4883cf25f0bc5c21fdc5b92fd6a221935c3cb0272a46ffbcf3ca95400d008f0f7d92922162230d7a1dbe2964db2c96bd42aafbe684d5b5
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
require:
|
4
|
+
- rubocop-performance
|
5
|
+
- rubocop-rake
|
6
|
+
- rubocop-rspec
|
7
|
+
|
8
|
+
AllCops:
|
9
|
+
TargetRubyVersion: 3.3
|
10
|
+
NewCops: enable
|
11
|
+
|
12
|
+
Style/StringLiterals:
|
13
|
+
Enabled: true
|
14
|
+
EnforcedStyle: double_quotes
|
15
|
+
|
16
|
+
Style/StringLiteralsInInterpolation:
|
17
|
+
Enabled: true
|
18
|
+
EnforcedStyle: double_quotes
|
19
|
+
|
20
|
+
Style/Documentation:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Lint/SuppressedException:
|
24
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2024-08-09 12:12:46 UTC using RuboCop version 1.65.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: Severity, Include.
|
11
|
+
# Include: **/*.gemspec
|
12
|
+
Gemspec/RequiredRubyVersion:
|
13
|
+
Exclude:
|
14
|
+
- 'dry-operation_generators-rspec.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-rspec.rb'
|
24
|
+
|
25
|
+
# Offense count: 1
|
26
|
+
RSpec/MessageChain:
|
27
|
+
Exclude:
|
28
|
+
- 'spec/support/pre/rails.rb'
|
29
|
+
|
30
|
+
# Offense count: 3
|
31
|
+
RSpec/MultipleExpectations:
|
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/rspec/operations/schema_generator_spec.rb'
|
41
|
+
|
42
|
+
# Offense count: 1
|
43
|
+
# This cop supports safe autocorrection (--autocorrect).
|
44
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
|
45
|
+
# URISchemes: http, https
|
46
|
+
Layout/LineLength:
|
47
|
+
Max: 146
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
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.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
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
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
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.
|
45
|
+
|
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.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
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.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
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.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
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:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
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.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
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.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
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.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
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.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
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].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ 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
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Joel AZEMAR
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# Operation Generators RSpec
|
2
|
+
|
3
|
+
Operation Generators RSpec is a utility library designed to add the test file to the files required for new Business Logic actions with Dry Rb ecosystem.
|
4
|
+
|
5
|
+
This library doesn't make sense without [dry-operation_generators](https://github.com/joel/dry-operation_generators)
|
6
|
+
|
7
|
+
Generates the counterpart test files:
|
8
|
+
|
9
|
+
```shell
|
10
|
+
spec/operations/users/create/
|
11
|
+
├── contract_spec.rb
|
12
|
+
├── operation_spec.rb
|
13
|
+
└── schema_spec.rb
|
14
|
+
```
|
15
|
+
|
16
|
+
Please check out [operation_generators](https://github.com/joel/dry-operation_generators)
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Install the gem and add to the application's Gemfile by executing:
|
21
|
+
|
22
|
+
$ bundle add operation_generators-rspec
|
23
|
+
|
24
|
+
If Bundler is not being used to manage dependencies, install the gem by executing:
|
25
|
+
|
26
|
+
$ gem install operation_generators-rspec
|
27
|
+
|
28
|
+
NOTE: The gem needs to be required as `rspec`
|
29
|
+
|
30
|
+
$ gem "operation_generators-rspec", require: "rspec"
|
31
|
+
|
32
|
+
Otherwise, you can require "rspec" on your code.
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
Once installed, you can print out the Rails Generators Help:
|
37
|
+
|
38
|
+
```shell
|
39
|
+
rails generate --help
|
40
|
+
```
|
41
|
+
|
42
|
+
You should see
|
43
|
+
|
44
|
+
```shell
|
45
|
+
Operations:
|
46
|
+
operations:schema
|
47
|
+
|
48
|
+
Rspec:
|
49
|
+
rspec:operations:schema
|
50
|
+
```
|
51
|
+
|
52
|
+
Now the Generators should appear:
|
53
|
+
|
54
|
+
```shell
|
55
|
+
Rspec:
|
56
|
+
...
|
57
|
+
rspec:operations:contract
|
58
|
+
rspec:operations:operation
|
59
|
+
rspec:operations:schema
|
60
|
+
...
|
61
|
+
```
|
62
|
+
|
63
|
+
They are automatically call when the generator it's call:
|
64
|
+
|
65
|
+
```shell
|
66
|
+
rails generate operations:contract user create firstname:string{optional} --test_framework=rspec
|
67
|
+
invoke rspec
|
68
|
+
create spec/operations/users/create/contract_spec.rb
|
69
|
+
create app/operations/users/create/contract.rb
|
70
|
+
```
|
71
|
+
|
72
|
+
## Development
|
73
|
+
|
74
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
75
|
+
|
76
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
There is a generator of generators you can use to quickly add a new generator:
|
81
|
+
|
82
|
+
```shell
|
83
|
+
./bin/generator <generator name>
|
84
|
+
```
|
85
|
+
|
86
|
+
That provides the skeleton for the new generator. Note that the test suite should still run after the generated files.
|
87
|
+
|
88
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/orgs/joel/dry-operation_generators-rspec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/joel/dry-operation_generators-rspec/blob/main/CODE_OF_CONDUCT.md).
|
89
|
+
|
90
|
+
## License
|
91
|
+
|
92
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
93
|
+
|
94
|
+
## Code of Conduct
|
95
|
+
|
96
|
+
Everyone interacting in the Isms project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/joel/dry-operation_generators-rspec/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require "rubocop/rake_task"
|
9
|
+
|
10
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
11
|
+
task.options = ["-A"] # auto_correct
|
12
|
+
end
|
13
|
+
|
14
|
+
task default: %i[spec rubocop]
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
module <%= class_name.pluralize %>
|
6
|
+
module Base
|
7
|
+
class SchemaTest < ActiveSupport::TestCase
|
8
|
+
|
9
|
+
# This method should return attributes with the keys as symbols.
|
10
|
+
# symbolize_keys
|
11
|
+
def model_attributes
|
12
|
+
# attributes_for(:<%= singular_name %>) # More efficient
|
13
|
+
create(:<%= singular_name %>).attributes.symbolize_keys
|
14
|
+
end
|
15
|
+
|
16
|
+
def attributes
|
17
|
+
model_attributes.merge(
|
18
|
+
schema_attributes
|
19
|
+
).slice(*described_class.key_list)
|
20
|
+
skip("Skipping: Please replace with the correct attributes for this test.")
|
21
|
+
end
|
22
|
+
|
23
|
+
def schema_attributes
|
24
|
+
{
|
25
|
+
# TODO: Add attributes here.
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def valid_attributes
|
30
|
+
attributes
|
31
|
+
end
|
32
|
+
|
33
|
+
def invalid_attributes
|
34
|
+
attributes.merge(
|
35
|
+
{
|
36
|
+
# TODO: Add attributes here
|
37
|
+
}
|
38
|
+
)
|
39
|
+
skip("Skipping: Please replace with the correct attributes for this test.")
|
40
|
+
end
|
41
|
+
|
42
|
+
should "not provide attributes that are not defined in the schema" do
|
43
|
+
assert_empty schema_attributes.keys - described_class.key_list
|
44
|
+
end
|
45
|
+
|
46
|
+
context "validations" do
|
47
|
+
|
48
|
+
subject { described_class }
|
49
|
+
|
50
|
+
context "with valid attributes" do
|
51
|
+
|
52
|
+
should "be successful" do
|
53
|
+
assert subject.call(valid_attributes).success?
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
context "with invalid attributes" do
|
59
|
+
|
60
|
+
should "be unsuccessful" do
|
61
|
+
result = subject.call(invalid_attributes)
|
62
|
+
assert result.failure?
|
63
|
+
# assert_equal({:email => ["must be filled"]}, result.errors.to_h) # rubocop:disable Rails/DeprecatedActiveModelErrorsMethods
|
64
|
+
skip("Skipping: Add the correct error messages here.")
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
module <%= class_name.pluralize %>
|
6
|
+
module <%= verb.capitalize %>
|
7
|
+
class SchemaTest < ActiveSupport::TestCase
|
8
|
+
|
9
|
+
# This method should return attributes with the keys as symbols.
|
10
|
+
# symbolize_keys
|
11
|
+
# i.e create(:user).attributes.symbolize_keys
|
12
|
+
def model_attributes
|
13
|
+
# attributes_for(:<%= singular_name %>) # More efficient
|
14
|
+
create(:<%= singular_name %>).attributes.symbolize_keys
|
15
|
+
end
|
16
|
+
|
17
|
+
def attributes
|
18
|
+
model_attributes.merge(
|
19
|
+
schema_attributes
|
20
|
+
).slice(*described_class.key_list)
|
21
|
+
skip("Skipping: Please replace with the correct attributes for this test.")
|
22
|
+
end
|
23
|
+
|
24
|
+
def schema_attributes
|
25
|
+
{
|
26
|
+
<%- if verb =~ /update|all/ -%>
|
27
|
+
id: SecureRandom.uuid_v7,
|
28
|
+
<%- end -%>
|
29
|
+
# TODO: Add attributes here.
|
30
|
+
<%- @reference_parsed_fields.each do |field| -%>
|
31
|
+
<%- case Operations.configuration.primary_key_type -%>
|
32
|
+
<%- when :integer -%>
|
33
|
+
<%= field.foreign_key %>: 42,
|
34
|
+
<%- when /string|uuid/ -%>
|
35
|
+
<%= field.foreign_key %>: SecureRandom.uuid_v7,
|
36
|
+
<%- end -%>
|
37
|
+
<%- end -%>
|
38
|
+
<%- @regular_parsed_fields.each do |field| -%>
|
39
|
+
<%= field.name %>: "<%= field.type %>",
|
40
|
+
<%- end -%>
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def valid_attributes
|
45
|
+
attributes
|
46
|
+
end
|
47
|
+
|
48
|
+
def invalid_attributes
|
49
|
+
attributes.merge(
|
50
|
+
{
|
51
|
+
# TODO: Add attributes here
|
52
|
+
<%- @regular_parsed_fields.select { |f| f.requirement == "required" }.each do |field| -%>
|
53
|
+
# <%= field.name %>: nil,
|
54
|
+
<%- end -%>
|
55
|
+
}
|
56
|
+
)
|
57
|
+
skip("Skipping: Please replace with the correct attributes for this test.")
|
58
|
+
end
|
59
|
+
|
60
|
+
should "not provide attributes that are not defined in the schema" do
|
61
|
+
assert_empty schema_attributes.keys - described_class.key_list
|
62
|
+
end
|
63
|
+
|
64
|
+
context "validations" do
|
65
|
+
|
66
|
+
subject { described_class }
|
67
|
+
|
68
|
+
context "with valid attributes" do
|
69
|
+
|
70
|
+
should "be successful" do
|
71
|
+
assert subject.call(valid_attributes).success?
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
context "with invalid attributes" do
|
77
|
+
|
78
|
+
should "be unsuccessful" do
|
79
|
+
result = subject.call(invalid_attributes)
|
80
|
+
assert result.failure?
|
81
|
+
<%- @regular_parsed_fields.select { |f| f.requirement == "required" }.each do |field| -%>
|
82
|
+
# assert_equal({:<%= field.name %> => ["must be filled"]}, result.errors.to_h) # rubocop:disable Rails/DeprecatedActiveModelErrorsMethods
|
83
|
+
<%- end -%>
|
84
|
+
skip("Skipping: Add the correct error messages here.")
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators"
|
4
|
+
require "operations/base"
|
5
|
+
|
6
|
+
# hook_for :test_framework, as: "operations:schema"
|
7
|
+
# "rspec:operations:schema" => Rspec::Generators::Operations::SchemaGenerator
|
8
|
+
|
9
|
+
module Rspec
|
10
|
+
module Generators
|
11
|
+
module Operations
|
12
|
+
class SchemaGenerator < Rails::Generators::NamedBase
|
13
|
+
include ::Operations::Base::Generators::BaseGenerator
|
14
|
+
|
15
|
+
source_root File.expand_path("schema/templates", __dir__)
|
16
|
+
|
17
|
+
desc "Creates a schema test file for the operation"
|
18
|
+
|
19
|
+
def generate_files
|
20
|
+
super
|
21
|
+
|
22
|
+
template "schema_spec.rb.erb", "#{root_test_file_path}/operations/#{plural_name}/#{verb}/schema_spec.rb"
|
23
|
+
template "base/schema_spec.rb.erb", "#{root_test_file_path}/operations/#{plural_name}/base/schema_spec.rb"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dry-operation_generators-rspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0.alpha1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joel AZEMAR
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-08-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
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
|
+
description: Write a longer description or delete this line.
|
28
|
+
email:
|
29
|
+
- joel.azemar@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".rspec"
|
35
|
+
- ".rubocop.yml"
|
36
|
+
- ".rubocop_todo.yml"
|
37
|
+
- CHANGELOG.md
|
38
|
+
- CODE_OF_CONDUCT.md
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/dry-operation_generators-rspec.rb
|
43
|
+
- lib/dry-operation_generators-rspec/version.rb
|
44
|
+
- lib/generators/rspec/operations/schema/templates/base/schema_spec.rb.erb
|
45
|
+
- lib/generators/rspec/operations/schema/templates/schema_spec.rb.erb
|
46
|
+
- lib/generators/rspec/operations/schema_generator.rb
|
47
|
+
homepage: http://mygemserver.com
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata:
|
51
|
+
rubygems_mfa_required: 'true'
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 3.0.0
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubygems_version: 3.5.11
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Write a short summary, because RubyGems requires one.
|
71
|
+
test_files: []
|