Skip to content

Commit

Permalink
Show the number of new comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Aug 25, 2011
1 parent 88902db commit 70fd35a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions app/helpers/node_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def read_it(content)
if current_account
status = node.read_status(current_account)
visit = case status
when :not_read then ", non visité"
when :new_comments then ", Nouveaux !"
else ", déjà visité"
when :not_read then ", non visité"
when Integer then ", #{pluralize status, "nouveau", "nouveaux"} !"
else ", déjà visité"
end
visit = content_tag(:span, visit, :class => "visit")
else
Expand Down
11 changes: 7 additions & 4 deletions app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,14 @@ def self.last_reading(node_id, account_id)
end

def read_status(account)
return @read_status if @read_status
r = Node.last_reading(self.id, account.id) if account
return :not_read if r.nil?
return :no_comments if last_commented_at.nil?
return :new_comments if r < last_commented_at
return :read
@read_status = case
when r.nil? then :not_read
when last_commented_at.nil? then :no_comments
when r >= last_commented_at then :read
else comments.where("created_at > ?", r).count
end
end

def board_status(account)
Expand Down
2 changes: 1 addition & 1 deletion spec/models/section_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
require 'spec_helper'

describe Section do
subject { FactoryGirl.build(:section) }
subject { FactoryGirl.build(:section, :title => "Ruby") }

it { should be_valid }

Expand Down

0 comments on commit 70fd35a

Please sign in to comment.