added user_is_following method, added 2 model specs
This commit is contained in:
parent
47f7e10860
commit
8eda9aaf52
3 changed files with 15 additions and 4 deletions
|
|
@ -40,10 +40,7 @@ class TagsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_followed?
|
def tag_followed?
|
||||||
if @tag_followed.nil?
|
TagFollowing.user_is_following?(current_user, params[:name])
|
||||||
@tag_followed = TagFollowing.joins(:tag).where(:tags => {:name => params[:name].downcase}, :user_id => current_user.id).exists?
|
|
||||||
end
|
|
||||||
@tag_followed
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def prep_tags_for_javascript
|
def prep_tags_for_javascript
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,9 @@ class TagFollowing < ActiveRecord::Base
|
||||||
belongs_to :tag, :class_name => "ActsAsTaggableOn::Tag"
|
belongs_to :tag, :class_name => "ActsAsTaggableOn::Tag"
|
||||||
|
|
||||||
validates_uniqueness_of :tag_id, :scope => :user_id
|
validates_uniqueness_of :tag_id, :scope => :user_id
|
||||||
|
|
||||||
|
def self.user_is_following?(user, tagname)
|
||||||
|
tagname.nil? ? false : joins(:tag).where(:tags => {:name => tagname.downcase}, :user_id => user.id).exists?
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -13,4 +13,13 @@ describe TagFollowing do
|
||||||
it 'allows multiple tag followings for different users' do
|
it 'allows multiple tag followings for different users' do
|
||||||
TagFollowing.new(:tag => @tag, :user => bob).valid?.should be_true
|
TagFollowing.new(:tag => @tag, :user => bob).valid?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'user is following a tag' do
|
||||||
|
TagFollowing.user_is_following?(alice, @tag.name).should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'user not following a tag' do
|
||||||
|
TagFollowing.user_is_following?(bob, @tag.name).should be_false
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue