cells 3.11.3 → 4.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +15 -13
- data/Appraisals +23 -0
- data/CHANGES.md +20 -3
- data/Gemfile +5 -7
- data/README.md +317 -236
- data/Rakefile +1 -1
- data/TODO.md +3 -0
- data/cells.gemspec +19 -28
- data/gemfiles/rails3.2.gemfile +14 -0
- data/gemfiles/rails4.0.gemfile +14 -0
- data/gemfiles/rails4.1.gemfile +15 -0
- data/gemfiles/rails4.2.gemfile +14 -0
- data/lib/cell.rb +28 -21
- data/lib/cell/caching.rb +10 -22
- data/lib/cell/caching/notification.rb +15 -0
- data/lib/cell/concept.rb +4 -69
- data/lib/cell/development.rb +11 -0
- data/lib/{cells → cell}/engines.rb +1 -1
- data/lib/cell/layout.rb +20 -0
- data/lib/cell/partial.rb +17 -0
- data/lib/cell/{base/prefixes.rb → prefixes.rb} +1 -1
- data/lib/cell/rails.rb +58 -50
- data/lib/cell/railtie.rb +60 -0
- data/lib/cell/{base/self_contained.rb → self_contained.rb} +1 -1
- data/lib/cell/templates.rb +60 -0
- data/lib/cell/test_case.rb +4 -162
- data/lib/cell/testing.rb +15 -0
- data/lib/cell/twin.rb +11 -29
- data/lib/cell/version.rb +10 -0
- data/lib/cell/view_model.rb +196 -88
- data/lib/cells.rb +1 -20
- data/lib/rails/generators/cell/cell_generator.rb +43 -0
- data/lib/rails/generators/cell/templates/cell.rb.erb +8 -0
- data/lib/{generators/templates/concept → rails/generators/cell/templates}/view.erb +0 -0
- data/lib/{generators/templates/concept → rails/generators/cell/templates}/view.haml +0 -0
- data/lib/rails/generators/cell/templates/view.slim +2 -0
- data/lib/rails/generators/concept/concept_generator.rb +38 -0
- data/lib/{generators/templates/concept/cell.rb → rails/generators/concept/templates/concept.rb.erb} +2 -2
- data/lib/{generators → rails/generators/concept}/templates/view.erb +0 -0
- data/lib/{generators → rails/generators/concept}/templates/view.haml +0 -0
- data/lib/rails/generators/concept/templates/view.slim +2 -0
- data/lib/rails/generators/test_unit/cell/cell_generator.rb +21 -0
- data/lib/{generators/templates/cell_test.rb → rails/generators/test_unit/cell/templates/unit_test.rb.erb} +3 -3
- data/lib/rails/generators/test_unit/concept/concept_generator.rb +21 -0
- data/lib/rails/generators/test_unit/concept/templates/unit_test.rb.erb +11 -0
- data/lib/{cells → tasks}/cells.rake +0 -0
- data/test/builder_test.rb +58 -0
- data/test/caching_test.rb +298 -0
- data/test/cell_benchmark.rb +32 -0
- data/test/cell_generator_test.rb +51 -82
- data/test/cell_test.rb +8 -23
- data/test/concept_generator_test.rb +22 -13
- data/test/concept_test.rb +41 -75
- data/test/dummy/app/views/musician/hamlet.html.erb +1 -0
- data/test/dummy/config/application.rb +21 -8
- data/test/{app/cells/bassist/play.html.erb → fixtures/bassist/play.erb} +0 -0
- data/test/fixtures/concepts/record/views/layout.erb +1 -0
- data/test/{app → fixtures}/concepts/record/views/show.erb +0 -0
- data/test/{app → fixtures}/concepts/record/views/song.erb +0 -0
- data/test/fixtures/inherit_views_test/popper/tap.erb +1 -0
- data/test/fixtures/inherit_views_test/tapper/play.erb +1 -0
- data/test/fixtures/inherit_views_test/tapper/tap.erb +1 -0
- data/test/fixtures/partial_test/with_partial/show.erb +1 -0
- data/test/fixtures/partials/_show.html.erb +1 -0
- data/test/fixtures/partials/_show.xml.erb +1 -0
- data/test/fixtures/song/ivar.erb +1 -0
- data/test/fixtures/song/show.erb +1 -0
- data/test/fixtures/song/with_erb.erb +4 -0
- data/test/fixtures/song/with_html.erb +1 -0
- data/test/fixtures/song/with_locals.erb +2 -0
- data/test/fixtures/song_with_layout/happy.erb +1 -0
- data/test/fixtures/song_with_layout/merry.erb +1 -0
- data/test/fixtures/song_with_layout/show.erb +1 -0
- data/test/fixtures/song_with_layout/show_with_layout.erb +1 -0
- data/test/fixtures/templates_caching_test/song/show.erb +1 -0
- data/test/fixtures/url_helper_test/song/edit.erb +8 -0
- data/test/fixtures/url_helper_test/song/with_block.erb +2 -0
- data/test/fixtures/url_helper_test/song/with_capture.erb +4 -0
- data/test/fixtures/url_helper_test/song/with_content_tag.erb +6 -0
- data/test/fixtures/url_helper_test/song/with_form_for_block.erb +3 -0
- data/test/fixtures/url_helper_test/song/with_link_to.erb +3 -0
- data/test/layout_test.rb +57 -0
- data/test/partial_test.rb +27 -0
- data/test/prefixes_test.rb +36 -10
- data/test/public_test.rb +42 -0
- data/test/rails_extensions_test.rb +51 -0
- data/test/render_test.rb +103 -0
- data/test/templates_test.rb +45 -0
- data/test/test_case_test.rb +21 -122
- data/test/test_helper.rb +37 -33
- data/test/twin_test.rb +3 -7
- data/test/url_helper_test.rb +89 -0
- metadata +92 -357
- data/gemfiles/Gemfile.rails3-0 +0 -7
- data/gemfiles/Gemfile.rails3-1 +0 -7
- data/gemfiles/Gemfile.rails3-2 +0 -7
- data/gemfiles/Gemfile.rails4-0 +0 -12
- data/gemfiles/Gemfile.rails4-1 +0 -12
- data/lib/cell/base.rb +0 -82
- data/lib/cell/base/view.rb +0 -15
- data/lib/cell/builder.rb +0 -71
- data/lib/cell/deprecations.rb +0 -41
- data/lib/cell/dsl.rb +0 -7
- data/lib/cell/rack.rb +0 -32
- data/lib/cell/rails/helper_api.rb +0 -37
- data/lib/cell/rails/view_model.rb +0 -159
- data/lib/cell/rails3_0_strategy.rb +0 -82
- data/lib/cell/rails3_1_strategy.rb +0 -40
- data/lib/cell/rails4_0_strategy.rb +0 -39
- data/lib/cell/rails4_1_strategy.rb +0 -40
- data/lib/cell/rendering.rb +0 -109
- data/lib/cells/rails.rb +0 -86
- data/lib/cells/railtie.rb +0 -38
- data/lib/cells/version.rb +0 -3
- data/lib/generators/USAGE +0 -30
- data/lib/generators/cells/base.rb +0 -22
- data/lib/generators/cells/cell_generator.rb +0 -15
- data/lib/generators/cells/view_generator.rb +0 -18
- data/lib/generators/erb/cell_generator.rb +0 -15
- data/lib/generators/erb/concept_generator.rb +0 -17
- data/lib/generators/haml/cell_generator.rb +0 -17
- data/lib/generators/haml/concept_generator.rb +0 -17
- data/lib/generators/rails/cell_generator.rb +0 -16
- data/lib/generators/rails/concept_generator.rb +0 -16
- data/lib/generators/slim/cell_generator.rb +0 -17
- data/lib/generators/templates/cell.rb +0 -9
- data/lib/generators/templates/view.slim +0 -4
- data/lib/generators/test_unit/cell_generator.rb +0 -14
- data/lib/generators/trailblazer/base.rb +0 -21
- data/lib/generators/trailblazer/view_generator.rb +0 -18
- data/test/app/cells/album/views/cover.haml +0 -1
- data/test/app/cells/bad_guitarist/_dii.html.erb +0 -1
- data/test/app/cells/bad_guitarist_cell.rb +0 -2
- data/test/app/cells/bassist/_dii.html.erb +0 -1
- data/test/app/cells/bassist/ahem.html.erb +0 -1
- data/test/app/cells/bassist/compose.html.erb +0 -1
- data/test/app/cells/bassist/contact_form.html.erb +0 -1
- data/test/app/cells/bassist/form_for.erb +0 -3
- data/test/app/cells/bassist/form_for_in_haml.haml +0 -2
- data/test/app/cells/bassist/jam.html.erb +0 -3
- data/test/app/cells/bassist/play.js.erb +0 -1
- data/test/app/cells/bassist/pose.html.erb +0 -1
- data/test/app/cells/bassist/promote.html.erb +0 -1
- data/test/app/cells/bassist/provoke.html.erb +0 -1
- data/test/app/cells/bassist/shout.html.erb +0 -1
- data/test/app/cells/bassist/sing.html.haml +0 -1
- data/test/app/cells/bassist/slap.html.erb +0 -1
- data/test/app/cells/bassist/yell.en.html.erb +0 -1
- data/test/app/cells/bassist_cell.rb +0 -25
- data/test/app/cells/club_security.rb +0 -2
- data/test/app/cells/club_security/guard/help.html.erb +0 -1
- data/test/app/cells/club_security/guard_cell.rb +0 -6
- data/test/app/cells/club_security/medic/help.html.erb +0 -1
- data/test/app/cells/club_security/medic_cell.rb +0 -8
- data/test/app/cells/layouts/b.erb +0 -1
- data/test/app/cells/layouts/metal.html.erb +0 -1
- data/test/app/cells/rails_helper_api_test/bassist/edit.html.erb +0 -5
- data/test/app/cells/shouter/sing.html.erb +0 -1
- data/test/app/cells/song/dashboard.haml +0 -7
- data/test/app/cells/song/details.html.haml +0 -1
- data/test/app/cells/song/info.html.haml +0 -1
- data/test/app/cells/song/lyrics.html.haml +0 -6
- data/test/app/cells/song/plays.haml +0 -1
- data/test/app/cells/song/scale.haml +0 -1
- data/test/app/cells/song/show.html.haml +0 -3
- data/test/app/cells/song/title.html.haml +0 -1
- data/test/app/cells/trumpeter/promote.html.erb +0 -1
- data/test/app/cells/trumpeter_cell.rb +0 -8
- data/test/app/cells/view_model_test/comments/show.haml +0 -7
- data/test/app/concepts/record/views/layout.haml +0 -2
- data/test/app/views/shared/_dong.html.erb +0 -1
- data/test/cell_module_test.rb +0 -170
- data/test/cells_module_test.rb +0 -27
- data/test/deprecations_test.rb +0 -101
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/views/musician/hamlet.html.haml +0 -1
- data/test/dummy/config/environments/development.rb +0 -16
- data/test/dummy/config/environments/production.rb +0 -46
- data/test/dummy/config/environments/test.rb +0 -33
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/label/app/cells/label/show.erb +0 -1
- data/test/dummy/label/app/cells/label_cell.rb +0 -5
- data/test/dummy/label/label.gemspec +0 -20
- data/test/dummy/label/lib/label.rb +0 -4
- data/test/dummy/label/lib/label/version.rb +0 -3
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -26
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/stylesheets/.gitkeep +0 -0
- data/test/helper_test.rb +0 -81
- data/test/rack_test.rb +0 -32
- data/test/rails/asset_pipeline_test.rb +0 -20
- data/test/rails/caching_test.rb +0 -456
- data/test/rails/cells_test.rb +0 -119
- data/test/rails/forms_test.rb +0 -75
- data/test/rails/integration_test.rb +0 -299
- data/test/rails/render_test.rb +0 -189
- data/test/rails/view_model_test.rb +0 -226
- data/test/rails/view_test.rb +0 -49
- data/test/rails_helper_api_test.rb +0 -58
- data/test/self_contained_test.rb +0 -31
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<p><%= yield %></p>
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
TTttttap I'm not good enough!
|
@@ -0,0 +1 @@
|
|
1
|
+
Dooom!
|
@@ -0,0 +1 @@
|
|
1
|
+
Tap tap tap!
|
@@ -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 @@
|
|
1
|
+
<p>Yew!</p>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= "Happy #{yield}!" %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= "Merry #{what}, #{yield}" %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= title %>
|
@@ -0,0 +1 @@
|
|
1
|
+
Friday
|
@@ -0,0 +1 @@
|
|
1
|
+
The Great Mind Eraser
|
data/test/layout_test.rb
ADDED
@@ -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
|
data/test/prefixes_test.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class BassistCell::FenderCell < Cell::
|
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
|
-
|
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
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
data/test/public_test.rb
ADDED
@@ -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 "<b>Up For Breakfast</b>" # 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
|
data/test/render_test.rb
ADDED
@@ -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?
|