Skip to content

Commit

Permalink
seperated out application tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danwrong committed Apr 21, 2009
1 parent cc19ebc commit 60cccf5
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 114 deletions.
114 changes: 0 additions & 114 deletions test/app/evil_test.rb

This file was deleted.

52 changes: 52 additions & 0 deletions test/app/frontend_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require File.join(File.dirname(__FILE__), '../test_helper')
require 'evil/application'

class FrontendTest < Test::Unit::TestCase
include Sinatra::Test

context 'running the evil application' do
setup do
@app = Evil::Application
end


context 'GET a template page' do
setup do
@template = Factory.create(:template)
@app.reload!
get @template.route
end

should 'be successful' do
assert_equal 200, response.status
end

should 'render with text/html as default content_type' do
assert_match /text\/html/, response.headers['Content-Type']
assert_match /utf-8/, response.headers['Content-Type']
end

should 'set a Cache-Control header from the template\'s ttl' do
assert_match /max-age=#{@template.ttl}/, response.headers['Cache-Control']
end
end

context 'GET a template page with another content type set' do
setup do
@template = Factory.create(:template, :content_type => 'application/xml')
@app.reload!
get @template.route
end

should 'be successful' do
assert_equal 200, response.status
end

should 'render with text/html as default content_type' do
assert_match /application\/xml/, response.headers['Content-Type']
assert_match /utf-8/, response.headers['Content-Type']
end
end
end

end
45 changes: 45 additions & 0 deletions test/app/openid_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require File.join(File.dirname(__FILE__), '../test_helper')
require 'evil/application'

class OpenidTest < Test::Unit::TestCase
include Sinatra::Test

context 'running the evil application' do
setup do
@app = Evil::Application
end

context 'while not logged in' do

context 'GET /admin' do
setup do
get '/admin'
end

should 'not be authorized' do
assert_equal 401, response.status
assert_match /openid_url/, response.body
end
end
end


context 'while logged in' do
setup do
Factory.create(:whitelist)
@env = { 'rack.session' => { :identity_url => 'www.example.com' } }
end

context 'GET /admin' do
setup do
get '/admin', {}, @env
end

should 'be successful' do
assert response.ok?
end
end
end
end

end
22 changes: 22 additions & 0 deletions test/app/plugin_config_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require File.join(File.dirname(__FILE__), '../test_helper')
require 'evil/application'

class PluginConfigTest < Test::Unit::TestCase
include Sinatra::Test

context 'running the evil application' do
setup do
@app = Evil::Application
end


context 'while logged in' do
setup do
Factory.create(:whitelist)
@env = { 'rack.session' => { :identity_url => 'www.example.com' } }
end
end

end

end
51 changes: 51 additions & 0 deletions test/app/template_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require File.join(File.dirname(__FILE__), '../test_helper')
require 'evil/application'

class TemplateTest < Test::Unit::TestCase
include Sinatra::Test

context 'running the evil application' do
setup do
@app = Evil::Application
end

context 'while logged in' do
setup do
Factory.create(:whitelist)
@env = { 'rack.session' => { :identity_url => 'www.example.com' } }
end

context 'GET /admin/templates/id with existing template' do
setup do
@template = Factory.create(:template)
get "/admin/templates/#{@template.id}", {}, @env
end

should 'be successful' do
assert_equal 200, response.status
end
end

context 'GET /admin/templates/nothinghere with non-existing template' do
setup do
get '/admin/templates/nothinghere', {}, @env
end

should 'be not found' do
assert_equal 404, response.status
end
end

context 'GET /admin/templates/new' do
setup do
get '/admin/templates/new', {}, @env
end

should 'be successful' do
assert_equal 200, response.status
end
end
end
end

end
2 changes: 2 additions & 0 deletions test/units/models/template_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require File.join(File.dirname(__FILE__), '../../test_helper')

class TemplateTest < Test::Unit::TestCase
include Evil::Models

Expand Down
2 changes: 2 additions & 0 deletions test/units/models/whitelist_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require File.join(File.dirname(__FILE__), '../../test_helper')

class WhitelistTest < Test::Unit::TestCase
include Evil::Models

Expand Down
2 changes: 2 additions & 0 deletions test/units/plugin/base_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require File.join(File.dirname(__FILE__), '../../test_helper')

class BaseTest < Test::Unit::TestCase
should 'initialize with a name and a block that recieves the new instance' do
plugin = Evil::Plugin::Base.new 'Test Plugin' do |p|
Expand Down

0 comments on commit 60cccf5

Please sign in to comment.