From 11da39a68ac51625fa7d27c827111c93faebc304 Mon Sep 17 00:00:00 2001 From: Nick Gorbikoff Date: Wed, 3 Oct 2018 23:47:13 -0500 Subject: [PATCH 1/3] Adding haml 5.0.4 and simple test --- .../fixtures/comment/haml/show/view/show.haml | 13 ++ test/haml_test.rb | 136 ++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 test/fixtures/comment/haml/show/view/show.haml create mode 100644 test/haml_test.rb diff --git a/test/fixtures/comment/haml/show/view/show.haml b/test/fixtures/comment/haml/show/view/show.haml new file mode 100644 index 0000000..8e8e8c8 --- /dev/null +++ b/test/fixtures/comment/haml/show/view/show.haml @@ -0,0 +1,13 @@ +%div New += form model, "/posts", path_prefix: :comment do |f| + = f.input :id + = f.textarea :body + = f.checkbox :public, value: true + = f.collection :replies do |reply| + = reply.input :content + = f.nested :owner do |owner| + = owner.input :name + = owner.input :email + = f.input :uuid + = f.submit value: "Submit" + diff --git a/test/haml_test.rb b/test/haml_test.rb new file mode 100644 index 0000000..1bcf55e --- /dev/null +++ b/test/haml_test.rb @@ -0,0 +1,136 @@ +require 'test_helper' +require 'formular/helper' +require 'trailblazer/cell' +require 'cell/haml' + +class Comment::Haml + class Show < Trailblazer::Cell + include Cell::Haml + include Formular::Helper + + self.view_paths = ['test/fixtures'] + + def show + render view: :show + end + + # def form(model: nil, **options, &block) + # Formular::Builders::Basic.new(model: model, path_prefix: :comment).form(options, &block) + # end + end +end + +class HamlTest < Minitest::Spec + describe 'valid, initial rendering' do + let(:model) { Comment.new(1, 'Nice!', [Reply.new(1, 'some exciting words'), Reply.new], Owner.new(1, 'Joe Blog', 'joe@somewhere.com'), '0x', true) } + + it do + Comment::Haml::Show.new(model).().must_equal %(
New
+ + + + + +
New
+ + + + + +
New
+ + + + + + + +
New
+ + + + + +
New
+ + + + + +
New
+ + + + + + + + + +
New
+ + + + + +
New
+ + + + + +
New
+ + + + + + + +
New
+ + + + + +
New
+ + + + + +
New
+ + + + + + + + + +
) + end + end +end + +# describe "with errors" do +# let (:model) do +# F5::Form.new(Comment.new(nil, "hang ten in east berlin", [])) +# end +# +# before { model.validate({}) } +# +# it do +# Comment::HamlCell.new(model).().must_eq %{
ID +# +# +# ["body size cannot be greater than 10"] +# +# ["uuid must be filled"] +#
} +# end +# end +# end From 7bdb1583fff826c97d5267b7f8df66f578fa7f10 Mon Sep 17 00:00:00 2001 From: Nick Gorbikoff Date: Wed, 3 Oct 2018 23:50:35 -0500 Subject: [PATCH 2/3] Adding haml 5.0.4 and simple test --- formular.gemspec | 1 + lib/formular/helper.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/formular.gemspec b/formular.gemspec index 054eb81..0e2c61e 100644 --- a/formular.gemspec +++ b/formular.gemspec @@ -26,6 +26,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "trailblazer-cells" spec.add_development_dependency "cells-slim" spec.add_development_dependency "cells-erb" + spec.add_development_dependency "cells-haml" spec.add_development_dependency "minitest" spec.add_development_dependency "minitest-line" end diff --git a/lib/formular/helper.rb b/lib/formular/helper.rb index 5e552f0..bcddc99 100644 --- a/lib/formular/helper.rb +++ b/lib/formular/helper.rb @@ -1,5 +1,5 @@ module Formular - # TODO: indirectly tested in erb_test and slim_test. Should probably test directly + # TODO: indirectly tested in erb_test, haml_test and slim_test. Should probably test directly module Helper def form(model, url, **options, &block) form_options = options From c6c887d815a3b98c6b646dd72145299f837a70f4 Mon Sep 17 00:00:00 2001 From: Nick Gorbikoff Date: Thu, 4 Oct 2018 13:32:36 -0500 Subject: [PATCH 3/3] Changing HAML test and haml fixture template https://github.com/trailblazer/formular/pull/63#issuecomment-427123742 --- formular.gemspec | 1 + .../fixtures/comment/haml/show/view/show.haml | 26 +++--- test/haml_test.rb | 89 +------------------ 3 files changed, 17 insertions(+), 99 deletions(-) diff --git a/formular.gemspec b/formular.gemspec index 0e2c61e..0053cf6 100644 --- a/formular.gemspec +++ b/formular.gemspec @@ -27,6 +27,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "cells-slim" spec.add_development_dependency "cells-erb" spec.add_development_dependency "cells-haml" + spec.add_development_dependency "actionview" spec.add_development_dependency "minitest" spec.add_development_dependency "minitest-line" end diff --git a/test/fixtures/comment/haml/show/view/show.haml b/test/fixtures/comment/haml/show/view/show.haml index 8e8e8c8..750f486 100644 --- a/test/fixtures/comment/haml/show/view/show.haml +++ b/test/fixtures/comment/haml/show/view/show.haml @@ -1,13 +1,17 @@ %div New -= form model, "/posts", path_prefix: :comment do |f| - = f.input :id - = f.textarea :body - = f.checkbox :public, value: true - = f.collection :replies do |reply| - = reply.input :content - = f.nested :owner do |owner| - = owner.input :name - = owner.input :email - = f.input :uuid - = f.submit value: "Submit" += form(model, "/posts", path_prefix: :comment) do |f| + - capture_haml do + = f.input :id + = f.textarea :body + = f.checkbox :public, value: true + = f.collection :replies do |reply| + - capture_haml do + = reply.input :content + = f.nested :owner do |owner| + - capture_haml do + = owner.input :name + = owner.input :email + = f.input :uuid + = f.submit value: "Submit" + diff --git a/test/haml_test.rb b/test/haml_test.rb index 1bcf55e..c56bb30 100644 --- a/test/haml_test.rb +++ b/test/haml_test.rb @@ -14,9 +14,6 @@ def show render view: :show end - # def form(model: nil, **options, &block) - # Formular::Builders::Basic.new(model: model, path_prefix: :comment).form(options, &block) - # end end end @@ -25,91 +22,7 @@ class HamlTest < Minitest::Spec let(:model) { Comment.new(1, 'Nice!', [Reply.new(1, 'some exciting words'), Reply.new], Owner.new(1, 'Joe Blog', 'joe@somewhere.com'), '0x', true) } it do - Comment::Haml::Show.new(model).().must_equal %(
New
- - - - - -
New
- - - - - -
New
- - - - - - - -
New
- - - - - -
New
- - - - - -
New
- - - - - - - - - -
New
- - - - - -
New
- - - - - -
New
- - - - - - - -
New
- - - - - -
New
- - - - - -
New
- - - - - - - - - -
) + Comment::Haml::Show.new(model).().must_equal %(
New
\n
\n\n\n\n\n\n\n\n\n
) end end end