factory_bot_generator 0.2.2 → 0.3.0
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 +5 -5
- data/README.md +0 -8
- data/lib/factory_bot_generator/version.rb +1 -1
- data/lib/factory_bot_generator.erb +16 -4
- data/lib/factory_bot_generator.rb +7 -13
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d109d84bb9b1f53730ad78b3e64220fc46e3a6914339601192da8963dc90a98d
|
4
|
+
data.tar.gz: 6d46bba5c9cf44ab321ca7284de9449690ab52984bb976c83e79088867beb22a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8feb1156a77a804540f806b883ec1b35a904544854fdd91393a0df5055a97b3774a53b8e089445f19b3dd1277bd3e02013b7793a6af8e089ff7a7eb4ace4c7d9
|
7
|
+
data.tar.gz: b138f3540710d5e67059c0d031f527a9241b96591369e8bae197cd604414a40846a825b7aa2629f6a00e19bfb04556720286620ca1a7f5911cee05ec572d8a3a
|
data/README.md
CHANGED
@@ -29,15 +29,7 @@ puts FactoryBotGenerator::Base.render(user, { exclude: [:password, :last_name, :
|
|
29
29
|
|
30
30
|
```
|
31
31
|
|
32
|
-
## Development
|
33
32
|
|
34
|
-
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.
|
35
|
-
|
36
|
-
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
37
|
-
|
38
|
-
## Contributing
|
39
|
-
|
40
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/factory_bot_generator.
|
41
33
|
|
42
34
|
## License
|
43
35
|
|
@@ -1,8 +1,20 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :<%= name %>, class: <%= record.class %> do
|
3
|
-
|
4
|
-
|
5
|
-
<%= "%-#{indent}s" % column %>
|
6
|
-
|
3
|
+
<%- columns.each do |column| -%>
|
4
|
+
<%- quote = FactoryBotGenerator::Base::QUOTE_AROUND_VALUE_TYPES.include?(record.class.columns_hash[column].type) -%>
|
5
|
+
<%= "%-#{indent}s" % column %> <%= "'" if quote %><%= record.public_send(column) %><%= "'" if quote %>
|
6
|
+
<%- end -%>
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
--------------------------------
|
11
|
+
|
12
|
+
FactoryBot.define do
|
13
|
+
factory :<%= name %>, class: <%= record.class %> do
|
14
|
+
<%- columns.each do |column| -%>
|
15
|
+
<%- next if record.public_send(column).blank? -%>
|
16
|
+
<%- quote = FactoryBotGenerator::Base::QUOTE_AROUND_VALUE_TYPES.include?(record.class.columns_hash[column].type) -%>
|
17
|
+
<%= "%-#{indent}s" % column %> <%= "'" if quote %><%= record.public_send(column) %><%= "'" if quote %>
|
18
|
+
<%- end -%>
|
7
19
|
end
|
8
20
|
end
|
@@ -6,28 +6,22 @@ module FactoryBotGenerator
|
|
6
6
|
class Base
|
7
7
|
QUOTE_AROUND_VALUE_TYPES = %i[string date datetime text].freeze
|
8
8
|
EXCLUDE_COLUMNS = %w[created_at updated_at].freeze
|
9
|
+
TEMPLATE_PATH = File.join(File.dirname(__FILE__), 'factory_bot_generator.erb')
|
10
|
+
TEMPLATE = File.read(TEMPLATE_PATH)
|
9
11
|
|
10
12
|
def self.render(record, options = {})
|
11
13
|
new(record, options).render
|
12
14
|
end
|
13
15
|
|
14
|
-
attr_reader :record, :options
|
15
|
-
|
16
16
|
def initialize(record, options)
|
17
17
|
@record = record
|
18
18
|
@options = options
|
19
19
|
end
|
20
20
|
|
21
|
+
attr_reader :record, :options
|
22
|
+
|
21
23
|
def render
|
22
|
-
|
23
|
-
file: 'factory_bot_generator.erb',
|
24
|
-
locals: {
|
25
|
-
name: name,
|
26
|
-
columns: columns,
|
27
|
-
record: record,
|
28
|
-
indent: indent
|
29
|
-
}
|
30
|
-
)
|
24
|
+
ERB.new(TEMPLATE, trim_mode: '-').result(binding)
|
31
25
|
end
|
32
26
|
|
33
27
|
private
|
@@ -41,11 +35,11 @@ module FactoryBotGenerator
|
|
41
35
|
end
|
42
36
|
|
43
37
|
def indent
|
44
|
-
@indent ||= columns.max_by(&:size).size
|
38
|
+
@indent ||= columns.max_by(&:size).size + 1
|
45
39
|
end
|
46
40
|
|
47
41
|
def record_class
|
48
|
-
record.class
|
42
|
+
@record_class ||= record.class
|
49
43
|
end
|
50
44
|
|
51
45
|
def exclude_columns
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_bot_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Serge Kislak
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundle-audit
|
@@ -121,7 +121,7 @@ homepage: ''
|
|
121
121
|
licenses:
|
122
122
|
- MIT
|
123
123
|
metadata: {}
|
124
|
-
post_install_message:
|
124
|
+
post_install_message:
|
125
125
|
rdoc_options: []
|
126
126
|
require_paths:
|
127
127
|
- lib
|
@@ -136,9 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
- !ruby/object:Gem::Version
|
137
137
|
version: '0'
|
138
138
|
requirements: []
|
139
|
-
|
140
|
-
|
141
|
-
signing_key:
|
139
|
+
rubygems_version: 3.3.26
|
140
|
+
signing_key:
|
142
141
|
specification_version: 4
|
143
142
|
summary: Render FactoryBot factory existing object.
|
144
143
|
test_files: []
|