formify 0.23.3 → 0.23.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d387f14adee1aab5ba2f626904abe5fc20eee18f8c6d82c0968970d45850ea5d
4
- data.tar.gz: 9b42bb3728eacc41ed335b072cb7ff62674b8962c0a88a89b7b807e178751fcd
3
+ metadata.gz: b8ec24756e4113f41b073fae53bea2727af37448702997cb7300ad998e711892
4
+ data.tar.gz: 67a4b6381c4d1f450aa5d4f4f8d129503ab9ac8ae5f3295a10439ef9d8f5fe98
5
5
  SHA512:
6
- metadata.gz: a4370591ee00cd01b5326083af40b14e68782cff2372a6d07976f9e1dbac031ed1650f83a078c8b27a6e72e4f4e8b3888cb617f24b936af142ecd6f9266beb61
7
- data.tar.gz: 64f08ef88b34e267d7e85c2caf7c6db5426ec06e9232a75607b66b51e8266aa67136c79187b1685813aade23ba194ef8eba8e47a819c4b2f37a0a06ec607b1fd
6
+ metadata.gz: e4247a9ffe03b3ada26969f4aeedb22581fb42e7eb6980a06c3ac8fb32c2317c7a48e1c365c8a9a403077dad6efac8cb3c77f5c4243161e1c77895762c9bf15c
7
+ data.tar.gz: 52e1920e659391229a66c0b26e01426d433a84fc508ab39c0b2152028479e0916652a9481170bd0268b461eeddb79f4cdcba69770f5bf19d3ced1c5d8fc55589
data/.gitignore CHANGED
@@ -49,4 +49,5 @@ build-iPhoneSimulator/
49
49
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
50
  .rvmrc
51
51
 
52
- .rspec_status
52
+ .rspec_status
53
+ .DS_Store
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- formify (0.23.3)
4
+ formify (0.23.4)
5
5
  rails
6
6
  resonad
7
7
  with_advisory_lock
@@ -9,63 +9,63 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actioncable (6.0.2.1)
13
- actionpack (= 6.0.2.1)
12
+ actioncable (6.0.2.2)
13
+ actionpack (= 6.0.2.2)
14
14
  nio4r (~> 2.0)
15
15
  websocket-driver (>= 0.6.1)
16
- actionmailbox (6.0.2.1)
17
- actionpack (= 6.0.2.1)
18
- activejob (= 6.0.2.1)
19
- activerecord (= 6.0.2.1)
20
- activestorage (= 6.0.2.1)
21
- activesupport (= 6.0.2.1)
16
+ actionmailbox (6.0.2.2)
17
+ actionpack (= 6.0.2.2)
18
+ activejob (= 6.0.2.2)
19
+ activerecord (= 6.0.2.2)
20
+ activestorage (= 6.0.2.2)
21
+ activesupport (= 6.0.2.2)
22
22
  mail (>= 2.7.1)
23
- actionmailer (6.0.2.1)
24
- actionpack (= 6.0.2.1)
25
- actionview (= 6.0.2.1)
26
- activejob (= 6.0.2.1)
23
+ actionmailer (6.0.2.2)
24
+ actionpack (= 6.0.2.2)
25
+ actionview (= 6.0.2.2)
26
+ activejob (= 6.0.2.2)
27
27
  mail (~> 2.5, >= 2.5.4)
28
28
  rails-dom-testing (~> 2.0)
29
- actionpack (6.0.2.1)
30
- actionview (= 6.0.2.1)
31
- activesupport (= 6.0.2.1)
29
+ actionpack (6.0.2.2)
30
+ actionview (= 6.0.2.2)
31
+ activesupport (= 6.0.2.2)
32
32
  rack (~> 2.0, >= 2.0.8)
33
33
  rack-test (>= 0.6.3)
34
34
  rails-dom-testing (~> 2.0)
35
35
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
36
- actiontext (6.0.2.1)
37
- actionpack (= 6.0.2.1)
38
- activerecord (= 6.0.2.1)
39
- activestorage (= 6.0.2.1)
40
- activesupport (= 6.0.2.1)
36
+ actiontext (6.0.2.2)
37
+ actionpack (= 6.0.2.2)
38
+ activerecord (= 6.0.2.2)
39
+ activestorage (= 6.0.2.2)
40
+ activesupport (= 6.0.2.2)
41
41
  nokogiri (>= 1.8.5)
42
- actionview (6.0.2.1)
43
- activesupport (= 6.0.2.1)
42
+ actionview (6.0.2.2)
43
+ activesupport (= 6.0.2.2)
44
44
  builder (~> 3.1)
45
45
  erubi (~> 1.4)
46
46
  rails-dom-testing (~> 2.0)
47
47
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
48
- activejob (6.0.2.1)
49
- activesupport (= 6.0.2.1)
48
+ activejob (6.0.2.2)
49
+ activesupport (= 6.0.2.2)
50
50
  globalid (>= 0.3.6)
51
- activemodel (6.0.2.1)
52
- activesupport (= 6.0.2.1)
53
- activerecord (6.0.2.1)
54
- activemodel (= 6.0.2.1)
55
- activesupport (= 6.0.2.1)
56
- activestorage (6.0.2.1)
57
- actionpack (= 6.0.2.1)
58
- activejob (= 6.0.2.1)
59
- activerecord (= 6.0.2.1)
51
+ activemodel (6.0.2.2)
52
+ activesupport (= 6.0.2.2)
53
+ activerecord (6.0.2.2)
54
+ activemodel (= 6.0.2.2)
55
+ activesupport (= 6.0.2.2)
56
+ activestorage (6.0.2.2)
57
+ actionpack (= 6.0.2.2)
58
+ activejob (= 6.0.2.2)
59
+ activerecord (= 6.0.2.2)
60
60
  marcel (~> 0.3.1)
61
- activesupport (6.0.2.1)
61
+ activesupport (6.0.2.2)
62
62
  concurrent-ruby (~> 1.0, >= 1.0.2)
63
63
  i18n (>= 0.7, < 2)
64
64
  minitest (~> 5.1)
65
65
  tzinfo (~> 1.1)
66
66
  zeitwerk (~> 2.2)
67
67
  builder (3.2.4)
68
- concurrent-ruby (1.1.5)
68
+ concurrent-ruby (1.1.6)
69
69
  coveralls (0.8.23)
70
70
  json (>= 1.8, < 3)
71
71
  simplecov (~> 0.16.1)
@@ -88,40 +88,40 @@ GEM
88
88
  mini_mime (>= 0.1.1)
89
89
  marcel (0.3.3)
90
90
  mimemagic (~> 0.3.2)
91
- method_source (0.9.2)
91
+ method_source (1.0.0)
92
92
  mimemagic (0.3.4)
93
93
  mini_mime (1.0.2)
94
94
  mini_portile2 (2.4.0)
95
95
  minitest (5.14.0)
96
96
  nio4r (2.5.2)
97
- nokogiri (1.10.7)
97
+ nokogiri (1.10.9)
98
98
  mini_portile2 (~> 2.4.0)
99
- rack (2.1.2)
99
+ rack (2.2.2)
100
100
  rack-test (1.1.0)
101
101
  rack (>= 1.0, < 3)
102
- rails (6.0.2.1)
103
- actioncable (= 6.0.2.1)
104
- actionmailbox (= 6.0.2.1)
105
- actionmailer (= 6.0.2.1)
106
- actionpack (= 6.0.2.1)
107
- actiontext (= 6.0.2.1)
108
- actionview (= 6.0.2.1)
109
- activejob (= 6.0.2.1)
110
- activemodel (= 6.0.2.1)
111
- activerecord (= 6.0.2.1)
112
- activestorage (= 6.0.2.1)
113
- activesupport (= 6.0.2.1)
102
+ rails (6.0.2.2)
103
+ actioncable (= 6.0.2.2)
104
+ actionmailbox (= 6.0.2.2)
105
+ actionmailer (= 6.0.2.2)
106
+ actionpack (= 6.0.2.2)
107
+ actiontext (= 6.0.2.2)
108
+ actionview (= 6.0.2.2)
109
+ activejob (= 6.0.2.2)
110
+ activemodel (= 6.0.2.2)
111
+ activerecord (= 6.0.2.2)
112
+ activestorage (= 6.0.2.2)
113
+ activesupport (= 6.0.2.2)
114
114
  bundler (>= 1.3.0)
115
- railties (= 6.0.2.1)
115
+ railties (= 6.0.2.2)
116
116
  sprockets-rails (>= 2.0.0)
117
117
  rails-dom-testing (2.0.3)
118
118
  activesupport (>= 4.2.0)
119
119
  nokogiri (>= 1.6)
120
120
  rails-html-sanitizer (1.3.0)
121
121
  loofah (~> 2.3)
122
- railties (6.0.2.1)
123
- actionpack (= 6.0.2.1)
124
- activesupport (= 6.0.2.1)
122
+ railties (6.0.2.2)
123
+ actionpack (= 6.0.2.2)
124
+ activesupport (= 6.0.2.2)
125
125
  method_source
126
126
  rake (>= 0.8.7)
127
127
  thor (>= 0.20.3, < 2.0)
@@ -164,7 +164,7 @@ GEM
164
164
  websocket-extensions (0.1.4)
165
165
  with_advisory_lock (4.6.0)
166
166
  activerecord (>= 4.2)
167
- zeitwerk (2.2.2)
167
+ zeitwerk (2.3.0)
168
168
 
169
169
  PLATFORMS
170
170
  ruby
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Formify
4
+ module ControllerHelpers # :nodoc:
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ def redirect_to_with_flash(*args, **keywords)
9
+ keywords.slice(%i[danger info success]).each do |k, v|
10
+ flash[k] = v
11
+ end
12
+
13
+ Rails.logger.info "Redirecting to: #{args.first}"
14
+
15
+ super(*args, **keywords)
16
+ end
17
+
18
+ def render_form_result(form:, on_failure: nil, on_success: nil, result:)
19
+ if result.success?
20
+ if form.translation_success.present?
21
+ flash[:success] = form.translation_success
22
+ end
23
+ on_success.call(result) if on_success.present?
24
+ elsif on_failure.is_a?(Proc)
25
+ flash[:danger] = result.error.message
26
+ on_failure.call(result) if on_failure.present?
27
+ else
28
+ flash.now[:danger] = result.error.message
29
+ render on_failure
30
+ end
31
+
32
+ yield(result) if block_given?
33
+ end
34
+
35
+ def save_and_render_form(form:, on_failure: nil, on_success: nil, &block)
36
+ render_form_result(
37
+ form: form,
38
+ on_failure: on_failure,
39
+ on_success: on_success,
40
+ result: form.save,
41
+ &block
42
+ )
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module Formify
2
- VERSION = '0.23.3'.freeze
2
+ VERSION = '0.23.4'.freeze
3
3
  end
@@ -49,12 +49,22 @@ class FormGenerator < Rails::Generators::NamedBase
49
49
 
50
50
  def all_attributes
51
51
  @all_attributes ||= begin
52
- ret = flattened_form_attributes
52
+ flattened_form_attributes
53
53
  .map(&:strip)
54
54
  .sort
55
55
  end
56
56
  end
57
57
 
58
+ def all_attributes_to_pass
59
+ @all_attributes_to_pass ||= begin
60
+ ret = flattened_form_attributes
61
+ .map(&:strip)
62
+ .sort
63
+ ret.delete(first_attribute) if create?
64
+ ret
65
+ end
66
+ end
67
+
58
68
  def attributes_with_delegates
59
69
  @attributes_with_delegates ||= attributes_and_delegates.keys.sort
60
70
  end
@@ -24,8 +24,8 @@ describe Forms::<%= class_name %>, type: :form do
24
24
  <% if all_attributes.any? %>
25
25
  let(:attributes) do
26
26
  {
27
- <% all_attributes.each_with_index do |attr, i| -%>
28
- <%= attr %>: <%= attr %><%= ',' unless all_attributes.count == (i + 1)%>
27
+ <% all_attributes_to_pass.each_with_index do |attr, i| -%>
28
+ <%= attr %>: <%= attr %><%= ',' unless all_attributes_to_pass.count == (i + 1)%>
29
29
  <% end -%>
30
30
  }
31
31
  end
@@ -34,10 +34,14 @@ describe Forms::<%= class_name %>, type: :form do
34
34
  it { expect_valid }<% if spec_comments? -%> # Expect the form to be valid<% end %>
35
35
  it { expect(result).to be_success }
36
36
  it { expect(value).to be_a(<%= inferred_model_name %>) }<% if spec_comments? -%> # Model name inferred<% end %>
37
+ <% all_attributes.each do |attr| -%>
38
+ it { expect(value.<%= attr %>).to eq(<%= attr %>)}
39
+ <% end -%>
37
40
  <% all_attributes.each do |attr| -%>
38
41
 
39
42
  describe '#<%= attr %>' do
40
43
  it { expect_error_with_missing_attribute(:<%= attr %>) }
44
+ it { expect_error_with_attribute_value(:<%= attr %>, nil) }
41
45
  xit { expect_error_with_attribute_value(:<%= attr %>, <%= attr.upcase %>_BAD_VALUE, message: nil) } # :message is optional
42
46
  xit { expect_valid_with_attribute_value(:<%= attr %>, <%= attr.upcase %>_GOOD_VALUE) }
43
47
  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.23.3
4
+ version: 0.23.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Jackson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-01 00:00:00.000000000 Z
11
+ date: 2020-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,6 +131,7 @@ files:
131
131
  - bin/setup
132
132
  - formify.gemspec
133
133
  - lib/formify.rb
134
+ - lib/formify/controller_helpers.rb
134
135
  - lib/formify/errors/form_error.rb
135
136
  - lib/formify/errors/validation_error.rb
136
137
  - lib/formify/form.rb