Implements comment sorting in proposals and debates
This commit is contained in:
@@ -16,7 +16,7 @@ module CommentableActions
|
|||||||
def show
|
def show
|
||||||
set_resource_votes(resource)
|
set_resource_votes(resource)
|
||||||
@commentable = resource
|
@commentable = resource
|
||||||
@root_comments = resource.comments.roots.recent.page(params[:page]).per(10).for_render
|
@root_comments = resource.comments.roots.send("sort_by_#{@current_order}").page(params[:page]).per(10).for_render
|
||||||
@comments = @root_comments.inject([]){|all, root| all + Comment.descendants_of(root).for_render}
|
@comments = @root_comments.inject([]){|all, root| all + Comment.descendants_of(root).for_render}
|
||||||
@all_visible_comments = @root_comments + @comments
|
@all_visible_comments = @root_comments + @comments
|
||||||
|
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ FactoryGirl.define do
|
|||||||
factory :comment do
|
factory :comment do
|
||||||
association :commentable, factory: :debate
|
association :commentable, factory: :debate
|
||||||
user
|
user
|
||||||
body 'Comment body'
|
sequence(:body) { |n| "Comment body #{n}" }
|
||||||
|
|
||||||
trait :hidden do
|
trait :hidden do
|
||||||
hidden_at Time.now
|
hidden_at Time.now
|
||||||
|
|||||||
@@ -20,6 +20,22 @@ feature 'Commenting debates' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'Comment order' do
|
||||||
|
c1 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.now - 2)
|
||||||
|
c2 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.now - 1)
|
||||||
|
c3 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.now)
|
||||||
|
|
||||||
|
visit debate_path(debate)
|
||||||
|
|
||||||
|
expect(c1.body).to appear_before(c2.body)
|
||||||
|
expect(c2.body).to appear_before(c3.body)
|
||||||
|
|
||||||
|
visit debate_path(debate, order: :created_at)
|
||||||
|
|
||||||
|
expect(c3.body).to appear_before(c2.body)
|
||||||
|
expect(c2.body).to appear_before(c1.body)
|
||||||
|
end
|
||||||
|
|
||||||
scenario 'Turns links into html links' do
|
scenario 'Turns links into html links' do
|
||||||
create :comment, commentable: debate, body: 'Built with http://rubyonrails.org/'
|
create :comment, commentable: debate, body: 'Built with http://rubyonrails.org/'
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,22 @@ feature 'Commenting proposals' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'Comment order' do
|
||||||
|
c1 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.now - 2)
|
||||||
|
c2 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.now - 1)
|
||||||
|
c3 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.now)
|
||||||
|
|
||||||
|
visit proposal_path(proposal)
|
||||||
|
|
||||||
|
expect(c1.body).to appear_before(c2.body)
|
||||||
|
expect(c2.body).to appear_before(c3.body)
|
||||||
|
|
||||||
|
visit proposal_path(proposal, order: :created_at)
|
||||||
|
|
||||||
|
expect(c3.body).to appear_before(c2.body)
|
||||||
|
expect(c2.body).to appear_before(c1.body)
|
||||||
|
end
|
||||||
|
|
||||||
scenario 'Turns links into html links' do
|
scenario 'Turns links into html links' do
|
||||||
create :comment, commentable: proposal, body: 'Built with http://rubyonrails.org/'
|
create :comment, commentable: proposal, body: 'Built with http://rubyonrails.org/'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user