community_test.rb
2.49 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
require File.dirname(__FILE__) + '/../../../../test/test_helper'
class CommunityTest < ActiveSupport::TestCase
include CommunityDataExport
def setup
@communityA = fast_create(Community, :name => "Community A")
@john = fast_create(Person, :name => "John Snow")
@arya = fast_create(Person, :name => "Arya Stark")
@joffrey = fast_create(Person, :name => "Joffrey Lannister")
@communityA.add_member @john
@communityA.add_admin @arya
end
should "get list of members on community A" do
attributes = community_attr_to_hash(@communityA)
assert_equal attributes["members-count"], 2
assert_equal attributes["members"].count, 2
member = attributes["members"].select { |member|
member["name"] == "Arya Stark"
}
assert_equal member.count, 1
assert member.first["is_admin"]
end
should "get software info from community A" do
environment = Environment.default
environment.enabled_plugins = ['MpogSoftwarePlugin']
environment.add_admin(@arya)
environment.save
thrones_the_game = SoftwareInfo.new
thrones_the_game.community_id = @communityA.id
thrones_the_game.public_software = true
license_gpl = LicenseInfo.create(
:version=>"CC-GPL-V2",
:link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt"
)
thrones_the_game.license_info = license_gpl
software = Category.create(:name => _("Software"), :environment => environment)
categories = []
categories << Category.create(:name => "TBS", :environment => environment, :parent => software)
categories << Category.create(:name => "War", :environment => environment, :parent => software)
thrones_the_game.community.categories << categories
thrones_the_game.finality = "teste"
thrones_the_game.save
@communityA.software_info = thrones_the_game
@communityA.save!
attributes = community_attr_to_hash(@communityA)
assert attributes.has_key?("software_data")
assert_equal attributes["software_data"]["public_software"], true
assert_equal attributes["software_data"]["acronym"], ""
assert attributes["software_data"].has_key?("license_info")
assert_equal attributes["software_data"]["license_info"]["version"], "CC-GPL-V2"
found_category = attributes["software_data"]["categories"].select { |category|
category["name"] == "TBS"
}
assert_equal attributes["software_data"]["categories"].count, 2
assert_equal found_category.count, 1
assert_equal found_category.first["name"], "TBS"
end
end