Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

handling empty lists

  • Loading branch information...
commit d8afcb579f559131877b729b21d37e9a2bd40b6b 1 parent 13cbec7
Laura authored April 08, 2011
10  app/controllers/board_controller.rb
... ...
@@ -1,10 +1,10 @@
1 1
 class BoardController < ApplicationController
2 2
   def show
3  
-    @backlog = Story.order("column_ord").find_by_state("B")
4  
-    @priority = Story.order("column_ord").find_by_state("P") 
5  
-    @active = Story.order("column_ord").find_by_state("A")
6  
-    @delegated = Story.order("column_ord").find_by_state("D") 
7  
-    @complete = Story.order("column_ord").find_by_state("C")
  3
+    @backlog =  Story.order("column_ord").find_all_by_state("B") 
  4
+    @priority = Story.order("column_ord").find_all_by_state("P")  
  5
+    @active =  Story.order("column_ord").find_all_by_state("A") 
  6
+    @delegated =  Story.order("column_ord").find_all_by_state("D") 
  7
+    @complete =  Story.order("column_ord").find_all_by_state("C") 
8 8
     respond_to do |format|
9 9
       format.html # show.html.erb
10 10
       format.xml  { render :xml => @stories }
10  app/views/board/show.html.erb
@@ -11,35 +11,35 @@ a<%= link_to 'New Story', new_story_path %>
11 11
 <td>
12 12
 <div  class="backlog">
13 13
 <ul id="B" class="sortcol">
14  
-<%= render(@backlog) %>
  14
+<%= if @backlog then  render(@backlog) end%>
15 15
 </ul>
16 16
 </div>
17 17
 </td>
18 18
 <td>
19 19
 <div class="priority">
20 20
 <ul id="P" class="sortcol">
21  
-<%= render(@priority) %>
  21
+<%= if @priority then render(@priority) end%>
22 22
 </ul>
23 23
 </div>
24 24
 </td>
25 25
 <td>
26 26
 <div  class="active">
27 27
 <ul id="A" class="sortcol">
28  
-<%= render(@active) %>
  28
+<%= if @active then render(@active) end %>
29 29
 </ul>
30 30
 </div>
31 31
 </td>
32 32
 <td>
33 33
 <div class="delegated">
34 34
 <ul id="D" class="sortcol">
35  
-<%= render(@delegated) %>
  35
+<%= if @delegated then render(@delegated) end%>
36 36
 </ul>
37 37
 </div>
38 38
 </td>
39 39
 <td>
40 40
 <div  class="complete">
41 41
 <ul id="C" class="sortcol">
42  
-<%= render(@complete) %>
  42
+<%= if @complete then render(@complete) end %>
43 43
 </ul>
44 44
 </div>
45 45
 </td>
5  test/fixtures/stories.yml
@@ -6,6 +6,7 @@ backlog:
6 6
   need_by: 2011-03-12
7 7
   delegatee:
8 8
   column_ord:
  9
+  state: B
9 10
 
10 11
 priority:
11 12
   task: MyString
@@ -15,13 +16,13 @@ priority:
15 16
   column_ord: 2
16 17
   state: P
17 18
 
18  
-active:
  19
+another_backlog:
19 20
   task: MyString
20 21
   notes: MyText
21 22
   need_by: 2011-03-12
22 23
   delegatee: MyString
23 24
   column_ord:
24  
-  state: A
  25
+  state: B
25 26
 
26 27
 delegated:
27 28
   task: MyString
4  test/functional/board_controller_test.rb
@@ -5,10 +5,10 @@ class BoardControllerTest < ActionController::TestCase
5 5
     get :show
6 6
     assert_response :success
7 7
     assert_select '.backlog', 1, 'board shows backlog section' do
8  
-    	assert_select 'li', 1
  8
+    	assert_select 'li', assigns[:backlog].size
9 9
     end
10 10
     assert_select '.active', 1, 'board shows active section' do
11  
-    	assert_select 'li', 1
  11
+    	assert_select 'li', 0
12 12
     end
13 13
     assert_select '.priority', 1, 'board shows priority section' do
14 14
     	assert_select 'li', 1
4  test/unit/story_test.rb
@@ -10,4 +10,8 @@ class StoryTest < ActiveSupport::TestCase
10 10
   	story = Story.new()
11 11
   	assert_equal story.state, 'B'
12 12
   end
  13
+  
  14
+  test "can find more than one story" do
  15
+  	assert_equal Story.order("column_ord").find_all_by_state("B").size, 2
  16
+  end
13 17
 end

0 notes on commit d8afcb5

Please sign in to comment.
Something went wrong with that request. Please try again.