followers_controller_test.rb 1.88 KB
require_relative "../test_helper"
require 'followers_controller'

class FollowersControllerTest < ActionController::TestCase
  def setup
    @profile = create_user('testuser').person
  end

  should 'return followed people list' do
    login_as(@profile.identifier)
    person = fast_create(Person)
    fast_create(ProfileFollower, :profile_id => person.id, :follower_id => @profile.id)

    get :index, :profile => @profile.identifier
    assert_includes assigns(:followed_people), person
  end

  should 'redirect to login page if not logged in' do
    person = fast_create(Person)
    get :index, :profile => @profile.identifier
    assert_redirected_to :controller => 'account', :action => 'login'
  end

  should 'render set category modal' do
    login_as(@profile.identifier)
    get :set_category, :profile => @profile.identifier, :followed_profile_id => 3
    assert_tag :tag => "input", :attributes => { :id => "followed_profile_id", :value => 3 }
  end

  should 'update followed person category' do
    login_as(@profile.identifier)
    person = fast_create(Person)
    fast_create(ProfileFollower, :profile_id => person.id, :follower_id => @profile.id)

    post :set_category, :profile => @profile.identifier, :category_name => "category test", :followed_profile_id => person.id
    follower = ProfileFollower.find_by(:profile_id => person.id, :follower_id => @profile.id)
    assert_equal "WRONG","FIX THIS TEST TO USE CATEGORY INsTEAD OF GROUP" #follower.group, "category test"
  end

  should 'not update category of not followed person' do
    login_as(@profile.identifier)
    person = fast_create(Person)

    post :set_category, :profile => @profile.identifier, :category_name => "category test", :followed_profile_id => person.id
    follower = ProfileFollower.find_by(:profile_id => person.id, :follower_id => @profile.id)
    ProfileFollower.any_instance.expects(:update_attributes).times(0)
  end
end