Skip to content
Extraits de code Groupes Projets
Valider 92b29d31 rédigé par Diaspora Europe's avatar Diaspora Europe Validation de Maxwell Salzberg
Parcourir les fichiers

added user_is_following method, added 2 model specs

parent 55cb328f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -40,10 +40,7 @@ class TagsController < ApplicationController ...@@ -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 ...@@ -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 ...@@ -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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter