colab_integration_plugin_controller_test.rb
2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require File.dirname(__FILE__) + '/../../../../test/test_helper'
require File.dirname(__FILE__) + '/../../controllers/colab_integration_plugin_controller'
class ColabIntegrationPluginController; def rescue_action(e) raise e end; end
class ColabIntegrationPluginControllerTest < ActionController::TestCase
include ProfileDataExport
def setup
@controller = ColabIntegrationPluginController.new
@john = fast_create(Person, :name => "John Snow")
@arya = fast_create(Person, :name => "Arya Stark")
@joffrey = fast_create(Person, :name => "Joffrey Lannister")
@stark = fast_create(Community, :name => "House Stark")
@stark.add_member @john
@stark.add_admin @arya
@article = create(TinyMceArticle, :name => "The Night's Watch Oath", :body => "Night gathers, and now my watch begins...", :profile => @john)
@game_of_thrones = fast_create(Community, :name => "Game of Thrones")
@game_of_thrones.add_member @john
@game_of_thrones.add_member @arya
@game_of_thrones.add_member @joffrey
end
should "return a json with all information from the environment" do
get :index
environment_data = JSON.parse(@response.body)
assert_equal environment_data["total"], 5
persons = environment_data["profiles"].select{ |profile|
profile["type"] == "Person"
}
assert_equal persons.count, 3
communities = environment_data["profiles"].select{ |profile|
profile["type"] == "Community"
}
assert_equal communities.count, 2
persons_with_article = persons.select{ |person|
person["articles-count"] > 0
}
assert_equal persons_with_article.count, 1
assert_nothing_raised do
Time.parse environment_data["timestamp"]
end
end
should "return a json with only the last updated profiles" do
time = Time.at 0
Profile.destroy_all
kingsland = Community.create!(:name => "Kings Land", :identifier => "kings-land")
winterfell = Community.create!(:name => "Winterfell", :identifier => "winterfell")
get :index, :timestamp => time.to_s
environment_data = JSON.parse(@response.body)
assert_equal environment_data["total"], 2
winterfell.updated_at = time
winterfell.save!
get :index, :timestamp => time.to_s
environment_data = JSON.parse(@response.body)
assert_equal environment_data["total"], 1
end
should "return a hash with activities of the user" do
person = fast_create(Person, :name => "User")
fast_create(Community, :name => "User Community").add_member person
fast_create(Community, :name => "User Community 2").add_member person
attrs = attr_to_hash(person)
assert_equal 2, attrs['activities-count']
assert attrs['activities'].first.has_key?("verb")
assert attrs['activities'].first.has_key?("params")
assert attrs['activities'].first["verb"] == "join_community"
end
end