Skip to content

Commit

Permalink
List activities for subscriptions/digest (publiclab#2058)
Browse files Browse the repository at this point in the history
* Function changed

* test changed

* digest page showing all nodes for now

* Query worked

* unit test added

* view updated

* small change

* small change

* functional test added
  • Loading branch information
grvsachdeva authored and jywarren committed Feb 2, 2018
1 parent 2aa0caa commit e74969a
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 10 deletions.
7 changes: 6 additions & 1 deletion app/controllers/subscription_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class SubscriptionController < ApplicationController

respond_to :html, :xml, :json
before_filter :require_user, :only => [:create, :delete, :index]
before_filter :require_user, :only => [:create, :delete, :index, :digest]

def index
@title = "Subscriptions"
Expand Down Expand Up @@ -110,6 +110,11 @@ def delete
end
end

def digest
@wikis = current_user.content_followed_in_period(Time.now - 1.week, Time.now)
render :template => "subscriptions/digest"
end

private

def set_following(value,type,id)
Expand Down
11 changes: 8 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,13 @@ def questions
Node.questions.where(status: 1, uid: id)
end

def content_followed_in_past_period(time_period)
self.node.where("created >= #{time_period.to_i} AND changed >= #{time_period.to_i}")
def content_followed_in_period(start_time, end_time)
tagnames = TagSelection.where(following: true, user_id: uid)
node_ids = []
tagnames.each do |tagname|
node_ids = node_ids + NodeTag.where(tid: tagname.tid).collect(&:nid)
end
Node.where(nid: node_ids).where("created >= #{start_time.to_i} OR changed >= #{start_time.to_i} AND created <= #{end_time.to_i} AND changed <= #{end_time.to_i}")
end

def social_link(site)
Expand Down Expand Up @@ -345,4 +350,4 @@ def self.contributor_count_for(start_time,end_time)
contributors
end

end
end
3 changes: 3 additions & 0 deletions app/views/subscriptions/digest.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h2>Content you've subscribed to in the past week</h2>

<%= render partial: "wiki/wikis" %>
8 changes: 6 additions & 2 deletions app/views/wiki/_wikis.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
<% @wikis.each do |wiki| %>
<tr>
<td style="width:50%"><i class="fa fa-file"></i> <a href="<%= wiki.path %>"><%= wiki.latest.title %></a></td>
<td><%= distance_of_time_in_words(Time.at(wiki.latest.created_at), Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %> <%= raw t('wiki._wikis.by') %>
<% if params["action"] == "digest" %>
<td><%= distance_of_time_in_words(Time.at(wiki.updated_at), Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %> <%= raw t('wiki._wikis.by') %>
<% else %>
<td><%= distance_of_time_in_words(Time.at(wiki.latest.created_at), Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %> <%= raw t('wiki._wikis.by') %>
<% end %>
<a href="/profile/<%= wiki.latest.author.name %>"><%= wiki.latest.author.name %></a></td>
<td><%= wiki.revisions.length %></td>
<td class="hidden-xs"><%= number_with_delimiter(wiki.totalviews) %></td>
<td><%= number_with_delimiter(wiki.cached_likes) %></td>
</tr>
<% end %>
</table>
<%= will_paginate @wikis, :renderer => BootstrapPagination::Rails if @paginated %>
<%= will_paginate @wikis, :renderer => BootstrapPagination::Rails if @paginated %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
put 'subscribe/:type/:name' => 'subscription#add'
get 'subscribe/:type/:name' => 'subscription#add'
get 'subscriptions' => 'subscription#index'
get 'subscriptions/digest' => 'subscription#digest'

get 'wiki/stale' => 'wiki#stale'
get 'wiki/new' => 'wiki#new'
Expand Down
22 changes: 22 additions & 0 deletions test/functional/subscription_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'test_helper'

class SubscriptionControllerTest < ActionController::TestCase

def setup
activate_authlogic
end

test 'should redirect to login if user is not logged in and trying to access digest' do
get :digest

assert_redirected_to '/login'
end

test 'should show digest if user logged in' do
UserSession.create(users(:bob))
get :digest

assert_response :success
end

end
12 changes: 8 additions & 4 deletions test/unit/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ class UserTest < ActiveSupport::TestCase
assert !users(:bob).has_tag('test:no')
end

test 'returns nodes created in past given period of time' do
lurker = users(:lurker)
node2 = users(:lurker).node.find_by_nid(20)
assert_equal [node2], lurker.content_followed_in_past_period(2.hours.ago)
test 'returns nodes created in given period of time' do
bob = users(:bob)
node_count = 6
nodes_fix = [1,2,8,9,10,15]
count_return = bob.content_followed_in_period(2.hours.ago,Time.now).count
nodes_time = bob.content_followed_in_period(2.hours.ago,Time.now).pluck(:nid)
assert_equal node_count, count_return
assert_equal nodes_fix,nodes_time.sort
end

test 'returns value of power tag' do
Expand Down

0 comments on commit e74969a

Please sign in to comment.