-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created relationships controller for following/unfollowing users
- Loading branch information
scarvill91
committed
Apr 29, 2015
1 parent
aa9fe10
commit 2e3f9c9
Showing
5 changed files
with
41 additions
and
0 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://coffeescript.org/ |
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,15 @@ | ||
class RelationshipsController < ApplicationController | ||
before_action :logged_in_user | ||
|
||
def create | ||
user = User.find(params[:followed_id]) | ||
current_user.follow(user) | ||
redirect_to user | ||
end | ||
|
||
def destroy | ||
user = Relationship.find(params[:id]).followed | ||
current_user.unfollow(user) | ||
redirect_to user | ||
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,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,18 @@ | ||
require 'test_helper' | ||
|
||
class RelationshipsControllerTest < ActionController::TestCase | ||
|
||
test "create should require logged-in user" do | ||
assert_no_difference 'Relationship.count' do | ||
post :create | ||
end | ||
assert_redirected_to login_url | ||
end | ||
|
||
test "destroy should require logged-in user" do | ||
assert_no_difference 'Relationship.count' do | ||
delete :destroy, id: relationships(:one) | ||
end | ||
assert_redirected_to login_url | ||
end | ||
end |