public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Search Repo:
Working on the people#show page
Comment wall with tests
Michael Hartl (author)
Thu Feb 28 17:24:27 -0800 2008
commit  aa92e8399bf58e6661db9c5bc1493f0238e4d68b
tree    a5666e6cc24344aa2b96d236643aea45bc5462eb
parent  6403fd4b11b8ab42b311f1809b3d8cd758d37f62
...
4
5
6
7
 
8
9
10
...
4
5
6
 
7
8
9
10
0
@@ -4,7 +4,7 @@
0
 class ApplicationController < ActionController::Base
0
   helper :all # include all helpers, all the time
0
   include AuthenticatedSystem
0
- include ApplicationHelper
0
+ include SharedHelper
0
 
0
   # See ActionController::RequestForgeryProtection for details
0
   # Uncomment the :secret if you're not using the cookie session store
...
12
13
14
 
 
 
 
 
15
16
17
...
12
13
14
15
16
17
18
19
20
21
22
0
@@ -12,6 +12,11 @@
0
   
0
   def show
0
     @person = Person.find(params[:id])
0
+ if current_person?(@person)
0
+ link = edit_person_path(@person)
0
+ flash.now[:notice] = %(You are viewing your own profile.
0
+ <a href="#{link}">Click here to edit it</a>)
0
+ end
0
     respond_to do |format|
0
       format.html
0
     end
...
24
25
26
27
28
29
30
31
32
33
...
39
40
41
42
43
44
45
...
24
25
26
 
 
 
 
27
28
29
...
35
36
37
 
38
39
40
0
@@ -24,10 +24,6 @@
0
     link_to(link[:content], link[:href], options)
0
   end
0
   
0
- def current_person?(person)
0
- logged_in? and person == current_person
0
- end
0
-
0
   # Set the input focus for a specific id
0
   # Usage: <%= set_focus_to_id 'form_field_label' %>
0
   def set_focus_to_id(id)
0
@@ -39,7 +35,6 @@
0
       title
0
     end
0
   end
0
-
0
 
0
   # TODO: polish these & move them somewhere
0
   def linked_image(person, options = {})
...
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
0
@@ -1 +1,8 @@
0
+# Methods added to this helper are available in both controllers and views.
0
+module SharedHelper
0
+
0
+ def current_person?(person)
0
+ logged_in? and person == current_person
0
+ end
0
+end
...
 
 
 
 
...
1
2
3
4
0
@@ -1 +1,5 @@
0
+<li>
0
+ <%= sanitize comment.body %> left by <%= comment.commenter.name %>
0
+ <%= time_ago_in_words(comment.created_at) %> ago
0
+</li>
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
0
@@ -1 +1,18 @@
0
+<h3>Leave a wall comment</h3>
0
+
0
+<% form_for :comment, :url => person_comments_path(@person) do |f| %>
0
+ <div class="form_tag">
0
+ <%= f.text_area :body %>
0
+ </div>
0
+
0
+ <div class="form_tag">
0
+ <%= submit_tag "Submit" %>
0
+ </div>
0
+<% end %>
0
+
0
+<%- unless @person.comments.empty? -%>
0
+ <ul class="wall">
0
+ <%= render :partial => 'comment', :collection => @person.comments %>
0
+ </ul>
0
+<%- end -%>
...
1
 
2
3
 
4
5
6
7
 
 
8
9
10
11
...
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
 
...
 
1
2
 
3
4
5
6
 
7
8
9
10
11
12
...
14
15
16
 
 
 
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
0
@@ -1,10 +1,11 @@
0
-<h3 style="clear">About <%= @person.name %></h3>
0
+<% set_main_title("About #{h @person.name}") %>
0
 
0
-<%- if logged_in? and @person != current_person -%>
0
+<%- unless current_person?(@person) -%>
0
   <%= email_link @person %>
0
   <%- unless Connection.exists?(@person, current_person) -%>
0
     |
0
- <%= button_to "Connection request", person_connections_path(@person) %>
0
+ <%= link_to "Connect with #{@person.name}!",
0
+ person_connections_path(@person), :method => :post %>
0
   <%- end -%>
0
 <%- end -%>
0
 
0
0
@@ -13,28 +14,6 @@
0
 </div>
0
 <p><%= sanitize @person.description %></p>
0
 
0
-<%- if logged_in? and @person == current_person -%>
0
- <%= link_to "Edit profile", edit_person_path(@person) %>
0
-<%- end -%>
0
 
0
-<h3>Leave a wall comment</h3>
0
-
0
-<ul>
0
-<%- @person.comments.each do |comment| -%>
0
-<li>
0
- <%= sanitize comment.body %> left by <%= comment.commenter.name %>
0
- <%= time_ago_in_words(comment.created_at) %> ago
0
-</li>
0
-<%- end -%>
0
-</ul>
0
-
0
-<% form_for :comment, :url => person_comments_path(@person) do |f| %>
0
- <div class="form_tag">
0
- <%= f.text_area :body %>
0
- </div>
0
-
0
- <div class="form_tag">
0
- <%= submit_tag "Submit" %>
0
- </div>
0
-<% end %>
0
+<%= render :partial => 'wall' %>
...
11
12
13
 
 
14
15
16
...
11
12
13
14
15
16
17
18
0
@@ -11,6 +11,8 @@
0
       id = nil
0
     end
0
     # Stub out the controller if it's defined.
0
+ # This means, e.g., that if a spec defines mocked-out photos for a person,
0
+ # it current_person.photos will have the right assocation.
0
     if defined?(controller)
0
       controller.stub!(:current_person).and_return(person)
0
     else
...
23
24
25
26
27
 
28
29
30
...
23
24
25
 
 
26
27
28
29
0
@@ -23,8 +23,7 @@
0
   text-decoration: none;
0
 }
0
 
0
-#navlist li a:link { color: #448; }
0
-#navlist li a:visited { color: #667; }
0
+#navlist li a:link, a:visited { color: #448; }
0
 
0
 #navlist li a:hover
0
 {
...
55
56
57
58
 
59
60
61
...
55
56
57
 
58
59
60
61
0
@@ -55,7 +55,7 @@
0
       with_options :person_id => @person do |page|
0
         page.get :new
0
         page.post :create, :comment => { }
0
- page.delete :destroy, :id => comments(:one)
0
+ page.delete :destroy, :id => comments(:wall)
0
       end
0
     end
0
   
...
25
26
27
28
29
30
31
32
33
 
34
35
36
37
38
39
40
41
...
118
119
120
121
 
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
 
 
 
 
 
 
 
 
 
148
149
150
...
25
26
27
 
28
29
30
31
 
32
33
34
35
36
37
38
39
40
...
117
118
119
 
120
121
122
123
 
 
124
 
125
126
127
128
129
 
 
 
 
130
131
132
133
134
135
 
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
0
@@ -25,12 +25,11 @@
0
     end
0
     
0
     it "should have a working show page" do
0
- Person.should_receive(:find).with(@person).and_return(@person)
0
       get :show, :id => @person
0
       response.should be_success
0
       response.should render_template("show")
0
     end
0
-
0
+
0
     it "should have a working edit page" do
0
       login_as @person
0
       get :edit, :id => @person
0
0
0
0
0
0
@@ -118,33 +117,34 @@
0
   end
0
   
0
   describe "show" do
0
- integrate_views
0
+ integrate_views
0
     
0
     it "should display the edit link for current user" do
0
       login_as @person
0
- # The mock is needed to get @person.photos.
0
- Person.should_receive(:find).with(@person).and_return(@person)
0
       get :show, :id => @person
0
- assigns[:person].photos = @person.photos
0
       response.should have_tag("a[href=?]", edit_person_path(@person))
0
     end
0
     
0
     it "should not display the edit link for other viewers" do
0
       login_as(:aaron)
0
- # Note: the Person mock must go *after* the login_as.
0
- # The reason is subtle: login_as calls the people() fixture method,
0
- # which (apparently) uses find under the hood.
0
- Person.should_receive(:find).with(@person).and_return(@person)
0
       get :show, :id => @person
0
       response.should_not have_tag("a[href=?]", edit_person_path(@person))
0
     end
0
     
0
     it "should not display the edit link for non-logged-in viewers" do
0
       logout
0
- Person.should_receive(:find).with(@person).and_return(@person)
0
       get :show, :id => @person
0
       response.should_not have_tag("a[href=?]", edit_person_path(@person))
0
     end
0
+
0
+ it "should have a working comment wall" do
0
+ comment = comments(:wall)
0
+ get :show, :id => @person
0
+ response.should have_tag("ul[class=?]", "wall") do
0
+ with_tag("li", /#{comment.body}/)
0
+ end
0
+ end
0
+
0
   end
0
   
0
   private
...
1
2
3
4
5
 
 
 
6
7
8
...
1
2
 
 
 
3
4
5
6
7
8
0
@@ -1,8 +1,8 @@
0
 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
0
 
0
-one:
0
- person_id: 1
0
- commenter_id: 2
0
+wall:
0
+ person: quentin
0
+ commenter: aaron
0
   body: MyText
0
   type: WallComment
0
 
...
25
26
27
 
 
 
28
29
30
...
40
41
42
43
44
 
 
 
45
46
47
...
25
26
27
28
29
30
31
32
33
...
43
44
45
 
 
46
47
48
49
50
51
0
@@ -25,6 +25,9 @@
0
       u = create_person(:email => nil)
0
       u.errors.on(:email).should_not be_nil
0
     end
0
+ end
0
+
0
+ describe "associations" do
0
     
0
     it "should have associated photos" do
0
       @person.photos.should_not be_nil
0
@@ -40,8 +43,9 @@
0
     end
0
     
0
     it "should have many wall comments" do
0
- create_person.comments.should be_a_kind_of(Array)
0
- end
0
+ @person.comments.should be_a_kind_of(Array)
0
+ @person.comments.should_not be_empty
0
+ end
0
   end
0
   
0
   describe "photo methods" do

Comments

    No one has commented yet.