Commit bdff2d88be32c7a010d0e97dd790593e99e470ae
Exists in
master
and in
29 other branches
Merge commit 'refs/merge-requests/364' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/364 Conflicts: test/unit/person_test.rb
Showing
2 changed files
with
14 additions
and
15 deletions
Show diff stats
app/models/person.rb
| @@ -471,8 +471,9 @@ class Person < Profile | @@ -471,8 +471,9 @@ class Person < Profile | ||
| 471 | Scrap.find_by_sql("SELECT id, updated_at, '#{Scrap.to_s}' AS klass FROM #{Scrap.table_name} WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} WHERE action_tracker.user_id = #{self.id} and action_tracker.verb != 'leave_scrap_to_self' and action_tracker.verb != 'add_member_in_community' ORDER BY updated_at DESC") | 471 | Scrap.find_by_sql("SELECT id, updated_at, '#{Scrap.to_s}' AS klass FROM #{Scrap.table_name} WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} WHERE action_tracker.user_id = #{self.id} and action_tracker.verb != 'leave_scrap_to_self' and action_tracker.verb != 'add_member_in_community' ORDER BY updated_at DESC") |
| 472 | end | 472 | end |
| 473 | 473 | ||
| 474 | + # by default, all fields are private | ||
| 474 | def public_fields | 475 | def public_fields |
| 475 | - self.fields_privacy.nil? ? self.active_fields : self.fields_privacy.reject{ |k, v| v != 'public' }.keys.map(&:to_s) | 476 | + self.fields_privacy.nil? ? [] : self.fields_privacy.reject{ |k, v| v != 'public' }.keys.map(&:to_s) |
| 476 | end | 477 | end |
| 477 | 478 | ||
| 478 | protected | 479 | protected |
test/unit/person_test.rb
| @@ -55,7 +55,7 @@ class PersonTest < ActiveSupport::TestCase | @@ -55,7 +55,7 @@ class PersonTest < ActiveSupport::TestCase | ||
| 55 | 55 | ||
| 56 | p1 = u.person | 56 | p1 = u.person |
| 57 | assert_equal u, p1.user | 57 | assert_equal u, p1.user |
| 58 | - | 58 | + |
| 59 | p2 = Person.new(:environment => Environment.default) | 59 | p2 = Person.new(:environment => Environment.default) |
| 60 | p2.user = u | 60 | p2.user = u |
| 61 | assert !p2.valid? | 61 | assert !p2.valid? |
| @@ -202,7 +202,7 @@ class PersonTest < ActiveSupport::TestCase | @@ -202,7 +202,7 @@ class PersonTest < ActiveSupport::TestCase | ||
| 202 | should 'have friends' do | 202 | should 'have friends' do |
| 203 | p1 = create_user('testuser1').person | 203 | p1 = create_user('testuser1').person |
| 204 | p2 = create_user('testuser2').person | 204 | p2 = create_user('testuser2').person |
| 205 | - | 205 | + |
| 206 | p1.add_friend(p2) | 206 | p1.add_friend(p2) |
| 207 | 207 | ||
| 208 | p1.friends.reload | 208 | p1.friends.reload |
| @@ -237,7 +237,7 @@ class PersonTest < ActiveSupport::TestCase | @@ -237,7 +237,7 @@ class PersonTest < ActiveSupport::TestCase | ||
| 237 | p2 = create_user('testuser2').person | 237 | p2 = create_user('testuser2').person |
| 238 | p3 = create_user('testuser3').person | 238 | p3 = create_user('testuser3').person |
| 239 | p4 = create_user('testuser4').person | 239 | p4 = create_user('testuser4').person |
| 240 | - | 240 | + |
| 241 | p1.add_friend(p2, 'group1') | 241 | p1.add_friend(p2, 'group1') |
| 242 | p1.add_friend(p3, 'group2') | 242 | p1.add_friend(p3, 'group2') |
| 243 | p1.add_friend(p4, 'group1') | 243 | p1.add_friend(p4, 'group1') |
| @@ -248,7 +248,7 @@ class PersonTest < ActiveSupport::TestCase | @@ -248,7 +248,7 @@ class PersonTest < ActiveSupport::TestCase | ||
| 248 | should 'not suggest duplicated friend groups' do | 248 | should 'not suggest duplicated friend groups' do |
| 249 | p1 = create_user('testuser1').person | 249 | p1 = create_user('testuser1').person |
| 250 | p2 = create_user('testuser2').person | 250 | p2 = create_user('testuser2').person |
| 251 | - | 251 | + |
| 252 | p1.add_friend(p2, 'friends') | 252 | p1.add_friend(p2, 'friends') |
| 253 | 253 | ||
| 254 | assert_equal p1.suggested_friend_groups, p1.suggested_friend_groups.uniq | 254 | assert_equal p1.suggested_friend_groups, p1.suggested_friend_groups.uniq |
| @@ -307,7 +307,7 @@ class PersonTest < ActiveSupport::TestCase | @@ -307,7 +307,7 @@ class PersonTest < ActiveSupport::TestCase | ||
| 307 | assert_equal 'my contact', person.contact_information | 307 | assert_equal 'my contact', person.contact_information |
| 308 | end | 308 | end |
| 309 | 309 | ||
| 310 | - should 'provide desired info fields' do | 310 | + should 'provide desired info fields' do |
| 311 | p = Person.new(:environment => Environment.default) | 311 | p = Person.new(:environment => Environment.default) |
| 312 | assert p.respond_to?(:photo) | 312 | assert p.respond_to?(:photo) |
| 313 | assert p.respond_to?(:address) | 313 | assert p.respond_to?(:address) |
| @@ -472,7 +472,7 @@ class PersonTest < ActiveSupport::TestCase | @@ -472,7 +472,7 @@ class PersonTest < ActiveSupport::TestCase | ||
| 472 | should 'require custom_area_of_study if area_of_study is others' do | 472 | should 'require custom_area_of_study if area_of_study is others' do |
| 473 | e = Environment.default | 473 | e = Environment.default |
| 474 | e.expects(:required_person_fields).returns(['area_of_study', 'custom_area_of_study']).at_least_once | 474 | e.expects(:required_person_fields).returns(['area_of_study', 'custom_area_of_study']).at_least_once |
| 475 | - | 475 | + |
| 476 | person = Person.new(:environment => e, :area_of_study => 'Others') | 476 | person = Person.new(:environment => e, :area_of_study => 'Others') |
| 477 | assert !person.valid? | 477 | assert !person.valid? |
| 478 | assert person.errors.invalid?(:custom_area_of_study) | 478 | assert person.errors.invalid?(:custom_area_of_study) |
| @@ -507,7 +507,7 @@ class PersonTest < ActiveSupport::TestCase | @@ -507,7 +507,7 @@ class PersonTest < ActiveSupport::TestCase | ||
| 507 | should 'not require custom_formation if formation is not others' do | 507 | should 'not require custom_formation if formation is not others' do |
| 508 | e = Environment.default | 508 | e = Environment.default |
| 509 | e.expects(:required_person_fields).returns(['formation']).at_least_once | 509 | e.expects(:required_person_fields).returns(['formation']).at_least_once |
| 510 | - | 510 | + |
| 511 | person = Person.new(:environment => e, :formation => 'Agrometeorology') | 511 | person = Person.new(:environment => e, :formation => 'Agrometeorology') |
| 512 | assert !person.valid? | 512 | assert !person.valid? |
| 513 | assert ! person.errors.invalid?(:custom_formation) | 513 | assert ! person.errors.invalid?(:custom_formation) |
| @@ -854,7 +854,7 @@ class PersonTest < ActiveSupport::TestCase | @@ -854,7 +854,7 @@ class PersonTest < ActiveSupport::TestCase | ||
| 854 | assert !p1.is_a_friend?(p3) | 854 | assert !p1.is_a_friend?(p3) |
| 855 | p1.add_friend(p4) | 855 | p1.add_friend(p4) |
| 856 | assert p1.is_a_friend?(p4) | 856 | assert p1.is_a_friend?(p4) |
| 857 | - | 857 | + |
| 858 | action_tracker = fast_create(ActionTracker::Record) | 858 | action_tracker = fast_create(ActionTracker::Record) |
| 859 | 859 | ||
| 860 | assert_difference(Delayed::Job, :count, 1) do | 860 | assert_difference(Delayed::Job, :count, 1) do |
| @@ -873,7 +873,7 @@ class PersonTest < ActiveSupport::TestCase | @@ -873,7 +873,7 @@ class PersonTest < ActiveSupport::TestCase | ||
| 873 | assert !p1.is_a_friend?(p3) | 873 | assert !p1.is_a_friend?(p3) |
| 874 | p1.add_friend(p4) | 874 | p1.add_friend(p4) |
| 875 | assert p1.is_a_friend?(p4) | 875 | assert p1.is_a_friend?(p4) |
| 876 | - | 876 | + |
| 877 | action_tracker = fast_create(ActionTracker::Record, :user_id => p1.id) | 877 | action_tracker = fast_create(ActionTracker::Record, :user_id => p1.id) |
| 878 | 878 | ||
| 879 | Delayed::Job.delete_all | 879 | Delayed::Job.delete_all |
| @@ -926,7 +926,7 @@ class PersonTest < ActiveSupport::TestCase | @@ -926,7 +926,7 @@ class PersonTest < ActiveSupport::TestCase | ||
| 926 | community.add_member(p4) | 926 | community.add_member(p4) |
| 927 | assert p4.is_member_of?(community) | 927 | assert p4.is_member_of?(community) |
| 928 | assert !p2.is_member_of?(community) | 928 | assert !p2.is_member_of?(community) |
| 929 | - | 929 | + |
| 930 | action_tracker = fast_create(ActionTracker::Record) | 930 | action_tracker = fast_create(ActionTracker::Record) |
| 931 | article = mock() | 931 | article = mock() |
| 932 | action_tracker.stubs(:target).returns(article) | 932 | action_tracker.stubs(:target).returns(article) |
| @@ -1277,12 +1277,10 @@ class PersonTest < ActiveSupport::TestCase | @@ -1277,12 +1277,10 @@ class PersonTest < ActiveSupport::TestCase | ||
| 1277 | assert person.has_permission?('bli', Profile.new) | 1277 | assert person.has_permission?('bli', Profile.new) |
| 1278 | end | 1278 | end |
| 1279 | 1279 | ||
| 1280 | - should 'active fields are public if fields privacy is nil' do | 1280 | + should 'active fields are private if fields privacy is nil' do |
| 1281 | p = fast_create(Person) | 1281 | p = fast_create(Person) |
| 1282 | p.expects(:fields_privacy).returns(nil) | 1282 | p.expects(:fields_privacy).returns(nil) |
| 1283 | - f = %w(sex birth_date) | ||
| 1284 | - p.expects(:active_fields).returns(f) | ||
| 1285 | - assert_equal f, p.public_fields | 1283 | + assert_equal [], p.public_fields |
| 1286 | end | 1284 | end |
| 1287 | 1285 | ||
| 1288 | should 'return public fields' do | 1286 | should 'return public fields' do |