formify 0.17.11 → 0.18.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92290bd077f34427d7c3fae643e120c50f755e03a4b963c207fb9ae577b55943
4
- data.tar.gz: bc297f0e277b6a95d97505e14006bb1a04a8e3a5575d520b5460e7a74ca5b525
3
+ metadata.gz: 5af8a8ef17424640f0c17ab10db57a3d33583502d782735f25105f86137af652
4
+ data.tar.gz: b5e92fbef6b454208e670d5e4b62c6e88700256a81720857c45c6a70603680b5
5
5
  SHA512:
6
- metadata.gz: 4591c40b0b78d043982d6eaa1bf9a00b5ca594cb0c960d4d784965a6b65973a9aa395383637aecfa671735da9a3ee128cb417a6284d529ef2a9a818d73e539f6
7
- data.tar.gz: 769ab8597e36f6a1eaaaee557ef466298bdbd6944a1ce70f75a7c51a4344c559d06a4baca31b7961ec6e914ea6842572b41733e8f561cfbd8a28993c00ac4609
6
+ metadata.gz: f831d099c2c6e6322bce4f2d560510068118912d6659e4d6653706cc1160f103759609e04fa7bc54a468cf4bf5b06d0c89c2705e30744c7bf47301dbc38e1d89
7
+ data.tar.gz: b841eebd0201d2523a1ffab9d356fb1b2c931b90d4f82a67d5868c4307fc8e86d7c1cb25abd013eb1fcf9868dbbdf6c64d62a604194291dfffa6c1303d31991b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- formify (0.17.11)
4
+ formify (0.18.0)
5
5
  rails
6
6
  resonad
7
7
  with_advisory_lock
@@ -1,3 +1,3 @@
1
1
  module Formify
2
- VERSION = '0.17.11'.freeze
2
+ VERSION = '0.18.0'.freeze
3
3
  end
@@ -16,6 +16,11 @@ class FormGenerator < Rails::Generators::NamedBase
16
16
  description: 'Disable naming convention transformations like forcing plural collections',
17
17
  type: :boolean
18
18
 
19
+ class_option :spec_comments,
20
+ default: true,
21
+ description: 'Set to false to not include any comments in generated specs.',
22
+ type: :boolean
23
+
19
24
  def transform_naming
20
25
  return unless pluralize_collection?
21
26
 
@@ -85,6 +90,18 @@ class FormGenerator < Rails::Generators::NamedBase
85
90
  .map(&:first)
86
91
  end
87
92
 
93
+ def factory?(attr)
94
+ factories.include?(attr.to_sym)
95
+ end
96
+
97
+ def factory_bot?
98
+ @factory_bot = Class.const_defined?(FactoryBot)
99
+ end
100
+
101
+ def factories
102
+ @factories ||= FactoryBot.factories.map(&:name)
103
+ end
104
+
88
105
  def form
89
106
  @form ||= name.split('/').last.to_s.underscore
90
107
  end
@@ -131,6 +148,10 @@ class FormGenerator < Rails::Generators::NamedBase
131
148
  @scope_names ||= scopes.map(&:camelcase)
132
149
  end
133
150
 
151
+ def spec_comments?
152
+ @spec_comments ||= options[:spec_comments]
153
+ end
154
+
134
155
  def split_name
135
156
  @split_name ||= name.split('/')
136
157
  end
@@ -6,20 +6,30 @@ require 'formify/spec_helpers'
6
6
  describe Forms::<%= class_name %>, type: :form do
7
7
  include Formify::SpecHelpers
8
8
 
9
+ <% all_attributes.each do |attr| -%>
10
+ <% if factory_bot? && factory?(attr) -%>
11
+ let(:<%= attr %>) { FacotryBot.create(<%= attr %>) }
12
+ <% else -%>
13
+ let(:<%= attr %>) { <%= attr.upcase %>_VALUE }
14
+ <% end -%>
15
+ <% end -%>
16
+
17
+ <% if spec_comments? -%>
9
18
  # :attributes is used to initialize the form.
10
19
  # These values should result in a valid form.
11
20
  # You can override these in blocks or use let(:attributes_override) { { foo: bar } }
21
+ <% end -%>
12
22
  let(:attributes) do
13
23
  {
14
24
  <% all_attributes.each_with_index do |attr, i| -%>
15
- <%= attr %>: <%= attr.upcase %>_VALUE<%= ',' unless all_attributes.count == (i + 1)%>
25
+ <%= attr %>: <%= attr %><%= ',' unless all_attributes.count == (i + 1)%>
16
26
  <% end -%>
17
27
  }
18
28
  end
19
29
 
20
- it { expect_valid } # Expect the form to be valid
30
+ it { expect_valid }<% if spec_comments? -%> # Expect the form to be valid<% end -%>
21
31
  it { expect(result).to be_success }
22
- it { expect(value).to be_a(<%= inferred_model_name %>) } # Model name inferred
32
+ it { expect(value).to be_a(<%= inferred_model_name %>) }<% if spec_comments? -%> # Model name inferred<% end -%>
23
33
 
24
34
  <% all_attributes.each do |attr| -%>
25
35
  describe '#<%= attr %>' do
@@ -29,8 +39,10 @@ describe Forms::<%= class_name %>, type: :form do
29
39
  end
30
40
 
31
41
  <% end -%>
42
+ <% if spec_comments? -%>
32
43
  # Other Expectation Helpers
33
44
  # xit { expect_error_message(message) }
34
45
  # xit { expect_error_with_attribute(attribute) }
35
46
  # xit { expect_not_valid(attribute: nil, message: nil) } # :attribute and :message are optional
47
+ <% end -%>
36
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.11
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Jackson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-20 00:00:00.000000000 Z
11
+ date: 2019-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler