Commit 4b26bbae71bf199cf66d9397d2a25a9f01946965

Authored by Marcos Pereira
1 parent 66a944b5
Exists in private-scraps

Changes categories to circles

Backend categories relation 1x1 changed to 1xN
app/controllers/my_profile/follow_categories_controller.rb
... ... @@ -5,11 +5,11 @@ class FollowCategoriesController < MyProfileController
5 5 end
6 6  
7 7 def new
8   - @follow_category = FollowCategory.new
  8 + @follow_category = Circle.new
9 9 end
10 10  
11 11 def create
12   - @follow_category = FollowCategory.new(:name => params[:follow_category][:name],
  12 + @follow_category = Circle.new(:name => params[:follow_category][:name],
13 13 :person => current_person)
14 14 if @follow_category.save
15 15 redirect_to :action => 'index'
... ... @@ -19,12 +19,13 @@ class FollowCategoriesController < MyProfileController
19 19 end
20 20  
21 21 def edit
22   - @follow_category = FollowCategory.find_by_id(params[:id])
  22 + @follow_category = Circle.find_by_id(params[:id])
23 23 render_not_found if @follow_category.nil?
24 24 end
25 25  
  26 + #TODO FIX METHOD
26 27 def update
27   - @follow_category = FollowCategory.find_by_id(params[:id])
  28 + @follow_category = Circle.find_by_id(params[:id])
28 29 return render_not_found if @follow_category.nil?
29 30  
30 31 if @follow_category.update(params[:follow_category])
... ... @@ -35,7 +36,7 @@ class FollowCategoriesController < MyProfileController
35 36 end
36 37  
37 38 def destroy
38   - @follow_category = FollowCategory.find_by_id(params[:id])
  39 + @follow_category = Circle.find_by_id(params[:id])
39 40 return render_not_found if @follow_category.nil?
40 41  
41 42 if !@follow_category.destroy
... ...
app/controllers/my_profile/followers_controller.rb
... ... @@ -3,27 +3,21 @@ class FollowersController < MyProfileController
3 3 before_filter :only_for_person, :only => :index
4 4  
5 5 def index
6   - @followed_people = current_person.following_profiles.order(:type).paginate(:per_page => 15, :page => params[:npage])
  6 + @followed_people = current_person.followed_profiles.order(:type).paginate(:per_page => 15, :page => params[:npage])
7 7 end
8 8  
9 9 def set_category_modal
10   - categories = FollowCategory.where(:person => current_person).map(&:name)
  10 + categories = Circle.where(:person => current_person).map(&:name)
11 11 profile = Profile.find(params[:followed_profile_id])
12 12 render :partial => 'blocks/profile_info_actions/follow_categories', :locals => { :categories => categories, :profile => profile }
13 13 end
14 14  
  15 + #TODO fix
15 16 def update_category
16 17 params["followed_profile_id"] ||= profile.id
17   - follower = ProfileFollower.find_by(follower_id: current_person.id, profile_id: params[:followed_profile_id])
18 18 if params[:category_name]
19   - category = FollowCategory.find_or_create_by(:name => params[:category_name], :person => current_person)
20   - else
21   - category = nil
22   - end
23   -
24   - if follower
25   - follower.follow_category = category
26   - follower.save
  19 + category = Circle.find_or_create_by(:name => params[:category_name], :person => current_person)
  20 + follower = ProfileFollower.find_or_create_by(circle: category, profile: Profile.find_by(:id => params[:followed_profile_id]))
27 21 end
28 22  
29 23 redirect_url = params["redirect_to"] ? params["redirect_to"] : url_for(:controller => "followers", :action => "index", :profile => current_person.identifier)
... ...
app/controllers/public/profile_controller.rb
... ... @@ -4,7 +4,7 @@ class ProfileController < PublicController
4 4 before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add]
5 5 before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail]
6 6 before_filter :login_required, :only => [:add, :join, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity, :send_mail, :follow, :unfollow]
7   - before_filter :allow_following?, :only => [:follow, :unfollow]
  7 + before_filter :allow_followers?, :only => [:follow, :unfollow]
8 8  
9 9 helper TagsHelper
10 10 helper ActionTrackerHelper
... ... @@ -158,10 +158,10 @@ class ProfileController < PublicController
158 158  
159 159 def follow
160 160 if !current_person.follows?(profile)
161   - group = params['follow'] ? params['follow']['category'] : ''
162   - current_person.follow(profile, group)
  161 + #group = params['follow'] ? params['follow']['category'] : ''
  162 + #current_person.follow(profile, group)
163 163  
164   - categories = FollowCategory.where(:person => current_person).map(&:name)
  164 + categories = Circle.where(:person => current_person).map(&:name)
165 165 render :partial => 'blocks/profile_info_actions/follow_categories', :locals => { :categories => categories }
166 166 else
167 167 render :text => _("It was not possible to follow %s") % profile.name, :status => 400
... ... @@ -462,8 +462,8 @@ class ProfileController < PublicController
462 462 [:image, :domains, :preferred_domain, :environment]
463 463 end
464 464  
465   - def allow_following?
466   - render_not_found unless profile.allow_following?
  465 + def allow_followers?
  466 + render_not_found unless profile.allow_followers?
467 467 end
468 468  
469 469 end
... ...
app/models/add_member.rb
... ... @@ -22,7 +22,7 @@ class AddMember < Task
22 22 self.roles = [Profile::Roles.member(organization.environment.id).id]
23 23 end
24 24 target.affiliate(requestor, self.roles.select{|r| !r.to_i.zero? }.map{|i| Role.find(i)})
25   - person.follow(organization, _('memberships'))
  25 + person.follow(organization, Circle.find_or_create_by(:person => person, :name =>_('memberships')))
26 26 end
27 27  
28 28 def title
... ...
app/models/circle.rb 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +class Circle < ApplicationRecord
  2 + has_many :profile_followers
  3 + belongs_to :person
  4 +
  5 + attr_accessible :name, :person, :profile_type
  6 +
  7 + validates :name, presence: true
  8 + validates :person_id, presence: true
  9 +
  10 + validates :person_id, :uniqueness => {:scope => :name, :message => "can't add two circles with the same name"}
  11 +
  12 + scope :by_owner, -> person{
  13 + where(:person => person)
  14 + }
  15 +
  16 + scope :with_name, -> name{
  17 + where(:name => name)
  18 + }
  19 +
  20 +end
... ...
app/models/favorite_enterprise_person.rb
... ... @@ -8,7 +8,7 @@ class FavoriteEnterprisePerson &lt; ApplicationRecord
8 8 belongs_to :person
9 9  
10 10 after_create do |favorite|
11   - favorite.person.follow(favorite.enterprise, _('favorites'))
  11 + favorite.person.follow(favotire.enterprise, Circle.find_or_create_by(:person => favorite.person, :name =>_('favorites')))
12 12 end
13 13  
14 14 protected
... ...
app/models/follow_category.rb
... ... @@ -1,8 +0,0 @@
1   -class FollowCategory < ApplicationRecord
2   - belongs_to :environment
3   - has_many :profile_followers
4   - belongs_to :person
5   -
6   - attr_accessible :name, :person
7   - validates :name, presence: true
8   -end
app/models/friendship.rb
... ... @@ -9,13 +9,15 @@ class Friendship &lt; ApplicationRecord
9 9 after_create do |friendship|
10 10 Friendship.update_cache_counter(:friends_count, friendship.person, 1)
11 11 Friendship.update_cache_counter(:friends_count, friendship.friend, 1)
12   - friendship.person.follow(friendship.friend, friendship.group)
  12 + friendship.person.follow(friendship.friend, Circle.find_or_create_by(:person => friendship.person, :name => friendship.group))
13 13 end
14 14  
15 15 after_destroy do |friendship|
16 16 Friendship.update_cache_counter(:friends_count, friendship.person, -1)
17 17 Friendship.update_cache_counter(:friends_count, friendship.friend, -1)
18   - friendship.person.unfollow(friendship.friend)
  18 +
  19 + circle=Circle.find_by(:person => friendship.person, :name => friendship.group)
  20 + friendship.person.remove_profile_from_circle(friendship.friend, circle) if circle
19 21 end
20 22  
21 23 def self.remove_friendship(person1, person2)
... ...
app/models/person.rb
... ... @@ -92,7 +92,7 @@ class Person &lt; Profile
92 92 has_many :following_articles, :class_name => 'Article', :through => :article_followers, :source => :article
93 93 has_many :friendships, :dependent => :destroy
94 94 has_many :friends, :class_name => 'Person', :through => :friendships
95   - has_many :follow_categories
  95 + has_many :circles
96 96  
97 97 scope :online, -> {
98 98 joins(:user).where("users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes)
... ... @@ -200,17 +200,33 @@ class Person &lt; Profile
200 200 end
201 201 end
202 202  
203   - def follow(profile, category_name = "")
204   - unless self.following_profiles.include?(profile)
205   - profile_follower = ProfileFollower.new
206   - profile_follower.profile = profile
207   - profile_follower.follower = self
208   - category = FollowCategory.find_or_create_by(:name => category_name, :person => self)
209   - profile_follower.follow_category = category
210   - profile_follower.save
  203 + def follow (profile, circles)
  204 + circles = [circles] unless circles.is_a?(Array)
  205 + circles.each do |new_circle|
  206 + ProfileFollower.create(profile: profile, circle: new_circle)
211 207 end
212 208 end
213 209  
  210 + def update_profile_circles (profile, new_circles)
  211 + circles_to_add = new_circles - self.circles
  212 + circles_to_remove = self.circles - new_circles
  213 +
  214 + circles_to_add.each do |new_circle|
  215 + ProfileFollower.create(profile: profile, circle: new_circle)
  216 + end
  217 +
  218 + ProfileFollower.where('circle_id IN (?) AND profile_id = ?',
  219 + circles_to_remove.map(&:id), profile.id).destroy_all
  220 + end
  221 +
  222 + def unfollow(profile)
  223 + ProfileFollower.with_follower(self).with_profile(profile).destroy_all
  224 + end
  225 +
  226 + def remove_profile_from_circle(profile, circle)
  227 + ProfileFollower.with_profile(profile).with_circle(circle).destroy_all
  228 + end
  229 +
214 230 def already_request_friendship?(person)
215 231 person.tasks.where(requestor_id: self.id, type: 'AddFriend', status: Task::Status::ACTIVE).first
216 232 end
... ... @@ -219,11 +235,6 @@ class Person &lt; Profile
219 235 Friendship.where(friend_id: friend, person_id: id).first.destroy
220 236 end
221 237  
222   - def unfollow(profile)
223   - follower = ProfileFollower.where(follower_id: id, profile_id: profile.id) if profile
224   - follower.first.destroy if follower.present?
225   - end
226   -
227 238 FIELDS = %w[
228 239 description
229 240 image
... ... @@ -596,8 +607,8 @@ class Person &lt; Profile
596 607 person.has_permission?(:manage_friends, self)
597 608 end
598 609  
599   - def following_profiles
600   - Profile.following_profiles self
  610 + def followed_profiles
  611 + Profile.followed_by self
601 612 end
602 613  
603 614 def in_social_circle?(person)
... ...
app/models/profile.rb
... ... @@ -5,7 +5,7 @@ class Profile &lt; ApplicationRecord
5 5  
6 6 attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :environment, :lat, :lng, :is_template, :fields_privacy, :preferred_domain_id, :category_ids, :country, :city, :state, :national_region_code, :email, :contact_email, :redirect_l10n, :notification_time,
7 7 :redirection_after_login, :custom_url_redirection,
8   - :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret, :profile_admin_mail_notification, :allow_following
  8 + :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret, :profile_admin_mail_notification, :allow_followers
9 9  
10 10 # use for internationalizable human type names in search facets
11 11 # reimplement on subclasses
... ... @@ -203,15 +203,22 @@ class Profile &lt; ApplicationRecord
203 203 scope :more_active, -> { order 'activities_count DESC' }
204 204 scope :more_recent, -> { order "created_at DESC" }
205 205  
206   - scope :following_profiles, -> person {
207   - distinct.select('profiles.*, follow_categories.name AS category').
208   - joins('left join profile_followers ON profile_followers.profile_id = profiles.id').
209   - joins('left join follow_categories ON follow_categories.id = profile_followers.follow_category_id').
210   - where('profile_followers.follower_id = ?', person.id)
  206 + scope :followed_by, -> person{
  207 + distinct.select('profiles.*, circles.name as category'). #TODO remove category from here
  208 + joins('left join profiles_circles ON profiles_circles.profile_id = profiles.id').
  209 + joins('left join circles ON circles.id = profiles_circles.circle_id').
  210 + where('circles.person_id = ?', person.id)
211 211 }
212 212  
213   - settings_items :allow_following, :type => :boolean, :default => true
214   - alias_method :allow_following?, :allow_following
  213 + scope :in_circle, -> circle{
  214 + distinct.select('profiles.*').
  215 + joins('left join profiles_circles ON profiles_circles.profile_id = profiles.id').
  216 + joins('left join circles ON circles.id = profiles_circles.circle_id').
  217 + where('circles.id = ?', circle.id)
  218 + }
  219 +
  220 + settings_items :allow_followers, :type => :boolean, :default => true
  221 + alias_method :allow_followers?, :allow_followers
215 222  
216 223 acts_as_trackable :dependent => :destroy
217 224  
... ... @@ -226,7 +233,7 @@ class Profile &lt; ApplicationRecord
226 233 has_many :email_templates, :foreign_key => :owner_id
227 234  
228 235 has_many :profile_followers
229   - has_many :followers, :class_name => 'Person', :through => :profile_followers
  236 + has_many :followers, :class_name => 'Person', :through => :profile_followers, :source => :person
230 237  
231 238 # Although this should be a has_one relation, there are no non-silly names for
232 239 # a foreign key on article to reference the template to which it is
... ... @@ -777,7 +784,7 @@ private :generate_url, :url_options
777 784 else
778 785 self.affiliate(person, Profile::Roles.admin(environment.id), attributes) if members.count == 0
779 786 self.affiliate(person, Profile::Roles.member(environment.id), attributes)
780   - person.follow(self, _('memberships'))
  787 + person.follow(self, Circle.find_or_create_by(:person => person, :name =>_('memberships')))
781 788 end
782 789 person.tasks.pending.of("InviteMember").select { |t| t.data[:community_id] == self.id }.each { |invite| invite.cancel }
783 790 remove_from_suggestion_list person
... ...
app/models/profile_follower.rb
1 1 class ProfileFollower < ApplicationRecord
  2 + self.table_name = :profiles_circles
2 3 track_actions :new_follower, :after_create, :keep_params => ["follower.name", "follower.url", "follower.profile_custom_icon"], :custom_user => :profile
3 4  
4   - attr_accessible :profile, :follower, :follow_category
  5 + attr_accessible :profile, :circle
5 6  
6   - belongs_to :profile, :foreign_key => :profile_id
7   - belongs_to :follower, :class_name => 'Person', :foreign_key => :follower_id
8   - belongs_to :follow_category, :foreign_key => :follow_category_id
  7 + belongs_to :profile
  8 + belongs_to :circle
9 9  
10   - validates_presence_of :profile_id, :follower_id
11   - validates :profile_id, :uniqueness => {:scope => :follower_id, :message => "can't follow the same profile twice"}
  10 + has_one :person, through: :circle
  11 + alias follower person
  12 +
  13 + validates_presence_of :profile_id, :circle_id
  14 + validates :profile_id, :uniqueness => {:scope => :circle_id, :message => "can't put a profile in the same circle twice"}
  15 +
  16 + scope :with_follower, -> person{
  17 + joins(:circle).where('circles.person_id = ?', person.id)
  18 + }
  19 +
  20 + scope :with_profile, -> profile{
  21 + where(:profile => profile)
  22 + }
  23 +
  24 + scope :with_circle, -> circle{
  25 + where(:circle => circle)
  26 + }
12 27  
13 28 end
... ...
app/views/blocks/profile_info_actions/_common.html.erb
1 1 <li><%= report_abuse(profile, :button) %></li>
2   -<%if logged_in? && (user != profile) && profile.allow_following?%>
  2 +<%if logged_in? && (user != profile) && profile.allow_followers?%>
3 3 <li>
4 4 <% if user.follows?(profile) %>
5 5 <%= button(:unfollow, content_tag('span', _('Unfollow')), {:profile => profile.identifier, :controller => 'profile', :action => 'unfollow'}) %>
... ...
app/views/followers/_profile_list.html.erb
... ... @@ -4,7 +4,7 @@
4 4 <%= link_to_profile profile_image(profile) + tag('br') + profile.short_name,
5 5 profile.identifier, :class => 'profile-link' %>
6 6 <p class="category-name">
7   - <%= profile.category %>
  7 + <%= profile.category #TODO get categories through scope%>
8 8 </p>
9 9 <div class="controll">
10 10 <%= button_without_text :remove, content_tag('span',_('unfollow')),
... ...
app/views/profile_editor/edit.html.erb
... ... @@ -24,7 +24,7 @@
24 24  
25 25 <h2><%= _('Privacy options') %></h2>
26 26 <div>
27   - <%= labelled_check_box _("Allow other users to follow me"), 'profile_data[allow_following]', true, @profile.allow_following?, :class => "person-can-be-followed" %>
  27 + <%= labelled_check_box _("Allow other users to follow me"), 'profile_data[allow_followers]', true, @profile.allow_followers?, :class => "person-can-be-followed" %>
28 28 </div>
29 29 <% if profile.person? %>
30 30 <br>
... ...
db/migrate/20160608123748_create_profile_followers_table.rb
1 1 class CreateProfileFollowersTable < ActiveRecord::Migration
2 2 def up
3   - create_table :profile_followers do |t|
  3 + create_table :profiles_circles do |t|
4 4 t.column :profile_id, :integer
5   - t.column :follower_id, :integer
6   - t.column :follow_category_id, :integer
  5 + t.column :circle_id, :integer
7 6 t.timestamps
8 7 end
9 8  
10   - create_table :follow_categories do |t|
  9 + create_table :circles do |t|
11 10 t.column :name, :string
12 11 t.belongs_to :person
  12 + t.column :profile_type, :string
13 13 end
14 14  
15   - add_foreign_key :profile_followers, :follow_categories, :on_delete => :nullify
  15 + add_foreign_key :profiles_circles, :circles, :on_delete => :nullify
16 16  
17   - add_index :profile_followers, [:profile_id, :follower_id], :name => "profile_followers_composite_key_index", :unique => true
  17 + add_index :profiles_circles, [:profile_id, :circle_id], :name => "profiles_circles_composite_key_index", :unique => true
  18 + add_index :circles, [:person_id, :name], :name => "circles_composite_key_index", :unique => true
18 19  
19 20 #insert one category for each friend group a person has
20   - execute("INSERT INTO follow_categories(name, person_id) SELECT DISTINCT (CASE WHEN (f.group IS NULL OR f.group = '') THEN 'friendships' ELSE f.group END), f.person_id FROM friendships as f")
  21 + execute("INSERT INTO circles(name, person_id, profile_type) SELECT DISTINCT (CASE WHEN (f.group IS NULL OR f.group = '') THEN 'friendships' ELSE f.group END), f.person_id, 'Person' FROM friendships as f")
21 22 #insert 'memberships' category if a person is in a community as a member, moderator or profile admin
22   - execute("INSERT INTO follow_categories(name, person_id) SELECT DISTINCT 'memberships', ra.accessor_id FROM role_assignments as ra JOIN roles ON ra.role_id = roles.id WHERE roles.name IN ('Member','Moderator','Profile Administrator')")
  23 + execute("INSERT INTO circles(name, person_id, profile_type) SELECT DISTINCT 'memberships', ra.accessor_id, 'Community' FROM role_assignments as ra JOIN roles ON ra.role_id = roles.id WHERE roles.name IN ('Member','Moderator','Profile Administrator')")
23 24 #insert 'favorites' category if a person has any favorited enterprise
24   - execute("INSERT INTO follow_categories(name, person_id) SELECT DISTINCT 'favorites', person_id FROM favorite_enterprise_people")
  25 + execute("INSERT INTO circles(name, person_id, profile_type) SELECT DISTINCT 'favorites', person_id, 'Enterprise' FROM favorite_enterprise_people")
25 26  
26 27 #insert a follower entry for each friend, with the category the same as the friendship group or equals 'friendships'
27   - execute("INSERT INTO profile_followers(follower_id, profile_id, follow_category_id) SELECT DISTINCT f.person_id, f.friend_id, c.id FROM friendships as f JOIN follow_categories as c ON f.person_id = c.person_id WHERE c.name = f.group OR c.name = 'friendships'")
  28 + execute("INSERT INTO profiles_circles(profile_id, circle_id) SELECT DISTINCT f.friend_id, c.id FROM friendships as f JOIN circles as c ON f.person_id = c.person_id WHERE c.name = f.group OR c.name = 'friendships'")
28 29 #insert a follower entry for each favorited enterprise, with the category 'favorites'
29   - execute("INSERT INTO profile_followers(follower_id, profile_id, follow_category_id) SELECT DISTINCT f.person_id, f.enterprise_id, c.id FROM favorite_enterprise_people AS f JOIN follow_categories as c ON f.person_id = c.person_id WHERE c.name = 'favorites' ")
  30 + execute("INSERT INTO profiles_circles(profile_id, circle_id) SELECT DISTINCT f.enterprise_id, c.id FROM favorite_enterprise_people AS f JOIN circles as c ON f.person_id = c.person_id WHERE c.name = 'favorites' ")
30 31 #insert a follower entry for each community a person participates as a member, moderator or admininstrator
31   - execute("INSERT INTO profile_followers(follower_id, profile_id, follow_category_id) SELECT DISTINCT ra.accessor_id, ra.resource_id, c.id FROM role_assignments as ra JOIN roles ON ra.role_id = roles.id JOIN follow_categories as c ON ra.accessor_id = c.person_id WHERE roles.name IN ('Member','Moderator','Profile Administrator') AND c.name = 'memberships'")
32   -
  32 + execute("INSERT INTO profiles_circles(profile_id, circle_id) SELECT DISTINCT ra.resource_id, c.id FROM role_assignments as ra JOIN roles ON ra.role_id = roles.id JOIN circles as c ON ra.accessor_id = c.person_id WHERE roles.name IN ('Member','Moderator','Profile Administrator') AND c.name = 'memberships'")
33 33 end
34 34  
35 35 def down
36   - remove_foreign_key :profile_followers, :follow_categories
37   - drop_table :follow_categories
38   - remove_index :profile_followers, :name => "profile_followers_composite_key_index"
39   - drop_table :profile_followers
  36 + remove_foreign_key :profiles_circles, :circles
  37 + remove_index :profiles_circles, :name => "profiles_circles_composite_key_index"
  38 + remove_index :circles, :name => "circles_composite_key_index"
  39 + drop_table :circles
  40 + drop_table :profiles_circles
40 41 end
41 42 end
... ...
features/step_definitions/followers_steps.rb
1 1 Given /^the user "(.+)" has the following categories to follow$/ do |user_name,table|
2 2 person = User.find_by(:login => user_name).person
3 3 table.hashes.each do |category|
4   - FollowCategory.create!(:person => person, :name => category[:name])
  4 + Circle.create!(:person => person, :name => category[:name])
5 5 end
6 6 end
7 7  
... ... @@ -10,7 +10,7 @@ Then /^&quot;(.+)&quot; should be a follower of &quot;(.+)&quot; (?:with no category|with category &quot;
10 10 followers = profile.followers
11 11 person = Person.find_by(identifier: person)
12 12 followers.should include(person)
13   -
  13 + # TODO fix profile follower follower
14 14 if category
15 15 ProfileFollower.find_by(:follower => person, :profile => profile).follow_category.name.should == category
16 16 else
... ... @@ -30,8 +30,9 @@ Given /^&quot;(.+)&quot; is a follower of &quot;(.+)&quot; (?:with no category|with category &quot;(.+)&quot;)
30 30 person = Person.find_by(identifier: person)
31 31 params = {:follower => person, :profile => profile}
32 32  
  33 + # TODO fix profile follower follower
33 34 if category
34   - category = FollowCategory.find_by(:name => category, :person => person)
  35 + category = Circle.find_by(:name => category, :person => person)
35 36 params.merge!({:follow_category => category})
36 37 end
37 38 ProfileFollower.create!(params)
... ...
test/functional/follow_categories_controller_tests.rb
... ... @@ -10,8 +10,8 @@ class FollowCategoriesControllerTest &lt; ActionController::TestCase
10 10 end
11 11  
12 12 should 'return all categories of a profile' do
13   - category1 = FollowCategory.create(:name => "category1", :person => @person)
14   - category2 = FollowCategory.create(:name => "category2", :person => @person)
  13 + category1 = Circle.create(:name => "category1", :person => @person)
  14 + category2 = Circle.create(:name => "category2", :person => @person)
15 15 get :index, :profile => @person.identifier
16 16  
17 17 assert_equivalent [category1, category2], assigns[:categories]
... ... @@ -39,7 +39,7 @@ class FollowCategoriesControllerTest &lt; ActionController::TestCase
39 39 end
40 40  
41 41 should 'retrieve an existing category when editing' do
42   - category = FollowCategory.create(:name => "category", :person => @person)
  42 + category = Circle.create(:name => "category", :person => @person)
43 43 get :edit, :profile => @person.identifier, :id => category.id
44 44 assert_equal category.name, assigns[:follow_category].name
45 45 end
... ... @@ -50,7 +50,7 @@ class FollowCategoriesControllerTest &lt; ActionController::TestCase
50 50 end
51 51  
52 52 should 'update an existing category' do
53   - category = FollowCategory.create(:name => "category", :person => @person)
  53 + category = Circle.create(:name => "category", :person => @person)
54 54 get :update, :profile => @person.identifier, :id => category.id,
55 55 :follow_category => { :name => "new name" }
56 56  
... ... @@ -60,7 +60,7 @@ class FollowCategoriesControllerTest &lt; ActionController::TestCase
60 60 end
61 61  
62 62 should 'not update an existing category without a name' do
63   - category = FollowCategory.create(:name => "category", :person => @person)
  63 + category = Circle.create(:name => "category", :person => @person)
64 64 get :update, :profile => @person.identifier, :id => category.id,
65 65 :follow_category => { :name => nil }
66 66  
... ... @@ -75,7 +75,7 @@ class FollowCategoriesControllerTest &lt; ActionController::TestCase
75 75 end
76 76  
77 77 should 'destroy an existing category and update related profiles' do
78   - category = FollowCategory.create(:name => "category", :person => @person)
  78 + category = Circle.create(:name => "category", :person => @person)
79 79 follower = fast_create(ProfileFollower, :profile_id => fast_create(Person).id,
80 80 :follower_id => @person.id, :follow_category_id => category.id)
81 81  
... ... @@ -93,8 +93,8 @@ class FollowCategoriesControllerTest &lt; ActionController::TestCase
93 93 end
94 94  
95 95 should 'display notice when ' do
96   - category = FollowCategory.create(:name => "category", :person => @person)
97   - FollowCategory.any_instance.stubs(:destroy).returns(false)
  96 + category = Circle.create(:name => "category", :person => @person)
  97 + Circle.any_instance.stubs(:destroy).returns(false)
98 98  
99 99 get :destroy, :profile => @person.identifier, :id => category.id
100 100 assert_not_nil session[:notice]
... ...