From c4bef2114e2da7a44dfac36c0924c31dc9b98201 Mon Sep 17 00:00:00 2001 From: Marcos Ronaldo Date: Thu, 16 Jun 2016 12:04:50 -0300 Subject: [PATCH] fixes some tests and add migration TODO finisht it --- app/controllers/public/content_viewer_controller.rb | 4 ++-- app/models/person.rb | 6 ------ db/migrate/20160616143830_create_followers_for_social_circles.rb | 11 +++++++++++ db/schema.rb | 3 --- test/functional/profile_controller_test.rb | 13 ++++++++----- test/unit/person_test.rb | 3 ++- 6 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20160616143830_create_followers_for_social_circles.rb diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index 24b633f..0a4ccfe 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -128,9 +128,9 @@ class ContentViewerController < ApplicationController end unless @page.display_to?(user) - if !profile.visible? || profile.secret? || (user && user.follows?(profile)) || user.blank? + if !profile.visible? || profile.secret? || (user && profile.in_social_circle?(user)) || user.blank? render_access_denied - else #!profile.public? + else private_profile_partial_parameters render :template => 'profile/_private_profile', :status => 403, :formats => [:html] end diff --git a/app/models/person.rb b/app/models/person.rb index 97be317..c1f42b9 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -603,10 +603,4 @@ class Person < Profile self.is_a_friend?(person) || super end - #protected - - #def followed_by?(profile) - # self == profile || self.followers.include?(profile) - #end - end diff --git a/db/migrate/20160616143830_create_followers_for_social_circles.rb b/db/migrate/20160616143830_create_followers_for_social_circles.rb new file mode 100644 index 0000000..f22077c --- /dev/null +++ b/db/migrate/20160616143830_create_followers_for_social_circles.rb @@ -0,0 +1,11 @@ +class CreateFollowersForSocialCircles < ActiveRecord::Migration + def up + #OK amizades + #membros de comunidade + #OK fans de empreendimento + + execute("INSERT INTO profile_followers(follower_id, profile_id, group) SELECT friend_id, person_id, group FROM friendships") + execute("INSERT INTO profile_followers(follower_id, profile_id, group) SELECT f.person_id, f.enterprise_id, 'favorites' FROM favorite_enterprise_people AS f") + + end +end diff --git a/db/schema.rb b/db/schema.rb index a8a8a18..9d86ca4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -375,9 +375,6 @@ ActiveRecord::Schema.define(version: 20160422163123) do t.integer "external_environment_id" end - add_index "environment_external_environments", ["environment_id"], name: "index_environment_external_environments_on_environment_id", using: :btree - add_index "environment_external_environments", ["external_environment_id"], name: "index_environment_external_environments_on_external_environment_id", using: :btree - create_table "environments", force: :cascade do |t| t.string "name" t.string "contact_email" diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 57da6e0..cc0a2e4 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -771,12 +771,13 @@ class ProfileControllerTest < ActionController::TestCase assert_equal 15, assigns(:activities).size end - should 'not see the friends activities in the current profile' do + should 'not see the followers activities in the current profile' do p2 = create_user.person - refute profile.is_a_friend?(p2) + refute profile.follows?(p2) p3 = create_user.person - p3.add_friend(profile) - assert p3.is_a_friend?(profile) + profile.follow(p3) + assert profile.follows?(p3) + ActionTracker::Record.destroy_all scrap1 = create(Scrap, defaults_for_scrap(:sender => p2, :receiver => p3)) @@ -964,7 +965,9 @@ class ProfileControllerTest < ActionController::TestCase should 'have activities defined if logged in and is following profile' do login_as(profile.identifier) p1= fast_create(Person) - p1.add_friend(profile) + + profile.follow(p1) + ActionTracker::Record.destroy_all get :index, :profile => p1.identifier assert_equal [], assigns(:activities) diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index f4ee39c..67dffd0 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1035,12 +1035,13 @@ class PersonTest < ActiveSupport::TestCase p2 = create_user('p2').person p3 = create_user('p3').person c = fast_create(Community, :name => "Foo") + c.add_member(p1) process_delayed_job_queue c.add_member(p3) process_delayed_job_queue - assert_equal 4, ActionTracker::Record.count + assert_equal 5, ActionTracker::Record.count assert_equal 5, ActionTrackerNotification.count has_add_member_notification = false ActionTrackerNotification.all.map do |notification| -- libgit2 0.21.2