cells 3.11.3 → 4.0.0.beta1

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.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +15 -13
  4. data/Appraisals +23 -0
  5. data/CHANGES.md +20 -3
  6. data/Gemfile +5 -7
  7. data/README.md +317 -236
  8. data/Rakefile +1 -1
  9. data/TODO.md +3 -0
  10. data/cells.gemspec +19 -28
  11. data/gemfiles/rails3.2.gemfile +14 -0
  12. data/gemfiles/rails4.0.gemfile +14 -0
  13. data/gemfiles/rails4.1.gemfile +15 -0
  14. data/gemfiles/rails4.2.gemfile +14 -0
  15. data/lib/cell.rb +28 -21
  16. data/lib/cell/caching.rb +10 -22
  17. data/lib/cell/caching/notification.rb +15 -0
  18. data/lib/cell/concept.rb +4 -69
  19. data/lib/cell/development.rb +11 -0
  20. data/lib/{cells → cell}/engines.rb +1 -1
  21. data/lib/cell/layout.rb +20 -0
  22. data/lib/cell/partial.rb +17 -0
  23. data/lib/cell/{base/prefixes.rb → prefixes.rb} +1 -1
  24. data/lib/cell/rails.rb +58 -50
  25. data/lib/cell/railtie.rb +60 -0
  26. data/lib/cell/{base/self_contained.rb → self_contained.rb} +1 -1
  27. data/lib/cell/templates.rb +60 -0
  28. data/lib/cell/test_case.rb +4 -162
  29. data/lib/cell/testing.rb +15 -0
  30. data/lib/cell/twin.rb +11 -29
  31. data/lib/cell/version.rb +10 -0
  32. data/lib/cell/view_model.rb +196 -88
  33. data/lib/cells.rb +1 -20
  34. data/lib/rails/generators/cell/cell_generator.rb +43 -0
  35. data/lib/rails/generators/cell/templates/cell.rb.erb +8 -0
  36. data/lib/{generators/templates/concept → rails/generators/cell/templates}/view.erb +0 -0
  37. data/lib/{generators/templates/concept → rails/generators/cell/templates}/view.haml +0 -0
  38. data/lib/rails/generators/cell/templates/view.slim +2 -0
  39. data/lib/rails/generators/concept/concept_generator.rb +38 -0
  40. data/lib/{generators/templates/concept/cell.rb → rails/generators/concept/templates/concept.rb.erb} +2 -2
  41. data/lib/{generators → rails/generators/concept}/templates/view.erb +0 -0
  42. data/lib/{generators → rails/generators/concept}/templates/view.haml +0 -0
  43. data/lib/rails/generators/concept/templates/view.slim +2 -0
  44. data/lib/rails/generators/test_unit/cell/cell_generator.rb +21 -0
  45. data/lib/{generators/templates/cell_test.rb → rails/generators/test_unit/cell/templates/unit_test.rb.erb} +3 -3
  46. data/lib/rails/generators/test_unit/concept/concept_generator.rb +21 -0
  47. data/lib/rails/generators/test_unit/concept/templates/unit_test.rb.erb +11 -0
  48. data/lib/{cells → tasks}/cells.rake +0 -0
  49. data/test/builder_test.rb +58 -0
  50. data/test/caching_test.rb +298 -0
  51. data/test/cell_benchmark.rb +32 -0
  52. data/test/cell_generator_test.rb +51 -82
  53. data/test/cell_test.rb +8 -23
  54. data/test/concept_generator_test.rb +22 -13
  55. data/test/concept_test.rb +41 -75
  56. data/test/dummy/app/views/musician/hamlet.html.erb +1 -0
  57. data/test/dummy/config/application.rb +21 -8
  58. data/test/{app/cells/bassist/play.html.erb → fixtures/bassist/play.erb} +0 -0
  59. data/test/fixtures/concepts/record/views/layout.erb +1 -0
  60. data/test/{app → fixtures}/concepts/record/views/show.erb +0 -0
  61. data/test/{app → fixtures}/concepts/record/views/song.erb +0 -0
  62. data/test/fixtures/inherit_views_test/popper/tap.erb +1 -0
  63. data/test/fixtures/inherit_views_test/tapper/play.erb +1 -0
  64. data/test/fixtures/inherit_views_test/tapper/tap.erb +1 -0
  65. data/test/fixtures/partial_test/with_partial/show.erb +1 -0
  66. data/test/fixtures/partials/_show.html.erb +1 -0
  67. data/test/fixtures/partials/_show.xml.erb +1 -0
  68. data/test/fixtures/song/ivar.erb +1 -0
  69. data/test/fixtures/song/show.erb +1 -0
  70. data/test/fixtures/song/with_erb.erb +4 -0
  71. data/test/fixtures/song/with_html.erb +1 -0
  72. data/test/fixtures/song/with_locals.erb +2 -0
  73. data/test/fixtures/song_with_layout/happy.erb +1 -0
  74. data/test/fixtures/song_with_layout/merry.erb +1 -0
  75. data/test/fixtures/song_with_layout/show.erb +1 -0
  76. data/test/fixtures/song_with_layout/show_with_layout.erb +1 -0
  77. data/test/fixtures/templates_caching_test/song/show.erb +1 -0
  78. data/test/fixtures/url_helper_test/song/edit.erb +8 -0
  79. data/test/fixtures/url_helper_test/song/with_block.erb +2 -0
  80. data/test/fixtures/url_helper_test/song/with_capture.erb +4 -0
  81. data/test/fixtures/url_helper_test/song/with_content_tag.erb +6 -0
  82. data/test/fixtures/url_helper_test/song/with_form_for_block.erb +3 -0
  83. data/test/fixtures/url_helper_test/song/with_link_to.erb +3 -0
  84. data/test/layout_test.rb +57 -0
  85. data/test/partial_test.rb +27 -0
  86. data/test/prefixes_test.rb +36 -10
  87. data/test/public_test.rb +42 -0
  88. data/test/rails_extensions_test.rb +51 -0
  89. data/test/render_test.rb +103 -0
  90. data/test/templates_test.rb +45 -0
  91. data/test/test_case_test.rb +21 -122
  92. data/test/test_helper.rb +37 -33
  93. data/test/twin_test.rb +3 -7
  94. data/test/url_helper_test.rb +89 -0
  95. metadata +92 -357
  96. data/gemfiles/Gemfile.rails3-0 +0 -7
  97. data/gemfiles/Gemfile.rails3-1 +0 -7
  98. data/gemfiles/Gemfile.rails3-2 +0 -7
  99. data/gemfiles/Gemfile.rails4-0 +0 -12
  100. data/gemfiles/Gemfile.rails4-1 +0 -12
  101. data/lib/cell/base.rb +0 -82
  102. data/lib/cell/base/view.rb +0 -15
  103. data/lib/cell/builder.rb +0 -71
  104. data/lib/cell/deprecations.rb +0 -41
  105. data/lib/cell/dsl.rb +0 -7
  106. data/lib/cell/rack.rb +0 -32
  107. data/lib/cell/rails/helper_api.rb +0 -37
  108. data/lib/cell/rails/view_model.rb +0 -159
  109. data/lib/cell/rails3_0_strategy.rb +0 -82
  110. data/lib/cell/rails3_1_strategy.rb +0 -40
  111. data/lib/cell/rails4_0_strategy.rb +0 -39
  112. data/lib/cell/rails4_1_strategy.rb +0 -40
  113. data/lib/cell/rendering.rb +0 -109
  114. data/lib/cells/rails.rb +0 -86
  115. data/lib/cells/railtie.rb +0 -38
  116. data/lib/cells/version.rb +0 -3
  117. data/lib/generators/USAGE +0 -30
  118. data/lib/generators/cells/base.rb +0 -22
  119. data/lib/generators/cells/cell_generator.rb +0 -15
  120. data/lib/generators/cells/view_generator.rb +0 -18
  121. data/lib/generators/erb/cell_generator.rb +0 -15
  122. data/lib/generators/erb/concept_generator.rb +0 -17
  123. data/lib/generators/haml/cell_generator.rb +0 -17
  124. data/lib/generators/haml/concept_generator.rb +0 -17
  125. data/lib/generators/rails/cell_generator.rb +0 -16
  126. data/lib/generators/rails/concept_generator.rb +0 -16
  127. data/lib/generators/slim/cell_generator.rb +0 -17
  128. data/lib/generators/templates/cell.rb +0 -9
  129. data/lib/generators/templates/view.slim +0 -4
  130. data/lib/generators/test_unit/cell_generator.rb +0 -14
  131. data/lib/generators/trailblazer/base.rb +0 -21
  132. data/lib/generators/trailblazer/view_generator.rb +0 -18
  133. data/test/app/cells/album/views/cover.haml +0 -1
  134. data/test/app/cells/bad_guitarist/_dii.html.erb +0 -1
  135. data/test/app/cells/bad_guitarist_cell.rb +0 -2
  136. data/test/app/cells/bassist/_dii.html.erb +0 -1
  137. data/test/app/cells/bassist/ahem.html.erb +0 -1
  138. data/test/app/cells/bassist/compose.html.erb +0 -1
  139. data/test/app/cells/bassist/contact_form.html.erb +0 -1
  140. data/test/app/cells/bassist/form_for.erb +0 -3
  141. data/test/app/cells/bassist/form_for_in_haml.haml +0 -2
  142. data/test/app/cells/bassist/jam.html.erb +0 -3
  143. data/test/app/cells/bassist/play.js.erb +0 -1
  144. data/test/app/cells/bassist/pose.html.erb +0 -1
  145. data/test/app/cells/bassist/promote.html.erb +0 -1
  146. data/test/app/cells/bassist/provoke.html.erb +0 -1
  147. data/test/app/cells/bassist/shout.html.erb +0 -1
  148. data/test/app/cells/bassist/sing.html.haml +0 -1
  149. data/test/app/cells/bassist/slap.html.erb +0 -1
  150. data/test/app/cells/bassist/yell.en.html.erb +0 -1
  151. data/test/app/cells/bassist_cell.rb +0 -25
  152. data/test/app/cells/club_security.rb +0 -2
  153. data/test/app/cells/club_security/guard/help.html.erb +0 -1
  154. data/test/app/cells/club_security/guard_cell.rb +0 -6
  155. data/test/app/cells/club_security/medic/help.html.erb +0 -1
  156. data/test/app/cells/club_security/medic_cell.rb +0 -8
  157. data/test/app/cells/layouts/b.erb +0 -1
  158. data/test/app/cells/layouts/metal.html.erb +0 -1
  159. data/test/app/cells/rails_helper_api_test/bassist/edit.html.erb +0 -5
  160. data/test/app/cells/shouter/sing.html.erb +0 -1
  161. data/test/app/cells/song/dashboard.haml +0 -7
  162. data/test/app/cells/song/details.html.haml +0 -1
  163. data/test/app/cells/song/info.html.haml +0 -1
  164. data/test/app/cells/song/lyrics.html.haml +0 -6
  165. data/test/app/cells/song/plays.haml +0 -1
  166. data/test/app/cells/song/scale.haml +0 -1
  167. data/test/app/cells/song/show.html.haml +0 -3
  168. data/test/app/cells/song/title.html.haml +0 -1
  169. data/test/app/cells/trumpeter/promote.html.erb +0 -1
  170. data/test/app/cells/trumpeter_cell.rb +0 -8
  171. data/test/app/cells/view_model_test/comments/show.haml +0 -7
  172. data/test/app/concepts/record/views/layout.haml +0 -2
  173. data/test/app/views/shared/_dong.html.erb +0 -1
  174. data/test/cell_module_test.rb +0 -170
  175. data/test/cells_module_test.rb +0 -27
  176. data/test/deprecations_test.rb +0 -101
  177. data/test/dummy/app/helpers/application_helper.rb +0 -2
  178. data/test/dummy/app/views/musician/hamlet.html.haml +0 -1
  179. data/test/dummy/config/environments/development.rb +0 -16
  180. data/test/dummy/config/environments/production.rb +0 -46
  181. data/test/dummy/config/environments/test.rb +0 -33
  182. data/test/dummy/db/test.sqlite3 +0 -0
  183. data/test/dummy/label/app/cells/label/show.erb +0 -1
  184. data/test/dummy/label/app/cells/label_cell.rb +0 -5
  185. data/test/dummy/label/label.gemspec +0 -20
  186. data/test/dummy/label/lib/label.rb +0 -4
  187. data/test/dummy/label/lib/label/version.rb +0 -3
  188. data/test/dummy/public/404.html +0 -26
  189. data/test/dummy/public/422.html +0 -26
  190. data/test/dummy/public/500.html +0 -26
  191. data/test/dummy/public/favicon.ico +0 -0
  192. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  193. data/test/helper_test.rb +0 -81
  194. data/test/rack_test.rb +0 -32
  195. data/test/rails/asset_pipeline_test.rb +0 -20
  196. data/test/rails/caching_test.rb +0 -456
  197. data/test/rails/cells_test.rb +0 -119
  198. data/test/rails/forms_test.rb +0 -75
  199. data/test/rails/integration_test.rb +0 -299
  200. data/test/rails/render_test.rb +0 -189
  201. data/test/rails/view_model_test.rb +0 -226
  202. data/test/rails/view_test.rb +0 -49
  203. data/test/rails_helper_api_test.rb +0 -58
  204. data/test/self_contained_test.rb +0 -31
@@ -0,0 +1 @@
1
+ <p><%= yield %></p>
@@ -0,0 +1 @@
1
+ TTttttap I'm not good enough!
@@ -0,0 +1 @@
1
+ Adenosine Breakdown
@@ -0,0 +1 @@
1
+ I Am Wrong And I Am Right
@@ -0,0 +1 @@
1
+ <xml>I Am Wrong And I Am Right</xml>
@@ -0,0 +1 @@
1
+ <%= @title %>
@@ -0,0 +1 @@
1
+ <%= title %>
@@ -0,0 +1,4 @@
1
+ ERB:
2
+ <%= content_tag(:span) do %>
3
+ <%= title %>
4
+ <% end %>
@@ -0,0 +1 @@
1
+ <p>Yew!</p>
@@ -0,0 +1,2 @@
1
+ <%= title %>
2
+ <%= length %>
@@ -0,0 +1 @@
1
+ <%= "Happy #{yield}!" %>
@@ -0,0 +1 @@
1
+ <%= "Merry #{what}, #{yield}" %>
@@ -0,0 +1 @@
1
+ <%= title %>
@@ -0,0 +1 @@
1
+ The Great Mind Eraser
@@ -0,0 +1,8 @@
1
+ <%= form_tag "/songs" do %>
2
+ <%= label_tag :title %>
3
+ <%= text_field_tag :title %>
4
+
5
+ <%= content_tag :ul do %>
6
+ <%= content_tag :li, "Airplays: 1" %>
7
+ <%= end %>
8
+ <%= end %>
@@ -0,0 +1,2 @@
1
+ Nice!
2
+ <%= cap { "<b>yeah</b>" } %>
@@ -0,0 +1,4 @@
1
+ Nice!
2
+ <%= capture do %>
3
+ <%= "<b>Great!</b>" %>
4
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <%= content_tag :span do %>
2
+ "Title:"
3
+ <%= content_tag :div do %>
4
+ <%= "Still Knee Deep" %>
5
+ <% end %>
6
+ <%- end -%>
@@ -0,0 +1,3 @@
1
+ <%= form_for(OpenStruct.new, url: "/songs", as: :song) do |f| %>
2
+ <%= f.text_field :id %>
3
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <%= link_to songs_path do %>
2
+ <%= image_tag "all.png" %>
3
+ <% end %>
@@ -0,0 +1,57 @@
1
+ require 'test_helper'
2
+
3
+ class SongWithLayoutCell < Cell::ViewModel
4
+ self.view_paths = ['test/fixtures']
5
+
6
+ def show
7
+ render layout: :merry
8
+ end
9
+
10
+ def unknown
11
+ render layout: :no_idea_what_u_mean
12
+ end
13
+
14
+ def what
15
+ "Xmas"
16
+ end
17
+
18
+ def string
19
+ "Right"
20
+ end
21
+
22
+ private
23
+ def title
24
+ "<b>Papertiger</b>"
25
+ end
26
+ end
27
+
28
+ class SongWithLayoutOnClassCell < SongWithLayoutCell
29
+ # inherit_views SongWithLayoutCell
30
+ layout :merry
31
+
32
+ def show
33
+ render
34
+ end
35
+
36
+ def show_with_layout
37
+ render layout: :happy
38
+ end
39
+ end
40
+
41
+ class LayoutTest < MiniTest::Spec
42
+ # render show.haml calling method.
43
+ # same context as content view as layout call method.
44
+ it { SongWithLayoutCell.new(nil).show.must_equal "Merry Xmas, <b>Papertiger</b>\n" }
45
+
46
+ # raises exception when layout not found!
47
+
48
+ it { assert_raises(Cell::TemplateMissingError) { SongWithLayoutCell.new(nil).unknown } }
49
+ # assert message of exception.
50
+ it { }
51
+
52
+ # with ::layout.
53
+ it { SongWithLayoutOnClassCell.new(nil).show.must_equal "Merry Xmas, <b>Papertiger</b>\n" }
54
+
55
+ # with ::layout and :layout, :layout wins.
56
+ it { SongWithLayoutOnClassCell.new(nil).show_with_layout.must_equal "Happy Friday!" }
57
+ end
@@ -0,0 +1,27 @@
1
+ require "test_helper"
2
+ require "cell/partial"
3
+
4
+ class PartialTest < MiniTest::Spec
5
+ class WithPartial < Cell::ViewModel
6
+ self.view_paths = ['test/fixtures'] # doesn't exist.
7
+ self.template_engine = :erb
8
+
9
+ include Partial
10
+
11
+ def show
12
+ render partial: "../fixtures/partials/show.html"
13
+ end
14
+
15
+ def show_with_format
16
+ render partial: "../fixtures/partials/show", formats: [:xml]
17
+ end
18
+
19
+ def show_without_partial
20
+ render :show
21
+ end
22
+ end
23
+
24
+ it { WithPartial.new(nil).show.must_equal "I Am Wrong And I Am Right" }
25
+ it { WithPartial.new(nil).show_with_format.must_equal "<xml>I Am Wrong And I Am Right</xml>" }
26
+ it { WithPartial.new(nil).show_without_partial.must_equal "Adenosine Breakdown" }
27
+ end
@@ -1,15 +1,13 @@
1
1
  require 'test_helper'
2
2
 
3
- class BassistCell::FenderCell < Cell::Rails
3
+ class BassistCell::FenderCell < Cell::ViewModel
4
4
  end
5
5
 
6
6
  class BassistCell::IbanezCell < BassistCell
7
7
  end
8
8
 
9
9
  class PrefixesTest < MiniTest::Spec
10
- include Cell::TestCase::TestMethods
11
-
12
- class SingerCell < Cell::Base
10
+ class SingerCell < Cell::ViewModel
13
11
  end
14
12
 
15
13
  class BackgroundVocalsCell < SingerCell
@@ -54,9 +52,9 @@ class PrefixesTest < MiniTest::Spec
54
52
  end
55
53
 
56
54
  class InheritViewsTest < MiniTest::Spec
57
- include Cell::TestCase::TestMethods
55
+ class SlapperCell < Cell::ViewModel
56
+ self.view_paths = ['test/fixtures'] # todo: REMOVE!
58
57
 
59
- class SlapperCell < Cell::Rails
60
58
  inherit_views ::BassistCell
61
59
 
62
60
  def play
@@ -67,9 +65,37 @@ class InheritViewsTest < MiniTest::Spec
67
65
  class FunkerCell < SlapperCell
68
66
  end
69
67
 
70
- unless ::Cell.rails_version.~("3.0")
71
- # test if normal cells inherit views.
72
- it { cell("inherit_views_test/slapper").render_state(:play).must_equal "Doo" }
73
- it { cell("inherit_views_test/funker").render_state(:play).must_equal "Doo" }
68
+ it { SlapperCell.new(nil)._prefixes.must_equal ["inherit_views_test/slapper", "bassist"] }
69
+ it { FunkerCell.new(nil)._prefixes.must_equal ["inherit_views_test/funker", "inherit_views_test/slapper", "bassist"] }
70
+
71
+ # test if normal cells inherit views.
72
+ it { cell('inherit_views_test/slapper').play.must_equal 'Doo' }
73
+ it { cell('inherit_views_test/funker').play.must_equal 'Doo' }
74
+
75
+
76
+ # TapperCell
77
+ class TapperCell < Cell::ViewModel
78
+ self.view_paths = ['test/fixtures']
79
+
80
+ def play
81
+ render
82
+ end
83
+
84
+ def tap
85
+ render
86
+ end
74
87
  end
88
+
89
+ class PopperCell < TapperCell
90
+ end
91
+
92
+ # Tapper renders its play
93
+ it { cell('inherit_views_test/tapper').call(:play).must_equal 'Dooom!' }
94
+ # Tapper renders its tap
95
+ it { cell('inherit_views_test/tapper').call(:tap).must_equal 'Tap tap tap!' }
96
+
97
+ # Popper renders Tapper's play
98
+ it { cell('inherit_views_test/popper').call(:play).must_equal 'Dooom!' }
99
+ # Popper renders its tap
100
+ it { cell('inherit_views_test/popper').call(:tap).must_equal "TTttttap I'm not good enough!" }
75
101
  end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ class PublicTest < MiniTest::Spec
4
+ class SongCell < Cell::ViewModel
5
+ def initialize(controller, *args)
6
+ @parent_controller = controller # TODO: this is removed in 4.0.
7
+ @initialize_args = *args
8
+ end
9
+ attr_reader :initialize_args
10
+
11
+ def show
12
+ initialize_args.inspect
13
+ end
14
+
15
+ def detail
16
+ "* #{initialize_args}"
17
+ end
18
+ end
19
+
20
+ # ViewModel.cell returns the cell instance.
21
+ it { Cell::ViewModel.cell("public_test/song", nil).must_be_instance_of SongCell }
22
+
23
+ # ViewModel.cell passes options to cell.
24
+ it { Cell::ViewModel.cell("public_test/song", nil, Object, genre: "Metal").initialize_args.must_equal [Object, {:genre=>"Metal"}] }
25
+
26
+ # ViewModel.cell(collection: []) renders cells.
27
+ it { Cell::ViewModel.cell('public_test/song', nil, collection: [Object, Module]).must_equal '[Object, {}][Module, {}]' }
28
+
29
+ # ViewModel.cell(collection: []) renders cells with custom join.
30
+ it { Cell::ViewModel.cell('public_test/song', nil, collection: [Object, Module], collection_join: '<br/>').must_equal '[Object, {}]<br/>[Module, {}]' }
31
+
32
+ # ViewModel.cell(collection: []) renders html_safe.
33
+ it { Cell::ViewModel.cell("public_test/song", nil, collection: [Object]).class.must_equal ActiveSupport::SafeBuffer }
34
+
35
+ # ViewModel.cell(collection: []) passes generic options to cell.
36
+ it { Cell::ViewModel.cell('public_test/song', nil, collection: [Object, Module], genre: 'Metal').must_equal "[Object, {:genre=>\"Metal\"}][Module, {:genre=>\"Metal\"}]" }
37
+
38
+ # ViewModel.cell(collection: [], method: :detail) invokes #detail instead of #show.
39
+ it { Cell::ViewModel.cell('public_test/song', nil, collection: [Object, Module], method: :detail).must_equal '* [Object, {}]* [Module, {}]' }
40
+ end
41
+
42
+ # TODO: test AV::concept.
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+ class ViewExtensionsTest < ActionController::TestCase
4
+ tests MusicianController
5
+
6
+ class Cell < Cell::Concept
7
+ def show
8
+ "<b>#{model}</b>"
9
+ end
10
+ end
11
+
12
+ class SongCell < ::Cell::ViewModel
13
+ def show
14
+ "<b>#{model}</b>"
15
+ end
16
+ end
17
+
18
+
19
+ # #concept is available in controller views.
20
+ test "concept(..).show" do
21
+ get :view_with_concept_with_show
22
+ @response.body.must_equal "&lt;b&gt;Up For Breakfast&lt;/b&gt;" # TODO: test options/with twin.
23
+ end
24
+
25
+ test "concept(..).call" do
26
+ get :view_with_concept_with_call
27
+ @response.body.must_equal "<b>A Tale That Wasn't Right</b>" # TODO: test options/with twin.
28
+ end
29
+
30
+ test "concept(..) without #call" do
31
+ get :view_with_concept_without_call
32
+ @response.body.must_equal "<b>A Tale That Wasn't Right</b>"
33
+ end
34
+
35
+ test "cell(..) with #call" do
36
+ get :view_with_cell_with_call
37
+ @response.body.must_equal "<b>A Tale That Wasn't Right</b>"
38
+ end
39
+
40
+ # Controller#concept
41
+ test "Controller#concept(..).call" do
42
+ get :action_with_concept_with_call
43
+ @response.body.must_equal "<b>A Tale That Wasn't Right</b>" # TODO: test options/with twin.
44
+ end
45
+
46
+ # Controller#cell
47
+ test "Controller#cell(..).call" do
48
+ get :action_with_cell_with_call
49
+ @response.body.must_equal "<b>A Tale That Wasn't Right</b>" # TODO: test options/with twin.
50
+ end
51
+ end
@@ -0,0 +1,103 @@
1
+ require 'test_helper'
2
+
3
+ class SongCell < Cell::ViewModel
4
+ self.view_paths = ['test/fixtures']
5
+
6
+ def show
7
+ render
8
+ end
9
+
10
+ def ivar
11
+ @title = "Carnage"
12
+ render
13
+ end
14
+
15
+ def unknown
16
+ render
17
+ end
18
+
19
+ def string
20
+ "Right"
21
+ end
22
+
23
+ # TODO: just pass hash.
24
+ def with_locals
25
+ render locals: {length: 280, title: "Shot Across The Bow"}
26
+ end
27
+
28
+ def with_erb
29
+ render template_engine: :erb
30
+ end
31
+
32
+ def with_view_name
33
+ @title = "Man Of Steel"
34
+ render :ivar
35
+ end
36
+
37
+ def receiving_options(layout=:default)
38
+ "#{layout}"
39
+ end
40
+
41
+ def with_html
42
+ render
43
+ end
44
+
45
+ private
46
+ def title
47
+ "Papertiger"
48
+ end
49
+ end
50
+
51
+ class RenderTest < MiniTest::Spec
52
+ # render show.haml calling method.
53
+ it { SongCell.new(nil).show.must_equal "Papertiger\n" }
54
+
55
+ # render ivar.haml using instance variable.
56
+ it { SongCell.new(nil).ivar.must_equal "Carnage\n" }
57
+
58
+ # render string.
59
+ it { SongCell.new(nil).string.must_equal "Right" }
60
+
61
+ # #call renders :show
62
+ it { SongCell.new(nil).call.must_equal "Papertiger\n" }
63
+
64
+ # call(:form) renders :form
65
+ it { SongCell.new(nil).call(:with_view_name).must_equal "Man Of Steel\n" }
66
+
67
+ # #call returns html_safe.
68
+ it { SongCell.new(nil).call.must_be_instance_of ActiveSupport::SafeBuffer }
69
+
70
+ # throws an exception when not found.
71
+ it do
72
+ exception = assert_raises(Cell::TemplateMissingError) { SongCell.new(nil).unknown }
73
+ exception.message.must_equal "Template missing: view: `unknown.erb` prefixes: [\"song\"] view_paths:[\"test/fixtures\"]"
74
+ end
75
+
76
+ # allows locals
77
+ it { SongCell.new(nil).with_locals.must_equal "Shot Across The Bow\n280\n" }
78
+
79
+ # render :form is a shortcut.
80
+ it { SongCell.new(nil).with_view_name.must_equal "Man Of Steel\n" }
81
+
82
+ # :template_engine renders ERB.
83
+ # it { SongCell.new(nil).with_erb.must_equal "ERB:\n<span>\n Papertiger\n</span>" }
84
+
85
+ # view: "show.html"
86
+
87
+ # allows passing in options DISCUSS: how to handle that in cache block/builder?
88
+ it { SongCell.new(nil).receiving_options.must_equal "default" }
89
+ it { SongCell.new(nil).receiving_options(:fancy).must_equal "fancy" }
90
+ it { SongCell.new(nil).call(:receiving_options, :fancy).must_equal "fancy" }
91
+
92
+ # doesn't escape HTML.
93
+ it { SongCell.new(nil).call(:with_html).must_equal "<p>Yew!</p>" }
94
+ end
95
+
96
+ # test inheritance
97
+
98
+ # test view: :bla and :bla
99
+ # with layout and locals.
100
+ # with layout and :text
101
+
102
+ # render with format (e.g. when using ERB for one view)
103
+ # should we allow changing the format "per run", so a cell can do .js and .haml? or should that be configurable on class level?