From 5ab5223463cf5f2b2b75d62b61e068f13dad05e1 Mon Sep 17 00:00:00 2001 From: Luciano Prestes Cavalcanti Date: Tue, 10 Feb 2015 10:12:09 -0200 Subject: [PATCH] Add unit tests to methods license_info and another_license of SoftwareInfo --- test/helpers/plugin_test_helper.rb | 7 +++++++ test/unit/software_info_test.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 0 deletions(-) create mode 100644 test/unit/software_info_test.rb diff --git a/test/helpers/plugin_test_helper.rb b/test/helpers/plugin_test_helper.rb index 10bea2a..a3f0063 100644 --- a/test/helpers/plugin_test_helper.rb +++ b/test/helpers/plugin_test_helper.rb @@ -78,4 +78,11 @@ module PluginTestHelper user end + def create_license_info version, link = "" + license = LicenseInfo.create(:version => version) + license.link = link + license.save + + license + end end diff --git a/test/unit/software_info_test.rb b/test/unit/software_info_test.rb new file mode 100644 index 0000000..b6fc5ce --- /dev/null +++ b/test/unit/software_info_test.rb @@ -0,0 +1,44 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' + +class SoftwareInfoValidationTest < ActiveSupport::TestCase + + include PluginTestHelper + + def setup + @license_another = create_license_info("Another") + end + + should "Return original license_info when license is not 'Another'" do + @software_info = create_software_info("software_test") + @license_info = create_license_info("license_test") + + @software_info.license_info = @license_info + + assert_equal @software_info.license_info, @license_info + end + + should "Return license_info with nil id when license is 'Another'" do + @software_info = create_software_info("software_test") + + @software_info.license_info = @license_another + + assert_equal @software_info.license_info_id, @license_another.id + assert_equal @software_info.license_info.id, nil + end + + should "Return fake license_info when call method another_license" do + @software_info = create_software_info("software_test") + + another_license_version = "Another Version" + another_license_link = "#another_link" + + @software_info.another_license(another_license_version, another_license_link) + + assert_equal @software_info.license_info_id, @license_another.id + assert_equal @software_info.license_info.id, nil + assert_equal @software_info.license_info.version, another_license_version + assert_equal @software_info.license_info.link, another_license_link + end + +end \ No newline at end of file -- libgit2 0.21.2