check for db limits on content tag asset name sync

test plan:
* add a wiki page to a course
* add the wiki page as a module item
* edit the module item title to be
more than 255 characters long
* should not return an 'unexpected error'

fixes #CNVS-3052 frd

Change-Id: I8c6f18a8da7ecdce9a53f88d40ce82fd6d4e85c8
Reviewed-on: https://gerrit.instructure.com/22173
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
Product-Review: Jeremy Stanley <jeremy@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: August Thornton <august@instructure.com>
This commit is contained in:
James Williams 2013-07-10 08:20:53 -06:00
parent a9755546b6
commit c2a5ae1239
2 changed files with 27 additions and 4 deletions

View File

@ -165,17 +165,25 @@ class ContentTag < ActiveRecord::Base
def content_or_self
content || self
end
def asset_safe_title(column)
name = self.title.to_s
if (limit = self.content.class.try(:columns_hash)[column].try(:limit)) && name.length > limit
name = name[0, limit][/.{0,#{limit}}/mu]
end
name
end
def update_asset_name!
return unless self.sync_title_to_asset_title?
correct_context = self.content && self.content.respond_to?(:context) && self.content.context == self.context
if correct_context
if self.content.respond_to?("name=") && self.content.respond_to?("name") && self.content.name != self.title
self.content.update_attribute(:name, self.title)
self.content.update_attribute(:name, asset_safe_title('name'))
elsif self.content.respond_to?("title=") && self.content.title != self.title
self.content.update_attribute(:title, self.title)
self.content.update_attribute(:title, asset_safe_title('title'))
elsif self.content.respond_to?("display_name=") && self.content.display_name != self.title
self.content.update_attribute(:display_name, self.title)
self.content.update_attribute(:display_name, asset_safe_title('display_name'))
end
end
end

View File

@ -161,6 +161,21 @@ describe ContentTag do
@assignment.title.should == 'some assignment (renamed)'
end
it "should not attempt to update asset name attribute if it's over the db limit" do
course
@page = @course.wiki.wiki_pages.create!(:title => "some page")
@page.workflow_state = 'unpublished'
@page.save!
@module = @course.context_modules.create!(:name => "module")
@tag = @module.add_item({:type => 'WikiPage', :title => 'oh noes!' * 35, :id => @page.id})
@tag.workflow_state.should == 'unpublished'
@tag.update_asset_name!
@page.reload
@tag.title[0, 250].should == @page.title[0, 250]
end
it "should publish/unpublish the tag if the linked wiki page is published/unpublished" do
course
@page = @course.wiki.wiki_pages.create!(:title => "some page")