Skip to content

Commit

Permalink
A BUG! fixed render :state in cell views.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Apr 12, 2010
1 parent 57c5092 commit 99118a2
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 5 deletions.
7 changes: 3 additions & 4 deletions lib/cells/cell/view.rb
Expand Up @@ -18,19 +18,18 @@ def try_picking_template_for_path(template_path)
### so that we can overwrite the helper and cleanly reuse the internal method? using the same
### method both internally and externally sucks ass.
def render(options = {}, local_assigns = {}, &block)
### TODO: delegate dynamically:
### TODO: we have to find out if this is a call to the cells #render method, or to the rails
### method (e.g. when rendering a layout). what a shit.
if view = options[:view]
return cell.render_view_for(options, view)
if (options.keys & [:view, :state]).present? ### TODO: is there something like has_keys?
# that's better: simply delegate render back to the cell/controller.
return cell.render(options)
end

# rails compatibility we should get rid of:
if partial_path = options[:partial]
# adds the cell name to the partial name.
options[:partial] = expand_view_path(partial_path)
end
#throw Exception.new

super(options, local_assigns, &block)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cells/version.rb
@@ -1,5 +1,5 @@
# encoding: utf-8

module Cells
VERSION = '3.3.1'.freeze
VERSION = '3.3.2'
end
3 changes: 3 additions & 0 deletions test/app/cells/bassist/jam.html.erb
@@ -0,0 +1,3 @@
<% @chords.each do |chord| %>
<%= render :state => :play %>
<% end %>
1 change: 1 addition & 0 deletions test/app/cells/bassist/play.html.erb
@@ -0,0 +1 @@
Doo
3 changes: 3 additions & 0 deletions test/app/cells/bassist_cell.rb
@@ -0,0 +1,3 @@
class BassistCell < Cell::Base

end
16 changes: 16 additions & 0 deletions test/render_test.rb
Expand Up @@ -283,4 +283,20 @@ def another_state
end
assert_equal "Metal:A/another_state/a,b", render_cell(:a, :existing_view)
end

context "render :state within a view" do
should "return the state content" do
assert_equal( "\nDoo\n\nDoo\n\nDoo\n\nDoo\n",
bassist_mock do
def jam
@chords = %w(d a c g)
render
end
def play
render
end
end.render_state(:jam)
)
end
end
end
6 changes: 6 additions & 0 deletions test/support/internal_assertions_helper.rb
Expand Up @@ -60,5 +60,11 @@ def cell_mock(options={}, &block)
cell.instance_eval(&block) if block_given?
cell
end

def bassist_mock(options={}, &block)
cell = BassistCell.new(@controller, options)
cell.instance_eval(&block) if block_given?
cell
end
end
end
2 changes: 2 additions & 0 deletions test/test_helper.rb
Expand Up @@ -74,3 +74,5 @@
include Cells::AssertionsHelper
include Cells::InternalAssertionsHelper
end

require File.join(File.dirname(__FILE__), *%w[app cells bassist_cell])

0 comments on commit 99118a2

Please sign in to comment.