BUG: new messages to person that is not sharing
Conversation recipient validated - Conversation foreign recipient not required to be validated. - Added 'peter' as spec_helper user. - New fixture, new statistic values. - Clearer identifier names
This commit is contained in:
parent
f4c756cd34
commit
4e83e4c7ed
5 changed files with 47 additions and 4 deletions
|
|
@ -15,10 +15,21 @@ class Conversation < ActiveRecord::Base
|
|||
belongs_to :author, :class_name => 'Person'
|
||||
|
||||
validate :max_participants
|
||||
validate :local_recipients
|
||||
|
||||
def max_participants
|
||||
errors.add(:max_participants, "too many participants") if participants.count > 20
|
||||
end
|
||||
|
||||
def local_recipients
|
||||
recipients.each do |recipient|
|
||||
if recipient.local?
|
||||
if recipient.owner.contacts.where(:person_id => self.author.id).count == 0
|
||||
errors.add(:all_recipients, "recipient not allowed")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
accepts_nested_attributes_for :messages
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ describe Statistics do
|
|||
{"id" => bob.id , "count" => 1 },
|
||||
{"id" => eve.id , "count" => 0 },
|
||||
{"id" => local_luke.id , "count" => 0 },
|
||||
{"id" => local_leia.id , "count" => 0 }]
|
||||
{"id" => local_leia.id , "count" => 0 },
|
||||
{"id" => peter.id , "count" => 0 }]
|
||||
end
|
||||
|
||||
describe '#posts_count_sql' do
|
||||
|
|
@ -68,7 +69,8 @@ describe Statistics do
|
|||
{"id" => bob.id , "count" => 2 },
|
||||
{"id" => eve.id , "count" => 1 },
|
||||
{"id" => local_luke.id , "count" => 2 },
|
||||
{"id" => local_leia.id , "count" => 2 }]
|
||||
{"id" => local_leia.id , "count" => 2 },
|
||||
{"id" => peter.id , "count" => 1 }]
|
||||
|
||||
result_should_equal User.connection.select_all(@stats.contacts_sharing_with_count_sql)
|
||||
end
|
||||
|
|
@ -96,7 +98,8 @@ describe Statistics do
|
|||
{"id" => bob.id , "count" => 1, "connected" => 1 },
|
||||
{"id" => eve.id , "count" => 0, "connected" => 1 },
|
||||
{"id" => local_luke.id , "count" => 0, "connected" => 0 },
|
||||
{"id" => local_leia.id , "count" => 0, "connected" => 0 }]
|
||||
{"id" => local_leia.id , "count" => 0, "connected" => 0 },
|
||||
{"id" => peter.id , "count" => 0, "connected" => 0 }]
|
||||
|
||||
expect(@stats.fb_connected_distribution).to match_array(@result)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -108,4 +108,20 @@ describe Conversation, :type => :model do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#invalid parameters' do
|
||||
before do
|
||||
@invalid_hash = {
|
||||
:author => peter.person,
|
||||
:participant_ids => [peter.person.id, @user1.person.id],
|
||||
:subject => "cool stuff",
|
||||
:messages_attributes => [ {:author => peter.person, :text => 'hey'} ]
|
||||
}
|
||||
end
|
||||
|
||||
it 'with invalid recipient' do
|
||||
conversation = Conversation.create(@invalid_hash)
|
||||
expect(conversation).to be_invalid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -48,6 +48,10 @@ def remote_raphael
|
|||
@remote_raphael ||= Person.where(:diaspora_handle => 'raphael@remote.net').first
|
||||
end
|
||||
|
||||
def peter
|
||||
@peter ||= User.where(:username => 'peter').first
|
||||
end
|
||||
|
||||
def photo_fixture_name
|
||||
@photo_fixture_name = File.join(File.dirname(__FILE__), 'fixtures', 'button.png')
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,5 +34,14 @@ FixtureBuilder.configure do |fbuilder|
|
|||
|
||||
local_leia.contacts.create(:person => remote_raphael, :aspects => [leias_aspect])
|
||||
local_luke.contacts.create(:person => remote_raphael, :aspects => [lukes_aspect])
|
||||
|
||||
# Set up a follower
|
||||
peter = FactoryGirl.create(:user_with_aspect, :username => "peter")
|
||||
peters_aspect = peter.aspects.where(:name => "generic").first
|
||||
|
||||
peter.contacts.create!(:person => alice.person,
|
||||
:aspects => [peters_aspect],
|
||||
:sharing => false,
|
||||
:receiving => true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue