Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 8
- Log:
Updated to HEAD revision from SVN repository for 22-Jul-2006 at
about 6:30pm.
- Author:
- adh
- Date:
- Sat Jul 22 19:30:50 +0100 2006
- Size:
- 3899 Bytes
1 | ENV["RAILS_ENV"] = "test" |
2 | require File.expand_path(File.dirname(__FILE__) + "/../config/environment") |
3 | require 'test_help' |
4 | |
5 | require File.dirname(__FILE__) + '/unit_test_assistant' #? |
6 | |
7 | class Test::Unit::TestCase |
8 | # Transactional fixtures accelerate your tests by wrapping each test method |
9 | # in a transaction that's rolled back on completion. This ensures that the |
10 | # test database remains unchanged so your fixtures don't have to be reloaded |
11 | # between every test method. Fewer database queries means faster tests. |
12 | # |
13 | # Read Mike Clark's excellent walkthrough at |
14 | # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting |
15 | # |
16 | # Every Active Record database supports transactions except MyISAM tables |
17 | # in MySQL. Turn off transactional fixtures in this case; however, if you |
18 | # don't care one way or the other, switching from MyISAM to InnoDB tables |
19 | # is recommended. |
20 | self.use_transactional_fixtures = false |
21 | |
22 | # Instantiated fixtures are slow, but give you @david where otherwise you |
23 | # would need people(:david). If you don't want to migrate your existing |
24 | # test cases which use the @david style and don't mind the speed hit (each |
25 | # instantiated fixtures translates to a database query per test method), |
26 | # then set this back to true. |
27 | self.use_instantiated_fixtures = true # default: false |
28 | |
29 | # Add more helper methods to be used by all tests here... |
30 | |
31 | # Shorthand method to get a DB connection in test |
32 | def db |
33 | ActiveRecord::Base.connection |
34 | end |
35 | |
36 | def setup_forum_fixture |
37 | create_fixtures 'forums', 'posts', 'topics', 'users', 'topic_reads', 'tags', 'topics_tags' |
38 | end |
39 | |
40 | FtaPrototypes::set_prototype :Forum, { |
41 | 'name' => 'Prototype Forum', 'description' => 'Prototype Forum Description', |
42 | 'created_at' => Time.now |
43 | } |
44 | |
45 | FtaPrototypes::set_prototype :Post, { |
46 | 'topic_id' => 1, 'l' => 1, 'r' => 1, 'subject' => 'Prototype Post Subject', |
47 | 'text' => 'Prototype Post Text', |
48 | 'messageid' => "prototype@#{RForum::CONFIG[:hostname]}" |
49 | } |
50 | |
51 | FtaPrototypes::set_prototype :Topic, { |
52 | 'forum_id' => 1, 'subject' => 'Prototype Topic Subject', 'last_post_created_at' => Time.at(946702800) |
53 | } |
54 | |
55 | FtaPrototypes::set_prototype :User, { |
56 | 'name' => 'ryan', 'firstname' => 'ryan', 'surname' => 'platte', |
57 | 'email' => 'ryan.platte@example.com' |
58 | } |
59 | |
60 | # Asserts that all messages in a topic belong to the same nested set, and |
61 | # the nested set is well formed |
62 | |
63 | def assert_nested_set_well_formed(topic_id) |
64 | posts = Post.find_all("topic_id = #{topic_id}", 'l ASC') |
65 | return if posts.empty? |
66 | |
67 | num_posts = posts.size |
68 | |
69 | # Check the topmost post |
70 | top_post = posts.shift |
71 | assert_equal 1, top_post.l |
72 | assert_equal num_posts * 2, top_post.r |
73 | |
74 | # Check all other posts |
75 | prev = top_post |
76 | posts.each do |cur| |
77 | assert cur.l > top_post.l |
78 | assert cur.r > top_post.l |
79 | |
80 | assert cur.l < top_post.r |
81 | assert cur.r < top_post.r |
82 | |
83 | if cur.children_count == 0 |
84 | assert_equal cur.l + 1, cur.r |
85 | end |
86 | |
87 | if prev.id == cur.parent_id |
88 | assert_equal prev.l + 1, cur.l |
89 | assert prev.r > cur.r |
90 | end |
91 | |
92 | prev = cur |
93 | end |
94 | end |
95 | end |
96 | |
97 | class ActiveRecord::Errors |
98 | |
99 | def to_s |
100 | s = "Problems with #{@base.class} ##{@base.id || 'nil'} :\n" |
101 | self.each { |attr, msg| |
102 | s << " #{attr} : #{msg} (value: #{@base[attr.to_s] || 'nil'})\n" |
103 | } |
104 | s |
105 | end |
106 | end |
107 | |
108 | # setup_class_controller method |
109 | class Test::Unit::TestCase |
110 | |
111 | private |
112 | |
113 | def setup_controller_test(controller_class = nil, host = nil) |
114 | if controller_class |
115 | @controller = controller_class.new |
116 | elsif self.class.to_s =~ /(\w+Controller)Test/ |
117 | @controller = Object::const_get($1).new |
118 | else |
119 | raise "Cannot derive the name of controller under test from class name #{self.class}" |
120 | end |
121 | @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new |
122 | @request.host = host || 'localhost' |
123 | return @request, @response |
124 | end |
125 | end |