Skip to content
Browse files

tests for single match

  • Loading branch information...
1 parent 6be3fef commit 291970ebcb6b8f10d33023659225830eac0ca8a8 @justinfrench committed Sep 16, 2009
Showing with 60 additions and 4 deletions.
  1. +1 −1 test/{publicious_controller_test.rb → no_matches_test.rb}
  2. +58 −0 test/single_match_test.rb
  3. +1 −3 test/test_helper.rb
View
2 test/publicious_controller_test.rb → test/no_matches_test.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/test_helper'
-class PubliciousControllerTest < ActionController::TestCase
+class NoMatchesTest < ActionController::TestCase
tests PubliciousController
test "when no assets are found" do
View
58 test/single_match_test.rb
@@ -0,0 +1,58 @@
+require File.dirname(__FILE__) + '/test_helper'
+
+class SingleMatchTest < ActionController::TestCase
+ tests PubliciousController
+
+ def setup
+ super
+ PubliciousController.view_paths = ['/tmp/app/views','/tmp/vendor/my_plugin/app/views']
+
+ @path = ['foo', 'bah.css']
+
+ @vendordir = "/tmp/vendor"
+ @plugindir = "/tmp/vendor/my_plugin"
+ @publicdir = "/tmp/vendor/my_plugin/public"
+ @stylesheetsdir = "/tmp/vendor/my_plugin/public/stylesheets"
+ @filename = "/tmp/vendor/my_plugin/public/stylesheets/#{@path.join('/')}"
+ @filecontents = "hello from stylesheet"
+
+ FileUtils.mkdir(@vendordir)
+ FileUtils.mkdir(@plugindir)
+ FileUtils.mkdir(@publicdir)
+ FileUtils.mkdir(@stylesheetsdir)
+
+ FileUtils.mkdir(File.dirname(@filename))
+ File.open(@filename, 'w') do |file|
+ file << "hello from stylesheet"
+ end
+
+ get :show, :path => @path
+ end
+
+ def teardown
+ super
+ begin
+ FileUtils.rm_r(@vendordir)
+ rescue StandardError => e
+ puts "Error while removing #{@plugindir}"
+ end
+ end
+
+ test "view_paths should contain two items" do
+ assert_equal 2, @controller.view_paths.size
+ end
+
+ test "public_paths should contain one item (one less than view paths)" do
+ assert_equal 1, @controller.send(:public_paths).size
+ end
+
+ test "public_paths should contain the plugin's public dir" do
+ assert_equal @publicdir, @controller.send(:public_paths).first
+ end
+
+ test "should respond with the file contents" do
+ assert_equal File.read(@filename), @controller.response.body
+ assert_equal @filecontents, @controller.response.body
+ end
+
+end
View
4 test/test_helper.rb
@@ -9,7 +9,5 @@ class ApplicationController < ActionController::Base
end
require File.dirname(__FILE__) + '/../app/controllers/publicious_controller'
+require File.dirname(__FILE__) + '/../config/routes'
-ActionController::Routing::Routes.draw do |map|
- map.connect ':controller/:action/:id'
-end

0 comments on commit 291970e

Please sign in to comment.
Something went wrong with that request. Please try again.