Commit eb9790f649084129746fca12660ef1c33f9c9a81

Authored by Gabriela Navarro
1 parent 049fef28
Exists in master

Add unit and functional tests for colab_integration plugin

Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
test/functional/colab_integration_plugin_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../../controllers/colab_integration_plugin_controller'
  3 +
  4 +class ColabIntegrationPluginController; def rescue_action(e) raise e end; end
  5 +
  6 +class ColabIntegrationPluginControllerTest < ActionController::TestCase
  7 +
  8 + def setup
  9 + @john = fast_create(Person, :name => "John Snow")
  10 + @arya = fast_create(Person, :name => "Arya Stark")
  11 + @joffrey = fast_create(Person, :name => "Joffrey Lannister")
  12 +
  13 + @stark = fast_create(Community, :name => "House Stark")
  14 + @stark.add_member @john
  15 + @stark.add_admin @arya
  16 +
  17 + @article = create(TinyMceArticle, :name => "The Night's Watch Oath", :body => "Night gathers, and now my watch begins...", :profile => @john)
  18 +
  19 + @game_of_thrones = fast_create(Community, :name => "Game of Thrones")
  20 + @game_of_thrones.add_member @john
  21 + @game_of_thrones.add_member @arya
  22 + @game_of_thrones.add_member @joffrey
  23 + end
  24 +
  25 + should "return a json with all information from the environment" do
  26 + get :index
  27 +
  28 + environment_data = JSON.parse(@response.body)
  29 + assert_equal environment_data["total"], 5
  30 +
  31 + persons = environment_data["profiles"].select{ |profile|
  32 + profile["type"] == "Person"
  33 + }
  34 + assert_equal persons.count, 3
  35 +
  36 + communities = environment_data["profiles"].select{ |profile|
  37 + profile["type"] == "Community"
  38 + }
  39 + assert_equal communities.count, 2
  40 +
  41 + persons_with_article = persons.select{ |person|
  42 + person["articles-count"] > 0
  43 + }
  44 + assert_equal persons_with_article.count, 1
  45 + end
  46 +end
... ...
test/unit/article_test.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +
  3 +class ArticleTest < ActiveSupport::TestCase
  4 + def setup
  5 + @john = fast_create(Person, :name => "John Snow")
  6 + end
  7 +
  8 + should 'get the attributes of John TinyMceArticle' do
  9 + lord = fast_create(Person, :name => "Lord Commander")
  10 + article = create(TinyMceArticle, :name => "The Night's Watch Oath", :body => "Night gathers, and now my watch begins...", :profile => @john, :author => lord)
  11 +
  12 + attributes = article.attr_to_hash
  13 +
  14 + assert_equal attributes["type"], "TinyMceArticle"
  15 + assert_equal attributes["data"]["title"], "The Night's Watch Oath"
  16 + assert_equal attributes["data"]["author_id"], lord.id
  17 + end
  18 +
  19 + should 'get the attributes of John Event' do
  20 + article = create(Event, :name => "Run Away", :body => "...", :profile => @john)
  21 +
  22 + attributes = article.attr_to_hash
  23 +
  24 + assert_equal attributes["type"], "Event"
  25 + assert_equal attributes["data"]["title"], "Run Away"
  26 + end
  27 +end
... ...
test/unit/community_test.rb 0 → 100644
... ... @@ -0,0 +1,68 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +
  3 +class CommunityTest < ActiveSupport::TestCase
  4 + def setup
  5 + @communityA = fast_create(Community, :name => "Community A")
  6 + @john = fast_create(Person, :name => "John Snow")
  7 + @arya = fast_create(Person, :name => "Arya Stark")
  8 + @joffrey = fast_create(Person, :name => "Joffrey Lannister")
  9 +
  10 + @communityA.add_member @john
  11 + @communityA.add_admin @arya
  12 + end
  13 +
  14 + should "get list of members on community A" do
  15 + attributes = @communityA.attr_to_hash
  16 +
  17 + assert_equal attributes["members-count"], 2
  18 + assert_equal attributes["members"].count, 2
  19 +
  20 + member = attributes["members"].select { |member|
  21 + member["name"] == "Arya Stark"
  22 + }
  23 +
  24 + assert_equal member.count, 1
  25 + assert member.first["is_admin"]
  26 + end
  27 +
  28 + should "get software info from community A" do
  29 + environment = Environment.default
  30 + environment.enabled_plugins = ['MpogSoftwarePlugin']
  31 + environment.add_admin(@arya)
  32 + environment.save
  33 +
  34 + thrones_the_game = SoftwareInfo.new
  35 + thrones_the_game.community_id = @communityA.id
  36 + thrones_the_game.public_software = true
  37 +
  38 + license_gpl = LicenseInfo.create(
  39 + :version=>"CC-GPL-V2",
  40 + :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt"
  41 + )
  42 + thrones_the_game.license_info = license_gpl
  43 +
  44 + software = Category.create(:name => _("Software"), :environment => environment)
  45 + categories = []
  46 + categories << Category.create(:name => "TBS", :environment => environment, :parent => software)
  47 + categories << Category.create(:name => "War", :environment => environment, :parent => software)
  48 + thrones_the_game.community.categories << categories
  49 +
  50 + thrones_the_game.save
  51 +
  52 + attributes = @communityA.attr_to_hash
  53 +
  54 + assert attributes.has_key?("software_data")
  55 + assert_equal attributes["software_data"]["public_software"], true
  56 + assert_equal attributes["software_data"]["acronym"], ""
  57 +
  58 + assert attributes["software_data"].has_key?("license_info")
  59 + assert_equal attributes["software_data"]["license_info"]["version"], "CC-GPL-V2"
  60 +
  61 + found_category = attributes["software_data"]["categories"].select { |category|
  62 + category["name"] == "TBS"
  63 + }
  64 + assert_equal attributes["software_data"]["categories"].count, 2
  65 + assert_equal found_category.count, 1
  66 + assert_equal found_category.first["name"], "TBS"
  67 + end
  68 +end
... ...