diff --git a/app/api/srch/search.rb b/app/api/srch/search.rb
index cf2a5caa22..30eef7afa2 100644
--- a/app/api/srch/search.rb
+++ b/app/api/srch/search.rb
@@ -77,7 +77,7 @@ class Search < Grape::API
doc_type: 'QUESTIONS',
doc_url: model.path(:question),
doc_title: model.title,
- score: model.answers.length
+ score: model.comments.length
)
end
DocList.new(results_list.flatten, search_request)
@@ -257,7 +257,7 @@ class Search < Grape::API
doc_type: 'QUESTIONS',
doc_url: model.path(:question),
doc_title: model.title,
- score: model.answers.length
+ score: model.comments.length
)
end
@@ -320,7 +320,7 @@ class Search < Grape::API
doc_title: model.title,
doc_author: model.user.username,
doc_image_url: model.images.empty? ? 0 : model.images.first.path,
- score: model.answers.length,
+ score: model.comments.length,
latitude: model.lat,
longitude: model.lon,
blurred: model.blurred?,
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 35e2e9fcbb..d71b65fe3b 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -137,7 +137,7 @@ def set_locale
end
def comments_node_and_path
- @node = @comment.aid == 0 ? @comment.node : @comment.answer.node
+ @node = @comment.node
@path = params[:type] && params[:type] == 'question' ? @node.path(:question) : @node.path
end
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index ed11c2ace1..47a46a8719 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -145,22 +145,14 @@ def activity
# group by day: http://stackoverflow.com/questions/5970938/group-by-day-from-timestamp
comments = comments.group('DATE(FROM_UNIXTIME(timestamp))') if Rails.env == 'production'
comments = comments.to_a # ensure it can be serialized for caching
- answer_comments = Comment.joins(:answer, :user)
- .order('timestamp DESC')
- .where('timestamp - answers.created_at > ?', 86_400)
- .limit(20)
- .group(['answers.id', 'comments.cid']) # ONLY_FULL_GROUP_BY, issue #3120
- answer_comments = answer_comments.group('DATE(FROM_UNIXTIME(timestamp))') if Rails.env == 'production'
- answer_comments = answer_comments.to_a # ensure it can be serialized for caching
- activity = (notes + wikis + comments + answer_comments).sort_by(&:created_at).reverse
+ activity = (notes + wikis + comments).sort_by(&:created_at).reverse
response = [
activity,
blog,
notes,
wikis,
revisions,
- comments,
- answer_comments
+ comments
]
response
end
diff --git a/app/models/answer.rb b/app/models/answer.rb
deleted file mode 100644
index 0c15a3fb43..0000000000
--- a/app/models/answer.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-class Answer < ApplicationRecord
- include CommentsShared
- include NodeShared
- extend RawStats
-
- belongs_to :node, foreign_key: 'nid'
- belongs_to :user, foreign_key: 'uid'
- has_many :answer_selections, foreign_key: 'aid'
- has_many :comments, foreign_key: 'aid', dependent: :destroy
-
- validates :content, presence: true
-
- scope :past_week, -> { where("created_at > ?", (Time.now - 7.days)) }
- scope :past_month, -> { where("created_at > ?", (Time.now - 1.months)) }
-
- def body
- finder = content.gsub(Callouts.const_get(:FINDER), Callouts.const_get(:PRETTYLINKMD))
- finder = finder.gsub(Callouts.const_get(:HASHTAGNUMBER), Callouts.const_get(:NODELINKMD))
- finder.gsub(Callouts.const_get(:HASHTAG), Callouts.const_get(:HASHLINKMD))
- end
-
- def body_markdown
- RDiscount.new(body, :autolink).to_html
- end
-
- # users who like this answer
- def likers
- answer_selections
- .joins(:user)
- .references(:rusers)
- .where(liking: true)
- .where('rusers.status': 1)
- .collect(&:user)
- end
-end
diff --git a/app/models/comment.rb b/app/models/comment.rb
index 34cc0a3e9b..61960055e8 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -4,7 +4,6 @@ class Comment < ApplicationRecord
belongs_to :node, foreign_key: 'nid', touch: true, counter_cache: true
belongs_to :user, foreign_key: 'uid'
- belongs_to :answer, foreign_key: 'aid'
has_many :likes, as: :likeable
has_many :replied_comments, class_name: "Comment", foreign_key: 'reply_to', dependent: :destroy
@@ -21,7 +20,7 @@ class Comment < ApplicationRecord
def self.inheritance_column
'rails_type'
end
-
+
def self.search(query)
Comment.where('MATCH(comment) AGAINST(?)', query)
.where(status: 1)
@@ -90,7 +89,7 @@ def next_thread
end
def parent
- aid.zero? ? node : answer&.node
+ node
end
def status_value
@@ -155,14 +154,14 @@ def notify(current_user)
uids = uids_to_notify - already
uids+= current_user.followers.collect(&:uid)
uids.uniq!
-
+
# Send Browser Notification Using Action Cable
notify_user_ids = uids_to_notify + already
notify_user_ids = notify_user_ids.uniq
send_browser_notification notify_user_ids
-
+
uids = uids.select { |i| i != 0 } # remove bad comments (some early ones lack uid)
-
+
notify_users(uids, current_user)
notify_tag_followers(already + uids)
end
diff --git a/app/models/node.rb b/app/models/node.rb
index 6cbcf678f9..130818f145 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -91,7 +91,6 @@ def updated_month
has_many :drupal_content_field_map_editor, foreign_key: 'nid' # , dependent: :destroy # re-enable in Rails 5
has_many :images, foreign_key: :nid
has_many :node_selections, foreign_key: :nid, dependent: :destroy
- has_many :answers, foreign_key: :nid, dependent: :destroy
belongs_to :user, foreign_key: 'uid'
@@ -639,7 +638,7 @@ def self.for_tagname_and_type(tagname, type = 'note', options = {})
def self.for_wildcard_tagname_and_type(tagname, type = 'note')
search_term = tagname[0..-2] + '%'
Node.where(status: 1, type: type)
- .includes(:revision, :tag, :answers)
+ .includes(:revision, :tag)
.references(:term_data, :node_revisions)
.where('term_data.name LIKE (?) OR term_data.parent LIKE (?)', search_term, search_term)
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 259651849d..b3d1bdb336 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -57,7 +57,6 @@ module Frequency
has_many :following_users, through: :active_relationships, source: :followed
has_many :followers, through: :passive_relationships, source: :follower
has_many :likes
- has_many :answers, foreign_key: :uid
has_many :answer_selections, foreign_key: :user_id
has_many :revisions, through: :node
has_many :comments, foreign_key: :uid
@@ -436,11 +435,10 @@ def find_by_username_case_insensitive(username)
# all users who've posted a node, comment, or answer in the given period
def contributor_count_for(start_time, end_time)
notes = Node.where(type: 'note', status: 1, created: start_time.to_i..end_time.to_i).pluck(:uid)
- answers = Answer.where(created_at: start_time..end_time).pluck(:uid)
questions = Node.questions.where(status: 1, created: start_time.to_i..end_time.to_i).pluck(:uid)
comments = Comment.where(timestamp: start_time.to_i..end_time.to_i).pluck(:uid)
revisions = Revision.where(status: 1, timestamp: start_time.to_i..end_time.to_i).pluck(:uid)
- contributors = (notes + answers + questions + comments + revisions).compact.uniq.size
+ contributors = (notes + questions + comments + revisions).compact.uniq.size
contributors
end
@@ -467,12 +465,11 @@ def create_with_omniauth(auth)
def count_all_time_contributor
notes = Node.where(type: 'note', status: 1).pluck(:uid)
- answers = Answer.pluck(:uid)
questions = Node.questions.where(status: 1).pluck(:uid)
comments = Comment.pluck(:uid)
revisions = Revision.where(status: 1).pluck(:uid)
- (notes + answers + questions + comments + revisions).compact.uniq.size
+ (notes + questions + comments + revisions).compact.uniq.size
end
def watching_location(nwlat, selat, nwlng, selng)
diff --git a/app/views/home/home.html.erb b/app/views/home/home.html.erb
index c9906c38be..fc0a196d1c 100644
--- a/app/views/home/home.html.erb
+++ b/app/views/home/home.html.erb
@@ -1,7 +1,6 @@
<% cache('feature_home-intro', skip_digest: true) do %>
<%= feature("home-intro") %>
<% end %>
-
diff --git a/app/views/questions/_questions_shadow.html.erb b/app/views/questions/_questions_shadow.html.erb
index 7ca030bf30..8ba911886c 100644
--- a/app/views/questions/_questions_shadow.html.erb
+++ b/app/views/questions/_questions_shadow.html.erb
@@ -15,7 +15,7 @@
diff --git a/db/migrate/20220726161355_drop_answers.rb b/db/migrate/20220726161355_drop_answers.rb
new file mode 100644
index 0000000000..6fb9296679
--- /dev/null
+++ b/db/migrate/20220726161355_drop_answers.rb
@@ -0,0 +1,5 @@
+class DropAnswers < ActiveRecord::Migration[5.2]
+ def change
+ drop_table :answers
+ end
+end
diff --git a/test/fixtures/answers.yml b/test/fixtures/answers.yml
deleted file mode 100644
index a23a85ffff..0000000000
--- a/test/fixtures/answers.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-one:
- id: 1
- uid: 1
- nid: 8
- content: Test answer
- created_at: <%= Time.now %>
- updated_at: <%= Time.now %>
- cached_likes: 1
- accepted: false
-
-two:
- id: 2
- uid: 2
- nid: 8
- content: Another Test answer
- created_at: <%= Time.now %>
- updated_at: <%= Time.now %>
- cached_likes: 0
- accepted: true
diff --git a/test/fixtures/comments.yml b/test/fixtures/comments.yml
index 7fa6f60c63..950737b4f6 100644
--- a/test/fixtures/comments.yml
+++ b/test/fixtures/comments.yml
@@ -50,16 +50,14 @@ moderator:
answer_comment_one:
uid: 1
- nid: 0
- aid: 1
+ nid: 56
status: 1
comment: Answer comment one
timestamp: <%= Time.now.to_i + 7 %>
answer_comment_two:
uid: 2
- nid: 0
- aid: 1
+ nid: 56
status: 1
comment: Answer comment two
timestamp: <%= Time.now.to_i + 8 %>
@@ -75,7 +73,6 @@ wiki_comment:
question:
uid: 1
nid: 8
- aid: 0
status: 1
comment: Question comment
timestamp: <%= Time.now.to_i + 9 %>
@@ -104,7 +101,6 @@ comment_status_4:
question_one:
uid: 2
nid: 8
- aid: 0
status: 1
comment: Question comment one
timestamp: <%= Time.now.to_i + 11 %>
@@ -113,7 +109,6 @@ question_one:
question_callout:
uid: 2
nid: 8
- aid: 0
status: 1
comment: Hey, @bob nice question
timestamp: <%= Time.now.to_i + 12 %>
@@ -122,7 +117,6 @@ question_callout:
question_tag:
uid: 2
nid: 8
- aid: 0
status: 1
comment: 'Question #everything'
timestamp: <%= Time.now.to_i + 13 %>
diff --git a/test/fixtures/nodes.yml b/test/fixtures/nodes.yml
index 82a9c0e3f7..259e62dddf 100644
--- a/test/fixtures/nodes.yml
+++ b/test/fixtures/nodes.yml
@@ -686,3 +686,16 @@ email:
type: "note"
cached_likes: 0
slug: "note-email-links"
+
+# Node to link comments with no parent nodes, so that other tests don't fail
+dummy_node:
+ nid: 56
+ uid: 2
+ title: "Dummy Node"
+ path: "/notes/jeff/12-23-2020/dummy-node"
+ created: <%= DateTime.new(2020,12,23).to_i %>
+ changed: <%= DateTime.new(2020,12,23).to_i %>
+ status: 8 # Intentional status so that other tests do not fail.
+ type: "note"
+ cached_likes: 0
+ slug: "note-dummy-node"
\ No newline at end of file
diff --git a/test/functional/api/search_api_test.rb b/test/functional/api/search_api_test.rb
index 234e39829b..9d9413156b 100644
--- a/test/functional/api/search_api_test.rb
+++ b/test/functional/api/search_api_test.rb
@@ -128,7 +128,7 @@ def app
end
test 'search Tag Nearby Nodes functionality with a valid query' do
- get '/api/srch/taglocations?nwlat=180.0&selat=0.0&nwlng=0.0&selng=176.5'
+ get "/api/srch/taglocations?nwlat=180.0&selat=0.0&nwlng=0.0&selng=176.5"
assert last_response.ok?
# Expected search pattern
@@ -178,7 +178,7 @@ def app
end
test 'search Tag Nearby Nodes functionality with a valid query and specific period' do
- get '/api/srch/taglocations?nwlat=171.0&selat=0.0&nwlng=0.0&selng=174.8&sort_by=recent&order_direction=ASC&to=2018-08-16'
+ get "/api/srch/taglocations?nwlat=171.0&selat=0.0&nwlng=0.0&selng=174.8&sort_by=recent&order_direction=ASC&to=2018-08-16" # Very weird Test failing here
assert last_response.ok?
# Expected search pattern
@@ -204,7 +204,7 @@ def app
end
test 'search Tag Nearby Nodes functionality with a valid query and from date greater then to date' do
- get '/api/srch/taglocations?nwlat=180.0&selat=0.0&nwlng=0.0&selng=180.0&sort_by=recent&order_direction=ASC&from=2018-08-16&to=2018-07-31'
+ get "/api/srch/taglocations?nwlat=180.0&selat=0.0&nwlng=0.0&selng=180.0&sort_by=recent&order_direction=ASC&from=2018-08-16&to=2018-07-31"
assert last_response.ok?
# Expected search pattern
diff --git a/test/functional/comment_controller_test.rb b/test/functional/comment_controller_test.rb
index 3a68dbe4e3..003d26bda2 100644
--- a/test/functional/comment_controller_test.rb
+++ b/test/functional/comment_controller_test.rb
@@ -174,7 +174,7 @@ def teardown
post :update, params: { id: comment.id, body: new_comment_body, type: 'question' }
comment.reload
assert_equal new_comment_body, comment.comment
- assert_redirected_to comment.answer.node.path(:question) + '?_=' + Time.now.to_i.to_s
+ assert_redirected_to comment.node.path(:question) + '?_=' + Time.now.to_i.to_s
assert_equal flash[:notice], 'Comment updated.'
end
diff --git a/test/functional/home_controller_test.rb b/test/functional/home_controller_test.rb
index ac3bfb8a5e..99ac9fc2df 100644
--- a/test/functional/home_controller_test.rb
+++ b/test/functional/home_controller_test.rb
@@ -11,7 +11,7 @@ def setup
get :home
assert_response :success
- assert_select "title", Sanitize.clean('🎈') + (" Public Lab: #{title}")
+ assert_select "title", Sanitize.clean('🎈') + (" Public Lab: #{title}") # Test failing here
end
test 'home should redirect to dashboard if logged in' do
diff --git a/test/functional/notes_controller_test.rb b/test/functional/notes_controller_test.rb
index ab327888de..ccce09ac48 100644
--- a/test/functional/notes_controller_test.rb
+++ b/test/functional/notes_controller_test.rb
@@ -803,17 +803,12 @@ def test_get_rss_feed
UserSession.create(users(:moderator))
node = nodes(:question)
node.save
- answer1 = answers(:one)
- answer1.save
- answer2 = answers(:two)
- answer2.save
n_count = Node.count
post :delete, params: { id: node.id }, xhr: true
assert_response :success
assert_equal Node.count, n_count - 1
- assert_equal Answer.count, 0
end
test 'moderator can publish the draft' do
diff --git a/test/functional/questions_controller_test.rb b/test/functional/questions_controller_test.rb
index 57f87571a9..a4d8d90a3d 100644
--- a/test/functional/questions_controller_test.rb
+++ b/test/functional/questions_controller_test.rb
@@ -96,7 +96,7 @@ def setup
assert_response :success
assert_equal assigns(:title), 'Unanswered questions'
assert_not_nil assigns(:questions)
- assert_equal assigns(:questions).first.answers.length, 0
+ assert_equal assigns(:questions).first.comments.length, 0
assert_template :index
end
diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb
index 47c6b8eef3..781fbc1eb0 100644
--- a/test/functional/wiki_controller_test.rb
+++ b/test/functional/wiki_controller_test.rb
@@ -484,7 +484,7 @@ def teardown
assert_response :success
assert_template :index
- assert_select "title", Sanitize.clean('🎈') + (" Public Lab: Popular wiki pages")
+ assert_select "title", Sanitize.clean('🎈') + (" Public Lab: Popular wiki pages") # Test failing here
end
test 'should display well liked wiki pages' do
diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb
index 16020ce226..7f1f8a6dcc 100644
--- a/test/unit/comment_test.rb
+++ b/test/unit/comment_test.rb
@@ -155,10 +155,8 @@ def setup
end
test 'should create comments for answers' do
- answer = answers(:one)
comment = Comment.new(
uid: users(:bob).id,
- aid: answer.id,
comment: 'Test comment'
)
assert comment.save
diff --git a/test/unit/doc_result_test.rb b/test/unit/doc_result_test.rb
index 16d6dcbf1f..cbed17e4b1 100644
--- a/test/unit/doc_result_test.rb
+++ b/test/unit/doc_result_test.rb
@@ -9,7 +9,7 @@ class DocResultTest < ActiveSupport::TestCase
doc_type: 'QUESTIONS',
doc_url: question.path(:question),
doc_title: question.title,
- score: question.answers.length
+ score: question.comments.length
)
assert_equal question.nid, result.doc_id
diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb
index 91a955f240..e7a8373f94 100644
--- a/test/unit/node_test.rb
+++ b/test/unit/node_test.rb
@@ -381,6 +381,7 @@ def setup
nodes(:hashtag_in_link),
nodes(:hashtag_in_url),
nodes(:email),
+ nodes(:dummy_node)
]
assert_equal expected, notes
end