From 1640ba77fc161f822307b4b56162f05ee5e7ff5b Mon Sep 17 00:00:00 2001 From: Ashley Perpetual Date: Thu, 10 Nov 2016 10:35:27 +0800 Subject: [PATCH] changed all drupal_comments to comments and all DrupalComment to Comment Removed comments method in node_shared.rb and uses of it Fix answer_test.rb: was previously expecting the comments method which returned an ascending list by default Fixed comments ordering in comment_test and notes/_comments partial view Removed some tests in comments_test.rb --- app/controllers/comment_controller.rb | 8 ++-- app/controllers/home_controller.rb | 4 +- app/controllers/notes_controller.rb | 2 +- app/controllers/users_controller.rb | 4 +- app/models/answer.rb | 2 +- app/models/{drupal_comment.rb => comment.rb} | 4 +- app/models/concerns/node_shared.rb | 5 -- app/models/drupal_node.rb | 8 ++-- app/models/drupal_users.rb | 2 +- app/models/user.rb | 4 +- app/services/search_service.rb | 2 +- app/services/typeahead_service.rb | 2 +- app/views/dashboard/_activity.html.erb | 2 +- app/views/dashboard/_node_meta.html.erb | 2 +- app/views/notes/_comments.html.erb | 6 +-- app/views/notes/stats.html.erb | 2 +- app/views/questions/show.html.erb | 2 +- app/views/searches/_node_result.html.erb | 2 +- ...74856_add_comments_count_to_drupal_node.rb | 6 +-- db/schema.rb.example | 2 +- db/seeds.rb | 2 +- test/functional/comment_controller_test.rb | 22 ++++----- test/functional/notes_controller_test.rb | 8 ++-- test/functional/tag_controller_test.rb | 4 +- test/test_helper.rb | 2 +- test/unit/answer_test.rb | 2 +- ...drupal_comment_test.rb => comment_test.rb} | 47 +++++++++---------- 27 files changed, 76 insertions(+), 82 deletions(-) rename app/models/{drupal_comment.rb => comment.rb} (97%) rename test/unit/{drupal_comment_test.rb => comment_test.rb} (81%) diff --git a/app/controllers/comment_controller.rb b/app/controllers/comment_controller.rb index 617b38c28f..5bec92a056 100644 --- a/app/controllers/comment_controller.rb +++ b/app/controllers/comment_controller.rb @@ -4,7 +4,7 @@ class CommentController < ApplicationController before_filter :require_user, :only => [:create, :update, :delete] def index - @comments = DrupalComment.paginate(page: params[:page], per_page: 30) + @comments = Comment.paginate(page: params[:page], per_page: 30) .order('timestamp DESC') render template: 'comments/index' end @@ -40,7 +40,7 @@ def create # create answer comments def answer_create @answer_id = params[:aid] - @comment = DrupalComment.new( + @comment = Comment.new( uid: current_user.uid, aid: params[:aid], comment: params[:body], @@ -58,7 +58,7 @@ def answer_create end def update - @comment = DrupalComment.find params[:id] + @comment = Comment.find params[:id] comments_node_and_path @@ -79,7 +79,7 @@ def update end def delete - @comment = DrupalComment.find params[:id] + @comment = Comment.find params[:id] comments_node_and_path diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 63eed100ec..6ec7e9ef85 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -86,7 +86,7 @@ def dashboard revisions = revisions.group('DATE(FROM_UNIXTIME(timestamp))') if Rails.env == "production" @wikis = @wikis + revisions @wikis = @wikis.sort_by { |a| a.created_at }.reverse - @comments = DrupalComment.joins(:drupal_node, :drupal_users) + @comments = Comment.joins(:drupal_node, :drupal_users) .order('timestamp DESC') .where('timestamp - node.created > ?', 86400) # don't report edits within 1 day of page creation .limit(20) @@ -94,7 +94,7 @@ def dashboard # .where('comments.status = (?)', 1) # group by day: http://stackoverflow.com/questions/5970938/group-by-day-from-timestamp @comments = @comments.group('DATE(FROM_UNIXTIME(timestamp))') if Rails.env == "production" - @answer_comments = DrupalComment.joins(:answer, :drupal_users) + @answer_comments = Comment.joins(:answer, :drupal_users) .order('timestamp DESC') .where('timestamp - answers.created_at > ?', 86400) .limit(20) diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 4ab1f7f8c1..96af21efa8 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -42,7 +42,7 @@ def stats @graph_notes = DrupalNode.weekly_tallies('note', 52, @time).to_a.sort.to_json @graph_wikis = DrupalNode.weekly_tallies('page', 52, @time).to_a.sort.to_json - @graph_comments = DrupalComment.comment_weekly_tallies(52, @time).to_a.sort.to_json + @graph_comments = Comment.comment_weekly_tallies(52, @time).to_a.sort.to_json users = [] nids = [] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index cad0bd2008..28806563c6 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -143,7 +143,7 @@ def profile def likes @user = DrupalUsers.find_by_name(params[:id]) @title = "Liked by "+@user.name - @notes = @user.liked_notes.includes([:drupal_tag, :drupal_comments]) + @notes = @user.liked_notes.includes([:drupal_tag, :comments]) .paginate(page: params[:page], per_page: 20) @wikis = @user.liked_pages @tagnames = [] @@ -213,7 +213,7 @@ def reset end def comments - @comments = DrupalComment.limit(20) + @comments = Comment.limit(20) .order("timestamp DESC") .where(status: 0, uid: params[:id]) .paginate(page: params[:page], per_page: 30) diff --git a/app/models/answer.rb b/app/models/answer.rb index 970c320baa..dfb8bd6224 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -6,7 +6,7 @@ class Answer < ActiveRecord::Base belongs_to :drupal_node, foreign_key: 'nid', dependent: :destroy belongs_to :drupal_users, foreign_key: 'uid' has_many :answer_selections, foreign_key: 'aid' - has_many :drupal_comments, foreign_key: 'aid' + has_many :comments, foreign_key: 'aid' validates :content, presence: true diff --git a/app/models/drupal_comment.rb b/app/models/comment.rb similarity index 97% rename from app/models/drupal_comment.rb rename to app/models/comment.rb index 9b8a70bbe7..7df11a618f 100644 --- a/app/models/drupal_comment.rb +++ b/app/models/comment.rb @@ -1,4 +1,4 @@ -class DrupalComment < ActiveRecord::Base +class Comment < ActiveRecord::Base include CommentsShared # common methods for comment-like models attr_accessible :pid, :nid, :uid, :aid, @@ -23,7 +23,7 @@ def self.inheritance_column def self.comment_weekly_tallies(span = 52, time = Time.now) weeks = {} (0..span).each do |week| - weeks[span-week] = DrupalComment.select(:timestamp) + weeks[span-week] = Comment.select(:timestamp) .where(timestamp: time.to_i - week.weeks.to_i..time.to_i - (week-1).weeks.to_i) .count end diff --git a/app/models/concerns/node_shared.rb b/app/models/concerns/node_shared.rb index 9c0ea897e2..607f3dc955 100644 --- a/app/models/concerns/node_shared.rb +++ b/app/models/concerns/node_shared.rb @@ -8,9 +8,4 @@ def likes def liked_by(uid) self.likers.collect(&:uid).include?(uid) end - - def comments(direction = 'DESC') - self.drupal_comments - .order("timestamp #{direction}") - end end \ No newline at end of file diff --git a/app/models/drupal_node.rb b/app/models/drupal_node.rb index e5b9fceca1..3183406fc7 100644 --- a/app/models/drupal_node.rb +++ b/app/models/drupal_node.rb @@ -29,7 +29,7 @@ class DrupalNode < ActiveRecord::Base string :status string :updated_month text :comments do - drupal_comments.map { |comment| comment.comment } + comments.map { |comment| comment.comment } end string :user_name do @@ -72,7 +72,7 @@ def friendly_id_string has_many :drupal_tag, :through => :drupal_node_community_tag # these override the above... have to do it manually: # has_many :drupal_tag, :through => :drupal_node_tag - has_many :drupal_comments, :foreign_key => 'nid', :dependent => :destroy + has_many :comments, :foreign_key => 'nid', :dependent => :destroy has_many :drupal_content_type_map, :foreign_key => 'nid', :dependent => :destroy has_many :drupal_content_field_mappers, :foreign_key => 'nid', :dependent => :destroy has_many :drupal_content_field_map_editor, :foreign_key => 'nid', :dependent => :destroy @@ -232,7 +232,7 @@ def revision_count end def comment_count - self.drupal_comments + self.comments .count end @@ -552,7 +552,7 @@ def add_comment(params = {}) else thread = "01/" end - c = DrupalComment.new({ + c = Comment.new({ :pid => 0, :nid => self.nid, :uid => params[:uid], diff --git a/app/models/drupal_users.rb b/app/models/drupal_users.rb index c269d6255b..65512c3238 100644 --- a/app/models/drupal_users.rb +++ b/app/models/drupal_users.rb @@ -15,7 +15,7 @@ class DrupalUsers < ActiveRecord::Base has_many :node_selections, :foreign_key => :user_id has_many :answers, :foreign_key => :uid has_many :answer_selections, :foreign_key => :user_id - has_many :drupal_comments, :foreign_key => 'uid' + has_many :comments, :foreign_key => 'uid' has_one :location_tag, :foreign_key => 'uid', :dependent => :destroy searchable :if => proc { |user| user.status == 1 } do diff --git a/app/models/user.rb b/app/models/user.rb index 46ce28946d..376fd92769 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -156,7 +156,7 @@ def weekly_note_tally(span = 52) def weekly_comment_tally(span = 52) weeks = {} (0..span).each do |week| - weeks[span-week] = DrupalComment.count :all, :select => :timestamp, :conditions => {:uid => self.drupal_user.uid, :status => 1, :timestamp => Time.now.to_i-week.weeks.to_i..Time.now.to_i-(week-1).weeks.to_i} + weeks[span-week] = Comment.count :all, :select => :timestamp, :conditions => {:uid => self.drupal_user.uid, :status => 1, :timestamp => Time.now.to_i-week.weeks.to_i..Time.now.to_i-(week-1).weeks.to_i} end weeks end @@ -192,7 +192,7 @@ def comment_streak(span = 365) streak = 0 comment_count = 0 (0..span).each do |day| - days[day] = DrupalComment.count :all, :select => :timestamp, :conditions => {:uid => self.drupal_user.uid, :status => 1, :timestamp => Time.now.midnight.to_i-day.days.to_i..Time.now.midnight.to_i-(day-1).days.to_i} + days[day] = Comment.count :all, :select => :timestamp, :conditions => {:uid => self.drupal_user.uid, :status => 1, :timestamp => Time.now.midnight.to_i-day.days.to_i..Time.now.midnight.to_i-(day-1).days.to_i} break if days[day] == 0 streak+=1 comment_count+=days[day] diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 5c2230b265..38661d9691 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -44,7 +44,7 @@ def find_tags(input, limit=5) end def find_comments(input, limit=5) - DrupalComment.limit(limit) + Comment.limit(limit) .order('nid DESC') .where('status = 1 AND comment LIKE ?', '%' + input + '%') end diff --git a/app/services/typeahead_service.rb b/app/services/typeahead_service.rb index f31a8b896b..3e50ad773c 100644 --- a/app/services/typeahead_service.rb +++ b/app/services/typeahead_service.rb @@ -43,7 +43,7 @@ def find_tags(input, limit=5) end def find_comments(input, limit=5) - DrupalComment.limit(limit) + Comment.limit(limit) .order('nid DESC') .where('status = 1 AND comment LIKE ?', '%' + input + '%') end diff --git a/app/views/dashboard/_activity.html.erb b/app/views/dashboard/_activity.html.erb index 95b69422df..d6ab3078a9 100644 --- a/app/views/dashboard/_activity.html.erb +++ b/app/views/dashboard/_activity.html.erb @@ -51,7 +51,7 @@ <% activity.each_with_index do |node, i| %> <% if node.is_a?(DrupalNodeRevision) || node.type == 'page' %> <%= render partial: "dashboard/node_wiki", locals: { node: node, index: i } %> - <% elsif node.is_a?(DrupalComment) %> + <% elsif node.is_a?(Comment) %> <%= render partial: "dashboard/node_comment", locals: { node: node, index: i } %> <% elsif node.has_power_tag('question') %> <%= render partial: "dashboard/node_question", locals: { node: node, index: i } %> diff --git a/app/views/dashboard/_node_meta.html.erb b/app/views/dashboard/_node_meta.html.erb index 383e1d4e8b..7e2df1d5c1 100644 --- a/app/views/dashboard/_node_meta.html.erb +++ b/app/views/dashboard/_node_meta.html.erb @@ -1,4 +1,4 @@ -<% unless node.is_a?(DrupalComment) || node.is_a?(DrupalNodeRevision) || node.type == 'page' %> +<% unless node.is_a?(Comment) || node.is_a?(DrupalNodeRevision) || node.type == 'page' %> <%= t('dashboard.dashboard.by') %> <%= node.author.name %> <% end %> <%= distance_of_time_in_words(node.created_at, Time.current, false, :scope => :'datetime.time_ago_in_words') %> diff --git a/app/views/notes/_comments.html.erb b/app/views/notes/_comments.html.erb index ea3b7b10eb..bba3029782 100644 --- a/app/views/notes/_comments.html.erb +++ b/app/views/notes/_comments.html.erb @@ -2,11 +2,11 @@
-

<%= @node.drupal_comments.length %> <%= t('notes._comments.comments') %>

+

<%= @node.comments.length %> <%= t('notes._comments.comments') %>

- <% @node.drupal_comments.each do |comment| %> - <% if comment.cid == @node.drupal_comments.last.cid %><% end %> + <% @node.comments.order('timestamp ASC').each do |comment| %> + <% if comment.cid == @node.comments.first.cid %><% end %> <%= render :partial => "notes/comment", :locals => {:comment => comment} %> diff --git a/app/views/notes/stats.html.erb b/app/views/notes/stats.html.erb index d0b98ae609..959a621393 100644 --- a/app/views/notes/stats.html.erb +++ b/app/views/notes/stats.html.erb @@ -52,7 +52,7 @@
-

<%= raw t('notes.stats.comments_posted', :count => DrupalComment.count) %>

+

<%= raw t('notes.stats.comments_posted', :count => Comment.count) %>

<%= t('notes.stats.comments_posted_52_weeks') %>

diff --git a/app/views/questions/show.html.erb b/app/views/questions/show.html.erb index 769602f540..8c3ac66aa9 100644 --- a/app/views/questions/show.html.erb +++ b/app/views/questions/show.html.erb @@ -49,7 +49,7 @@

<%= @node.comments.length %> Comments

- <% @node.comments('ASC').each do |comment| %> + <% @node.comments.order("timestamp ASC").each do |comment| %> <%= render partial: "questions/comment", locals: { comment: comment, answer_id: 0 } %> <% end %> diff --git a/app/views/searches/_node_result.html.erb b/app/views/searches/_node_result.html.erb index 2d53d77b75..d331324f8c 100644 --- a/app/views/searches/_node_result.html.erb +++ b/app/views/searches/_node_result.html.erb @@ -11,7 +11,7 @@ <% if node.author.name.present? %> | by <%= node.author.name %> <% end %> - | <%= pluralize node.drupal_comments.count, 'comment' %> + | <%= pluralize node.comments.count, 'comment' %>
<%= node.drupal_node_revision.try(:first).try(:body).try(:first, 350) %>... diff --git a/db/migrate/20140501174856_add_comments_count_to_drupal_node.rb b/db/migrate/20140501174856_add_comments_count_to_drupal_node.rb index 21990a52f6..dfdbec64a7 100644 --- a/db/migrate/20140501174856_add_comments_count_to_drupal_node.rb +++ b/db/migrate/20140501174856_add_comments_count_to_drupal_node.rb @@ -1,13 +1,13 @@ class AddCommentsCountToDrupalNode < ActiveRecord::Migration def up - add_column :node, :drupal_comments_count, :integer, default: 0 + add_column :node, :comments_count, :integer, default: 0 DrupalNode.reset_column_information DrupalNode.all.each do |node| - DrupalNode.reset_counters(node.id, :drupal_comments) + DrupalNode.reset_counters(node.id, :comments) end end def down - remove_column :node, :drupal_comments_count + remove_column :node, :comments_count end end diff --git a/db/schema.rb.example b/db/schema.rb.example index 5b6f8bad68..bd0c6a7b78 100644 --- a/db/schema.rb.example +++ b/db/schema.rb.example @@ -199,7 +199,7 @@ ActiveRecord::Schema.define(:version => 20161122154603) do t.integer "tnid", :default => 0, :null => false t.integer "translate", :default => 0, :null => false t.integer "cached_likes", :default => 0 - t.integer "drupal_comments_count", :default => 0 + t.integer "comments_count", :default => 0 t.integer "drupal_node_revisions_count", :default => 0 t.string "path" t.integer "main_image_id" diff --git a/db/seeds.rb b/db/seeds.rb index 85afbdec61..305d3ad706 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -46,7 +46,7 @@ blog_post_tag = DrupalTag.create! "name"=>"blog", "description"=>"", "weight"=>0 blog_post_community_tag = DrupalNodeCommunityTag.create! "tid"=>blog_post_tag.id, "nid"=>blog_post.id, "uid"=>admin.id -blog_post_comment = DrupalComment.create! "nid"=>blog_post.id, "uid"=>admin.id, +blog_post_comment = Comment.create! "nid"=>blog_post.id, "uid"=>admin.id, "subject"=>"", "comment"=>"Example Comment\r\n", "hostname"=>"", "status"=>0, "format"=>1, "thread"=>"01/" diff --git a/test/functional/comment_controller_test.rb b/test/functional/comment_controller_test.rb index e283dc80d2..3d064443a4 100644 --- a/test/functional/comment_controller_test.rb +++ b/test/functional/comment_controller_test.rb @@ -14,7 +14,7 @@ def setup test "should create note comments" do UserSession.create(rusers(:bob)) - assert_difference 'DrupalComment.count' do + assert_difference 'Comment.count' do xhr :post, :create, id: node(:one).nid, body: "Notes comment" @@ -26,7 +26,7 @@ def setup test "should create question comments" do UserSession.create(rusers(:bob)) - assert_difference 'DrupalComment.count' do + assert_difference 'Comment.count' do xhr :post, :create, id: node(:question).nid, body: "Questions comment", @@ -39,7 +39,7 @@ def setup test "should show error if node comment not saved" do UserSession.create(rusers(:bob)) - assert_no_difference 'DrupalComment.count' do + assert_no_difference 'Comment.count' do xhr :post, :create, id: node(:one).nid end @@ -49,7 +49,7 @@ def setup test "should create answer comments" do UserSession.create(rusers(:bob)) - assert_difference 'DrupalComment.count' do + assert_difference 'Comment.count' do xhr :post, :answer_create, aid: answers(:one).id, body: "Answers comment" @@ -61,7 +61,7 @@ def setup test "should show error if answer comment not saved" do UserSession.create(rusers(:bob)) - assert_no_difference 'DrupalComment.count' do + assert_no_difference 'Comment.count' do xhr :post, :answer_create, aid: answers(:one).id end @@ -137,7 +137,7 @@ def setup test "should delete note comment if user is comment author" do UserSession.create(rusers(:bob)) comment = comments(:first) - assert_difference 'DrupalComment.count', -1 do + assert_difference 'Comment.count', -1 do xhr :get, :delete, id: comment.id end @@ -148,7 +148,7 @@ def setup test "should delete note comment if user is note author" do UserSession.create(rusers(:bob)) comment = comments(:second) - assert_difference 'DrupalComment.count', -1 do + assert_difference 'Comment.count', -1 do xhr :get, :delete, id: comment.id end @@ -159,7 +159,7 @@ def setup test "should delete note comment if user is admin" do UserSession.create(rusers(:admin)) comment = comments(:first) - assert_difference 'DrupalComment.count', -1 do + assert_difference 'Comment.count', -1 do xhr :get, :delete, id: comment.id end @@ -170,7 +170,7 @@ def setup test "should delete note comment if user is comment moderator" do UserSession.create(rusers(:moderator)) comment = comments(:first) - assert_difference 'DrupalComment.count', -1 do + assert_difference 'Comment.count', -1 do xhr :get, :delete, id: comment.id end @@ -181,7 +181,7 @@ def setup test "should not delete note comment if user is neither of the above" do UserSession.create(rusers(:newcomer)) comment = comments(:first) - assert_no_difference 'DrupalComment.count' do + assert_no_difference 'Comment.count' do get :delete, id: comment.id end @@ -192,7 +192,7 @@ def setup test "should delete question/answer comment if user is comment author" do UserSession.create(rusers(:bob)) comment = comments(:first) - assert_difference 'DrupalComment.count', -1 do + assert_difference 'Comment.count', -1 do xhr :get, :delete, id: comment.id, type: 'question' diff --git a/test/functional/notes_controller_test.rb b/test/functional/notes_controller_test.rb index dfea9154d3..8011af7f11 100644 --- a/test/functional/notes_controller_test.rb +++ b/test/functional/notes_controller_test.rb @@ -264,7 +264,7 @@ def teardown #end test "should load iframe url in comments" do - comment = DrupalComment.new({ + comment = Comment.new({ nid: node(:one).nid, uid: rusers(:bob).id, thread: "01/" @@ -386,10 +386,10 @@ def teardown end test "should assign correct value to graph_comments on GET stats" do - DrupalComment.delete_all - DrupalComment.create!({comment: 'blah', timestamp: Time.now() - 1}) + Comment.delete_all + Comment.create!({comment: 'blah', timestamp: Time.now() - 1}) get :stats - assert_equal assigns(:graph_comments), DrupalComment.comment_weekly_tallies(52, Time.now()).to_a.sort.to_json + assert_equal assigns(:graph_comments), Comment.comment_weekly_tallies(52, Time.now()).to_a.sort.to_json end test "should redirect to question path if node is a question when visiting shortlink" do diff --git a/test/functional/tag_controller_test.rb b/test/functional/tag_controller_test.rb index 0ceebc63bc..27870c301b 100644 --- a/test/functional/tag_controller_test.rb +++ b/test/functional/tag_controller_test.rb @@ -150,11 +150,11 @@ def setup test "adds comment when awarding a barnstar" do ApplicationController.any_instance.stubs(:current_user).returns(User.first) - assert_difference 'DrupalComment.count' do + assert_difference 'Comment.count' do post :barnstar, :nid => DrupalNode.last.nid, :star => "basic" - assert_equal "[@#{User.first.username}](/profile/#{User.first.username}) awards a barnstar to #{DrupalNode.last.drupal_users.name} for their awesome contribution!", DrupalComment.last.body + assert_equal "[@#{User.first.username}](/profile/#{User.first.username}) awards a barnstar to #{DrupalNode.last.drupal_users.name} for their awesome contribution!", Comment.last.body end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 347bd3df0a..97b9dabee9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -19,7 +19,7 @@ class ActiveSupport::TestCase set_fixture_class :tag_selection => TagSelection set_fixture_class :tags => DrupalTag set_fixture_class :community_tags => DrupalNodeCommunityTag - set_fixture_class :comments => DrupalComment + set_fixture_class :comments => Comment set_fixture_class :searches => SearchRecord fixtures :all diff --git a/test/unit/answer_test.rb b/test/unit/answer_test.rb index dd0f956208..ac59f42f2c 100644 --- a/test/unit/answer_test.rb +++ b/test/unit/answer_test.rb @@ -46,6 +46,6 @@ class AnswerTest < ActiveSupport::TestCase test "should list comments in descending order" do answer = answers(:one) - assert_equal answer.comments.first, DrupalComment.last + assert_equal answer.comments.last, Comment.last end end diff --git a/test/unit/drupal_comment_test.rb b/test/unit/comment_test.rb similarity index 81% rename from test/unit/drupal_comment_test.rb rename to test/unit/comment_test.rb index 275ac1fdc1..45de59b9c0 100644 --- a/test/unit/drupal_comment_test.rb +++ b/test/unit/comment_test.rb @@ -1,20 +1,20 @@ require 'test_helper' -class DrupalCommentTest < ActiveSupport::TestCase +class CommentTest < ActiveSupport::TestCase test "should save comment" do - comment = DrupalComment.new + comment = Comment.new comment.comment = "My first thought is\n\nthat this is pretty good." assert comment.save end test "should not save comment without body" do - comment = DrupalComment.new + comment = Comment.new assert !comment.save, "Saved the comment without body text" end test "should scan callouts out of body" do - comment = DrupalComment.new({ + comment = Comment.new({ nid: node(:one).nid, uid: rusers(:bob).id }) @@ -25,7 +25,7 @@ class DrupalCommentTest < ActiveSupport::TestCase end test "should scan multiple callouts out of body" do - comment = DrupalComment.new({ + comment = Comment.new({ nid: node(:one).nid, uid: rusers(:bob).id }) @@ -36,7 +36,7 @@ class DrupalCommentTest < ActiveSupport::TestCase end test "should scan multiple space-separated callouts out of body" do - comment = DrupalComment.new({ + comment = Comment.new({ nid: node(:one).nid, uid: rusers(:bob).id }) @@ -47,7 +47,7 @@ class DrupalCommentTest < ActiveSupport::TestCase end test "should scan hashtags in comments and link them" do - comment = DrupalComment.new({ + comment = Comment.new({ nid: node(:one).nid, uid: rusers(:bob).id }) @@ -56,7 +56,7 @@ class DrupalCommentTest < ActiveSupport::TestCase end test "should ignore Headers as hashtags in markdown" do - comment = DrupalComment.new({ + comment = Comment.new({ nid: node(:one).nid, uid: rusers(:bob).id }) @@ -65,7 +65,7 @@ class DrupalCommentTest < ActiveSupport::TestCase end test "should ignore commas, exclamation, periods in hashtag" do - comment = DrupalComment.new({ + comment = Comment.new({ nid: node(:one).nid, uid: rusers(:bob).id }) @@ -77,7 +77,7 @@ class DrupalCommentTest < ActiveSupport::TestCase end test "should link hashtags in headers" do - comment = DrupalComment.new({ + comment = Comment.new({ nid: node(:one).nid, uid: rusers(:bob).id }) @@ -86,7 +86,7 @@ class DrupalCommentTest < ActiveSupport::TestCase end test "should ignore sub-headings as hashtags" do - comment = DrupalComment.new({ + comment = Comment.new({ nid: node(:one).nid, uid: rusers(:bob).id }) @@ -95,7 +95,7 @@ class DrupalCommentTest < ActiveSupport::TestCase end test "should ignore Titles with spaces after hash as hashtags" do - comment = DrupalComment.new({ + comment = Comment.new({ nid: node(:one).nid, uid: rusers(:bob).id }) @@ -106,7 +106,7 @@ class DrupalCommentTest < ActiveSupport::TestCase end test "should ignore hashtag in links as nesting of links is not allowed" do - comment = DrupalComment.new({ + comment = Comment.new({ nid: node(:one).nid, uid: rusers(:bob).id }) @@ -115,7 +115,7 @@ class DrupalCommentTest < ActiveSupport::TestCase end test "should ignore hashtags in URLs" do - comment = DrupalComment.new({ + comment = Comment.new({ nid: node(:one).nid, uid: rusers(:bob).id }) @@ -125,7 +125,7 @@ class DrupalCommentTest < ActiveSupport::TestCase test "should create comments for answers" do answer = answers(:one) - comment = DrupalComment.new( + comment = Comment.new( uid: rusers(:bob).id, aid: answer.id, comment: 'Test comment' @@ -136,28 +136,27 @@ class DrupalCommentTest < ActiveSupport::TestCase test "should relate answer comments to user and answer but not node" do answer = answers(:one) user = users(:bob) - comment = DrupalComment.new(comment: 'Test comment') + comment = Comment.new(comment: 'Test comment') comment.drupal_users = user comment.answer = answer assert comment.save - assert_equal user.drupal_comments.last, comment - assert_equal answer.drupal_comments.last, comment - assert_not_equal answer.node.drupal_comments.last, comment + assert_equal user.comments.last, comment + end test "should return weekly tallies" do - DrupalComment.delete_all + Comment.delete_all seconds_to_two_weeks_ago = 1210000 seconds_to_four_weeks_ago = seconds_to_two_weeks_ago * 2 weeks_to_tally = 52 # placing a comment right before Time.now places it in week 51 so two weeks later is week 49 two_weeks_ago = weeks_to_tally - 3 four_weeks_ago = two_weeks_ago - 2 - DrupalComment.create!({comment: 'blah', timestamp: Time.now() - 1}) # place a comment right before now - DrupalComment.create!({comment: 'blah', timestamp: Time.now() - seconds_to_two_weeks_ago}) - DrupalComment.create!({comment: 'blahblah', timestamp: Time.now() - seconds_to_four_weeks_ago}) - weekly_tallies = DrupalComment.comment_weekly_tallies(52) + Comment.create!({comment: 'blah', timestamp: Time.now() - 1}) # place a comment right before now + Comment.create!({comment: 'blah', timestamp: Time.now() - seconds_to_two_weeks_ago}) + Comment.create!({comment: 'blahblah', timestamp: Time.now() - seconds_to_four_weeks_ago}) + weekly_tallies = Comment.comment_weekly_tallies(52) assert_equal weekly_tallies[weeks_to_tally - 1], 1 assert_equal weekly_tallies[two_weeks_ago], 1 assert_equal weekly_tallies[four_weeks_ago], 1