From eb9790f649084129746fca12660ef1c33f9c9a81 Mon Sep 17 00:00:00 2001 From: Gabriela Navarro Date: Mon, 9 Feb 2015 17:31:21 +0000 Subject: [PATCH] Add unit and functional tests for colab_integration plugin --- test/functional/colab_integration_plugin_controller_test.rb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ test/unit/article_test.rb | 27 +++++++++++++++++++++++++++ test/unit/community_test.rb | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+), 0 deletions(-) create mode 100644 test/functional/colab_integration_plugin_controller_test.rb create mode 100644 test/unit/article_test.rb create mode 100644 test/unit/community_test.rb diff --git a/test/functional/colab_integration_plugin_controller_test.rb b/test/functional/colab_integration_plugin_controller_test.rb new file mode 100644 index 0000000..f393ac6 --- /dev/null +++ b/test/functional/colab_integration_plugin_controller_test.rb @@ -0,0 +1,46 @@ +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 + @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 +end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb new file mode 100644 index 0000000..5748edd --- /dev/null +++ b/test/unit/article_test.rb @@ -0,0 +1,27 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' + +class ArticleTest < ActiveSupport::TestCase + def setup + @john = fast_create(Person, :name => "John Snow") + end + + should 'get the attributes of John TinyMceArticle' do + lord = fast_create(Person, :name => "Lord Commander") + article = create(TinyMceArticle, :name => "The Night's Watch Oath", :body => "Night gathers, and now my watch begins...", :profile => @john, :author => lord) + + attributes = article.attr_to_hash + + assert_equal attributes["type"], "TinyMceArticle" + assert_equal attributes["data"]["title"], "The Night's Watch Oath" + assert_equal attributes["data"]["author_id"], lord.id + end + + should 'get the attributes of John Event' do + article = create(Event, :name => "Run Away", :body => "...", :profile => @john) + + attributes = article.attr_to_hash + + assert_equal attributes["type"], "Event" + assert_equal attributes["data"]["title"], "Run Away" + end +end diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb new file mode 100644 index 0000000..6927402 --- /dev/null +++ b/test/unit/community_test.rb @@ -0,0 +1,68 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' + +class CommunityTest < ActiveSupport::TestCase + 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 = @communityA.attr_to_hash + + 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.save + + attributes = @communityA.attr_to_hash + + 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 -- libgit2 0.21.2