public
Description:
Homepage:
Clone URL: git://github.com/relevance/streamlined.git
streamlined / test / test_functional_helper.rb
100644 90 lines (77 sloc) 4.198 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
base = File.dirname(__FILE__)
 
require File.join(base, 'test_helper')
require File.join(base, "lib", 'ar_helper')
require 'active_record/fixtures'
 
$: << File.join(base,"fixtures")
# getting messy: Poet needed by Poem
require "poet"
 
# Require sample fixtures, models, and UI classes
# .sort.each added to ensure that the list is sorted and person.rb is "required"
# before person_ui.rb; person_ui.rb references the Person class.
Dir.glob("#{base}/fixtures/*.rb").sort.each do |file|
  require File.basename(file, ".*")
end
 
EXPECTED_USERS = [/\d[[:punct:]]Justin[[:punct:]]Gehtland/, /\d[[:punct:]]Stu[[:punct:]]Halloway/,/\d[[:punct:]]Jason[[:punct:]]Rudolph/,/\d[[:punct:]]Glenn[[:punct:]]Vanderburg/]
EXPECTED_USERS_IN_XML = [/<Person>\n.*<last_name>Gehtland<\/last_name>\n.*<full_name>Justin Gehtland<\/full_name>\n.*<\/Person>/,
/<Person>\n.*<last_name>Halloway<\/last_name>\n.*<full_name>Stu Halloway<\/full_name>\n.*<\/Person>/,
/<Person>\n.*<last_name>Rudolph<\/last_name>\n.*<full_name>Jason Rudolph<\/full_name>\n.*<\/Person>/,
/<Person>\n.*<last_name>Vanderburg<\/last_name>\n.*<full_name>Glenn Vanderburg<\/full_name>\n.*<\/Person>/]
EXPECTED_USERS_IN_XML_FIRST_LAST = [/<Person>\n.*<first_name>Justin<\/first_name>\n.*<last_name>Gehtland<\/last_name>\n.*<full_name>Justin Gehtland<\/full_name>\n.*<\/Person>/,
/<Person>\n.*<first_name>Stu<\/first_name>\n.*<last_name>Halloway<\/last_name>\n.*<full_name>Stu Halloway<\/full_name>\n.*<\/Person>/,
/<Person>\n.*<first_name>Jason<\/first_name>\n.*<last_name>Rudolph<\/last_name>\n.*<full_name>Jason Rudolph<\/full_name>\n.*<\/Person>/,
/<Person>\n.*<first_name>Glenn<\/first_name>\n.*<last_name>Vanderburg<\/last_name>\n.*<full_name>Glenn Vanderburg<\/full_name>\n.*<\/Person>/]
EXPECTED_USERS_IN_JSON = [/\{id: \"1\", first_name: \"Justin\", last_name: \"Gehtland\"\}/,
/\{id: \"2\", first_name: \"Stu\", last_name: \"Halloway\"\}/,
/\{id: \"3\", first_name: \"Jason\", last_name: \"Rudolph\"\}/,
/\{id: \"4\", first_name: \"Glenn\", last_name: \"Vanderburg\"\}/]
EXPECTED_USERS_IN_JSON_EDGE = [/\{\"id\": 1, \"first_name\": \"Justin\", \"last_name\": \"Gehtland\"\}/,
/\{\"id\": 2, \"first_name\": \"Stu\", \"last_name\": \"Halloway\"\}/,
/\{\"id\": 3, \"first_name\": \"Jason\", \"last_name\": \"Rudolph\"\}/,
/\{\"id\": 4, \"first_name\": \"Glenn\", \"last_name\": \"Vanderburg\"\}/]
EXPECTED_USERS_IN_YAML = [/id: 1\n.* first_name: Justin\n.* last_name: Gehtland/,
/id: 2\n.* first_name: Stu\n.* last_name: Halloway/,
/id: 3\n.* first_name: Jason\n.* last_name: Rudolph/,
/id: 4\n.* first_name: Glenn\n.* last_name: Vanderburg/]
class Test::Unit::TestCase
self.fixture_path = File.dirname(__FILE__) + "/fixtures/"
self.use_instantiated_fixtures = false
self.use_transactional_fixtures = true
 
def create_fixtures(*table_names, &block)
Fixtures.create_fixtures(self.class.fixture_path, table_names, {}, &block)
end
 
def setup_routes
ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id.:format'
map.connect ':controller/:action/:id'
end
ActionController::Routing.use_controllers! %w(people)
end
def stock_controller_and_view(controller = PeopleController)
setup_routes
@controller = controller.new
@controller.logger = RAILS_DEFAULT_LOGGER
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@item = Struct.new(:id).new(1)
get 'index'
@view = @response.template
end
 
end
 
unless ActionController::Base.respond_to?(:view_paths=)
# Monkey patching ActionView. This sucks, but I got tired of trying to
# find how to get the base_path set.
class ActionView::Base
def initialize(base_path = nil, assigns_for_first_render = {}, controller = nil)#:nodoc:
@base_path, @assigns = base_path, assigns_for_first_render
@assigns_added = nil
@controller = controller
@logger = controller && controller.logger
@base_path = File.join(RAILS_ROOT, "app/views")
end
end
end
 
def assert_matches_all(expecteds, actual)
expecteds.each do |reg|
assert_match(reg, actual)
end
end