mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-05-03 01:15:48 -04:00
FIX: null dates crashed the client app. last_posted_at
was not updating properly on split topic.
This commit is contained in:
parent
876a570e3a
commit
3c7eb3a4e8
4 changed files with 15 additions and 6 deletions
app
spec/models
|
@ -18,6 +18,8 @@ Discourse.Formatter = (function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
longDate = function(dt) {
|
longDate = function(dt) {
|
||||||
|
if (!dt) return;
|
||||||
|
|
||||||
return moment(dt).longDate();
|
return moment(dt).longDate();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,6 +32,9 @@ Discourse.Formatter = (function(){
|
||||||
};
|
};
|
||||||
|
|
||||||
autoUpdatingRelativeAge = function(date,options) {
|
autoUpdatingRelativeAge = function(date,options) {
|
||||||
|
|
||||||
|
if (!date) return "";
|
||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
var format = options.format || "tiny";
|
var format = options.format || "tiny";
|
||||||
|
|
||||||
|
|
|
@ -272,7 +272,7 @@ Handlebars.registerHelper('number', function(property, options) {
|
||||||
@for Handlebars
|
@for Handlebars
|
||||||
**/
|
**/
|
||||||
Handlebars.registerHelper('date', function(property, options) {
|
Handlebars.registerHelper('date', function(property, options) {
|
||||||
var leaveAgo, val;
|
var leaveAgo;
|
||||||
if (property.hash) {
|
if (property.hash) {
|
||||||
if (property.hash.leaveAgo) {
|
if (property.hash.leaveAgo) {
|
||||||
leaveAgo = property.hash.leaveAgo === "true";
|
leaveAgo = property.hash.leaveAgo === "true";
|
||||||
|
@ -281,11 +281,11 @@ Handlebars.registerHelper('date', function(property, options) {
|
||||||
property = property.hash.path;
|
property = property.hash.path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val = Ember.Handlebars.get(this, property, options);
|
var val = Ember.Handlebars.get(this, property, options);
|
||||||
var date = null;
|
|
||||||
if (val) {
|
if (val) {
|
||||||
date = new Date(val);
|
var date = new Date(val);
|
||||||
|
return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(date, {format: 'medium', leaveAgo: leaveAgo}));
|
||||||
}
|
}
|
||||||
return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(date, {format: 'medium', leaveAgo: leaveAgo}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -270,7 +270,8 @@ class Topic < ActiveRecord::Base
|
||||||
def self.reset_highest(topic_id)
|
def self.reset_highest(topic_id)
|
||||||
result = exec_sql "UPDATE topics
|
result = exec_sql "UPDATE topics
|
||||||
SET highest_post_number = (SELECT COALESCE(MAX(post_number), 0) FROM posts WHERE topic_id = :topic_id AND deleted_at IS NULL),
|
SET highest_post_number = (SELECT COALESCE(MAX(post_number), 0) FROM posts WHERE topic_id = :topic_id AND deleted_at IS NULL),
|
||||||
posts_count = (SELECT count(*) FROM posts WHERE deleted_at IS NULL AND topic_id = :topic_id)
|
posts_count = (SELECT count(*) FROM posts WHERE deleted_at IS NULL AND topic_id = :topic_id),
|
||||||
|
last_posted_at = (SELECT MAX(created_at) FROM POSTS WHERE topic_id = :topic_id AND deleted_at IS NULL)
|
||||||
WHERE id = :topic_id
|
WHERE id = :topic_id
|
||||||
RETURNING highest_post_number", topic_id: topic_id
|
RETURNING highest_post_number", topic_id: topic_id
|
||||||
highest_post_number = result.first['highest_post_number'].to_i
|
highest_post_number = result.first['highest_post_number'].to_i
|
||||||
|
|
|
@ -276,6 +276,7 @@ describe Topic do
|
||||||
new_topic.should be_present
|
new_topic.should be_present
|
||||||
new_topic.featured_user1_id.should == another_user.id
|
new_topic.featured_user1_id.should == another_user.id
|
||||||
new_topic.like_count.should == 1
|
new_topic.like_count.should == 1
|
||||||
|
|
||||||
new_topic.category.should == category
|
new_topic.category.should == category
|
||||||
topic.featured_user1_id.should be_blank
|
topic.featured_user1_id.should be_blank
|
||||||
new_topic.posts.should =~ [p2, p4]
|
new_topic.posts.should =~ [p2, p4]
|
||||||
|
@ -283,6 +284,7 @@ describe Topic do
|
||||||
new_topic.reload
|
new_topic.reload
|
||||||
new_topic.posts_count.should == 2
|
new_topic.posts_count.should == 2
|
||||||
new_topic.highest_post_number.should == 2
|
new_topic.highest_post_number.should == 2
|
||||||
|
expect(new_topic.last_posted_at).to be_present
|
||||||
|
|
||||||
p2.reload
|
p2.reload
|
||||||
p2.sort_order.should == 1
|
p2.sort_order.should == 1
|
||||||
|
@ -298,6 +300,7 @@ describe Topic do
|
||||||
topic.posts_count.should == 2
|
topic.posts_count.should == 2
|
||||||
topic.posts.should =~ [p1, p3]
|
topic.posts.should =~ [p1, p3]
|
||||||
topic.highest_post_number.should == p3.post_number
|
topic.highest_post_number.should == p3.post_number
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue