Permalink
Browse files

moving rails_30? methods to Cell module since i want to cleanup the C…

…ells module (should go away soon).
  • Loading branch information...
1 parent b5aeeb6 commit aa0486698c57acd5c24e18f8451bb10bfe839366 @apotonick apotonick committed May 20, 2012
View
@@ -2,10 +2,21 @@
require 'cell/builder'
require 'cell/caching'
require 'cell/rendering'
-require 'cell/rails3_0_strategy' if Cells.rails3_0?
-require 'cell/rails3_1_strategy' if Cells.rails3_1_or_more?
module Cell
+ def self.rails3_0?
+ ::ActionPack::VERSION::MINOR == 0
+ end
+
+ def self.rails3_1_or_more?
+ ::ActionPack::VERSION::MINOR >= 1
+ end
+
+ def self.rails3_2_or_more? # FIXME: move to tests.
+ ::ActionPack::VERSION::MINOR >= 2
+ end
+
+
class Base < AbstractController::Base
abstract!
DEFAULT_VIEW_PATHS = [File.join('app', 'cells')]
@@ -14,6 +25,8 @@ class Base < AbstractController::Base
include AbstractController
include AbstractController::Rendering, Layouts, Helpers, Callbacks, Translation, Logger
+ require 'cell/rails3_0_strategy' if Cell.rails3_0?
+ require 'cell/rails3_1_strategy' if Cell.rails3_1_or_more?
include VersionStrategy
include Rendering
include Caching
@@ -12,7 +12,7 @@ def view_context_class
@view_context_class ||= begin
routes = _routes #if respond_to?(:_routes)
helpers = _helpers #if respond_to?(:_helpers)
- Cell::Rails::View.prepare(routes, helpers)
+ Cell::Base::View.prepare(routes, helpers)
end
end
end
View
@@ -70,18 +70,6 @@ module Cells
def self.setup
yield(Cell::Rails)
end
-
- def self.rails3_0?
- ::ActionPack::VERSION::MINOR == 0
- end
-
- def self.rails3_1_or_more?
- ::ActionPack::VERSION::MINOR >= 1
- end
-
- def self.rails3_2_or_more? # FIXME: move to tests.
- ::ActionPack::VERSION::MINOR >= 2
- end
end
require 'cell/rails'
View
@@ -149,7 +149,7 @@ class DrummerCell < BassistCell
assert_equal BassistCell, ::Cell::Rails.class_from_cell_name('bassist')
end
- if Cells.rails3_0?
+ if Cell.rails3_0?
should "provide possible_paths_for_state" do
assert_equal ["bad_guitarist/play", "bassist/play"], cell(:bad_guitarist).send(:possible_paths_for_state, :play)
end
@@ -166,4 +166,17 @@ class SingerCell < Cell::Rails
end
end
end
+
+ should "respond to #rails3_1_or_more?" do
+ if Rails::VERSION::MINOR == 0
+ assert ! Cell.rails3_1_or_more?
+ assert Cell.rails3_0?
+ elsif Rails::VERSION::MINOR == 1
+ assert Cell.rails3_1_or_more?
+ assert ! Cell.rails3_0?
+ elsif Rails::VERSION::MINOR == 2
+ assert Cell.rails3_1_or_more?
+ assert ! Cell.rails3_0?
+ end
+ end
end
View
@@ -16,25 +16,12 @@ class CellsModuleTest < ActiveSupport::TestCase
c.append_view_path "/road/to/nowhere"
end
- if Cells.rails3_2_or_more?
+ if Cell.rails3_2_or_more?
assert_equal "/road/to/nowhere", Cell::Rails.view_paths.paths.last.to_s
else
assert_equal "/road/to/nowhere", Cell::Rails.view_paths.last.to_s
end
end
end
-
- should "respond to #rails3_1_or_more?" do
- if Rails::VERSION::MINOR == 0
- assert ! Cells.rails3_1_or_more?
- assert Cells.rails3_0?
- elsif Rails::VERSION::MINOR == 1
- assert Cells.rails3_1_or_more?
- assert ! Cells.rails3_0?
- elsif Rails::VERSION::MINOR == 2
- assert Cells.rails3_1_or_more?
- assert ! Cells.rails3_0?
- end
- end
end
end
View
@@ -54,7 +54,7 @@ def listen(first, second="D")
should "respond to .setup_view_paths!" do
swap( Cell::Rails, :view_paths => []) do
Cell::Rails.setup_view_paths!
- if Cells.rails3_2_or_more?
+ if Cell.rails3_2_or_more?
assert_equal ActionView::PathSet.new(Cell::Rails::DEFAULT_VIEW_PATHS).paths, Cell::Rails.view_paths.paths
else
assert_equal ActionView::PathSet.new(Cell::Rails::DEFAULT_VIEW_PATHS), Cell::Rails.view_paths
@@ -81,8 +81,7 @@ def listen(first, second="D")
end
- if Cells.rails3_0?
- puts "rails-3.0"
+ if Cell.rails3_0?
context "invoking find_family_view_for_state" do
should "raise an error when a template is missing" do
assert_raises ActionView::MissingTemplate do
@@ -128,7 +128,7 @@ def groove; render; end
def groove; render; end
end
- if Cells.rails3_0?
+ if Cell.rails3_0?
e = assert_raise Cell::Rails::MissingTemplate do
render_cell(:bad_guitarist, :groove)
end
View
@@ -47,7 +47,7 @@ def play; render; end
context "#view_assigns" do
should "be emtpy when nothing was set" do
render_cell(:bassist, :play)
- if Cells.rails3_0?
+ if Cell.rails3_0?
assert_equal([:lookup_context], view_assigns.keys)
else
assert_equal({}, view_assigns)
@@ -61,7 +61,7 @@ def sleep
end
end
render_cell(:bassist, :sleep)
- if Cells.rails3_0?
+ if Cell.rails3_0?
assert_equal([:lookup_context, :duration], view_assigns.keys)
assert_equal("8h", view_assigns[:duration])
else

0 comments on commit aa04866

Please sign in to comment.