Browse files

heaps more tests, and a few fixes

  • Loading branch information...
1 parent fdd7343 commit 7b73de3270c126b21366f83830e56cc23812f814 @justinfrench committed Nov 22, 2009
Showing with 127 additions and 2 deletions.
  1. +31 −0 test/css_test.rb
  2. +62 −0 test/image_test.rb
  3. +31 −0 test/javascript_test.rb
  4. +1 −1 test/no_match_test.rb
  5. +1 −1 test/single_match_test.rb
  6. +1 −0 test/test_helper.rb
View
31 test/css_test.rb
@@ -0,0 +1,31 @@
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class CssTest < Test::Unit::TestCase
+
+ include TestHelper
+
+ def setup
+ super
+
+ setup_plugin :my_plugin
+
+ @path = 'foo/bah.css'
+ @filename = "/tmp/vendor/my_plugin/public/stylesheets/#{@path}"
+ @filecontents = "hello from stylesheet"
+ FileUtils.mkdir(File.dirname(@filename))
+ File.open(@filename, 'w') do |file|
+ file << @filecontents
+ end
+
+ get "/stylesheets/#{@path}"
+ end
+
+ def test_responds_ok
+ assert last_response.ok?
+ end
+
+ def test_responds_with_css_content_type
+ assert_equal "text/css", last_response.content_type
+ end
+
+end
View
62 test/image_test.rb
@@ -0,0 +1,62 @@
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class ImageTest < Test::Unit::TestCase
+
+ include TestHelper
+
+ def setup
+ super
+
+ setup_plugin :my_plugin
+
+ @gif_path = 'foo/bah.gif'
+ @jpg_path = 'foo/bah.jpg'
+ @png_path = 'foo/bah.png'
+
+ @gif_filename = "/tmp/vendor/my_plugin/public/images/#{@gif_path}"
+ @jpg_filename = "/tmp/vendor/my_plugin/public/images/#{@jpg_path}"
+ @png_filename = "/tmp/vendor/my_plugin/public/images/#{@png_path}"
+
+ @gif_filecontents = "hello from GIF"
+ @jpg_filecontents = "hello from JPG"
+ @png_filecontents = "hello from PNG"
+
+ FileUtils.mkdir(File.dirname(@jpg_filename))
+
+ File.open(@jpg_filename, 'w') do |file|
+ file << @jpg_filecontents
+ end
+
+ File.open(@gif_filename, 'w') do |file|
+ file << @gif_filecontents
+ end
+
+ File.open(@png_filename, 'w') do |file|
+ file << @png_filecontents
+ end
+ end
+
+ def test_responds_ok
+ get "/images/#{@gif_path}"
+ assert last_response.ok?
+
+ get "/images/#{@jpg_path}"
+ assert last_response.ok?
+
+ get "/images/#{@png_path}"
+ assert last_response.ok?
+
+ end
+
+ def test_responds_with_css_content_type
+ get "/images/#{@gif_path}"
+ assert_equal "image/gif", last_response.content_type
+
+ get "/images/#{@png_path}"
+ assert_equal "image/png", last_response.content_type
+
+ get "/images/#{@jpg_path}"
+ assert_equal "image/jpeg", last_response.content_type
+ end
+
+end
View
31 test/javascript_test.rb
@@ -0,0 +1,31 @@
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class JavascriptTest < Test::Unit::TestCase
+
+ include TestHelper
+
+ def setup
+ super
+
+ setup_plugin :my_plugin
+
+ @path = 'foo/bah.js'
+ @filename = "/tmp/vendor/my_plugin/public/javascripts/#{@path}"
+ @filecontents = "hello from javascript"
+ FileUtils.mkdir(File.dirname(@filename))
+ File.open(@filename, 'w') do |file|
+ file << @filecontents
+ end
+
+ get "/javascripts/#{@path}"
+ end
+
+ def test_responds_ok
+ assert last_response.ok?
+ end
+
+ def test_responds_with_css_content_type
+ assert_equal "text/javascript", last_response.content_type
+ end
+
+end
View
2 test/no_match_test.rb
@@ -4,7 +4,7 @@ class NoMatchTest < Test::Unit::TestCase
include TestHelper
- def test_redirect_logged_in_users_to_dashboard
+ def test_responds_with_not_found
get "/stylesheets/not_here.css"
assert last_response.not_found?
end
View
2 test/single_match_test.rb
@@ -14,7 +14,7 @@ def setup
@filecontents = "hello from stylesheet"
FileUtils.mkdir(File.dirname(@filename))
File.open(@filename, 'w') do |file|
- file << "hello from stylesheet"
+ file << @filecontents
end
get "/stylesheets/#{@path}"
View
1 test/test_helper.rb
@@ -3,6 +3,7 @@
require "rack/test"
require "action_controller"
require File.join(File.dirname(__FILE__), "../app/metal/publicious_metal")
+require File.join(File.dirname(__FILE__), "../rails/init")
RAILS_ROOT = "/tmp"

0 comments on commit 7b73de3

Please sign in to comment.