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