test/unit/view_handler_tests.rb in deas-0.32.0 vs test/unit/view_handler_tests.rb in deas-0.33.0
- old
+ new
@@ -24,27 +24,28 @@
should have_imeths :before_run, :prepend_before_run, :before_run_callbacks
should have_imeths :after_run, :prepend_after_run, :after_run_callbacks
should "specify layouts" do
subject.layout 'layouts/app'
- assert_equal ['layouts/app'], subject.layouts
+ assert_equal ['layouts/app'], subject.layouts.map(&:call)
- subject.layouts 'layouts/web', 'layouts/search'
- assert_equal ['layouts/app', 'layouts/web', 'layouts/search'], subject.layouts
+ subject.layout { 'layouts/web' }
+ assert_equal ['layouts/app', 'layouts/web'], subject.layouts.map(&:call)
end
end
class InitTests < UnitTests
desc "when init"
setup do
- @runner = test_runner(@handler_class)
+ @runner = test_runner(@handler_class)
@handler = @runner.handler
end
subject{ @handler }
should have_imeths :init, :init!, :run, :run!
+ should have_imeths :layouts
should "have called `init!` and it's callbacks" do
assert_equal true, subject.before_init_called
assert_equal true, subject.second_before_init_called
assert_equal true, subject.init_bang_called
@@ -57,10 +58,25 @@
assert_nil subject.after_run_called
end
end
+ class LayoutsTests < InitTests
+ desc "with layouts"
+ setup do
+ @params = { 'n' => Factory.integer }
+ @runner = test_runner(LayoutsViewHandler, :params => @params)
+ @handler = @runner.handler
+ end
+
+ should "build its layouts by instance eval'ing its class layout procs" do
+ exp = subject.class.layouts.map{ |proc| @handler.instance_eval(&proc) }
+ assert_equal exp, subject.layouts
+ end
+
+ end
+
class RunTests < InitTests
desc "and run"
should "call `run!` and it's callbacks" do
subject.run
@@ -274,9 +290,18 @@
before_run{ @before_run_called = true }
after_run{ @after_run_called = true }
def init!; @init_bang_called = true; end
def run!; @run_bang_called = true; end
+
+ end
+
+ class LayoutsViewHandler
+ include Deas::ViewHandler
+
+ layout '1.html'
+ layout { '2.html' }
+ layout { "#{params['n']}.html" }
end
end