added user_is_following method, added 2 model specs

This commit is contained in:
Diaspora Europe 2012-02-09 14:16:57 +01:00 committed by Maxwell Salzberg
parent 55cb328fe2
commit 92b29d31db
3 changed files with 15 additions and 4 deletions

View file

@ -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

View file

@ -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

View file

@ -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