yorisoi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +8 -0
  4. data/.travis.yml +22 -0
  5. data/Gemfile +15 -0
  6. data/Gemfile.lock +173 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +5 -0
  9. data/Rakefile +4 -0
  10. data/lib/tasks/yorisoi_tasks.rake +4 -0
  11. data/lib/yorisoi/version.rb +3 -0
  12. data/lib/yorisoi.rb +221 -0
  13. data/spec/controllers/samples_controller_spec.rb +52 -0
  14. data/spec/dummy/README.rdoc +28 -0
  15. data/spec/dummy/Rakefile +6 -0
  16. data/spec/dummy/app/assets/images/.keep +0 -0
  17. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  18. data/spec/dummy/app/assets/javascripts/samples.js +2 -0
  19. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  20. data/spec/dummy/app/assets/stylesheets/samples.css +4 -0
  21. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  22. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  23. data/spec/dummy/app/controllers/samples_controller.rb +21 -0
  24. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  25. data/spec/dummy/app/helpers/samples_helper.rb +2 -0
  26. data/spec/dummy/app/mailers/.keep +0 -0
  27. data/spec/dummy/app/models/.keep +0 -0
  28. data/spec/dummy/app/models/concerns/.keep +0 -0
  29. data/spec/dummy/app/models/sample.rb +12 -0
  30. data/spec/dummy/app/views/layouts/application.html.erb +13 -0
  31. data/spec/dummy/app/views/samples/new.html.erb +155 -0
  32. data/spec/dummy/bin/bundle +3 -0
  33. data/spec/dummy/bin/rails +4 -0
  34. data/spec/dummy/bin/rake +4 -0
  35. data/spec/dummy/bin/setup +29 -0
  36. data/spec/dummy/config/application.rb +32 -0
  37. data/spec/dummy/config/boot.rb +5 -0
  38. data/spec/dummy/config/database.def.yml +25 -0
  39. data/spec/dummy/config/database.travis.yml +3 -0
  40. data/spec/dummy/config/environment.rb +5 -0
  41. data/spec/dummy/config/environments/development.rb +41 -0
  42. data/spec/dummy/config/environments/production.rb +79 -0
  43. data/spec/dummy/config/environments/test.rb +42 -0
  44. data/spec/dummy/config/initializers/assets.rb +11 -0
  45. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  46. data/spec/dummy/config/initializers/constants.rb +5 -0
  47. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  48. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  49. data/spec/dummy/config/initializers/inflections.rb +16 -0
  50. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  51. data/spec/dummy/config/initializers/session_store.rb +3 -0
  52. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  53. data/spec/dummy/config/locales/en.yml +23 -0
  54. data/spec/dummy/config/routes.rb +6 -0
  55. data/spec/dummy/config/secrets.yml +22 -0
  56. data/spec/dummy/config.ru +4 -0
  57. data/spec/dummy/coverage/.last_run.json +5 -0
  58. data/spec/dummy/coverage/.resultset.json +1215 -0
  59. data/spec/dummy/coverage/.resultset.json.lock +0 -0
  60. data/spec/dummy/db/migrate/20150622110108_create_samples.rb +14 -0
  61. data/spec/dummy/db/schema.rb +27 -0
  62. data/spec/dummy/lib/assets/.keep +0 -0
  63. data/spec/dummy/log/.keep +0 -0
  64. data/spec/dummy/public/404.html +67 -0
  65. data/spec/dummy/public/422.html +67 -0
  66. data/spec/dummy/public/500.html +66 -0
  67. data/spec/dummy/public/css/def.css +1 -0
  68. data/spec/dummy/public/favicon.ico +0 -0
  69. data/spec/factories/sample.rb +14 -0
  70. data/spec/libs/conmare_with_normail_builder_spec.rb +244 -0
  71. data/spec/libs/yorisoi_spec.rb +237 -0
  72. data/spec/models/samples_spec.rb +38 -0
  73. data/spec/rails_helper.rb +64 -0
  74. data/spec/spec_helper.rb +95 -0
  75. data/spec/supports/active_model.rb +30 -0
  76. data/yorisoi.gemspec +32 -0
  77. metadata +245 -0
@@ -0,0 +1,237 @@
1
+ require 'rails_helper'
2
+
3
+ class TestHelper < ActionView::Base;
4
+ end
5
+
6
+ RSpec.describe Yorisoi::Builder do
7
+ before :each do
8
+ @sample = build(:sample)
9
+ @df = ActionView::Helpers::FormBuilder.new(:sample, @sample, TestHelper.new, {})
10
+ @f = Yorisoi::Builder.new(:sample, @sample, TestHelper.new, {})
11
+ end
12
+
13
+ context 'change use tag' do
14
+ before :each do
15
+ @sample.valid?
16
+ end
17
+
18
+ it 'change error child' do
19
+ @f = Yorisoi::Builder.new(:sample, @sample, TestHelper.new, {
20
+ builder_tag: {
21
+ errors_wrapper: ->(error_children, attribute) { %{<div class="error-messages #{attribute}">#{error_children}</div>}.html_safe },
22
+ error_wrapper: ->(error, attribute) { %{<p class="error-message #{attribute}">#{error}</p>}.html_safe }
23
+ }})
24
+ expect(@f.text_field(:text)).to have_tag('div.error-messages.text p.error-message.text')
25
+ end
26
+ end
27
+
28
+
29
+ context 'default use' do
30
+ context 'text_field' do
31
+ it 'not validated no error' do
32
+ expect(@f.text_field(:text)).not_to have_tag('ul.errors.text')
33
+ end
34
+
35
+ it 'validated get error' do
36
+ @sample.valid?
37
+ expect(@f.text_field(:text)).to have_tag('ul.errors.text')
38
+ end
39
+ end
40
+ end
41
+
42
+ context 'with label expanded' do
43
+ let(:label_and_value) do
44
+ %w(label_name value_name)
45
+ end
46
+
47
+ context 'no error' do
48
+ context 'checkbox' do
49
+ before :each do
50
+ @html = @f.check_box(:text, {}, label_and_value, nil)
51
+ end
52
+
53
+ it 'wrapped' do
54
+ expect(@html).to have_tag('div.normal-field')
55
+ end
56
+
57
+ it 'has label text' do
58
+ expect(@html).to include(label_and_value.last)
59
+ end
60
+
61
+ it 'has value' do
62
+ expect(@html).to have_tag('input[type="checkbox"]', value: label_and_value.first)
63
+ end
64
+ end
65
+
66
+ context 'radio button' do
67
+ before :each do
68
+ @html = @f.radio_button(:text, label_and_value)
69
+ end
70
+
71
+ it 'wrapped' do
72
+ expect(@html).to have_tag('div.normal-field')
73
+ end
74
+
75
+ it 'has label text' do
76
+ expect(@html).to include(label_and_value.last)
77
+ end
78
+
79
+ it 'has value' do
80
+ expect(@html).to have_tag('input[type="radio"]', value: label_and_value.first)
81
+ end
82
+ end
83
+ end
84
+
85
+ context 'has error' do
86
+ context 'checkbox' do
87
+ before :each do
88
+ @sample.valid?
89
+ @html = @f.check_box(:text, {}, label_and_value, nil)
90
+ end
91
+
92
+ it 'wrapped' do
93
+ expect(@html).to have_tag('div.field_with_errors')
94
+ end
95
+
96
+ it 'has label text' do
97
+ expect(@html).to include(label_and_value.last)
98
+ end
99
+
100
+ it 'has value' do
101
+ expect(@html).to have_tag('input[type="checkbox"]', value: label_and_value.first)
102
+ end
103
+ end
104
+
105
+ context 'radio button' do
106
+ before :each do
107
+ @sample.valid?
108
+ @html = @f.radio_button(:text, label_and_value)
109
+ end
110
+
111
+ it 'wrapped' do
112
+ expect(@html).to have_tag('div.field_with_errors')
113
+ end
114
+
115
+ it 'has label text' do
116
+ expect(@html).to include(label_and_value.last)
117
+ end
118
+
119
+ it 'has value' do
120
+ expect(@html).to have_tag('input[type="radio"]', value: label_and_value.first)
121
+ end
122
+ end
123
+ end
124
+
125
+ end
126
+
127
+ context 'multi button expanded' do
128
+ let(:labels_and_values) do
129
+ (1..10).to_a.collect do |n|
130
+ ["label name #{n}", "value name #{n}"]
131
+ end
132
+ end
133
+
134
+ context 'no error' do
135
+ context 'checkboxes' do
136
+ before :each do
137
+ @html = @f.check_boxes(:text, {}, labels_and_values)
138
+ end
139
+
140
+ it 'wrapped' do
141
+ expect(@html).to have_tag('div.normal-field', count: 10)
142
+ end
143
+
144
+ it 'has label text' do
145
+ labels_and_values.each do |label_and_value|
146
+ expect(@html).to include(label_and_value.last)
147
+ end
148
+ end
149
+
150
+ it 'has value' do
151
+ labels_and_values.each do |label_and_value|
152
+ expect(@html).to have_tag('input[type="checkbox"]', value: label_and_value.first)
153
+ end
154
+ end
155
+ end
156
+
157
+ context 'radio_buttons' do
158
+ before :each do
159
+ @html = @f.radio_buttons(:text, {}, labels_and_values)
160
+ end
161
+
162
+ it 'wrapped' do
163
+ expect(@html).to have_tag('div.normal-field', count: 10)
164
+ end
165
+
166
+ it 'has label text' do
167
+ labels_and_values.each do |label_and_value|
168
+ expect(@html).to include(label_and_value.last)
169
+ end
170
+ end
171
+
172
+ it 'has value' do
173
+ labels_and_values.each do |label_and_value|
174
+ expect(@html).to have_tag('input[type="radio"]', value: label_and_value.first)
175
+ end
176
+ end
177
+ end
178
+ end
179
+
180
+ context 'has error' do
181
+ context 'checkboxes' do
182
+ before :each do
183
+ @sample.valid?
184
+ @html = @f.check_boxes(:text, {}, labels_and_values)
185
+ end
186
+
187
+ it 'wrapped' do
188
+ expect(@html).to have_tag('div.field_with_errors', count: 10)
189
+ end
190
+
191
+ it 'has 1 error message' do
192
+ expect(@html).to have_tag('ul.errors.text', count: 1)
193
+ end
194
+
195
+ it 'has label text' do
196
+ labels_and_values.each do |label_and_value|
197
+ expect(@html).to include(label_and_value.last)
198
+ end
199
+ end
200
+
201
+ it 'has value' do
202
+ labels_and_values.each do |label_and_value|
203
+ expect(@html).to have_tag('input[type="checkbox"]', value: label_and_value.first)
204
+ end
205
+ end
206
+ end
207
+
208
+ context 'radio_buttons' do
209
+ before :each do
210
+ @sample.valid?
211
+ @html = @f.radio_buttons(:text, {}, labels_and_values)
212
+ end
213
+
214
+ it 'wrapped' do
215
+ @html
216
+ expect(@html).to have_tag('div.field_with_errors', count: 10)
217
+ end
218
+
219
+ it 'has 1 error message' do
220
+ expect(@html).to have_tag('ul.errors.text', count: 1)
221
+ end
222
+
223
+ it 'has label text' do
224
+ labels_and_values.each do |label_and_value|
225
+ expect(@html).to include(label_and_value.last)
226
+ end
227
+ end
228
+
229
+ it 'has value' do
230
+ labels_and_values.each do |label_and_value|
231
+ expect(@html).to have_tag('input[type="radio"]', value: label_and_value.first)
232
+ end
233
+ end
234
+ end
235
+ end
236
+ end
237
+ end
@@ -0,0 +1,38 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe Sample, :type => :model do
4
+ it 'check factory' do
5
+ expect(create(:valid_sample)).to be_a(Sample)
6
+ expect{create(:sample)}.to raise_exception
7
+ end
8
+
9
+ context 'presence' do
10
+ [:text, :password, :textarea, :select, :radio, :checkbox].each do |attribute_name|
11
+ it "blank #{attribute_name} get invalid" do
12
+ model = build(:valid_sample)
13
+ model[attribute_name] = nil
14
+ expect(model.has_error_on(attribute_name, :presence)).to be_truthy
15
+ end
16
+
17
+ it "input #{attribute_name} get valid" do
18
+ model = build(:valid_sample)
19
+ expect(model.has_error_on(attribute_name, :presence)).to be_falsey
20
+ end
21
+ end
22
+ end
23
+
24
+ context 'inclusion' do
25
+ [:select, :radio].each do |attribute_name|
26
+ it "out of selector #{attribute_name} get invalid" do
27
+ model = build(:valid_sample)
28
+ model[attribute_name] = :a
29
+ expect(model.has_error_on(attribute_name, :inclusion)).to be_truthy
30
+ end
31
+
32
+ it "in selector #{attribute_name} get valid" do
33
+ model = build(:valid_sample)
34
+ expect(model.has_error_on(attribute_name, :inclusion)).to be_falsey
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,64 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV['RAILS_ENV'] ||= 'test'
3
+ require File.expand_path('../dummy/config/environment', __FILE__)
4
+ # Prevent database truncation if the environment is production
5
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
6
+ require 'spec_helper'
7
+ require 'rspec/rails'
8
+ require 'factory_girl_rails'
9
+ require 'rspec-html-matchers'
10
+ # Add additional requires below this line. Rails is not loaded until this point!
11
+
12
+ # Requires supporting ruby files with custom matchers and macros, etc, in
13
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
14
+ # run as spec files by default. This means that files in spec/support that end
15
+ # in _spec.rb will both be required and run as specs, causing the specs to be
16
+ # run twice. It is recommended that you do not name files matching this glob to
17
+ # end with _spec.rb. You can configure this pattern with the --pattern
18
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
19
+ #
20
+ # The following line is provided for convenience purposes. It has the downside
21
+ # of increasing the boot-up time by auto-requiring all files in the support
22
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
23
+ # require only the support files necessary.
24
+ #
25
+ Dir[Rails.root.join("spec/supports/*.rb")].each { |f| require f }
26
+
27
+ # Checks for pending migrations before tests are run.
28
+ # If you are not using ActiveRecord, you can remove this line.
29
+ ActiveRecord::Migration.maintain_test_schema!
30
+
31
+ RSpec.configure do |config|
32
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
33
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
34
+
35
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
36
+ # examples within a transaction, remove the following line or assign false
37
+ # instead of true.
38
+ config.use_transactional_fixtures = true
39
+
40
+ # RSpec Rails can automatically mix in different behaviours to your tests
41
+ # based on their file location, for example enabling you to call `get` and
42
+ # `post` in specs under `spec/controllers`.
43
+ #
44
+ # You can disable this behaviour by removing the line below, and instead
45
+ # explicitly tag your specs with their type, e.g.:
46
+ #
47
+ # RSpec.describe UsersController, :type => :controller do
48
+ # # ...
49
+ # end
50
+ #
51
+ # The different available types are documented in the features, such as in
52
+ # https://relishapp.com/rspec/rspec-rails/docs
53
+ config.infer_spec_type_from_file_location!
54
+
55
+ RSpec.configure do |config|
56
+ config.include RSpecHtmlMatchers
57
+ end
58
+
59
+ config.include FactoryGirl::Syntax::Methods
60
+
61
+ config.before(:all) do
62
+ FactoryGirl.reload
63
+ end
64
+ end
@@ -0,0 +1,95 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
7
+ # this file to always be loaded, without a need to explicitly require it in any
8
+ # files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, consider making
14
+ # a separate helper file that requires the additional dependencies and performs
15
+ # the additional setup, and require it from the spec files that actually need
16
+ # it.
17
+ #
18
+ # The `.rspec` file also contains a few flags that are not defaults but that
19
+ # users commonly want.
20
+ #
21
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
22
+ RSpec.configure do |config|
23
+ # rspec-expectations config goes here. You can use an alternate
24
+ # assertion/expectation library such as wrong or the stdlib/minitest
25
+ # assertions if you prefer.
26
+ config.expect_with :rspec do |expectations|
27
+ # This option will default to `true` in RSpec 4. It makes the `description`
28
+ # and `failure_message` of custom matchers include text for helper methods
29
+ # defined using `chain`, e.g.:
30
+ # be_bigger_than(2).and_smaller_than(4).description
31
+ # # => "be bigger than 2 and smaller than 4"
32
+ # ...rather than:
33
+ # # => "be bigger than 2"
34
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
+ end
36
+
37
+ # rspec-mocks config goes here. You can use an alternate test double
38
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
39
+ config.mock_with :rspec do |mocks|
40
+ # Prevents you from mocking or stubbing a method that does not exist on
41
+ # a real object. This is generally recommended, and will default to
42
+ # `true` in RSpec 4.
43
+ mocks.verify_partial_doubles = true
44
+ end
45
+
46
+ # The settings below are suggested to provide a good initial experience
47
+ # with RSpec, but feel free to customize to your heart's content.
48
+ =begin
49
+ # These two settings work together to allow you to limit a spec run
50
+ # to individual examples or groups you care about by tagging them with
51
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
52
+ # get run.
53
+ config.filter_run :focus
54
+ config.run_all_when_everything_filtered = true
55
+
56
+ # Allows RSpec to persist some state between runs in order to support
57
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
58
+ # you configure your source control system to ignore this file.
59
+ config.example_status_persistence_file_path = "spec/examples.txt"
60
+
61
+ # Limits the available syntax to the non-monkey patched syntax that is
62
+ # recommended. For more details, see:
63
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
64
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
65
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
66
+ config.disable_monkey_patching!
67
+
68
+ # Many RSpec users commonly either run the entire suite or an individual
69
+ # file, and it's useful to allow more verbose output when running an
70
+ # individual spec file.
71
+ if config.files_to_run.one?
72
+ # Use the documentation formatter for detailed output,
73
+ # unless a formatter has already been configured
74
+ # (e.g. via a command-line flag).
75
+ config.default_formatter = 'doc'
76
+ end
77
+
78
+ # Print the 10 slowest examples and example groups at the
79
+ # end of the spec run, to help surface which specs are running
80
+ # particularly slow.
81
+ config.profile_examples = 10
82
+
83
+ # Run specs in random order to surface order dependencies. If you find an
84
+ # order dependency and want to debug it, you can fix the order by providing
85
+ # the seed, which is printed after each run.
86
+ # --seed 1234
87
+ config.order = :random
88
+
89
+ # Seed global randomization in this process using the `--seed` CLI option.
90
+ # Setting this allows you to use `--seed` to deterministically reproduce
91
+ # test failures related to randomization by passing the same `--seed` value
92
+ # as the one that triggered the failure.
93
+ Kernel.srand config.seed
94
+ =end
95
+ end
@@ -0,0 +1,30 @@
1
+ module ActiveModel
2
+ module Validations
3
+ def has_error_on(attribute, error)
4
+ return false unless self.respond_to?(:valid?)
5
+ self.valid?
6
+ self.errors.messages[attribute].try(:include?, error)
7
+ end
8
+ end
9
+
10
+
11
+ class Errors
12
+ def generate_message(attribute, type = :invalid, options = {})
13
+ message = type.to_sym
14
+ message_table[message] || message
15
+ end
16
+
17
+
18
+ def message_table
19
+ {
20
+ present: :absence,
21
+ accepted: :acceptance,
22
+ invalid: :format,
23
+ not_a_number: :numericality,
24
+ not_an_integer: :numericality,
25
+ blank: :presence,
26
+ wrong_length: :length
27
+ }
28
+ end
29
+ end
30
+ end
data/yorisoi.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "yorisoi/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "yorisoi"
9
+ spec.version = Yorisoi::VERSION
10
+ spec.authors = ['mmmpa']
11
+ spec.email = ['mmmpa.mmmpa@gmail.com']
12
+
13
+ spec.summary = 'Writing error message next each inputs.'
14
+ spec.description = 'Writing error message next each inputs.'
15
+ spec.homepage = 'http://mmmpa.net/'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files`.split("\n")
19
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+ spec.add_dependency "rails", "~> 4.2.1"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "sqlite3"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "rspec-rails"
29
+ spec.add_development_dependency 'rspec-html-matchers'
30
+ spec.add_development_dependency "factory_girl_rails"
31
+ spec.add_development_dependency "coveralls"
32
+ end