cells 3.3.10 → 3.4.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +0 -8
- data/Gemfile +4 -1
- data/README.rdoc +91 -107
- data/Rakefile +0 -4
- data/lib/cell.rb +5 -6
- data/lib/{cells/cell → cell}/active_helper.rb +1 -1
- data/lib/cell/base.rb +134 -0
- data/lib/cell/base_methods.rb +100 -0
- data/lib/cell/caching.rb +153 -0
- data/lib/cell/rails.rb +239 -0
- data/lib/cells.rb +25 -3
- data/lib/cells/assertions_helper.rb +1 -1
- data/lib/cells/helpers/capture_helper.rb +3 -3
- data/lib/cells/rails.rb +65 -4
- data/lib/cells/version.rb +3 -1
- data/rails_generators/cell/cell_generator.rb +47 -35
- data/rails_generators/cell/templates/cell.rb +1 -1
- data/rails_generators/cells_install/cells_install_generator.rb +5 -3
- data/rails_generators/erb/cell_generator.rb +20 -0
- data/rails_generators/{cell → erb}/templates/view.html.erb +0 -0
- data/test/active_helper_test.rb +1 -0
- data/test/app/cells/bad_guitarist_cell.rb +2 -0
- data/test/app/cells/bassist_cell.rb +1 -1
- data/test/app/controllers/musician_controller.rb +16 -0
- data/test/assertions_helper_test.rb +8 -18
- data/test/base_methods_test.rb +40 -0
- data/test/cell_generator_test.rb +33 -21
- data/test/helper_test.rb +31 -123
- data/test/rails/caching_test.rb +215 -0
- data/test/rails/capture_test.rb +52 -0
- data/test/rails/cells_test.rb +88 -0
- data/test/rails/integration_test.rb +37 -0
- data/test/rails/render_test.rb +140 -0
- data/test/rails/router_test.rb +74 -0
- data/test/rails/view_test.rb +24 -0
- data/test/test_helper.rb +30 -29
- metadata +68 -133
- data/.gitignore +0 -3
- data/about.yml +0 -7
- data/cells.gemspec +0 -26
- data/lib/cells/cell.rb +0 -16
- data/lib/cells/cell/base.rb +0 -470
- data/lib/cells/cell/caching.rb +0 -163
- data/lib/cells/cell/test_case.rb +0 -158
- data/lib/cells/cell/view.rb +0 -55
- data/lib/cells/rails/action_controller.rb +0 -37
- data/lib/cells/rails/action_view.rb +0 -37
- data/rails/init.rb +0 -44
- data/rails_generators/cells_install/templates/tasks.rake +0 -6
- data/test/app/cells/a/another_state.html.erb +0 -1
- data/test/app/cells/a/existing_view.html.erb +0 -1
- data/test/app/cells/a/inherited_view.html.erb +0 -1
- data/test/app/cells/a/inherited_view.js.erb +0 -1
- data/test/app/cells/a/view_with_locals.html.erb +0 -1
- data/test/app/cells/a/view_with_render_call.html.erb +0 -1
- data/test/app/cells/b/existing_view.html.erb +0 -1
- data/test/app/cells/b/existing_view.js.erb +0 -1
- data/test/app/cells/b/layouts/metal.html.erb +0 -1
- data/test/app/cells/b/view_with_render_call.html.erb +0 -1
- data/test/app/cells/bassist/jam.html.erb +0 -3
- data/test/app/cells/bassist/play.html.erb +0 -1
- data/test/app/cells/cells_test_one/renamed_instance_view.html.erb +0 -1
- data/test/app/cells/cells_test_one/super_state.html.erb +0 -1
- data/test/app/cells/cells_test_one_cell.rb +0 -20
- data/test/app/cells/cells_test_two_cell.rb +0 -4
- data/test/app/cells/helper_using/state_using_application_helper.html.erb +0 -3
- data/test/app/cells/helper_using/state_with_automatic_helper_invocation.html.erb +0 -3
- data/test/app/cells/helper_using/state_with_helper_invocation.html.erb +0 -3
- data/test/app/cells/helper_using/state_with_helper_method_invocation.html.erb +0 -3
- data/test/app/cells/layouts/metal.html.erb +0 -1
- data/test/app/cells/my_child/hello.html.erb +0 -1
- data/test/app/cells/my_mother/bye.html.erb +0 -1
- data/test/app/cells/my_mother/hello.html.erb +0 -1
- data/test/app/cells/my_test/_broken_partial.html.erb +0 -1
- data/test/app/cells/my_test/_partial.html.erb +0 -1
- data/test/app/cells/my_test/state_with_instance_var.html.erb +0 -1
- data/test/app/cells/my_test/state_with_link_to.html.erb +0 -3
- data/test/app/cells/my_test/state_with_not_included_helper_method.html.erb +0 -8
- data/test/app/cells/my_test/view_containing_broken_partial.html.erb +0 -3
- data/test/app/cells/my_test/view_containing_nonexistant_partial.html.erb +0 -3
- data/test/app/cells/my_test/view_containing_partial.html.erb +0 -3
- data/test/app/cells/my_test/view_containing_partial_without_cell_name.html.erb +0 -3
- data/test/app/cells/my_test/view_in_local_test_views_dir.html.erb +0 -1
- data/test/app/cells/my_test/view_with_explicit_english_translation.en.html.erb +0 -1
- data/test/app/cells/my_test/view_with_explicit_english_translation.html.erb +0 -1
- data/test/app/cells/my_test/view_with_instance_var.html.erb +0 -4
- data/test/app/cells/really_module/nested/happy_state.html.erb +0 -1
- data/test/app/cells/really_module/nested_cell.rb +0 -11
- data/test/app/cells/simple/two_templates_state.html.mytpl +0 -1
- data/test/app/cells/simple_cell.rb +0 -7
- data/test/app/cells/test/beep.html.erb +0 -1
- data/test/app/cells/test/state_invoking_capture.html.erb +0 -7
- data/test/app/cells/test/state_invoking_content_for.html.erb +0 -7
- data/test/app/cells/test/state_invoking_content_for_twice.html.erb +0 -9
- data/test/app/cells/test/state_with_not_included_helper_method.html.erb +0 -8
- data/test/app/cells/two_helpers_including/state_using_another_helper.html.erb +0 -3
- data/test/bugs_test.rb +0 -23
- data/test/caching_test.rb +0 -270
- data/test/capture_helper_test.rb +0 -59
- data/test/cells_test.rb +0 -352
- data/test/rails_test.rb +0 -35
- data/test/render_test.rb +0 -305
- data/test/test_case_test.rb +0 -106
@@ -0,0 +1,215 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
3
|
+
|
4
|
+
class DirectorCell < Cell::Rails
|
5
|
+
cache :count
|
6
|
+
@@counter = 0
|
7
|
+
|
8
|
+
def count
|
9
|
+
@@counter += 1
|
10
|
+
render :text => @@counter
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class CachingTest < ActiveSupport::TestCase
|
15
|
+
context "A cell" do
|
16
|
+
setup do
|
17
|
+
::ActionController::Base.cache_store = :memory_store
|
18
|
+
::ActionController::Base.perform_caching = true
|
19
|
+
end
|
20
|
+
|
21
|
+
should "respond to state_cached?" do
|
22
|
+
assert cell(:director).state_cached?(:count)
|
23
|
+
assert_not cell(:director).state_cached?(:sing)
|
24
|
+
end
|
25
|
+
|
26
|
+
context "caching a state" do
|
27
|
+
setup do
|
28
|
+
@proc = Proc.new{}
|
29
|
+
end
|
30
|
+
|
31
|
+
should "save the version proc" do
|
32
|
+
DirectorCell.cache :count, @proc
|
33
|
+
|
34
|
+
assert_equal @proc, cell(:director).class.version_procs[:count]
|
35
|
+
assert_equal({}, cell(:director).class.cache_options[:count])
|
36
|
+
end
|
37
|
+
|
38
|
+
should "save the cache options" do
|
39
|
+
DirectorCell.cache :count, @proc, :expires_in => 10.minutes
|
40
|
+
|
41
|
+
assert_equal @proc, cell(:director).class.version_procs[:count]
|
42
|
+
assert_equal({:expires_in => 10.minutes}, cell(:director).class.cache_options[:count])
|
43
|
+
end
|
44
|
+
|
45
|
+
should "not mix caching configuration with other classes" do
|
46
|
+
DirectorCell.cache :count
|
47
|
+
class SecondDirectorCell < DirectorCell; end
|
48
|
+
SecondDirectorCell.cache :count, @proc
|
49
|
+
|
50
|
+
assert_equal nil, cell(:director).class.version_procs[:count]
|
51
|
+
assert_equal @proc, cell(:"caching_test/second_director").class.version_procs[:count]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "caching without options" do
|
56
|
+
setup do
|
57
|
+
DirectorCell.class_eval do
|
58
|
+
@@counter = 0
|
59
|
+
cattr_accessor :count
|
60
|
+
end
|
61
|
+
|
62
|
+
key = cell(:director).cache_key(:count, :count => 0)
|
63
|
+
Cell::Base.expire_cache_key(key) ### TODO: separate test
|
64
|
+
end
|
65
|
+
|
66
|
+
should "cache forever" do
|
67
|
+
DirectorCell.class_eval do
|
68
|
+
cache :count
|
69
|
+
end
|
70
|
+
|
71
|
+
assert cell(:director).state_cached?(:count)
|
72
|
+
assert_equal nil, cell(:director).class.version_procs[:count]
|
73
|
+
assert_equal({}, cell(:director).class.cache_options[:count])
|
74
|
+
|
75
|
+
assert_equal render_cell(:director, :count), render_cell(:director, :count)
|
76
|
+
end
|
77
|
+
|
78
|
+
should "not cache at all" do
|
79
|
+
DirectorCell.class_eval do
|
80
|
+
def dictate
|
81
|
+
@@counter += 1
|
82
|
+
render :text => @@counter
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
assert_equal "1", render_cell(:director, :dictate)
|
87
|
+
assert_equal "2", render_cell(:director, :dictate)
|
88
|
+
end
|
89
|
+
|
90
|
+
should "expire the cache with a version proc" do
|
91
|
+
DirectorCell.class_eval do
|
92
|
+
cache :count, Proc.new { |cell|
|
93
|
+
cell.class.count >= 2 ? {:count => 2} : {:count => 0}
|
94
|
+
}
|
95
|
+
|
96
|
+
def count
|
97
|
+
render :text => @@count += 1
|
98
|
+
#@@count
|
99
|
+
end
|
100
|
+
end
|
101
|
+
DirectorCell.count = 0
|
102
|
+
|
103
|
+
assert_equal "1", render_cell(:director, :count)
|
104
|
+
assert_equal "1", render_cell(:director, :count) # cached.
|
105
|
+
|
106
|
+
DirectorCell.count = 2 # invalidates the view cache.
|
107
|
+
assert_equal "3", render_cell(:director, :count)
|
108
|
+
assert_equal "3", render_cell(:director, :count) # cached.
|
109
|
+
end
|
110
|
+
|
111
|
+
should "expire the cache with an instance method" do
|
112
|
+
DirectorCell.class_eval do
|
113
|
+
cache :count, :expire_count
|
114
|
+
|
115
|
+
def expire_count
|
116
|
+
self.class.count >= 2 ? {:count => 2} : {:count => 0}
|
117
|
+
end
|
118
|
+
|
119
|
+
def count
|
120
|
+
@@count += 1
|
121
|
+
render :text => @@count
|
122
|
+
end
|
123
|
+
end
|
124
|
+
DirectorCell.count = 0
|
125
|
+
|
126
|
+
assert_equal "1", render_cell(:director, :count)
|
127
|
+
assert_equal "1", render_cell(:director, :count) # cached.
|
128
|
+
|
129
|
+
DirectorCell.count = 2 # invalidates the view cache.
|
130
|
+
assert_equal "3", render_cell(:director, :count)
|
131
|
+
assert_equal "3", render_cell(:director, :count) # cached.
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "cache_key" do
|
137
|
+
setup do
|
138
|
+
@cell = cell(:director)
|
139
|
+
end
|
140
|
+
|
141
|
+
should "respond to cache_key" do
|
142
|
+
assert_equal "cells/director/count", @cell.cache_key(:count)
|
143
|
+
assert_equal @cell.cache_key(:count), ::Cell::Base.cache_key_for(:director, :count)
|
144
|
+
end
|
145
|
+
|
146
|
+
should "order options lexically" do
|
147
|
+
assert_equal "cells/director/count/a=1/b=2", @cell.cache_key(:count, :b => 2, :a => 1)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context "expire_cache_key" do
|
152
|
+
setup do
|
153
|
+
DirectorCell.class_eval do
|
154
|
+
cache :count
|
155
|
+
def count
|
156
|
+
render :text => @@count += 1
|
157
|
+
end
|
158
|
+
end
|
159
|
+
DirectorCell.count = 0
|
160
|
+
|
161
|
+
@key = cell(:director).cache_key(:count)
|
162
|
+
render_cell(:director, :count)
|
163
|
+
assert_equal "1", ::Cell::Base.cache_store.read(@key)
|
164
|
+
end
|
165
|
+
|
166
|
+
should "delete the view from cache" do
|
167
|
+
::Cell::Base.expire_cache_key(@key)
|
168
|
+
assert_not ::Cell::Base.cache_store.read(@key)
|
169
|
+
end
|
170
|
+
|
171
|
+
should "be available in controllers for sweepers" do
|
172
|
+
MusicianController.new.expire_cell_state(:director, :count)
|
173
|
+
assert_not ::Cell::Base.cache_store.read(@key)
|
174
|
+
end
|
175
|
+
|
176
|
+
should "accept cache options" do
|
177
|
+
key = cell(:director).cache_key(:count, :volume => 9)
|
178
|
+
assert ::Cell::Base.cache_store.write(key, 'ONE!')
|
179
|
+
|
180
|
+
MusicianController.new.expire_cell_state(:director, :count, :volume => 9)
|
181
|
+
assert_not ::Cell::Base.cache_store.read(key)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_find_family_view_for_state_with_caching
|
186
|
+
# test environment: --------------------------------------
|
187
|
+
BassistCell.instance_variable_set :@state2view_cache, {}
|
188
|
+
assert_equal({}, BassistCell.state2view_cache)
|
189
|
+
|
190
|
+
BassistCell.instance_eval do
|
191
|
+
self.default_template_format = :html
|
192
|
+
|
193
|
+
def play; render; end
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
cell = cell(:bassist)
|
198
|
+
cell.class.instance_eval do
|
199
|
+
def cache_configured?; false; end
|
200
|
+
end
|
201
|
+
cell.render_state :play
|
202
|
+
# in development/test environment, no view name caching should happen,
|
203
|
+
# if perform_caching is false.
|
204
|
+
assert_equal({}, BassistCell.state2view_cache)
|
205
|
+
|
206
|
+
# production environment: --------------------------------
|
207
|
+
cell = BassistCell.new(@controller)
|
208
|
+
cell.class.instance_eval do
|
209
|
+
def cache_configured?; true; end
|
210
|
+
end
|
211
|
+
|
212
|
+
cell.render_state :play
|
213
|
+
assert BassistCell.state2view_cache["play/html"]
|
214
|
+
end
|
215
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.join(File.dirname(__FILE__), '/../test_helper')
|
3
|
+
|
4
|
+
class ProducerCell < Cell::Base
|
5
|
+
helper ::Cells::Helpers::CaptureHelper
|
6
|
+
|
7
|
+
def logger(*args); puts args.inspect; end
|
8
|
+
end
|
9
|
+
|
10
|
+
class RailsCaptureTest < ActionController::TestCase
|
11
|
+
context "A Rails controller rendering cells" do
|
12
|
+
setup do
|
13
|
+
@routes = ActionDispatch::Routing::RouteSet.new
|
14
|
+
@routes.draw do
|
15
|
+
|map| match ':action', :to => MusicianController
|
16
|
+
end
|
17
|
+
@controller = MusicianController.new
|
18
|
+
end
|
19
|
+
|
20
|
+
should "see content from global_capture" do
|
21
|
+
@controller.class_eval do
|
22
|
+
def featured
|
23
|
+
render :inline => '<h3><%= @recorded %></h3>' << render_cell(:producer, :capture)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
ProducerCell.class_eval do
|
28
|
+
def capture; render; end
|
29
|
+
end
|
30
|
+
|
31
|
+
get 'featured'
|
32
|
+
assert_equal '<h3>DummDoo</h3> DummDoo', @response.body
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
should "see yieldable content from global_content_for" do
|
37
|
+
@controller.class_eval do
|
38
|
+
def featured
|
39
|
+
render_cell(:producer, :content_for)
|
40
|
+
render :inline => '<pre><%= yield :recorded %></pre>'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
ProducerCell.class_eval do
|
45
|
+
def content_for; render; end
|
46
|
+
end
|
47
|
+
|
48
|
+
get 'featured'
|
49
|
+
assert_equal "\n<pre>DummDooDiiDoo</pre>", @response.body
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/../test_helper')
|
2
|
+
|
3
|
+
|
4
|
+
class RailsCellsTest < ActiveSupport::TestCase
|
5
|
+
context "A rails cell" do
|
6
|
+
should "respond to view_paths" do
|
7
|
+
assert_kind_of ActionView::PathSet, Cell::Rails.view_paths, "must be a PathSet for proper template caching/reloading (see issue#2)"
|
8
|
+
end
|
9
|
+
|
10
|
+
should "respond to view_paths=" do
|
11
|
+
swap( Cell::Base, :view_paths => ['you', 'are', 'here']) do
|
12
|
+
assert_kind_of ActionView::PathSet, Cell::Base.view_paths, "must not wipe out the PathSet"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
context "invoking defaultize_render_options_for" do
|
18
|
+
should "set default values" do
|
19
|
+
cell(:bassist).class.default_template_format = :html ### FIXME: remove and get it working.
|
20
|
+
|
21
|
+
options = cell(:bassist).defaultize_render_options_for({}, :play)
|
22
|
+
|
23
|
+
assert_equal :html, options[:template_format]
|
24
|
+
assert_equal :play, options[:view]
|
25
|
+
end
|
26
|
+
|
27
|
+
should "allow overriding defaults" do
|
28
|
+
assert cell(:bassist).defaultize_render_options_for({:view => :slap}, :play)[:view] == :slap
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "invoking find_family_view_for_state" do
|
33
|
+
should "### use find_template" do
|
34
|
+
assert cell(:bassist).find_template("bassist/play")
|
35
|
+
assert_raises ActionView::MissingTemplate do
|
36
|
+
cell(:bassist).find_template("bassist/playyy")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
should "return play.html.erb" do
|
42
|
+
assert_equal "bassist/play", cell(:bassist).find_family_view_for_state(:play).virtual_path
|
43
|
+
end
|
44
|
+
|
45
|
+
should "find inherited play.html.erb" do
|
46
|
+
assert_equal "bassist/play", cell(:bad_guitarist).find_family_view_for_state(:play).virtual_path
|
47
|
+
end
|
48
|
+
|
49
|
+
should_eventually "find the EN-version if i18n instructs" do
|
50
|
+
swap I18n, :locale => :en do
|
51
|
+
assert_equal "bassist/yell.en.html.erb", cell(:bassist).find_family_view_for_state(:yell).virtual_path
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
should_eventually "return an already cached family view"
|
57
|
+
end
|
58
|
+
|
59
|
+
context "delegation" do
|
60
|
+
setup do
|
61
|
+
@request = ActionController::TestRequest.new
|
62
|
+
@request.env["action_dispatch.request.request_parameters"] = {:song => "Creatures"}
|
63
|
+
@cell = cell(:bassist)
|
64
|
+
@cell.request= @request
|
65
|
+
end
|
66
|
+
|
67
|
+
should_eventually "delegate log" do
|
68
|
+
assert_nothing_raised do
|
69
|
+
cell(:bassist).class.logger.info("everything is perfect!")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
should "respond to session" do
|
74
|
+
assert_kind_of Hash, @cell.session
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
should "precede cell ivars over controller ivars" do
|
80
|
+
@controller.instance_variable_set(:@note, "E")
|
81
|
+
BassistCell.class_eval do
|
82
|
+
def slap; @note = "A"; render; end
|
83
|
+
end
|
84
|
+
assert_equal "Boing in A", render_cell(:bassist, :slap)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/../test_helper')
|
2
|
+
|
3
|
+
require 'active_support/core_ext/object/to_query'
|
4
|
+
|
5
|
+
class RailsIntegrationTest < ActionController::TestCase
|
6
|
+
|
7
|
+
context "A Rails controller" do
|
8
|
+
setup do
|
9
|
+
@routes = ActionDispatch::Routing::RouteSet.new
|
10
|
+
@routes.draw do
|
11
|
+
|map| match ':action', :to => MusicianController
|
12
|
+
end
|
13
|
+
@controller = MusicianController.new
|
14
|
+
end
|
15
|
+
|
16
|
+
should "respond to render_cell" do
|
17
|
+
get 'promotion'
|
18
|
+
assert_equal "Doo", @response.body
|
19
|
+
end
|
20
|
+
|
21
|
+
should "respond to render_cell in the view" do
|
22
|
+
get 'featured'
|
23
|
+
assert_equal "Doo", @response.body
|
24
|
+
end
|
25
|
+
|
26
|
+
should "make params (and friends) available in a cell" do
|
27
|
+
BassistCell.class_eval do
|
28
|
+
def listen
|
29
|
+
render :text => "That's a #{params[:note]}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
get 'skills', :note => "D"
|
33
|
+
assert_equal "That's a D", @response.body
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/../test_helper')
|
2
|
+
require 'builder'
|
3
|
+
|
4
|
+
class RailsRenderTest < ActiveSupport::TestCase
|
5
|
+
context "Invoking render" do
|
6
|
+
|
7
|
+
should "render a plain view" do
|
8
|
+
BassistCell.class_eval do
|
9
|
+
def play; render; end
|
10
|
+
end
|
11
|
+
assert_equal "Doo", render_cell(:bassist, :play)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "also render alternative engines" do
|
15
|
+
BassistCell.class_eval do
|
16
|
+
def sing; @xm = Builder::XmlMarkup.new; render; end
|
17
|
+
end
|
18
|
+
assert_equal "", render_cell(:bassist, :sing) ### FIXME: where's the rendered xml?
|
19
|
+
end
|
20
|
+
|
21
|
+
should "accept the :template_format option" do
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
should "accept the :nothing option" do
|
26
|
+
BassistCell.class_eval do
|
27
|
+
def sleep; render :nothing => true; end
|
28
|
+
end
|
29
|
+
assert_equal "", render_cell(:bassist, :sleep)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
should "accept the :view option" do
|
34
|
+
BassistCell.class_eval do
|
35
|
+
def solo; render :view => :play; end
|
36
|
+
end
|
37
|
+
assert_equal "Doo", render_cell(:bassist, :solo)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "accept the :text options" do
|
41
|
+
BassistCell.class_eval do
|
42
|
+
def sing; render :text => "Shoobie"; end
|
43
|
+
end
|
44
|
+
assert_equal "Shoobie", render_cell(:bassist, :sing)
|
45
|
+
end
|
46
|
+
|
47
|
+
should "accept the :inline option" do
|
48
|
+
BassistCell.class_eval do
|
49
|
+
def sleep; render :inline => "<%= 'Snooore' %>"; end
|
50
|
+
end
|
51
|
+
assert_equal "Snooore", render_cell(:bassist, :sleep)
|
52
|
+
end
|
53
|
+
|
54
|
+
should "accept the :state option" do
|
55
|
+
BassistCell.class_eval do
|
56
|
+
def play; render; end
|
57
|
+
def groove; render :state => :play; end
|
58
|
+
end
|
59
|
+
assert_equal "Doo", render_cell(:bassist, :groove)
|
60
|
+
end
|
61
|
+
|
62
|
+
should "accept the :locals option" do
|
63
|
+
BassistCell.class_eval do
|
64
|
+
def ahem; render :locals => {:times => 2}; end
|
65
|
+
end
|
66
|
+
assert_equal "AhemAhem", render_cell(:bassist, :ahem)
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# layout
|
71
|
+
should "accept the :layout option" do
|
72
|
+
BassistCell.class_eval do
|
73
|
+
def play; render :layout => 'b'; end
|
74
|
+
end
|
75
|
+
assert_equal "<b>Doo</b>", render_cell(:bassist, :play)
|
76
|
+
end
|
77
|
+
|
78
|
+
should "raise an error for a non-existent template" do
|
79
|
+
BassistCell.class_eval do
|
80
|
+
def groove; render; end
|
81
|
+
end
|
82
|
+
|
83
|
+
assert_raises ActionView::MissingTemplate do
|
84
|
+
render_cell(:bassist, :groove)
|
85
|
+
end
|
86
|
+
|
87
|
+
### TODO: test error message sanity.
|
88
|
+
end
|
89
|
+
|
90
|
+
should "render instance variables from the cell" do
|
91
|
+
BassistCell.class_eval do
|
92
|
+
def slap
|
93
|
+
@note = "D"; render
|
94
|
+
end
|
95
|
+
end
|
96
|
+
assert_equal "Boing in D", render_cell(:bassist, :slap)
|
97
|
+
end
|
98
|
+
|
99
|
+
should "allow subsequent calls to render in the rendered view" do
|
100
|
+
BassistCell.class_eval do
|
101
|
+
def jam; @chords = [:a, :c]; render; end
|
102
|
+
def play; render; end
|
103
|
+
end
|
104
|
+
assert_equal "Doo\nDoo\n", render_cell(:bassist, :jam)
|
105
|
+
end
|
106
|
+
|
107
|
+
should "allow multiple calls to render" do
|
108
|
+
BassistCell.class_eval do
|
109
|
+
def play; render + render + render; end
|
110
|
+
end
|
111
|
+
assert_equal "DooDooDoo", render_cell(:bassist, :play)
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
# inheriting
|
118
|
+
should "inherit play.html.erb from BassistCell" do
|
119
|
+
assert_equal "Doo", render_cell(:bad_guitarist, :play)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context "A cell view" do
|
124
|
+
# rails view api
|
125
|
+
should "allow calls to params/response/..." do
|
126
|
+
BassistCell.class_eval do
|
127
|
+
def pose; render; end
|
128
|
+
end
|
129
|
+
|
130
|
+
@request.env["action_dispatch.request.request_parameters"] = {:what => 'get'}
|
131
|
+
@cell = cell(:bassist)
|
132
|
+
@cell.request = @request ### FIXME.
|
133
|
+
|
134
|
+
assert_equal "Come and get me!", @cell.render_state(:pose)
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|