Commit e32f8e54 by Rocky Duan

fixed spec

parent ceaf5c0c
......@@ -37,11 +37,11 @@ DEFAULT_PER_PAGE = 20
require './api/search'
require './api/commentables'
require './api/tags'
require './api/comment_threads'
require './api/comments'
require './api/users'
require './api/votes'
require './api/tags'
require './api/notifications_and_subscriptions'
if environment.to_s == "development"
......
......@@ -10,7 +10,7 @@ class Activity
belongs_to :target, inverse_of: :activities, polymorphic: true, index: true, autosave: true
validates_presence_of :actor
validates_presence_of :target
#validates_presence_of :target
end
......@@ -82,7 +82,6 @@ class CommentThread < Content
end
def self.perform_search(params, options={})
puts "params: #{params}"
page = [1, options[:page] || 1].max
per_page = options[:per_page] || 20
sort_key = options[:sort_key]
......
class Commentable
attr_accessor :id
attr_accessor :id, :_type
alias_attribute :_id, :id
class << self; alias_method :find, :new; end
def initialize(id)
self.id = id
self._type = self.class.to_s
end
def self.where(params={})
params[:id] ? [self.new(params[:id])] : self
end
def comment_threads
......
......@@ -5,13 +5,10 @@ class Notification
field :notification_type, type: String
field :info, type: Hash
#belongs_to :actor, class_name: "User", inverse_of: :activities, index: true, autosave: true
#belongs_to :target, inverse_of: :activities, polymorphic: true, index: true, autosave: true
attr_accessible :notification_type, :info
validates_presence_of :notification_type
validates_presence_of :target
validates_presence_of :info
has_and_belongs_to_many :receivers, class_name: "User", inverse_of: :notifications, autosave: true
......
......@@ -43,11 +43,10 @@ class AtUserObserver < Mongoid::Observer
thread_title: thread_title,
thread_id: thread_id,
actor_username: content.author_with_anonymity(:username),
actor_id: content.author_with_anonymity(:id),
commentable_id: commentable_id,
}
)
notification.actor = content.author_with_anonymity
notification.target = content
receivers = new_user_ids.map { |id| User.find(id) }
receivers.delete(content.author)
notification.receivers << receivers
......
......@@ -24,10 +24,9 @@ class PostReplyObserver < Mongoid::Observer
comment_id: comment.id,
commentable_id: comment.comment_thread.commentable_id,
actor_username: comment.author_with_anonymity(:username),
actor_id: comment.author_with_anonymity(:id),
},
)
notification.actor = comment.author_with_anonymity
notification.target = comment
receivers = (comment.comment_thread.subscribers + comment.author_with_anonymity(:followers, [])).uniq_by(&:id)
receivers.delete(comment.author)
notification.receivers << receivers
......
......@@ -6,6 +6,14 @@ class PostTopicObserver < Mongoid::Observer
end
def self.generate_notifications(comment_thread)
activity = Activity.new
activity.happend_at = comment_thread.created_at
activity.anonymous = comment_thread.anonymous
activity.actor = comment_thread.author
#activity.target_id = comment_thread.commentable.id
#activity.target_type = comment_thread.commentable._type
activity.activity_type = "post_topic"
activity.save!
if comment_thread.commentable.subscribers or (author.followers if not anonymous)
notification = Notification.new(
notification_type: "post_topic",
......@@ -14,10 +22,9 @@ class PostTopicObserver < Mongoid::Observer
thread_id: comment_thread.id,
thread_title: comment_thread.title,
actor_username: comment_thread.author_with_anonymity(:username),
actor_id: comment_thread.author_with_anonymity(:id),
},
)
notification.actor = comment_thread.author_with_anonymity
notification.target = comment_thread
receivers = (comment_thread.commentable.subscribers + comment_thread.author_with_anonymity(:followers, [])).uniq_by(&:id)
receivers.delete(comment_thread.author)
notification.receivers << receivers
......
ENV["SINATRA_ENV"] = "test"
require File.join(File.dirname(__FILE__), '..', 'app')
require 'sinatra'
......@@ -20,6 +22,10 @@ RSpec.configure do |config|
config.include Rack::Test::Methods
end
Mongoid.configure do |config|
config.connect_to "cs_comments_service_test"
end
def parse(text)
Yajl::Parser.parse text
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment