Initial commit of foodsoft 2
This commit is contained in:
commit
5b9a7e05df
657 changed files with 70444 additions and 0 deletions
36
vendor/plugins/will_paginate/test/lib/activerecord_test_case.rb
vendored
Normal file
36
vendor/plugins/will_paginate/test/lib/activerecord_test_case.rb
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
require 'lib/activerecord_test_connector'
|
||||
|
||||
class ActiveRecordTestCase < Test::Unit::TestCase
|
||||
# Set our fixture path
|
||||
if ActiveRecordTestConnector.able_to_connect
|
||||
self.fixture_path = File.join(File.dirname(__FILE__), '..', 'fixtures')
|
||||
self.use_transactional_fixtures = true
|
||||
end
|
||||
|
||||
def self.fixtures(*args)
|
||||
super if ActiveRecordTestConnector.connected
|
||||
end
|
||||
|
||||
def run(*args)
|
||||
super if ActiveRecordTestConnector.connected
|
||||
end
|
||||
|
||||
# Default so Test::Unit::TestCase doesn't complain
|
||||
def test_truth
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def assert_queries(num = 1)
|
||||
$query_count = 0
|
||||
yield
|
||||
ensure
|
||||
assert_equal num, $query_count, "#{$query_count} instead of #{num} queries were executed."
|
||||
end
|
||||
|
||||
def assert_no_queries(&block)
|
||||
assert_queries(0, &block)
|
||||
end
|
||||
end
|
||||
|
||||
ActiveRecordTestConnector.setup
|
||||
69
vendor/plugins/will_paginate/test/lib/activerecord_test_connector.rb
vendored
Normal file
69
vendor/plugins/will_paginate/test/lib/activerecord_test_connector.rb
vendored
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
require 'active_record'
|
||||
require 'active_record/version'
|
||||
require 'active_record/fixtures'
|
||||
|
||||
class ActiveRecordTestConnector
|
||||
cattr_accessor :able_to_connect
|
||||
cattr_accessor :connected
|
||||
|
||||
FIXTURES_PATH = File.join(File.dirname(__FILE__), '..', 'fixtures')
|
||||
|
||||
# Set our defaults
|
||||
self.connected = false
|
||||
self.able_to_connect = true
|
||||
|
||||
def self.setup
|
||||
unless self.connected || !self.able_to_connect
|
||||
setup_connection
|
||||
load_schema
|
||||
Dependencies.load_paths.unshift FIXTURES_PATH
|
||||
self.connected = true
|
||||
end
|
||||
rescue Exception => e # errors from ActiveRecord setup
|
||||
$stderr.puts "\nSkipping ActiveRecord tests: #{e}"
|
||||
$stderr.puts "Install SQLite3 to run the full test suite for will_paginate.\n\n"
|
||||
self.able_to_connect = false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.setup_connection
|
||||
db = ENV['DB'].blank?? 'sqlite3' : ENV['DB']
|
||||
|
||||
configurations = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'database.yml'))
|
||||
raise "no configuration for '#{db}'" unless configurations.key? db
|
||||
configuration = configurations[db]
|
||||
|
||||
ActiveRecord::Base.logger = Logger.new(STDOUT) if $0 == 'irb'
|
||||
puts "using #{configuration['adapter']} adapter" unless ENV['DB'].blank?
|
||||
|
||||
ActiveRecord::Base.establish_connection(configuration)
|
||||
ActiveRecord::Base.configurations = { db => configuration }
|
||||
prepare ActiveRecord::Base.connection
|
||||
|
||||
unless Object.const_defined?(:QUOTED_TYPE)
|
||||
Object.send :const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')
|
||||
end
|
||||
end
|
||||
|
||||
def self.load_schema
|
||||
ActiveRecord::Base.silence do
|
||||
ActiveRecord::Migration.verbose = false
|
||||
load File.join(FIXTURES_PATH, 'schema.rb')
|
||||
end
|
||||
end
|
||||
|
||||
def self.prepare(conn)
|
||||
class << conn
|
||||
IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SHOW FIELDS /]
|
||||
|
||||
def execute_with_counting(sql, name = nil, &block)
|
||||
$query_count ||= 0
|
||||
$query_count += 1 unless IGNORED_SQL.any? { |r| sql =~ r }
|
||||
execute_without_counting(sql, name, &block)
|
||||
end
|
||||
|
||||
alias_method_chain :execute, :counting
|
||||
end
|
||||
end
|
||||
end
|
||||
11
vendor/plugins/will_paginate/test/lib/load_fixtures.rb
vendored
Normal file
11
vendor/plugins/will_paginate/test/lib/load_fixtures.rb
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
require 'boot'
|
||||
require 'lib/activerecord_test_connector'
|
||||
|
||||
# setup the connection
|
||||
ActiveRecordTestConnector.setup
|
||||
|
||||
# load all fixtures
|
||||
Fixtures.create_fixtures(ActiveRecordTestConnector::FIXTURES_PATH, ActiveRecord::Base.connection.tables)
|
||||
|
||||
require 'will_paginate'
|
||||
WillPaginate.enable_activerecord
|
||||
165
vendor/plugins/will_paginate/test/lib/view_test_process.rb
vendored
Normal file
165
vendor/plugins/will_paginate/test/lib/view_test_process.rb
vendored
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
require 'action_controller'
|
||||
require 'action_controller/test_process'
|
||||
|
||||
require 'will_paginate'
|
||||
WillPaginate.enable_actionpack
|
||||
|
||||
ActionController::Routing::Routes.draw do |map|
|
||||
map.connect 'dummy/page/:page', :controller => 'dummy'
|
||||
map.connect 'dummy/dots/page.:page', :controller => 'dummy', :action => 'dots'
|
||||
map.connect 'ibocorp/:page', :controller => 'ibocorp',
|
||||
:requirements => { :page => /\d+/ },
|
||||
:defaults => { :page => 1 }
|
||||
|
||||
map.connect ':controller/:action/:id'
|
||||
end
|
||||
|
||||
ActionController::Base.perform_caching = false
|
||||
|
||||
class WillPaginate::ViewTestCase < Test::Unit::TestCase
|
||||
def setup
|
||||
super
|
||||
@controller = DummyController.new
|
||||
@request = @controller.request
|
||||
@html_result = nil
|
||||
@template = '<%= will_paginate collection, options %>'
|
||||
|
||||
@view = ActionView::Base.new
|
||||
@view.assigns['controller'] = @controller
|
||||
@view.assigns['_request'] = @request
|
||||
@view.assigns['_params'] = @request.params
|
||||
end
|
||||
|
||||
def test_no_complain; end
|
||||
|
||||
protected
|
||||
|
||||
def paginate(collection = {}, options = {}, &block)
|
||||
if collection.instance_of? Hash
|
||||
page_options = { :page => 1, :total_entries => 11, :per_page => 4 }.merge(collection)
|
||||
collection = [1].paginate(page_options)
|
||||
end
|
||||
|
||||
locals = { :collection => collection, :options => options }
|
||||
|
||||
if defined? ActionView::InlineTemplate
|
||||
# Rails 2.1
|
||||
args = [ ActionView::InlineTemplate.new(@view, @template, locals) ]
|
||||
else
|
||||
# older Rails versions
|
||||
args = [nil, @template, nil, locals]
|
||||
end
|
||||
|
||||
@html_result = @view.render_template(*args)
|
||||
@html_document = HTML::Document.new(@html_result, true, false)
|
||||
|
||||
if block_given?
|
||||
classname = options[:class] || WillPaginate::ViewHelpers.pagination_options[:class]
|
||||
assert_select("div.#{classname}", 1, 'no main DIV', &block)
|
||||
end
|
||||
end
|
||||
|
||||
def response_from_page_or_rjs
|
||||
@html_document.root
|
||||
end
|
||||
|
||||
def validate_page_numbers expected, links, param_name = :page
|
||||
param_pattern = /\W#{CGI.escape(param_name.to_s)}=([^&]*)/
|
||||
|
||||
assert_equal(expected, links.map { |e|
|
||||
e['href'] =~ param_pattern
|
||||
$1 ? $1.to_i : $1
|
||||
})
|
||||
end
|
||||
|
||||
def assert_links_match pattern, links = nil, numbers = nil
|
||||
links ||= assert_select 'div.pagination a[href]' do |elements|
|
||||
elements
|
||||
end
|
||||
|
||||
pages = [] if numbers
|
||||
|
||||
links.each do |el|
|
||||
assert_match pattern, el['href']
|
||||
if numbers
|
||||
el['href'] =~ pattern
|
||||
pages << ($1.nil?? nil : $1.to_i)
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal numbers, pages, "page numbers don't match" if numbers
|
||||
end
|
||||
|
||||
def assert_no_links_match pattern
|
||||
assert_select 'div.pagination a[href]' do |elements|
|
||||
elements.each do |el|
|
||||
assert_no_match pattern, el['href']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class DummyRequest
|
||||
attr_accessor :symbolized_path_parameters
|
||||
|
||||
def initialize
|
||||
@get = true
|
||||
@params = {}
|
||||
@symbolized_path_parameters = { :controller => 'foo', :action => 'bar' }
|
||||
end
|
||||
|
||||
def get?
|
||||
@get
|
||||
end
|
||||
|
||||
def post
|
||||
@get = false
|
||||
end
|
||||
|
||||
def relative_url_root
|
||||
''
|
||||
end
|
||||
|
||||
def params(more = nil)
|
||||
@params.update(more) if more
|
||||
@params
|
||||
end
|
||||
end
|
||||
|
||||
class DummyController
|
||||
attr_reader :request
|
||||
attr_accessor :controller_name
|
||||
|
||||
def initialize
|
||||
@request = DummyRequest.new
|
||||
@url = ActionController::UrlRewriter.new(@request, @request.params)
|
||||
end
|
||||
|
||||
def params
|
||||
@request.params
|
||||
end
|
||||
|
||||
def url_for(params)
|
||||
@url.rewrite(params)
|
||||
end
|
||||
end
|
||||
|
||||
module HTML
|
||||
Node.class_eval do
|
||||
def inner_text
|
||||
children.map(&:inner_text).join('')
|
||||
end
|
||||
end
|
||||
|
||||
Text.class_eval do
|
||||
def inner_text
|
||||
self.to_s
|
||||
end
|
||||
end
|
||||
|
||||
Tag.class_eval do
|
||||
def inner_text
|
||||
childless?? '' : super
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue