##// END OF EJS Templates
Adds test helpers for test repositories....
Jean-Philippe Lang -
r3606:1be15816dd30
parent child
Show More
@@ -1,220 +1,217
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'repositories_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class RepositoriesController; def rescue_action(e) raise e end; end
23 23
24 24 class RepositoriesSubversionControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
26 26 :repositories, :issues, :issue_statuses, :changesets, :changes,
27 27 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
28 28
29 # No '..' in the repository path for svn
30 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/subversion_repository'
31
32 29 def setup
33 30 @controller = RepositoriesController.new
34 31 @request = ActionController::TestRequest.new
35 32 @response = ActionController::TestResponse.new
36 33 Setting.default_language = 'en'
37 34 User.current = nil
38 35 end
39 36
40 if File.directory?(REPOSITORY_PATH)
37 if repository_configured?('subversion')
41 38 def test_show
42 39 get :show, :id => 1
43 40 assert_response :success
44 41 assert_template 'show'
45 42 assert_not_nil assigns(:entries)
46 43 assert_not_nil assigns(:changesets)
47 44 end
48 45
49 46 def test_browse_root
50 47 get :show, :id => 1
51 48 assert_response :success
52 49 assert_template 'show'
53 50 assert_not_nil assigns(:entries)
54 51 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
55 52 assert_equal 'dir', entry.kind
56 53 end
57 54
58 55 def test_browse_directory
59 56 get :show, :id => 1, :path => ['subversion_test']
60 57 assert_response :success
61 58 assert_template 'show'
62 59 assert_not_nil assigns(:entries)
63 60 assert_equal ['folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name)
64 61 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
65 62 assert_equal 'file', entry.kind
66 63 assert_equal 'subversion_test/helloworld.c', entry.path
67 64 assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ }
68 65 end
69 66
70 67 def test_browse_at_given_revision
71 68 get :show, :id => 1, :path => ['subversion_test'], :rev => 4
72 69 assert_response :success
73 70 assert_template 'show'
74 71 assert_not_nil assigns(:entries)
75 72 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name)
76 73 end
77 74
78 75 def test_file_changes
79 76 get :changes, :id => 1, :path => ['subversion_test', 'folder', 'helloworld.rb' ]
80 77 assert_response :success
81 78 assert_template 'changes'
82 79
83 80 changesets = assigns(:changesets)
84 81 assert_not_nil changesets
85 82 assert_equal %w(6 3 2), changesets.collect(&:revision)
86 83
87 84 # svn properties displayed with svn >= 1.5 only
88 85 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
89 86 assert_not_nil assigns(:properties)
90 87 assert_equal 'native', assigns(:properties)['svn:eol-style']
91 88 assert_tag :ul,
92 89 :child => { :tag => 'li',
93 90 :child => { :tag => 'b', :content => 'svn:eol-style' },
94 91 :child => { :tag => 'span', :content => 'native' } }
95 92 end
96 93 end
97 94
98 95 def test_directory_changes
99 96 get :changes, :id => 1, :path => ['subversion_test', 'folder' ]
100 97 assert_response :success
101 98 assert_template 'changes'
102 99
103 100 changesets = assigns(:changesets)
104 101 assert_not_nil changesets
105 102 assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision)
106 103 end
107 104
108 105 def test_entry
109 106 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c']
110 107 assert_response :success
111 108 assert_template 'entry'
112 109 end
113 110
114 111 def test_entry_should_send_if_too_big
115 112 # no files in the test repo is larger than 1KB...
116 113 with_settings :file_max_size_displayed => 0 do
117 114 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c']
118 115 assert_response :success
119 116 assert_template ''
120 117 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
121 118 end
122 119 end
123 120
124 121 def test_entry_at_given_revision
125 122 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.rb'], :rev => 2
126 123 assert_response :success
127 124 assert_template 'entry'
128 125 # this line was removed in r3 and file was moved in r6
129 126 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
130 127 :content => /Here's the code/
131 128 end
132 129
133 130 def test_entry_not_found
134 131 get :entry, :id => 1, :path => ['subversion_test', 'zzz.c']
135 132 assert_tag :tag => 'div', :attributes => { :class => /error/ },
136 133 :content => /The entry or revision was not found in the repository/
137 134 end
138 135
139 136 def test_entry_download
140 137 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'], :format => 'raw'
141 138 assert_response :success
142 139 assert_template ''
143 140 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
144 141 end
145 142
146 143 def test_directory_entry
147 144 get :entry, :id => 1, :path => ['subversion_test', 'folder']
148 145 assert_response :success
149 146 assert_template 'show'
150 147 assert_not_nil assigns(:entry)
151 148 assert_equal 'folder', assigns(:entry).name
152 149 end
153 150
154 151 def test_revision
155 152 get :revision, :id => 1, :rev => 2
156 153 assert_response :success
157 154 assert_template 'revision'
158 155 assert_tag :tag => 'ul',
159 156 :child => { :tag => 'li',
160 157 # link to the entry at rev 2
161 158 :child => { :tag => 'a',
162 159 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'},
163 160 :content => 'repo',
164 161 # link to partial diff
165 162 :sibling => { :tag => 'a',
166 163 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' }
167 164 }
168 165 }
169 166 }
170 167 end
171 168
172 169 def test_revision_with_repository_pointing_to_a_subdirectory
173 170 r = Project.find(1).repository
174 171 # Changes repository url to a subdirectory
175 172 r.update_attribute :url, (r.url + '/test/some')
176 173
177 174 get :revision, :id => 1, :rev => 2
178 175 assert_response :success
179 176 assert_template 'revision'
180 177 assert_tag :tag => 'ul',
181 178 :child => { :tag => 'li',
182 179 # link to the entry at rev 2
183 180 :child => { :tag => 'a',
184 181 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'},
185 182 :content => 'repo',
186 183 # link to partial diff
187 184 :sibling => { :tag => 'a',
188 185 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' }
189 186 }
190 187 }
191 188 }
192 189 end
193 190
194 191 def test_revision_diff
195 192 get :diff, :id => 1, :rev => 3
196 193 assert_response :success
197 194 assert_template 'diff'
198 195 end
199 196
200 197 def test_directory_diff
201 198 get :diff, :id => 1, :rev => 6, :rev_to => 2, :path => ['subversion_test', 'folder']
202 199 assert_response :success
203 200 assert_template 'diff'
204 201
205 202 diff = assigns(:diff)
206 203 assert_not_nil diff
207 204 # 2 files modified
208 205 assert_equal 2, Redmine::UnifiedDiff.new(diff).size
209 206 end
210 207
211 208 def test_annotate
212 209 get :annotate, :id => 1, :path => ['subversion_test', 'helloworld.c']
213 210 assert_response :success
214 211 assert_template 'annotate'
215 212 end
216 213 else
217 214 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
218 215 def test_fake; assert true end
219 216 end
220 217 end
@@ -1,145 +1,155
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 ENV["RAILS_ENV"] ||= "test"
19 19 require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
20 20 require 'test_help'
21 21 require File.expand_path(File.dirname(__FILE__) + '/helper_testcase')
22 22 require File.join(RAILS_ROOT,'test', 'mocks', 'open_id_authentication_mock.rb')
23 23
24 24 require File.expand_path(File.dirname(__FILE__) + '/object_daddy_helpers')
25 25 include ObjectDaddyHelpers
26 26
27 27 class ActiveSupport::TestCase
28 28 # Transactional fixtures accelerate your tests by wrapping each test method
29 29 # in a transaction that's rolled back on completion. This ensures that the
30 30 # test database remains unchanged so your fixtures don't have to be reloaded
31 31 # between every test method. Fewer database queries means faster tests.
32 32 #
33 33 # Read Mike Clark's excellent walkthrough at
34 34 # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
35 35 #
36 36 # Every Active Record database supports transactions except MyISAM tables
37 37 # in MySQL. Turn off transactional fixtures in this case; however, if you
38 38 # don't care one way or the other, switching from MyISAM to InnoDB tables
39 39 # is recommended.
40 40 self.use_transactional_fixtures = true
41 41
42 42 # Instantiated fixtures are slow, but give you @david where otherwise you
43 43 # would need people(:david). If you don't want to migrate your existing
44 44 # test cases which use the @david style and don't mind the speed hit (each
45 45 # instantiated fixtures translates to a database query per test method),
46 46 # then set this back to true.
47 47 self.use_instantiated_fixtures = false
48 48
49 49 # Add more helper methods to be used by all tests here...
50 50
51 51 def log_user(login, password)
52 52 User.anonymous
53 53 get "/login"
54 54 assert_equal nil, session[:user_id]
55 55 assert_response :success
56 56 assert_template "account/login"
57 57 post "/login", :username => login, :password => password
58 58 assert_equal login, User.find(session[:user_id]).login
59 59 end
60 60
61 61 def uploaded_test_file(name, mime)
62 62 ActionController::TestUploadedFile.new(ActiveSupport::TestCase.fixture_path + "/files/#{name}", mime)
63 63 end
64 64
65 65 # Use a temporary directory for attachment related tests
66 66 def set_tmp_attachments_directory
67 67 Dir.mkdir "#{RAILS_ROOT}/tmp/test" unless File.directory?("#{RAILS_ROOT}/tmp/test")
68 68 Dir.mkdir "#{RAILS_ROOT}/tmp/test/attachments" unless File.directory?("#{RAILS_ROOT}/tmp/test/attachments")
69 69 Attachment.storage_path = "#{RAILS_ROOT}/tmp/test/attachments"
70 70 end
71 71
72 72 def with_settings(options, &block)
73 73 saved_settings = options.keys.inject({}) {|h, k| h[k] = Setting[k].dup; h}
74 74 options.each {|k, v| Setting[k] = v}
75 75 yield
76 76 saved_settings.each {|k, v| Setting[k] = v}
77 77 end
78 78
79 79 def self.ldap_configured?
80 80 @test_ldap = Net::LDAP.new(:host => '127.0.0.1', :port => 389)
81 81 return @test_ldap.bind
82 82 rescue Exception => e
83 83 # LDAP is not listening
84 84 return nil
85 85 end
86
87 # Returns the path to the test +vendor+ repository
88 def self.repository_path(vendor)
89 File.join(RAILS_ROOT.gsub(%r{config\/\.\.}, ''), "/tmp/test/#{vendor.downcase}_repository")
90 end
91
92 # Returns true if the +vendor+ test repository is configured
93 def self.repository_configured?(vendor)
94 File.directory?(repository_path(vendor))
95 end
86 96
87 97 # Shoulda macros
88 98 def self.should_render_404
89 99 should_respond_with :not_found
90 100 should_render_template 'common/404'
91 101 end
92 102
93 103 def self.should_have_before_filter(expected_method, options = {})
94 104 should_have_filter('before', expected_method, options)
95 105 end
96 106
97 107 def self.should_have_after_filter(expected_method, options = {})
98 108 should_have_filter('after', expected_method, options)
99 109 end
100 110
101 111 def self.should_have_filter(filter_type, expected_method, options)
102 112 description = "have #{filter_type}_filter :#{expected_method}"
103 113 description << " with #{options.inspect}" unless options.empty?
104 114
105 115 should description do
106 116 klass = "action_controller/filters/#{filter_type}_filter".classify.constantize
107 117 expected = klass.new(:filter, expected_method.to_sym, options)
108 118 assert_equal 1, @controller.class.filter_chain.select { |filter|
109 119 filter.method == expected.method && filter.kind == expected.kind &&
110 120 filter.options == expected.options && filter.class == expected.class
111 121 }.size
112 122 end
113 123 end
114 124
115 125 def self.should_show_the_old_and_new_values_for(prop_key, model, &block)
116 126 context "" do
117 127 setup do
118 128 if block_given?
119 129 instance_eval &block
120 130 else
121 131 @old_value = model.generate!
122 132 @new_value = model.generate!
123 133 end
124 134 end
125 135
126 136 should "use the new value's name" do
127 137 @detail = JournalDetail.generate!(:property => 'attr',
128 138 :old_value => @old_value.id,
129 139 :value => @new_value.id,
130 140 :prop_key => prop_key)
131 141
132 142 assert_match @new_value.name, show_detail(@detail, true)
133 143 end
134 144
135 145 should "use the old value's name" do
136 146 @detail = JournalDetail.generate!(:property => 'attr',
137 147 :old_value => @old_value.id,
138 148 :value => @new_value.id,
139 149 :prop_key => prop_key)
140 150
141 151 assert_match @old_value.name, show_detail(@detail, true)
142 152 end
143 153 end
144 154 end
145 155 end
@@ -1,33 +1,31
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require 'mkmf'
19
20 18 require File.dirname(__FILE__) + '/../../../../../test_helper'
21 19
22 20 class SubversionAdapterTest < ActiveSupport::TestCase
23 21
24 if find_executable0('svn')
22 if repository_configured?('subversion')
25 23 def test_client_version
26 24 v = Redmine::Scm::Adapters::SubversionAdapter.client_version
27 25 assert v.is_a?(Array)
28 26 end
29 27 else
30 puts "Subversion binary NOT FOUND. Skipping unit tests !!!"
28 puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
31 29 def test_fake; assert true end
32 30 end
33 31 end
@@ -1,72 +1,69
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19
20 20 class RepositorySubversionTest < ActiveSupport::TestCase
21 21 fixtures :projects
22 22
23 # No '..' in the repository path for svn
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/subversion_repository'
25
26 23 def setup
27 24 @project = Project.find(1)
28 assert @repository = Repository::Subversion.create(:project => @project, :url => "file:///#{REPOSITORY_PATH}")
25 assert @repository = Repository::Subversion.create(:project => @project, :url => "file:///#{self.class.repository_path('subversion')}")
29 26 end
30 27
31 if File.directory?(REPOSITORY_PATH)
28 if repository_configured?('subversion')
32 29 def test_fetch_changesets_from_scratch
33 30 @repository.fetch_changesets
34 31 @repository.reload
35 32
36 33 assert_equal 10, @repository.changesets.count
37 34 assert_equal 18, @repository.changes.count
38 35 assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
39 36 end
40 37
41 38 def test_fetch_changesets_incremental
42 39 @repository.fetch_changesets
43 40 # Remove changesets with revision > 5
44 41 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 5}
45 42 @repository.reload
46 43 assert_equal 5, @repository.changesets.count
47 44
48 45 @repository.fetch_changesets
49 46 assert_equal 10, @repository.changesets.count
50 47 end
51 48
52 49 def test_latest_changesets
53 50 @repository.fetch_changesets
54 51
55 52 # with limit
56 53 changesets = @repository.latest_changesets('', nil, 2)
57 54 assert_equal 2, changesets.size
58 55 assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets
59 56
60 57 # with path
61 58 changesets = @repository.latest_changesets('subversion_test/folder', nil)
62 59 assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision)
63 60
64 61 # with path and revision
65 62 changesets = @repository.latest_changesets('subversion_test/folder', 8)
66 63 assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision)
67 64 end
68 65 else
69 66 puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
70 67 def test_fake; assert true end
71 68 end
72 69 end
General Comments 0
You need to be logged in to leave comments. Login now