yorisoi 0.0.1
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 +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +8 -0
- data/.travis.yml +22 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +173 -0
- data/MIT-LICENSE +20 -0
- data/README.md +5 -0
- data/Rakefile +4 -0
- data/lib/tasks/yorisoi_tasks.rake +4 -0
- data/lib/yorisoi/version.rb +3 -0
- data/lib/yorisoi.rb +221 -0
- data/spec/controllers/samples_controller_spec.rb +52 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/samples.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/assets/stylesheets/samples.css +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/samples_controller.rb +21 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/samples_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/sample.rb +12 -0
- data/spec/dummy/app/views/layouts/application.html.erb +13 -0
- data/spec/dummy/app/views/samples/new.html.erb +155 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config/application.rb +32 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.def.yml +25 -0
- data/spec/dummy/config/database.travis.yml +3 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/constants.rb +5 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +6 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/coverage/.last_run.json +5 -0
- data/spec/dummy/coverage/.resultset.json +1215 -0
- data/spec/dummy/coverage/.resultset.json.lock +0 -0
- data/spec/dummy/db/migrate/20150622110108_create_samples.rb +14 -0
- data/spec/dummy/db/schema.rb +27 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/css/def.css +1 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/sample.rb +14 -0
- data/spec/libs/conmare_with_normail_builder_spec.rb +244 -0
- data/spec/libs/yorisoi_spec.rb +237 -0
- data/spec/models/samples_spec.rb +38 -0
- data/spec/rails_helper.rb +64 -0
- data/spec/spec_helper.rb +95 -0
- data/spec/supports/active_model.rb +30 -0
- data/yorisoi.gemspec +32 -0
- metadata +245 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: caedf5f60896e709fb5b77a40139e185d5a8a8df
|
4
|
+
data.tar.gz: 37b578bb4f96733f41c02dc3ad353d3aa61323ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c254f7f6aa64901cd67db7fa48bf3b7f4e9917ae66dc4c0d79e3f0a2ce41941303ad72beeef6180070ba2b62dfebcc8a05b33516b6e45ebb594e05fe27d72e4c
|
7
|
+
data.tar.gz: cb797bfe4dacbfbe800efc3e7c64f0c3fc4dda12c7d4453a98cbe4072e96b1fd13409df75e7f4946f97d6d9ee062ad284edbd28dc2f8a3a0fbec929f4a34e9e2
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.1.5
|
4
|
+
- 2.2.2
|
5
|
+
env:
|
6
|
+
- DB=sqlite
|
7
|
+
before_install:
|
8
|
+
- gem install bundler -v 1.10.3
|
9
|
+
install:
|
10
|
+
- bundle install --without production --deployment
|
11
|
+
cache:
|
12
|
+
directories:
|
13
|
+
- vendor/bundle
|
14
|
+
before_script:
|
15
|
+
- cp spec/dummy/config/database.def.yml spec/dummy/config/database.yml
|
16
|
+
script:
|
17
|
+
- cd spec/dummy
|
18
|
+
- bundle exec rake db:create RAILS_ENV=test
|
19
|
+
- bundle exec rake db:migrate RAILS_ENV=test
|
20
|
+
- bundle exec rake db:test:prepare
|
21
|
+
- cd ../../
|
22
|
+
- bundle exec rake
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in yorisoi.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
|
+
# your gem to rubygems.org.
|
12
|
+
|
13
|
+
# To use a debugger
|
14
|
+
# gem 'byebug', group: [:development, :test]
|
15
|
+
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
yorisoi (0.0.1)
|
5
|
+
rails (~> 4.2.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionmailer (4.2.2)
|
11
|
+
actionpack (= 4.2.2)
|
12
|
+
actionview (= 4.2.2)
|
13
|
+
activejob (= 4.2.2)
|
14
|
+
mail (~> 2.5, >= 2.5.4)
|
15
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
16
|
+
actionpack (4.2.2)
|
17
|
+
actionview (= 4.2.2)
|
18
|
+
activesupport (= 4.2.2)
|
19
|
+
rack (~> 1.6)
|
20
|
+
rack-test (~> 0.6.2)
|
21
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
22
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
23
|
+
actionview (4.2.2)
|
24
|
+
activesupport (= 4.2.2)
|
25
|
+
builder (~> 3.1)
|
26
|
+
erubis (~> 2.7.0)
|
27
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
28
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
29
|
+
activejob (4.2.2)
|
30
|
+
activesupport (= 4.2.2)
|
31
|
+
globalid (>= 0.3.0)
|
32
|
+
activemodel (4.2.2)
|
33
|
+
activesupport (= 4.2.2)
|
34
|
+
builder (~> 3.1)
|
35
|
+
activerecord (4.2.2)
|
36
|
+
activemodel (= 4.2.2)
|
37
|
+
activesupport (= 4.2.2)
|
38
|
+
arel (~> 6.0)
|
39
|
+
activesupport (4.2.2)
|
40
|
+
i18n (~> 0.7)
|
41
|
+
json (~> 1.7, >= 1.7.7)
|
42
|
+
minitest (~> 5.1)
|
43
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
44
|
+
tzinfo (~> 1.1)
|
45
|
+
arel (6.0.0)
|
46
|
+
builder (3.2.2)
|
47
|
+
coveralls (0.8.2)
|
48
|
+
json (~> 1.8)
|
49
|
+
rest-client (>= 1.6.8, < 2)
|
50
|
+
simplecov (~> 0.10.0)
|
51
|
+
term-ansicolor (~> 1.3)
|
52
|
+
thor (~> 0.19.1)
|
53
|
+
diff-lcs (1.2.5)
|
54
|
+
docile (1.1.5)
|
55
|
+
domain_name (0.5.24)
|
56
|
+
unf (>= 0.0.5, < 1.0.0)
|
57
|
+
erubis (2.7.0)
|
58
|
+
factory_girl (4.5.0)
|
59
|
+
activesupport (>= 3.0.0)
|
60
|
+
factory_girl_rails (4.5.0)
|
61
|
+
factory_girl (~> 4.5.0)
|
62
|
+
railties (>= 3.0.0)
|
63
|
+
globalid (0.3.5)
|
64
|
+
activesupport (>= 4.1.0)
|
65
|
+
http-cookie (1.0.2)
|
66
|
+
domain_name (~> 0.5)
|
67
|
+
i18n (0.7.0)
|
68
|
+
json (1.8.3)
|
69
|
+
loofah (2.0.2)
|
70
|
+
nokogiri (>= 1.5.9)
|
71
|
+
mail (2.6.3)
|
72
|
+
mime-types (>= 1.16, < 3)
|
73
|
+
mime-types (2.6.1)
|
74
|
+
mini_portile (0.6.2)
|
75
|
+
minitest (5.7.0)
|
76
|
+
netrc (0.10.3)
|
77
|
+
nokogiri (1.6.6.2)
|
78
|
+
mini_portile (~> 0.6.0)
|
79
|
+
rack (1.6.4)
|
80
|
+
rack-test (0.6.3)
|
81
|
+
rack (>= 1.0)
|
82
|
+
rails (4.2.2)
|
83
|
+
actionmailer (= 4.2.2)
|
84
|
+
actionpack (= 4.2.2)
|
85
|
+
actionview (= 4.2.2)
|
86
|
+
activejob (= 4.2.2)
|
87
|
+
activemodel (= 4.2.2)
|
88
|
+
activerecord (= 4.2.2)
|
89
|
+
activesupport (= 4.2.2)
|
90
|
+
bundler (>= 1.3.0, < 2.0)
|
91
|
+
railties (= 4.2.2)
|
92
|
+
sprockets-rails
|
93
|
+
rails-deprecated_sanitizer (1.0.3)
|
94
|
+
activesupport (>= 4.2.0.alpha)
|
95
|
+
rails-dom-testing (1.0.6)
|
96
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
97
|
+
nokogiri (~> 1.6.0)
|
98
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
99
|
+
rails-html-sanitizer (1.0.2)
|
100
|
+
loofah (~> 2.0)
|
101
|
+
railties (4.2.2)
|
102
|
+
actionpack (= 4.2.2)
|
103
|
+
activesupport (= 4.2.2)
|
104
|
+
rake (>= 0.8.7)
|
105
|
+
thor (>= 0.18.1, < 2.0)
|
106
|
+
rake (10.4.2)
|
107
|
+
rest-client (1.8.0)
|
108
|
+
http-cookie (>= 1.0.2, < 2.0)
|
109
|
+
mime-types (>= 1.16, < 3.0)
|
110
|
+
netrc (~> 0.7)
|
111
|
+
rspec (3.3.0)
|
112
|
+
rspec-core (~> 3.3.0)
|
113
|
+
rspec-expectations (~> 3.3.0)
|
114
|
+
rspec-mocks (~> 3.3.0)
|
115
|
+
rspec-core (3.3.1)
|
116
|
+
rspec-support (~> 3.3.0)
|
117
|
+
rspec-expectations (3.3.0)
|
118
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
119
|
+
rspec-support (~> 3.3.0)
|
120
|
+
rspec-html-matchers (0.7.0)
|
121
|
+
nokogiri (~> 1)
|
122
|
+
rspec (~> 3)
|
123
|
+
rspec-mocks (3.3.1)
|
124
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
125
|
+
rspec-support (~> 3.3.0)
|
126
|
+
rspec-rails (3.3.2)
|
127
|
+
actionpack (>= 3.0, < 4.3)
|
128
|
+
activesupport (>= 3.0, < 4.3)
|
129
|
+
railties (>= 3.0, < 4.3)
|
130
|
+
rspec-core (~> 3.3.0)
|
131
|
+
rspec-expectations (~> 3.3.0)
|
132
|
+
rspec-mocks (~> 3.3.0)
|
133
|
+
rspec-support (~> 3.3.0)
|
134
|
+
rspec-support (3.3.0)
|
135
|
+
simplecov (0.10.0)
|
136
|
+
docile (~> 1.1.0)
|
137
|
+
json (~> 1.8)
|
138
|
+
simplecov-html (~> 0.10.0)
|
139
|
+
simplecov-html (0.10.0)
|
140
|
+
sprockets (3.2.0)
|
141
|
+
rack (~> 1.0)
|
142
|
+
sprockets-rails (2.3.2)
|
143
|
+
actionpack (>= 3.0)
|
144
|
+
activesupport (>= 3.0)
|
145
|
+
sprockets (>= 2.8, < 4.0)
|
146
|
+
sqlite3 (1.3.10)
|
147
|
+
term-ansicolor (1.3.2)
|
148
|
+
tins (~> 1.0)
|
149
|
+
thor (0.19.1)
|
150
|
+
thread_safe (0.3.5)
|
151
|
+
tins (1.5.4)
|
152
|
+
tzinfo (1.2.2)
|
153
|
+
thread_safe (~> 0.1)
|
154
|
+
unf (0.1.4)
|
155
|
+
unf_ext
|
156
|
+
unf_ext (0.0.7.1)
|
157
|
+
|
158
|
+
PLATFORMS
|
159
|
+
ruby
|
160
|
+
|
161
|
+
DEPENDENCIES
|
162
|
+
bundler (~> 1.10)
|
163
|
+
coveralls
|
164
|
+
factory_girl_rails
|
165
|
+
rake (~> 10.0)
|
166
|
+
rspec
|
167
|
+
rspec-html-matchers
|
168
|
+
rspec-rails
|
169
|
+
sqlite3
|
170
|
+
yorisoi!
|
171
|
+
|
172
|
+
BUNDLED WITH
|
173
|
+
1.10.4
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 mmmpa
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
[](https://travis-ci.org/mmmpa/yorisoi)
|
2
|
+
[](https://coveralls.io/r/mmmpa/yorisoi?branch=master)
|
3
|
+
|
4
|
+
# Yorisoi
|
5
|
+
Yorisoi(よりそい)はform_helperで作成したinput系がエラーをもつ場合、自動的に直下に表示するための`FormBuilder`です。
|
data/Rakefile
ADDED
data/lib/yorisoi.rb
ADDED
@@ -0,0 +1,221 @@
|
|
1
|
+
module Yorisoi
|
2
|
+
module Arralizer
|
3
|
+
refine Object do
|
4
|
+
def arralize
|
5
|
+
return self if self.is_a?(Array)
|
6
|
+
|
7
|
+
self.is_a?(NilClass) ? [] : [self]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
module Flipper
|
14
|
+
# https://gist.github.com/yuroyoro/3293046
|
15
|
+
refine Proc do
|
16
|
+
def flip
|
17
|
+
f = self.to_proc
|
18
|
+
case __arity(f)
|
19
|
+
when 0, 1 then
|
20
|
+
f
|
21
|
+
when 2 then
|
22
|
+
lambda { |x, y| self[y, x] }
|
23
|
+
else
|
24
|
+
lambda { |x, y, *arg| self[y, x, *arg] }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
private
|
30
|
+
def __arity(f)
|
31
|
+
(f.arity >= 0) ? f.arity : -(f.arity + 1)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
class Builder < ::ActionView::Helpers::FormBuilder
|
38
|
+
include ActionView::Helpers::TagHelper
|
39
|
+
using Arralizer
|
40
|
+
using Flipper
|
41
|
+
|
42
|
+
attr_accessor :wrapper, :invalid_wrapper, :errors_wrapper, :error_wrapper
|
43
|
+
|
44
|
+
|
45
|
+
def initialize(object_name, object, template, options)
|
46
|
+
self.default_tag = options[:builder_tag] || {}
|
47
|
+
super
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
(field_helpers - [:check_box, :radio_button, :fields_for, :hidden_field, :label]).each do |selector|
|
52
|
+
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
53
|
+
def #{selector}(attribute, options = {})
|
54
|
+
wrap_field(attribute, options) do
|
55
|
+
super
|
56
|
+
end
|
57
|
+
end
|
58
|
+
RUBY_EVAL
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def check_box(attribute, options = {}, label_and_value = %w(1 1), unchecked_value = '0')
|
63
|
+
wrap_field(attribute, options) do
|
64
|
+
if label_and_value.is_a?(Array)
|
65
|
+
@template.check_box(@object_name, attribute,
|
66
|
+
objectify_options(options.merge(around: around_proc(label_and_value.first))),
|
67
|
+
label_and_value.last, unchecked_value)
|
68
|
+
else
|
69
|
+
super
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def check_boxes(attribute, options = {}, labels_and_values = [['', '1']],
|
76
|
+
children_wrapper: check_box_wrapper, child_wrapper: check_box_child_wrapper)
|
77
|
+
wrap_field(attribute, options.merge(no_wrap: true)) do
|
78
|
+
children_wrapper.(labels_and_values.map do |label_and_value|
|
79
|
+
child_wrapper.(check_box(attribute, options.merge(multiple: true, no_errors: true), label_and_value, nil), attribute)
|
80
|
+
end.join.html_safe, attribute)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def default_tag=(tags)
|
86
|
+
self.wrapper = tags[:wrapper] || default_wrapper
|
87
|
+
self.invalid_wrapper = tags[:invalid_wrapper] || default_invalid_wrapper
|
88
|
+
self.errors_wrapper = tags[:errors_wrapper] || default_errors_wrapper
|
89
|
+
self.error_wrapper = (tags[:error_wrapper] || default_error_wrapper).flip.curry
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def label(attribute, options = {})
|
94
|
+
wrap_field(attribute, options.merge(no_errors: true)) { super }
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def pick_error(attribute)
|
99
|
+
return nil if @object.nil? || !(messages = @object.errors.messages[attribute]).present?
|
100
|
+
|
101
|
+
errors_wrapper.(messages.map(&error_wrapper.(attribute)).join.html_safe, attribute)
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
def radio_button(attribute, label_and_value, options = {})
|
106
|
+
wrap_field(attribute, options) do
|
107
|
+
if label_and_value.is_a?(Array)
|
108
|
+
@template.radio_button(@object_name, attribute, label_and_value.last,
|
109
|
+
objectify_options(options.merge(around: around_proc(label_and_value.first))))
|
110
|
+
else
|
111
|
+
super
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
def radio_buttons(attribute, options = {}, labels_and_values = [['', '1']],
|
118
|
+
children_wrapper: radio_button_wrapper, child_wrapper: radio_button_child_wrapper)
|
119
|
+
wrap_field(attribute, options.merge(no_wrap: true)) do
|
120
|
+
children_wrapper.(labels_and_values.map do |label_and_value|
|
121
|
+
child_wrapper.(radio_button(attribute, label_and_value, options.merge(no_errors: true)), attribute)
|
122
|
+
end.join.html_safe, attribute)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
def select(attribute, choices = nil, options = {}, html_options = {}, &block)
|
128
|
+
wrap_field(attribute, options) { super }
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
def wrap_field(attribute, options={})
|
133
|
+
no_errors = options.delete(:no_errors)
|
134
|
+
no_wrap = options.delete(:no_wrap)
|
135
|
+
|
136
|
+
if (error_html = pick_error(attribute)).present?
|
137
|
+
no_errors ? yield : yield + error_html
|
138
|
+
else
|
139
|
+
no_wrap ? yield : wrapper.(yield, attribute)
|
140
|
+
end.html_safe
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
private
|
145
|
+
def around_proc(label_text)
|
146
|
+
->(tag) {
|
147
|
+
%{<label><span class="label">#{label_text}</span><span class="input">#{tag}</span></label>}.html_safe
|
148
|
+
}
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
def check_box_wrapper
|
153
|
+
->(content, attribute) { content_tag(:ul, content, class: %w(check-boxes).push(attribute)) }
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
def check_box_child_wrapper
|
158
|
+
->(content, attribute) { content_tag(:li, content, class: %w(check-boxes-child).push(attribute)) }
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
def default_error_wrapper
|
163
|
+
->(content, attribute) { content_tag(:li, content, class: %w(error).push(attribute)) }
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
def default_errors_wrapper
|
168
|
+
->(content, attribute) { content_tag(:ul, content, class: %w(errors).push(attribute)) }
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
def default_invalid_wrapper
|
173
|
+
->(content, attribute) { content_tag(:div, content, class: %w(invalid-field).push(attribute)) }
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
def default_wrapper
|
178
|
+
->(content, attribute) { content_tag(:div, content, class: %w(normal-field).push(attribute)) }
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
def radio_button_wrapper
|
183
|
+
->(content, attribute) { content_tag(:ul, content, class: %w(radio-buttons).push(attribute)) }
|
184
|
+
end
|
185
|
+
|
186
|
+
|
187
|
+
def radio_button_child_wrapper
|
188
|
+
->(content, attribute) { content_tag(:li, content, class: %w(radio-buttons-child).push(attribute)) }
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
|
193
|
+
module ::ActionView
|
194
|
+
module Helpers
|
195
|
+
module ActiveModelInstanceTag
|
196
|
+
def content_tag(tag_name, single_or_multiple_records, prefix = nil, options = nil, &block)
|
197
|
+
supered = if (around = options.try(:[], 'around')).present?
|
198
|
+
options.delete('around')
|
199
|
+
around.call(super)
|
200
|
+
else
|
201
|
+
super
|
202
|
+
end
|
203
|
+
|
204
|
+
error_wrapping(supered)
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
def tag(type, options, *)
|
209
|
+
supered = if (around = options.try(:[], 'around')).present?
|
210
|
+
options.delete('around')
|
211
|
+
around.call(super)
|
212
|
+
else
|
213
|
+
super
|
214
|
+
end
|
215
|
+
|
216
|
+
tag_generate_errors?(options) ? error_wrapping(supered) : supered
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe SamplesController, :type => :controller do
|
4
|
+
render_views
|
5
|
+
|
6
|
+
describe "GET new" do
|
7
|
+
it "no error message" do
|
8
|
+
get :new
|
9
|
+
expect(response.body).not_to include('.error-message')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "POST create" do
|
14
|
+
it 'valid params NOT render error message' do
|
15
|
+
post :create, sample: attributes_for(:valid_sample)
|
16
|
+
expect(response.body).not_to have_tag('ul.errors.text')
|
17
|
+
expect(response.body).not_to have_tag('ul.errors.password')
|
18
|
+
expect(response.body).not_to have_tag('ul.errors.textarea')
|
19
|
+
expect(response.body).not_to have_tag('ul.errors.select')
|
20
|
+
expect(response.body).not_to have_tag('ul.errors.radio')
|
21
|
+
expect(response.body).not_to have_tag('ul.errors.checkbox')
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'invalid params render error message' do
|
25
|
+
it 'html class with attribute' do
|
26
|
+
post :create, sample: attributes_for(:sample)
|
27
|
+
expect(response.body).to have_tag('ul.errors.text')
|
28
|
+
expect(response.body).to have_tag('ul.errors.password')
|
29
|
+
expect(response.body).to have_tag('ul.errors.textarea')
|
30
|
+
expect(response.body).to have_tag('ul.errors.select')
|
31
|
+
expect(response.body).to have_tag('ul.errors.radio')
|
32
|
+
expect(response.body).to have_tag('ul.errors.checkbox')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'error message with html class with attribute' do
|
36
|
+
post :create, sample: attributes_for(:sample)
|
37
|
+
expect(response.body).to have_tag('li.text', text: 'presence')
|
38
|
+
expect(response.body).to have_tag('li.password', text: 'presence')
|
39
|
+
expect(response.body).to have_tag('li.textarea', text: 'presence')
|
40
|
+
expect(response.body).to have_tag('li.select', text: 'presence')
|
41
|
+
expect(response.body).to have_tag('li.radio', text: 'presence')
|
42
|
+
expect(response.body).to have_tag('li.checkbox', text: 'presence')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'multi error render multi message' do
|
46
|
+
post :create, sample: attributes_for(:valid_sample, text: 'あ' * 40)
|
47
|
+
expect(response.body).to have_tag('li.text', text: 'format')
|
48
|
+
expect(response.body).to have_tag('li.text', text: 'too_long')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class SamplesController < ApplicationController
|
2
|
+
def new
|
3
|
+
@sample = Sample.new
|
4
|
+
end
|
5
|
+
|
6
|
+
|
7
|
+
def create
|
8
|
+
Sample.create!(sample_params)
|
9
|
+
redirect_to new_path
|
10
|
+
rescue ActiveRecord::RecordInvalid => e
|
11
|
+
@sample = e.record
|
12
|
+
render :new
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
private
|
17
|
+
def sample_params
|
18
|
+
params.fetch(:sample, {}).permit(:text, :password, :textarea, :select, :radio, checkbox: [])
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
File without changes
|
File without changes
|
File without changes
|