-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finish tests for follow and unfollow
- Loading branch information
Showing
14 changed files
with
126 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the Relationships controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class RelationshipsController < ApplicationController | ||
def create | ||
user = User.find(params[:followed_id]) | ||
current_user.follow(user) | ||
redirect_to "/profile/#{user.username}" | ||
end | ||
|
||
def destroy | ||
user = Relationship.find(params[:id]).followed | ||
current_user.unfollow(user) | ||
redirect_to "/profile/#{user.username}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module RelationshipsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%= form_for(current_user.active_relationships.build) do |f| %> | ||
<div><%= hidden_field_tag :followed_id, @profile_user.id %></div> | ||
<%= f.submit "Follow", class: "btn btn-primary" %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%= form_for(current_user.active_relationships.find_by_followed_id(@profile_user.id), | ||
html: { method: :delete }) do |f| %> | ||
<%= f.submit "Unfollow", class: "btn" %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div class="container"> | ||
<% @users.each do |user| %> | ||
<div class="col-md-3"> | ||
<div style="text-align:center;"> | ||
<% if user.photo_file_name %> | ||
<img class="img-circle" id="profile-photo" style="width:50%;margin-bottom:20px;" src="<%= user.photo_path(:thumb) %>" /> | ||
<% else %> | ||
<img class="img-circle" id="profile-photo" style="width:50%;margin-bottom:20px;" src="https://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(user.email}"> | ||
<% end %> | ||
<h3><%= user.username %></h3> | ||
</div> | ||
</div> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html | ||
|
||
one: | ||
follower_id: 1 | ||
followed_id: 4 | ||
follower: jeff | ||
followed: bob | ||
|
||
two: | ||
follower_id: 1 | ||
followed_id: 3 | ||
follower: bob | ||
followed: jeff | ||
|
||
three: | ||
follower: jeff | ||
followed: admin | ||
|
||
four: | ||
follower: jeff | ||
followed: moderator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'test_helper' | ||
|
||
class RelationshipsControllerTest < ActionController::TestCase | ||
|
||
def setup | ||
activate_authlogic | ||
end | ||
|
||
test "create will follow other user with followed_id param" do | ||
user = rusers(:admin) | ||
followed_user = rusers(:jeff) | ||
UserSession.create(user) | ||
assert_difference 'Relationship.count', 1 do | ||
post :create, followed_id: followed_user.id | ||
end | ||
assert_response :redirect | ||
assert_redirected_to '/profile/' + followed_user.username | ||
end | ||
|
||
test "destroy will remove follow relationship" do | ||
user = rusers(:jeff) | ||
UserSession.create(user) | ||
followed_user = rusers(:bob) | ||
post :create, followed_id: followed_user.id | ||
|
||
|
||
assert_difference 'Relationship.count', -1 do | ||
delete :destroy, id: Relationship.last.id | ||
end | ||
|
||
assert_response :redirect | ||
assert_redirected_to '/profile/' + followed_user.username | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'test_helper' | ||
|
||
class RelationshipsHelperTest < ActionView::TestCase | ||
end |