Skip to content

Commit 0b09d5a

Browse files
jensengzwily
authored andcommitted
fix media comments in conversations, closes #5826
Change-Id: If2232496b6b51db8729e37b2bfb0dc99c925c4e4 Reviewed-on: https://gerrit.instructure.com/5989 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Zach Wily <zach@instructure.com>
1 parent 65f4522 commit 0b09d5a

2 files changed

Lines changed: 73 additions & 48 deletions

File tree

app/controllers/conversations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ def create_message_on_conversation(conversation=@conversation, update_for_sender
661661
media_id = params[:media_comment_id]
662662
media_type = params[:media_comment_type]
663663
if media_id.present? && media_type.present?
664-
media_comment = MediaObject.by_media_id.by_media_type(media_id, media_type).first
664+
media_comment = MediaObject.by_media_id(media_id).by_media_type(media_type).first
665665
if media_comment
666666
media_comment.context = @current_user
667667
media_comment.save

spec/selenium/conversations_spec.rb

Lines changed: 72 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,61 @@
33
shared_examples_for "conversations selenium tests" do
44
it_should_behave_like "in-process server selenium tests"
55

6-
context "conversation loading" do
7-
before do
8-
course_with_teacher_logged_in
9-
@user.watched_conversations_intro
10-
@user.save
6+
before do
7+
course_with_teacher_logged_in
8+
@user.watched_conversations_intro
9+
@user.save
10+
end
11+
12+
def new_conversation
13+
get "/conversations"
14+
keep_trying_until{ driver.find_element(:id, "create_message_form") }
15+
end
16+
17+
def submit_message_form(opts={})
18+
opts[:message] ||= "Test Message"
19+
opts[:attachments] ||= []
20+
21+
if browser = find_with_jquery("#create_message_form .browser:visible")
22+
browser.click
23+
keep_trying_until{
24+
if elem = find_with_jquery('.selectable:visible')
25+
elem.click
26+
end
27+
elem
28+
}
29+
end
30+
31+
find_with_jquery("#create_message_form textarea").send_keys(opts[:message])
32+
33+
opts[:attachments].each_with_index do |fullpath, i|
34+
driver.find_element(:id, "action_add_attachment").click
35+
36+
keep_trying_until {
37+
find_all_with_jquery("#create_message_form .file_input:visible")[i]
38+
}.send_keys(fullpath)
1139
end
1240

41+
if opts[:media_comment]
42+
driver.execute_script <<-JS
43+
$("#media_comment_id").val(#{opts[:media_comment].first.inspect})
44+
$("#media_comment_type").val(#{opts[:media_comment].last.inspect})
45+
$("#create_message_form .media_comment").show()
46+
$("#action_media_comment").hide()
47+
JS
48+
end
49+
50+
expect {
51+
find_with_jquery("#create_message_form button[type='submit']").click
52+
wait_for_ajax_requests
53+
}.to change(ConversationMessage, :count).by(1)
54+
55+
message = ConversationMessage.last
56+
driver.find_element(:id, "message_#{message.id}").should_not be_nil
57+
message
58+
end
59+
60+
context "conversation loading" do
1361
it "should load all conversations" do
1462
@me = @user
1563
num = 51
@@ -23,52 +71,29 @@
2371
end
2472
end
2573

26-
context "attachments" do
27-
def new_conversation
28-
get "/conversations"
29-
keep_trying_until{ driver.find_element(:id, "create_message_form") }
30-
end
74+
context "media comments" do
75+
it "should add a media comment to the message form" do
76+
# don't have a good way to test kaltura here, so we just fake it up
77+
Kaltura::ClientV3.should_receive(:config).at_least(:once).and_return({})
78+
mo = MediaObject.new
79+
mo.media_id = '0_12345678'
80+
mo.media_type = 'audio'
81+
mo.context = @user
82+
mo.user = @user
83+
mo.title = "test title"
84+
mo.save!
3185

32-
def submit_message_form(opts={})
33-
opts[:message] ||= "Test Message"
34-
opts[:attachments] ||= []
35-
36-
if browser = find_with_jquery("#create_message_form .browser:visible")
37-
browser.click
38-
keep_trying_until{
39-
if elem = find_with_jquery('.selectable:visible')
40-
elem.click
41-
end
42-
elem
43-
}
44-
end
45-
46-
find_with_jquery("#create_message_form textarea").send_keys(opts[:message])
47-
48-
opts[:attachments].each_with_index do |fullpath, i|
49-
driver.find_element(:id, "action_add_attachment").click
50-
51-
keep_trying_until {
52-
find_all_with_jquery("#create_message_form .file_input:visible")[i]
53-
}.send_keys(fullpath)
54-
end
55-
56-
expect {
57-
find_with_jquery("#create_message_form button[type='submit']").click
58-
wait_for_ajax_requests
59-
}.to change(ConversationMessage, :count).by(1)
60-
61-
message = ConversationMessage.last
62-
driver.find_element(:id, "message_#{message.id}").should_not be_nil
63-
message
64-
end
86+
new_conversation
87+
88+
message = submit_message_form(:media_comment => [mo.media_id, mo.media_type])
89+
message = "#message_#{message.id}"
6590

66-
before do
67-
course_with_teacher_logged_in
68-
@user.watched_conversations_intro
69-
@user.save
91+
find_all_with_jquery("#{message} .message_attachments li").size.should == 1
92+
find_with_jquery("#{message} .message_attachments li a .title").text.should == mo.title
7093
end
94+
end
7195

96+
context "attachments" do
7297
it "should be able to add an attachment to the message form" do
7398
new_conversation
7499

0 commit comments

Comments
 (0)