Permalink
Browse files

Add more real tests

  • Loading branch information...
weppos committed Dec 25, 2012
1 parent f9d8ff0 commit c770762fd0709e4cb5adabff07dc6a4653a51eb5
Showing with 109 additions and 15 deletions.
  1. +41 −0 test/dummy.rb
  2. +1 −15 test/test_helper.rb
  3. +66 −0 test/unit/action_controller_test.rb
  4. +1 −0 test/views/example/default.html.erb
View
@@ -0,0 +1,41 @@
+ENV["RAILS_ENV"] = "test"
+
+require "active_support"
+require "action_controller"
+require "rails/railtie"
+
+
+class Dummy
+ Routes = ActionDispatch::Routing::RouteSet.new
+ Routes.draw do
+ match ':controller(/:action(/:id))'
+ end
+end
+
+ActionController::Base.view_paths = File.join(File.dirname(__FILE__), 'views')
+ActionController::Base.send :include, Dummy::Routes.url_helpers
+
+class ActiveSupport::TestCase
+
+ setup do
+ @routes = Dummy::Routes
+ end
+
+
+ def controller
+ @controller_proxy ||= ControllerProxy.new(@controller)
+ end
+
+ class ControllerProxy
+ def initialize(controller)
+ @controller = controller
+ end
+ def method_missing(method, *args)
+ @controller.instance_eval do
+ m = method(method)
+ m.call(*args)
+ end
+ end
+ end
+
+end
View
@@ -1,20 +1,6 @@
require 'test/unit'
require 'mocha'
-
-ENV["RAILS_ENV"] = "test"
-
-require "active_support"
-require "action_controller"
-require "rails/railtie"
+require 'dummy'
$:.unshift File.expand_path('../../lib', __FILE__)
require 'breadcrumbs_on_rails'
-
-ActionController::Base.view_paths = File.join(File.dirname(__FILE__), 'views')
-
-BreadcrumbsOnRails::Routes = ActionDispatch::Routing::RouteSet.new
-BreadcrumbsOnRails::Routes.draw do
- match ':controller(/:action(/:id))'
-end
-
-ActionController::Base.send :include, BreadcrumbsOnRails::Routes.url_helpers
@@ -0,0 +1,66 @@
+require 'test_helper'
+
+
+class ExampleController < ActionController::Base
+ include BreadcrumbsOnRails::ActionController
+
+ def self.controller_name; "example"; end
+ def self.controller_path; "example"; end
+
+ layout false
+
+ def action_default
+ execute("action_default")
+ end
+
+ def action_compute_paths
+ add_breadcrumb "String", "/"
+ add_breadcrumb "Proc", proc { |c| "/?proc" }
+ execute("action_default")
+ end
+
+
+ private
+
+ def execute(method)
+ if method.to_s =~ /^action_(.*)/
+ render :action => (params[:template] || 'default')
+ end
+ end
+
+end
+
+class ExampleControllerTest < ActionController::TestCase
+ tests ExampleController
+
+ def test_render_default
+ get :action_default
+ assert_dom_equal %(),
+ @response.body
+ end
+
+ def test_render_compute_paths
+ get :action_compute_paths
+ assert_dom_equal %(<a href="/">String</a> &raquo; <a href="/?proc">Proc</a>),
+ @response.body
+ end
+
+end
+
+class ExampleHelpersTest < ActionView::TestCase
+ tests BreadcrumbsOnRails::ActionController::HelperMethods
+ include ActionView::Helpers::TagHelper
+ include ActionView::Helpers::UrlHelper
+
+ attr_accessor :breadcrumbs
+
+ setup do
+ self.breadcrumbs = []
+ end
+
+ def test_render_breadcrumbs
+ assert_dom_equal '', render_breadcrumbs
+ end
+
+end
+
@@ -0,0 +1 @@
+<%= render_breadcrumbs %>

0 comments on commit c770762

Please sign in to comment.