A trigger when a topic is updated, adds a couple of custom field tests

This commit is contained in:
Robin Ward 2015-01-02 15:56:44 -05:00
parent 4c166942ad
commit 6f72f265cb
3 changed files with 10 additions and 5 deletions

View File

@ -264,6 +264,9 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon
props = this.get('buffered.buffer');
Discourse.Topic.update(this.get('model'), props).then(function() {
// Note we roll back on success here because `update` saves
// the properties to the topic.
self.rollbackBuffer();
self.set('editingTopic', false);
}).catch(function(error) {
if (error && error.responseText) {
@ -271,10 +274,6 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon
} else {
bootbox.alert(I18n.t('generic_error'));
}
}).finally(function() {
// Note we even roll back on success here because `update` saves
// the properties to the topic.
self.rollbackBuffer();
});
},

View File

@ -2,6 +2,7 @@ require_dependency 'topic_view'
require_dependency 'promotion'
require_dependency 'url_helper'
require_dependency 'topics_bulk_action'
require_dependency 'discourse_event'
class TopicsController < ApplicationController
include UrlHelper
@ -134,6 +135,8 @@ class TopicsController < ApplicationController
success = PostRevisor.new(first_post, topic).revise!(current_user, changes, validate_post: false)
end
DiscourseEvent.trigger(:topic_saved, topic, params)
# this is used to return the title to the client as it may have been changed by "TextCleaner"
success ? render_serialized(topic, BasicTopicSerializer) : render_json_error(topic)
end

View File

@ -111,10 +111,13 @@ describe HasCustomFields do
db_item = CustomFieldsTestItem.find(test_item.id)
db_item.custom_fields.should == {"a" => ["b", "c", "d"]}
db_item.custom_fields["a"] = ["c", "d"]
db_item.custom_fields.update('a' => ['c', 'd'])
db_item.save
db_item.custom_fields.should == {"a" => ["c", "d"]}
db_item.custom_fields.delete('a')
db_item.custom_fields.should == {}
end
it "casts integers in arrays properly without error" do