Skip to content

Commit

Permalink
Merge branch '3-7'
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Oct 13, 2011
2 parents 4c62dd0 + d933b7e commit bb62f43
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 29 deletions.
6 changes: 6 additions & 0 deletions CHANGES.textile
@@ -1,3 +1,9 @@
h2. 3.6.8

h3. Changes
* Removed <code>@opts</code>.
* Deprecated @#options@ in favour of state-args.

h2. 3.6.7

h3. Changes
Expand Down
8 changes: 4 additions & 4 deletions lib/cell/rails.rb
Expand Up @@ -43,8 +43,8 @@ module Metal
include Caching


attr_reader :options # TODO: removed in 3.7.
attr_reader :parent_controller
attr_accessor :options

abstract!

Expand All @@ -55,10 +55,10 @@ def initialize(parent_controller, *args)
setup_backwardibility(*args)
end

# Some people still like #options and assume it's a hash.
# Some people still like #options and assume it's a hash. This will be removed in Cells 3.7.
def setup_backwardibility(*args)
@options = (args.first.is_a?(Hash) and args.size == 1) ? args.first : args
@opts = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :options)
@_options = (args.first.is_a?(Hash) and args.size == 1) ? args.first : args
@options = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(@_options, "#options is deprecated and will be removed in Cells 3.7. Please use state-args.")
end

def self.controller_path
Expand Down
11 changes: 6 additions & 5 deletions lib/cell/test_case.rb
Expand Up @@ -108,10 +108,11 @@ def render_cell(name, state, *args)
# Passes the optional block to <tt>cell.instance_eval</tt>.
#
# Example:
# assert_equal "Banks kill planet!" cell(:news, :topic => :terror).latest_headline
# assert_equal "Doo Dumm Dumm..." cell(:bassist).play
def cell(name, *args, &block)
cell = ::Cell::Base.create_cell_for(@controller, name, *args)
cell.instance_eval &block if block_given?
ActiveSupport::Deprecation.warn("Passing options to TestCase#cell is deprecated, please use state-args in #render_cell.", caller) if args.present?
cell
end

Expand All @@ -122,16 +123,16 @@ def cell(name, *args, &block)
#
# assert_equal("<h1>Modularity rocks.</h1>", in_view do content_tag(:h1, "Modularity rocks."))
def in_view(cell_class, &block)
subject = cell(cell_class, :block => block)
subject = cell(cell_class)
setup_test_states_in(subject) # add #in_view to subject cell.
subject.render_state(:in_view)
subject.render_state(:in_view, block)
end

protected
def setup_test_states_in(cell)
cell.instance_eval do
def in_view
render :inline => "<%= instance_exec(&block) %>", :locals => {:block => options[:block]}
def in_view(block=nil)
render :inline => "<%= instance_exec(&block) %>", :locals => {:block => block}
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/rails/caching_test.rb
Expand Up @@ -254,7 +254,7 @@ def count(i)
end
end

should "compute the key with a block" do
should "compute the key with a block receiving state-args" do
@class.cache :count do |cell, int|
(int % 2)==0 ? {:count => "even"} : {:count => "odd"}
end
Expand Down
8 changes: 2 additions & 6 deletions test/rails/cells_test.rb
Expand Up @@ -77,20 +77,16 @@ def listen(first, second="D")
end

include ActiveSupport::Testing::Deprecation
should "mark @opts as deprecated, but still works" do
should "mark @options as deprecated, but still works" do
res = nil
assert_deprecated do
res = cell(:bassist, :song => "Lockdown").instance_eval do
@opts[:song]
options[:song]
end
end
assert_equal "Lockdown", res
end

should "respond to #options and return the cell options" do
assert_equal({:song => "Lockdown"}, cell(:bassist, :song => "Lockdown").options)
end

if Cells.rails3_0?
puts "rails-3.0"
context "invoking find_family_view_for_state" do
Expand Down
31 changes: 18 additions & 13 deletions test/test_case_test.rb
@@ -1,7 +1,8 @@
require 'test_helper'

class TestCaseTest < Cell::TestCase

include ActiveSupport::Testing::Deprecation

context "A TestCase" do
setup do
@test = Cell::TestCase.new(:cell_test)
Expand All @@ -19,16 +20,20 @@ def play; render; end
assert_selector "p", "Doo", "<p>Doo</p>y"
end

should "respond to #cell" do
assert_kind_of BassistCell, cell(:bassist)
end

should "respond to #cell with a block" do
assert_respond_to cell(:bassist){ def whatever; end }, :whatever
end

should "respond to #cell with options and block" do
assert_equal({:topic => :peace}, cell(:bassist, :topic => :peace).options)
context "#cell" do
should "create a cell" do
assert_kind_of BassistCell, cell(:bassist)
end

should "accept a block" do
assert_respond_to cell(:bassist){ def whatever; end }, :whatever
end

should "mark options as deprecated" do
assert_deprecated do
res = cell(:bassist, :song => "Lockdown")
end
end
end

context "#subject_cell" do
Expand Down Expand Up @@ -103,11 +108,11 @@ class SingerCellTest < Cell::TestCase

context "#setup_test_states_in" do
should "add the :in_view state" do
c = cell(:bassist, :block => lambda{"Cells rock."})
c = cell(:bassist)
assert_not c.respond_to?(:in_view)

setup_test_states_in(c)
assert_equal "Cells rock.", c.render_state(:in_view)
assert_equal "Cells rock.", c.render_state(:in_view, lambda{"Cells rock."})
end
end

Expand Down

0 comments on commit bb62f43

Please sign in to comment.