Checkout of Instiki Trunk 1/21/2007.
This commit is contained in:
commit
69b62b6f33
1138 changed files with 139586 additions and 0 deletions
84
vendor/rails/actionpack/test/activerecord/active_record_assertions_test.rb
vendored
Normal file
84
vendor/rails/actionpack/test/activerecord/active_record_assertions_test.rb
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
require "#{File.dirname(__FILE__)}/../active_record_unit"
|
||||
require 'fixtures/company'
|
||||
|
||||
class ActiveRecordAssertionsController < ActionController::Base
|
||||
self.template_root = "#{File.dirname(__FILE__)}/../fixtures/"
|
||||
|
||||
# fail with 1 bad column
|
||||
def nasty_columns_1
|
||||
@company = Company.new
|
||||
@company.name = "B"
|
||||
@company.rating = 2
|
||||
render :inline => "snicker...."
|
||||
end
|
||||
|
||||
# fail with 2 bad columns
|
||||
def nasty_columns_2
|
||||
@company = Company.new
|
||||
@company.name = ""
|
||||
@company.rating = 2
|
||||
render :inline => "double snicker...."
|
||||
end
|
||||
|
||||
# this will pass validation
|
||||
def good_company
|
||||
@company = Company.new
|
||||
@company.name = "A"
|
||||
@company.rating = 69
|
||||
render :inline => "Goodness Gracious!"
|
||||
end
|
||||
|
||||
# this will fail validation
|
||||
def bad_company
|
||||
@company = Company.new
|
||||
render :inline => "Who's Bad?"
|
||||
end
|
||||
|
||||
# the safety dance......
|
||||
def rescue_action(e) raise; end
|
||||
end
|
||||
|
||||
class ActiveRecordAssertionsControllerTest < ActiveRecordTestCase
|
||||
fixtures :companies
|
||||
|
||||
def setup
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
@controller = ActiveRecordAssertionsController.new
|
||||
super
|
||||
end
|
||||
|
||||
# test for 1 bad apple column
|
||||
def test_some_invalid_columns
|
||||
process :nasty_columns_1
|
||||
assert_success
|
||||
assert_invalid_record 'company'
|
||||
assert_invalid_column_on_record 'company', 'rating'
|
||||
assert_valid_column_on_record 'company', 'name'
|
||||
assert_valid_column_on_record 'company', %w(name id)
|
||||
end
|
||||
|
||||
# test for 2 bad apples columns
|
||||
def test_all_invalid_columns
|
||||
process :nasty_columns_2
|
||||
assert_success
|
||||
assert_invalid_record 'company'
|
||||
assert_invalid_column_on_record 'company', 'rating'
|
||||
assert_invalid_column_on_record 'company', 'name'
|
||||
assert_invalid_column_on_record 'company', %w(name rating)
|
||||
end
|
||||
|
||||
# ensure we have no problems with an ActiveRecord
|
||||
def test_valid_record
|
||||
process :good_company
|
||||
assert_success
|
||||
assert_valid_record 'company'
|
||||
end
|
||||
|
||||
# ensure we have problems with an ActiveRecord
|
||||
def test_invalid_record
|
||||
process :bad_company
|
||||
assert_success
|
||||
assert_invalid_record 'company'
|
||||
end
|
||||
end
|
174
vendor/rails/actionpack/test/activerecord/active_record_store_test.rb
vendored
Normal file
174
vendor/rails/actionpack/test/activerecord/active_record_store_test.rb
vendored
Normal file
|
@ -0,0 +1,174 @@
|
|||
# Unfurl the safety net.
|
||||
path_to_ar = File.dirname(__FILE__) + '/../../../activerecord'
|
||||
if Object.const_defined?(:ActiveRecord) or File.exist?(path_to_ar)
|
||||
begin
|
||||
|
||||
# These tests exercise CGI::Session::ActiveRecordStore, so you're going to
|
||||
# need AR in a sibling directory to AP and have SQLite installed.
|
||||
|
||||
unless Object.const_defined?(:ActiveRecord)
|
||||
require File.join(path_to_ar, 'lib', 'active_record')
|
||||
end
|
||||
|
||||
require File.dirname(__FILE__) + '/../abstract_unit'
|
||||
require 'action_controller/session/active_record_store'
|
||||
|
||||
#ActiveRecord::Base.logger = Logger.new($stdout)
|
||||
begin
|
||||
CGI::Session::ActiveRecordStore::Session.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
||||
CGI::Session::ActiveRecordStore::Session.connection
|
||||
rescue Object
|
||||
$stderr.puts 'SQLite 3 unavailable; falling back to SQLite 2.'
|
||||
begin
|
||||
CGI::Session::ActiveRecordStore::Session.establish_connection(:adapter => 'sqlite', :database => ':memory:')
|
||||
CGI::Session::ActiveRecordStore::Session.connection
|
||||
rescue Object
|
||||
$stderr.puts 'SQLite 2 unavailable; skipping ActiveRecordStore test suite.'
|
||||
raise SystemExit
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module CommonActiveRecordStoreTests
|
||||
def test_basics
|
||||
s = session_class.new(:session_id => '1234', :data => { 'foo' => 'bar' })
|
||||
assert_equal 'bar', s.data['foo']
|
||||
assert s.save
|
||||
assert_equal 'bar', s.data['foo']
|
||||
|
||||
assert_not_nil t = session_class.find_by_session_id('1234')
|
||||
assert_not_nil t.data
|
||||
assert_equal 'bar', t.data['foo']
|
||||
end
|
||||
|
||||
def test_reload_same_session
|
||||
@new_session.update
|
||||
reloaded = CGI::Session.new(CGI.new, 'session_id' => @new_session.session_id, 'database_manager' => CGI::Session::ActiveRecordStore)
|
||||
assert_equal 'bar', reloaded['foo']
|
||||
end
|
||||
|
||||
def test_tolerates_close_close
|
||||
assert_nothing_raised do
|
||||
@new_session.close
|
||||
@new_session.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ActiveRecordStoreTest < Test::Unit::TestCase
|
||||
include CommonActiveRecordStoreTests
|
||||
|
||||
def session_class
|
||||
CGI::Session::ActiveRecordStore::Session
|
||||
end
|
||||
|
||||
def session_id_column
|
||||
"session_id"
|
||||
end
|
||||
|
||||
def setup
|
||||
session_class.create_table!
|
||||
|
||||
ENV['REQUEST_METHOD'] = 'GET'
|
||||
CGI::Session::ActiveRecordStore.session_class = session_class
|
||||
|
||||
@cgi = CGI.new
|
||||
@new_session = CGI::Session.new(@cgi, 'database_manager' => CGI::Session::ActiveRecordStore, 'new_session' => true)
|
||||
@new_session['foo'] = 'bar'
|
||||
end
|
||||
|
||||
# this test only applies for eager sesssion saving
|
||||
# def test_another_instance
|
||||
# @another = CGI::Session.new(@cgi, 'session_id' => @new_session.session_id, 'database_manager' => CGI::Session::ActiveRecordStore)
|
||||
# assert_equal @new_session.session_id, @another.session_id
|
||||
# end
|
||||
|
||||
def test_model_attribute
|
||||
assert_kind_of CGI::Session::ActiveRecordStore::Session, @new_session.model
|
||||
assert_equal({ 'foo' => 'bar' }, @new_session.model.data)
|
||||
end
|
||||
|
||||
def test_save_unloaded_session
|
||||
c = session_class.connection
|
||||
bogus_class = c.quote(Base64.encode64("\004\010o:\vBlammo\000"))
|
||||
c.insert("INSERT INTO #{session_class.table_name} ('#{session_id_column}', 'data') VALUES ('abcdefghijklmnop', #{bogus_class})")
|
||||
|
||||
sess = session_class.find_by_session_id('abcdefghijklmnop')
|
||||
assert_not_nil sess
|
||||
assert !sess.loaded?
|
||||
|
||||
# because the session is not loaded, the save should be a no-op. If it
|
||||
# isn't, this'll try and unmarshall the bogus class, and should get an error.
|
||||
assert_nothing_raised { sess.save }
|
||||
end
|
||||
|
||||
def teardown
|
||||
session_class.drop_table!
|
||||
end
|
||||
end
|
||||
|
||||
class ColumnLimitTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@session_class = CGI::Session::ActiveRecordStore::Session
|
||||
@session_class.create_table!
|
||||
end
|
||||
|
||||
def teardown
|
||||
@session_class.drop_table!
|
||||
end
|
||||
|
||||
def test_protection_from_data_larger_than_column
|
||||
# Can't test this unless there is a limit
|
||||
return unless limit = @session_class.data_column_size_limit
|
||||
too_big = ':(' * limit
|
||||
s = @session_class.new(:session_id => '666', :data => {'foo' => too_big})
|
||||
s.data
|
||||
assert_raise(ActionController::SessionOverflowError) { s.save }
|
||||
end
|
||||
end
|
||||
|
||||
class DeprecatedActiveRecordStoreTest < ActiveRecordStoreTest
|
||||
def session_id_column
|
||||
"sessid"
|
||||
end
|
||||
|
||||
def setup
|
||||
session_class.connection.execute 'create table old_sessions (id integer primary key, sessid text unique, data text)'
|
||||
session_class.table_name = 'old_sessions'
|
||||
session_class.send :setup_sessid_compatibility!
|
||||
|
||||
ENV['REQUEST_METHOD'] = 'GET'
|
||||
CGI::Session::ActiveRecordStore.session_class = session_class
|
||||
|
||||
@new_session = CGI::Session.new(CGI.new, 'database_manager' => CGI::Session::ActiveRecordStore, 'new_session' => true)
|
||||
@new_session['foo'] = 'bar'
|
||||
end
|
||||
|
||||
def teardown
|
||||
session_class.connection.execute 'drop table old_sessions'
|
||||
session_class.table_name = 'sessions'
|
||||
end
|
||||
end
|
||||
|
||||
class SqlBypassActiveRecordStoreTest < ActiveRecordStoreTest
|
||||
def session_class
|
||||
unless @session_class
|
||||
@session_class = CGI::Session::ActiveRecordStore::SqlBypass
|
||||
@session_class.connection = CGI::Session::ActiveRecordStore::Session.connection
|
||||
end
|
||||
@session_class
|
||||
end
|
||||
|
||||
def test_model_attribute
|
||||
assert_kind_of CGI::Session::ActiveRecordStore::SqlBypass, @new_session.model
|
||||
assert_equal({ 'foo' => 'bar' }, @new_session.model.data)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# End of safety net.
|
||||
rescue Object => e
|
||||
$stderr.puts "Skipping CGI::Session::ActiveRecordStore tests: #{e}"
|
||||
#$stderr.puts " #{e.backtrace.join("\n ")}"
|
||||
end
|
||||
end
|
161
vendor/rails/actionpack/test/activerecord/pagination_test.rb
vendored
Normal file
161
vendor/rails/actionpack/test/activerecord/pagination_test.rb
vendored
Normal file
|
@ -0,0 +1,161 @@
|
|||
require File.dirname(__FILE__) + '/../active_record_unit'
|
||||
|
||||
require 'fixtures/topic'
|
||||
require 'fixtures/reply'
|
||||
require 'fixtures/developer'
|
||||
require 'fixtures/project'
|
||||
|
||||
class PaginationTest < ActiveRecordTestCase
|
||||
fixtures :topics, :replies, :developers, :projects, :developers_projects
|
||||
|
||||
class PaginationController < ActionController::Base
|
||||
self.template_root = "#{File.dirname(__FILE__)}/../fixtures/"
|
||||
|
||||
def simple_paginate
|
||||
@topic_pages, @topics = paginate(:topics)
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_per_page
|
||||
@topic_pages, @topics = paginate(:topics, :per_page => 1)
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_order
|
||||
@topic_pages, @topics = paginate(:topics, :order => 'created_at asc')
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_order_by
|
||||
@topic_pages, @topics = paginate(:topics, :order_by => 'created_at asc')
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_include_and_order
|
||||
@topic_pages, @topics = paginate(:topics, :include => :replies, :order => 'replies.created_at asc, topics.created_at asc')
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_conditions
|
||||
@topic_pages, @topics = paginate(:topics, :conditions => ["created_at > ?", 30.minutes.ago])
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_class_name
|
||||
@developer_pages, @developers = paginate(:developers, :class_name => "DeVeLoPeR")
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_singular_name
|
||||
@developer_pages, @developers = paginate()
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_joins
|
||||
@developer_pages, @developers = paginate(:developers,
|
||||
:joins => 'LEFT JOIN developers_projects ON developers.id = developers_projects.developer_id',
|
||||
:conditions => 'project_id=1')
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_join
|
||||
@developer_pages, @developers = paginate(:developers,
|
||||
:join => 'LEFT JOIN developers_projects ON developers.id = developers_projects.developer_id',
|
||||
:conditions => 'project_id=1')
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_join_and_count
|
||||
@developer_pages, @developers = paginate(:developers,
|
||||
:join => 'd LEFT JOIN developers_projects ON d.id = developers_projects.developer_id',
|
||||
:conditions => 'project_id=1',
|
||||
:count => "d.id")
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def rescue_errors(e) raise e end
|
||||
|
||||
def rescue_action(e) raise end
|
||||
|
||||
end
|
||||
|
||||
def setup
|
||||
@controller = PaginationController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
super
|
||||
end
|
||||
|
||||
# Single Action Pagination Tests
|
||||
|
||||
def test_simple_paginate
|
||||
get :simple_paginate
|
||||
assert_equal 1, assigns(:topic_pages).page_count
|
||||
assert_equal 3, assigns(:topics).size
|
||||
end
|
||||
|
||||
def test_paginate_with_per_page
|
||||
get :paginate_with_per_page
|
||||
assert_equal 1, assigns(:topics).size
|
||||
assert_equal 3, assigns(:topic_pages).page_count
|
||||
end
|
||||
|
||||
def test_paginate_with_order
|
||||
get :paginate_with_order
|
||||
expected = [topics(:futurama),
|
||||
topics(:harvey_birdman),
|
||||
topics(:rails)]
|
||||
assert_equal expected, assigns(:topics)
|
||||
assert_equal 1, assigns(:topic_pages).page_count
|
||||
end
|
||||
|
||||
def test_paginate_with_order_by
|
||||
get :paginate_with_order
|
||||
expected = assigns(:topics)
|
||||
get :paginate_with_order_by
|
||||
assert_equal expected, assigns(:topics)
|
||||
assert_equal 1, assigns(:topic_pages).page_count
|
||||
end
|
||||
|
||||
def test_paginate_with_conditions
|
||||
get :paginate_with_conditions
|
||||
expected = [topics(:rails)]
|
||||
assert_equal expected, assigns(:topics)
|
||||
assert_equal 1, assigns(:topic_pages).page_count
|
||||
end
|
||||
|
||||
def test_paginate_with_class_name
|
||||
get :paginate_with_class_name
|
||||
|
||||
assert assigns(:developers).size > 0
|
||||
assert_equal DeVeLoPeR, assigns(:developers).first.class
|
||||
end
|
||||
|
||||
def test_paginate_with_joins
|
||||
get :paginate_with_joins
|
||||
assert_equal 2, assigns(:developers).size
|
||||
developer_names = assigns(:developers).map { |d| d.name }
|
||||
assert developer_names.include?('David')
|
||||
assert developer_names.include?('Jamis')
|
||||
end
|
||||
|
||||
def test_paginate_with_join_and_conditions
|
||||
get :paginate_with_joins
|
||||
expected = assigns(:developers)
|
||||
get :paginate_with_join
|
||||
assert_equal expected, assigns(:developers)
|
||||
end
|
||||
|
||||
def test_paginate_with_join_and_count
|
||||
get :paginate_with_joins
|
||||
expected = assigns(:developers)
|
||||
get :paginate_with_join_and_count
|
||||
assert_equal expected, assigns(:developers)
|
||||
end
|
||||
|
||||
def test_paginate_with_include_and_order
|
||||
get :paginate_with_include_and_order
|
||||
expected = Topic.find(:all, :include => 'replies', :order => 'replies.created_at asc, topics.created_at asc', :limit => 10)
|
||||
assert_equal expected, assigns(:topics)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue