Skip to content

Commit

Permalink
created relationships controller for following/unfollowing users
Browse files Browse the repository at this point in the history
  • Loading branch information
scarvill91 committed Apr 29, 2015
1 parent aa9fe10 commit 2e3f9c9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/relationships.coffee
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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/relationships.scss
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/
15 changes: 15 additions & 0 deletions app/controllers/relationships_controller.rb
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
2 changes: 2 additions & 0 deletions app/helpers/relationships_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module RelationshipsHelper
end
18 changes: 18 additions & 0 deletions test/controllers/relationships_controller_test.rb
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

0 comments on commit 2e3f9c9

Please sign in to comment.