2012-04-03 00:05:37 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2011 Instructure, Inc.
|
|
|
|
#
|
|
|
|
# This file is part of Canvas.
|
|
|
|
#
|
|
|
|
# Canvas is free software: you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
# Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License along
|
|
|
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
|
|
|
require 'db/migrate/20120402054921_populate_conversation_root_account_ids.rb'
|
|
|
|
|
2012-05-18 10:51:27 +08:00
|
|
|
describe 'PopulateConversationRootAccountIds' do
|
2012-04-03 00:05:37 +08:00
|
|
|
describe "up" do
|
|
|
|
it "should work" do
|
2013-01-29 03:33:48 +08:00
|
|
|
pending "no longer possible since context_messages no longer exists"
|
2012-04-03 00:05:37 +08:00
|
|
|
u = user
|
|
|
|
|
|
|
|
# messages w/ account contexts
|
|
|
|
u1 = user
|
|
|
|
a1a = Account.default
|
|
|
|
a1b = Account.create
|
2012-11-29 06:53:00 +08:00
|
|
|
cn1 = Conversation.initiate([u, u1], true)
|
2012-04-03 00:05:37 +08:00
|
|
|
cn1.add_message(u, "test1").update_attribute(:context, a1a)
|
|
|
|
cn1.add_message(u, "test2").update_attribute(:context, a1a)
|
|
|
|
cn1.add_message(u, "test3").update_attribute(:context, a1b)
|
|
|
|
cn1.root_account_ids.should eql []
|
|
|
|
|
|
|
|
# context message on course
|
|
|
|
u2 = user
|
|
|
|
a2 = Account.create
|
|
|
|
c2 = course(:account => a2)
|
2012-11-29 06:53:00 +08:00
|
|
|
cn2 = Conversation.initiate([u, u2], true)
|
2012-04-03 00:05:37 +08:00
|
|
|
cn2.add_message(u, "test")
|
|
|
|
Conversation.connection.execute "INSERT INTO context_messages(context_id, context_type) VALUES(#{c2.id}, 'Course')"
|
|
|
|
cn2.conversation_messages.update_all("context_message_id = (SELECT id FROM context_messages ORDER BY id DESC LIMIT 1)")
|
|
|
|
cn2.root_account_ids.should eql []
|
|
|
|
|
|
|
|
# context message on group
|
|
|
|
u3 = user
|
|
|
|
a3 = Account.create
|
|
|
|
g3 = group(:group_context => a3)
|
|
|
|
|
2012-11-29 06:53:00 +08:00
|
|
|
cn3 = Conversation.initiate([u, u3], true)
|
2012-04-03 00:05:37 +08:00
|
|
|
cn3.add_message(u, "test")
|
|
|
|
Conversation.connection.execute "INSERT INTO context_messages(context_id, context_type) VALUES(#{g3.id}, 'Group')"
|
|
|
|
cn3.conversation_messages.update_all("context_message_id = (SELECT id FROM context_messages ORDER BY id DESC LIMIT 1)")
|
|
|
|
cn3.root_account_ids.should eql []
|
|
|
|
|
|
|
|
# submission
|
|
|
|
u4 = user
|
|
|
|
a4 = Account.create
|
|
|
|
c4 = course(:account => a4, :active_all => true)
|
|
|
|
student_in_course(:user => u4, :course => c4, :active_all => true)
|
|
|
|
as4 = c4.assignments.create
|
|
|
|
s4 = as4.submit_homework(u4, :submission_type => "online_text_entry", :body => "")
|
2012-11-29 06:53:00 +08:00
|
|
|
cn4 = Conversation.initiate([u, u4], true)
|
2012-04-03 00:05:37 +08:00
|
|
|
cn4.add_message(u, '').update_attribute(:asset, s4)
|
|
|
|
cn4.root_account_ids.should eql []
|
|
|
|
|
|
|
|
# no root account info available
|
|
|
|
u5 = user
|
2012-11-29 06:53:00 +08:00
|
|
|
cn5 = Conversation.initiate([u, u5], true)
|
2012-04-03 00:05:37 +08:00
|
|
|
cn5.add_message(u, "test")
|
|
|
|
|
|
|
|
PopulateConversationRootAccountIds.up
|
|
|
|
|
|
|
|
cn1.reload.root_account_ids.should eql [a1a.id, a1b.id]
|
|
|
|
cn2.reload.root_account_ids.should eql [a2.id]
|
|
|
|
cn3.reload.root_account_ids.should eql [a3.id]
|
|
|
|
cn4.reload.root_account_ids.should eql [a4.id]
|
|
|
|
cn5.reload.root_account_ids.should eql []
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|