Skip to content

Commit cd938c8

Browse files
committed
Fix failing specs
1 parent 80de0d3 commit cd938c8

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

app/models/better_together/navigation_item.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,24 @@ def to_s
196196
title
197197
end
198198

199+
def self.permitted_attributes(id: false, destroy: false) # rubocop:todo Metrics/MethodLength
200+
# Base attributes used when creating/updating navigation items
201+
attrs = %i[
202+
url
203+
icon
204+
position
205+
visible
206+
item_type
207+
parent_id
208+
route_name
209+
linkable_type
210+
linkable_id
211+
navigation_area_id
212+
]
213+
214+
super + attrs
215+
end
216+
199217
def url
200218
fallback_url = "##{identifier}"
201219

app/policies/better_together/conversation_policy.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ def permitted_participants
4242
role = BetterTogether::Role.find_by(identifier: 'platform_manager')
4343
manager_ids = BetterTogether::PersonPlatformMembership.where(role_id: role.id).pluck(:member_id)
4444
BetterTogether::Person.where(id: manager_ids)
45-
.or(BetterTogether::Person.where('preferences @> ?',
46-
{ receive_messages_from_members: true }.to_json))
45+
.or(BetterTogether::Person.privacy_public.where('preferences @> ?',
46+
# rubocop:todo Layout/LineLength
47+
{ receive_messages_from_members: true }.to_json))
48+
# rubocop:enable Layout/LineLength
4749
.distinct
4850
end
4951
end

spec/features/conversations/create_spec.rb

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
require 'rails_helper'
44

55
RSpec.describe 'creating a new conversation', :as_platform_manager do
6+
include BetterTogether::ConversationHelpers
7+
68
let!(:user) { create(:better_together_user, :confirmed) }
79

8-
scenario 'between a platform manager and normal user' do
9-
visit new_conversation_path(locale: I18n.default_locale)
10-
select "#{user.person.name} - @#{user.person.identifier}", from: 'conversation[participant_ids][]'
11-
fill_in 'conversation[title]', with: Faker::Lorem.sentence(word_count: 3)
12-
click_button 'Create Conversation'
10+
before do
11+
# Ensure this person can be messaged by members so they appear in permitted_participants
12+
user.person.update!(preferences: (user.person.preferences || {}).merge('receive_messages_from_members' => true))
13+
end
14+
15+
scenario 'between a platform manager and normal user', :js do
16+
create_conversation([user.person], first_message: Faker::Lorem.sentence(word_count: 8))
1317
expect(BetterTogether::Conversation.count).to eq(1)
1418
end
1519

@@ -20,6 +24,21 @@
2024

2125
let(:user2) { create(:better_together_user) }
2226

27+
# rubocop:todo RSpec/ExampleLength
28+
scenario 'can create a conversation with a public person who opted into messages', :js do
29+
target = create(:better_together_user, :confirmed)
30+
# Ensure target is public and opted-in to receive messages from members
31+
target.person.update!(privacy: 'public',
32+
# rubocop:todo Layout/LineLength
33+
preferences: (target.person.preferences || {}).merge('receive_messages_from_members' => true))
34+
# rubocop:enable Layout/LineLength
35+
36+
expect do
37+
create_conversation([target.person], first_message: 'Hi there')
38+
end.to change(BetterTogether::Conversation, :count).by(1)
39+
end
40+
# rubocop:enable RSpec/ExampleLength
41+
2342
it 'cannot create conversations with private users' do
2443
visit new_conversation_path(locale: I18n.default_locale)
2544
expect('conversation[participant_ids][]').not_to have_content(user2.person.name) # rubocop:todo RSpec/ExpectActual

0 commit comments

Comments
 (0)