You are here: Home > Latest news from Darcs > Tests needed some fixing after move to Darcs

Revision 20080306145329-49d33-276936...

Tests needed some fixing after move to Darcs

test/fixtures/headlines.yml
test/functional/report_controller_test.rb
test/unit/chief_editor_test.rb
test/unit/headline_test.rb

Changes to headlines.yml

5
  author: raulseixas
  author: raulseixas
5
6
  description: gita
  description: gita
6
7
  happened_at: 2005-01-01 00:00:00
  happened_at: 2005-01-01 00:00:00
7
8
  reported_by: subversion
  reported_by: darcs
8
9
  rid: r12
  rid: 20050101000000-9043f-5f2e84cdc6ce0e5eea4a7fbedc01d63f4b956f56
9
10
10
11
dia_em_que_a_terra_parou:
dia_em_que_a_terra_parou:
11
12
  id: 2
  id: 2
12
3 more lines
16
  reported_by: subversion
  reported_by: subversion
16
17
  rid: r16
  rid: r16
17
18
18
19
svn_demo_headline:
demo_headline:
19
20
  id: 3
  id: 3
20
21
  author: james
  author: james
21
22
  happened_at: 2006-03-23 11:10:04
  happened_at: 2006-03-23 11:10:04
22
23
  reported_by: subversion
  reported_by: darcs
23
24
  rid: r32
  rid: 20060323111004-9043f-27bf64adfd9f00bb935ab5e2dbd86cc4e4b5bebd
24
25
  description: This is a subversion revision comment
  description: This is a Darcs revision comment
25
26
                 
                 
26
27
               The comment is a multiline comment that indicates the purpose
               The comment is a multiline comment that indicates the purpose
27
28
               of the revision.
               of the revision.
28

Changes to report_controller_test.rb

35
  end
  end
35
36
  
  
36
37
  def test_fetches_headlines_from_cache
  def test_fetches_headlines_from_cache
37
38
    get :list, { :reporter => 'subversion' }
    get :list, { :reporter => 'darcs' }
38
39
    assert_response :success
    assert_response :success
39
40
    assert_not_nil assigns(:headlines)
    assert_not_nil assigns(:headlines)
40
41
    expected = Headline.find(:all, :conditions => "reported_by = 'subversion'")
    expected = Headline.find(:all, :conditions => "reported_by = 'darcs'")
41
42
    assert_equal expected.size, assigns(:headlines).size
    assert_equal expected.size, assigns(:headlines).size
42
43
  end
  end
43
44
  
  
44
4 more lines
49
  end
  end
49
50
  
  
50
51
  def test_fetches_individual_headline_based_on_rid
  def test_fetches_individual_headline_based_on_rid
51
52
    svn_demo_headline = headlines('svn_demo_headline')
    demo_headline = headlines('demo_headline')
52
53
    get :show, { :reporter => svn_demo_headline.reported_by,
    get :show, { :reporter => demo_headline.reported_by,
53
54
                 :id => svn_demo_headline.rid }
                 :id => demo_headline.rid }
54
55
    assert_response :success
    assert_response :success
55
56
    assert_not_nil assigns(:headline)
    assert_not_nil assigns(:headline)
56
57
  end
  end
57
58
  
  
58
59
  def test_calling_show_with_an_id_delegates_to_chief_editor
  def test_calling_show_with_an_id_delegates_to_chief_editor
59
60
    FlexMock.use do |editor|
    FlexMock.use do |editor|
60
61
      editor.should_receive(:reporter_with).with('subversion').
      editor.should_receive(:reporter_with).with('darcs').
61
62
        and_return(SubversionReporter.new)
        and_return(DarcsReporter.new)
62
63
      editor.should_receive(:headline_with).with('subversion', '3').
      editor.should_receive(:headline_with).with('darcs', '3').
63
64
        returns(headlines('svn_demo_headline')).
        returns(headlines('demo_headline')).
64
65
        once
        once
65
66
      
      
66
67
      @controller = ReportController.new(editor)
      @controller = ReportController.new(editor)
67
68
      
      
68
69
      get :show, {:reporter => 'subversion', :id => 3}
      get :show, {:reporter => 'darcs', :id => 3}
69
70
    end
    end
70
71
  end
  end
71
72
  
  
72
73
  def test_calling_show_with_invalid_rid_redirects_to_index
  def test_calling_show_with_invalid_rid_redirects_to_index
73
74
    get :show, { :reporter => 'subversion', :id => 'r300' }
    get :show, { :reporter => 'darcs', :id => 'aaaa' }
74
75
    assert_equal 'The article r300 from the Subversion reporter could not be found', flash[:notice]
    assert_equal 'The article aaaa from the Darcs reporter could not be found', flash[:notice]
75
76
    assert_redirected_to :controller => 'root', :action => 'index'
    assert_redirected_to :controller => 'root', :action => 'index'
76
77
  end
  end
77
78
  
  
78
9 more lines
88
  #TODO more headlines registered than the package size
  #TODO more headlines registered than the package size
88
89
  
  
89
90
  def test_shows_breadcrumbs_trail_for_subversion_revision_pages
  def test_shows_breadcrumbs_trail_for_subversion_revision_pages
90
91
    svn_demo = headlines('svn_demo_headline')
    demo = headlines('demo_headline')
91
92
    get :show, :reporter => svn_demo.reported_by, :id => svn_demo.rid
    get :show, :reporter => demo.reported_by, :id => demo.rid
92
93
    
    
93
94
    assert_xml_element "//div[@id = 'crumbs' and contains(text(), 'You are here')]/a[@href = '/' and text() = 'Home']"
    assert_xml_element "//div[@id = 'crumbs' and contains(text(), 'You are here')]/a[@href = '/' and text() = 'Home']"
94
95
    assert_xml_element "//div[@id = 'crumbs']/a[@href = '/report/older/subversion' and text() = 'Latest news from Subversion']"
    assert_xml_element "//div[@id = 'crumbs']/a[@href = '/report/older/darcs' and text() = 'Latest news from Darcs']"
95
96
    assert_xml_element "//div[@id = 'crumbs']/a[@href = '#{@controller.url_for(:controller => 'report', :action => 'show', :reporter => 'subversion', :id => svn_demo.rid, :only_path => true)}' and text() = '#{svn_demo.title}']"
    assert_xml_element "//div[@id = 'crumbs']/a[@href = '#{@controller.url_for(:controller => 'report', :action => 'show', :reporter => 'darcs', :id => demo.rid, :only_path => true)}' and text() = '#{demo.title}']"
96
97
  end
  end
97
98
98
99
  def test_shows_breadcrumbs_trail_for_older_news_page
  def test_shows_breadcrumbs_trail_for_older_news_page
99
100
    get :older, :reporter => 'subversion'
    get :older, :reporter => 'darcs'
100
101
    
    
101
102
    assert_xml_element "//div[@id = 'crumbs' and contains(text(), 'You are here')]/a[@href = '/' and text() = 'Home']"
    assert_xml_element "//div[@id = 'crumbs' and contains(text(), 'You are here')]/a[@href = '/' and text() = 'Home']"
102
103
    assert_xml_element "//div[@id = 'crumbs']/a[@href = '/report/older/subversion' and text() = 'Latest news from Subversion']"
    assert_xml_element "//div[@id = 'crumbs']/a[@href = '/report/older/darcs' and text() = 'Latest news from Darcs']"
103
104
  end
  end
104
105
105
106
private
private
106

Changes to chief_editor_test.rb

78
    FlexMock.use do |reporter|
    FlexMock.use do |reporter|
78
79
      settings = StubConnectionSettingsProvider.new(:update_interval => 0)
      settings = StubConnectionSettingsProvider.new(:update_interval => 0)
79
80
      fetcher = { :active_reporters => [reporter] }
      fetcher = { :active_reporters => [reporter] }
80
81
      svn_demo_headline = headlines('svn_demo_headline')
 
82
      
      
81
83
      reporter.should_receive(:name).returns('subversion')
      reporter.should_receive(:name).returns('subversion')
82
84
      reporter.should_receive(:latest_headlines).once.
      reporter.should_receive(:latest_headlines).once.
83
7 more lines
92
    FlexMock.use do |reporter|
    FlexMock.use do |reporter|
91
93
      settings = StubConnectionSettingsProvider.new(:update_interval => 0)
      settings = StubConnectionSettingsProvider.new(:update_interval => 0)
92
94
      fetcher = { :active_reporters => [reporter] }
      fetcher = { :active_reporters => [reporter] }
93
95
      svn_demo_headline = headlines('svn_demo_headline')
      demo_headline = headlines('demo_headline')
94
96
      
      
95
97
      reporter.should_receive(:name).returns('subversion')
      reporter.should_receive(:name).returns('subversion')
96
98
      reporter.should_receive(:headlines).once.
      reporter.should_receive(:headlines).once.
97
99
        returns([svn_demo_headline])
        returns([demo_headline])
98
100
      
      
99
101
      ChiefEditor.new(settings, fetcher).news_from('subversion')
      ChiefEditor.new(settings, fetcher).news_from('subversion')
100
102
    end
    end
101
16 more lines
119
    FlexMock.use do |reporter|
    FlexMock.use do |reporter|
118
120
      settings = StubConnectionSettingsProvider.new(:update_interval => 0)
      settings = StubConnectionSettingsProvider.new(:update_interval => 0)
119
121
      fetcher = { :active_reporters => [reporter] }
      fetcher = { :active_reporters => [reporter] }
120
122
      svn_demo_headline = headlines('svn_demo_headline')
      demo_headline = headlines('demo_headline')
121
123
      
      
122
124
      reporter.should_receive(:name).
      reporter.should_receive(:name).returns('darcs')
123
125
        returns('subversion')
 
126
      
      
124
127
      reporter.should_receive(:headline).
      reporter.should_receive(:headline).
125
128
        with(svn_demo_headline.rid).
        with(demo_headline.rid).
126
129
        returns(svn_demo_headline).
        returns(demo_headline).
127
130
        once
        once
128
131
      
      
129
132
      chief_editor = ChiefEditor.new(settings, fetcher)
      chief_editor = ChiefEditor.new(settings, fetcher)
130
133
      
      
131
134
      chief_editor.headline_with(svn_demo_headline.reported_by,
      chief_editor.headline_with(demo_headline.reported_by,
132
135
                                 svn_demo_headline.rid)
                                 demo_headline.rid)
133
136
    end
    end
134
137
  end
  end
135
138
  
  
136
1 more lines
140
    FlexMock.use('1', '2') do |reporter, fetcher|
    FlexMock.use('1', '2') do |reporter, fetcher|
138
141
      fetcher.should_receive(:active_reporters).and_return([reporter])
      fetcher.should_receive(:active_reporters).and_return([reporter])
139
142
      reporter.should_receive(:cache?).returns(true)
      reporter.should_receive(:cache?).returns(true)
140
143
      reporter.should_receive(:name).returns('subversion')
      reporter.should_receive(:name).returns('darcs')
141
144
      reporter.should_receive(:headline).never
      reporter.should_receive(:headline).never
142
145
143
146
144
1 more lines
148
      
      
146
149
      chief_editor = ChiefEditor.new(settings, fetcher)
      chief_editor = ChiefEditor.new(settings, fetcher)
147
150
      
      
148
151
      svn_demo_headline = headlines('svn_demo_headline')
      demo_headline = headlines('demo_headline')
149
152
150
153
      headline = chief_editor.headline_with(svn_demo_headline.reported_by,
      headline = chief_editor.headline_with(demo_headline.reported_by,
151
154
                                            svn_demo_headline.rid)
                                            demo_headline.rid)
152
155
      
      
153
156
      reporter.mock_verify
      reporter.mock_verify
154
157
      
      
155
158
      assert_equal svn_demo_headline.description, headline.description
      assert_equal demo_headline.description, headline.description
156
159
    end
    end
157
160
  end
  end
158
161
  
  
159
22 more lines
184
  end
  end
182
185
183
186
  def test_retrieves_headlines_from_correct_reporter_on_cached_mode
  def test_retrieves_headlines_from_correct_reporter_on_cached_mode
184
187
    FlexMock.use('1', '2', '3') do |events_reporter, svn_reporter, fetcher|
    FlexMock.use('1', '2', '3') do |events_reporter, darcs_reporter, fetcher|
185
188
      settings = StubConnectionSettingsProvider.new(:update_interval => 8)
      settings = StubConnectionSettingsProvider.new(:update_interval => 8)
186
189
      
      
187
190
      events_reporter.should_receive(:name).returns('events')
      events_reporter.should_receive(:name).returns('events')
188
191
      events_reporter.should_receive(:cache?).returns(true)
      events_reporter.should_receive(:cache?).returns(true)
189
192
      svn_reporter.should_receive(:name).returns('subversion')
      darcs_reporter.should_receive(:name).returns('darcs')
190
193
      svn_reporter.should_receive(:cache?).returns(true)
      darcs_reporter.should_receive(:cache?).returns(true)
191
194
      fetcher.should_receive(:active_reporters).
      fetcher.should_receive(:active_reporters).
192
195
        and_return([events_reporter, svn_reporter]).
        and_return([events_reporter, darcs_reporter]).
193
196
        once
        once
194
197
      
      
195
198
      chief_editor = ChiefEditor.new(settings, fetcher)
      chief_editor = ChiefEditor.new(settings, fetcher)
196
199
      
      
197
200
      events_news = chief_editor.latest_news_from 'events'
      assert_equal 1, chief_editor.latest_news_from('events').size
198
201
      
 
202
      assert_equal 1, events_news.size
 
203
      
 
204
      subversion_news = chief_editor.latest_news_from 'subversion'
 
205
      
      
199
206
      assert_equal 3, subversion_news.size
      assert_equal 3, chief_editor.latest_news_from('darcs').size
200
207
    end
    end
201
208
  end
  end
202
209
  
  
203
21 more lines
231
  end
  end
225
232
  
  
226
233
  #TODO should signal when the reporter is not registered
  #TODO should signal when the reporter is not registered
227
234
end
end
228

Changes to headline_test.rb

 
#  Motiro - A project tracking tool
1
 
#  Copyright (C) 2006-2008  Thiago Arrais
2
 
#  
3
 
#  This program is free software; you can redistribute it and/or modify
4
 
#  it under the terms of the GNU General Public License as published by
5
 
#  the Free Software Foundation; either version 2 of the License, or
6
 
#  any later version.
7
 
#  
8
 
#  This program is distributed in the hope that it will be useful,
9
 
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
#  GNU General Public License for more details.
12
 
#  
13
 
#  You should have received a copy of the GNU General Public License
14
 
#  along with this program; if not, write to the Free Software
15
 
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16
 
17
1
require File.dirname(__FILE__) + '/../test_helper'
require File.dirname(__FILE__) + '/../test_helper'
18
2
19
3
class HeadlineTest < Test::Unit::TestCase
class HeadlineTest < Test::Unit::TestCase
20
15 more lines
19
  end
  end
36
20
  
  
37
21
  def test_cached
  def test_cached
38
22
    svn_demo_headline = headlines('svn_demo_headline')
    demo_headline = headlines('demo_headline')
39
23
    headline = Headline.new(:author => svn_demo_headline.author,
    headline = Headline.new(:author => demo_headline.author,
40
24
                            :description => svn_demo_headline.description,
                            :description => demo_headline.description,
41
25
                            :happened_at => [2006, 03, 23, 11, 10, 04])
                            :happened_at => [2006, 03, 23, 11, 10, 04])
42
26
    
    
43
27
    assert headline.cached?
    assert headline.cached?
44
52 more lines
80
  end
  end
97
81
  
  
98
82
  def test_search_by_reporter_name_and_rid
  def test_search_by_reporter_name_and_rid
99
83
    svn_demo_headline = headlines('svn_demo_headline')
    demo_headline = headlines('demo_headline')
100
84
    aHeadline = Headline.find_with_reporter_and_rid(svn_demo_headline.reported_by,
    aHeadline = Headline.find_with_reporter_and_rid(demo_headline.reported_by,
101
85
                                                    svn_demo_headline.rid)
                                                    demo_headline.rid)
102
86
    
    
103
87
    assert_not_nil aHeadline
    assert_not_nil aHeadline
104
88
    assert_equal svn_demo_headline, aHeadline
    assert_equal demo_headline, aHeadline
105
89
  end
  end
106
90
  
  
107
91
  def test_not_filled
  def test_not_filled
108
140 more lines
232
  end
  end
249
233
  
  
250
234
  def test_retrieves_latest_filled_headline
  def test_retrieves_latest_filled_headline
251
235
    hl = headlines(:svn_demo_headline)
    hl = headlines('darcs_headline')
252
236
    assert_equal hl.rid, Headline.latest_filled_headline_rid_for(hl.reported_by)
    assert_equal hl.rid, Headline.latest_filled_headline_rid_for(hl.reported_by)
253
237
  end
  end
254
238
  
  
255