colab_integration_plugin_controller_test.rb
2.06 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
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
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
end
should "return a hash with activities of the user" do
user = fast_create(Person, :name => "User")
fast_create(Community, :name => "User Community").add_member user
fast_create(Community, :name => "User Community 2").add_member user
assert_equal 2, user.activities_attrs.count
assert user.activities_attrs.first.has_key?("verb")
assert user.activities_attrs.first.has_key?("params")
assert user.activities_attrs.first["verb"] == "join_community"
end
end