require File.dirname(__FILE__) + '/../spec_helper' module PluginSpecHelper def self.valid_parameters { :root => 'http://some-repos.com/plugins/test_plugin', :auto_updatable => true, :name => 'foo_plugin' } end def self.valid_plugin RemoteResources.stubs(:read_svn_repository).returns('trunk/\ntags/\nbranches/\n') Release.any_instance.stubs(:load_data_from_plugin_meta).returns(true) Release.any_instance.stubs(:get_revision_number_from_repository).returns(true) plugin = Plugin.new(self.valid_parameters) plugin end def self.valid_plugin_with_stubbed_scan plugin = self.valid_plugin plugin.stubs(:scan_root_for_releases).returns(Proc.new { plugin.releases.create( :source_url => plugin.root, :name => 'bleeding_edge', :author => 'Testy McTest', :email => 'test@testy.com', :homepage => 'http://www.mygreathomepage.com', :description => 'My great plugin', :summary => 'Plugin summary', :revision_number => 1234 ) }) plugin.save plugin end def self.stub_remote_resources_for_single_trunk_plugin RemoteResources.stubs(:read_svn_repository).returns('trunk/\ntags/\nbranches/\n') sample_info = < 'http://some-repos.com/plugins/test_plugin', :name => 'name with spaces' plugin.should_not_be_valid end specify "should require a name to not contain special characters" do plugin = Plugin.new :root => 'http://some-repos.com/plugins/test_plugin', :name => 'we!rd*name' plugin.should_not_be_valid end specify "should have a unique name" do saved_plugin = PluginSpecHelper.valid_plugin_with_stubbed_scan new_plugin = Plugin.new :root => 'http://some-repos.com/another_plugin', :name => saved_plugin.name new_plugin.should_not_be_valid end specify "should have a unique repository root" do saved_plugin = PluginSpecHelper.valid_plugin_with_stubbed_scan new_plugin = Plugin.new :root => saved_plugin.root new_plugin.should_not_be_valid end specify "should not be savable" do @plugin.save.should_be false end specify "should be creatable with full set of valid parameters" do @plugin = Plugin.new(@valid_params) @plugin.stubs(:scan_root_for_releases).returns(true) @plugin.save.should_be true end end context "New plugin with a non-existent repostiory" do setup do @plugin = Plugin.new :root => 'http://some-repos.com/plugins/test_plugin' RemoteResources.stubs(:read_svn_repository).raises(RemoteResources::URLNotFoundException) end specify "shouldn not be valid" do @plugin.should_not_be_valid end end context "Saved plugin" do setup do @plugin = PluginSpecHelper.valid_plugin_with_stubbed_scan end specify "should be valid" do @plugin.should_be_valid end specify "should have the author of the most recent release" do @plugin.author.should_equal "Testy McTest" end specify "should have the email address of the most recent release" do @plugin.email.should_equal "test@testy.com" end specify "should have the homepage of the most recent release" do @plugin.homepage.should_equal 'http://www.mygreathomepage.com' end specify "should have the summary of the most recent release" do @plugin.summary.should_equal 'Plugin summary' end specify "should have the description of the most recent release" do @plugin.description.should_equal 'My great plugin' end specify "should have a root ending in a forward slash" do @plugin.root.should_equal "http://some-repos.com/plugins/test_plugin/" end specify "should make sure root has a trailing slash" do @plugin.root = 'http://notrailingslash.com' @plugin.save @plugin.root.should_equal 'http://notrailingslash.com/' end specify "should allow auto update flag to be set" do @plugin.auto_updatable = false @plugin.save @plugin.should_not_be_auto_updatable end specify "should be locatable in the database" do Plugin.find(@plugin.id).should_equal @plugin end specify "should always have at least a bleeding edge release" do @plugin.should_have_at_least(1).releases @plugin.bleeding_edge.should_be_an_instance_of Release end specify "should have a created at timestamp" do @plugin.created_at.should_be_an_instance_of Time end specify "should have an updated at timestamp that matches the time its latest release was created" do @plugin.updated_at.should_be_an_instance_of Time @plugin.updated_at.should_equal @plugin.latest_release.created_at end end context "Plugin with one tagged release" do setup do @plugin = PluginSpecHelper.valid_plugin_with_stubbed_scan @plugin.releases.create(:source_url => 'http://myrepo.com/', :name => '0.1.1') end specify "should have two releases" do @plugin.should_have(2).releases end specify "should ignore bleeding edge when sent latest release" do @plugin.latest_release.name.should_equal '0.1.1' end end context "Plugin with two releases" do setup do @plugin = PluginSpecHelper.valid_plugin_with_stubbed_scan @plugin.releases.create(:source_url => 'http://myrepo.com/', :name => '0.1.1') @plugin.releases.create(:source_url => 'http://myrepo.com/', :name => '0.1.2') end specify "should have a release count of three" do @plugin.should_have(3).releases end specify "should ignore bleeding edge when sent latest release" do @plugin.latest_release.name.should_equal '0.1.2' end end context "Plugin with root that has a standard subversion layout and three tags" do setup do @plugin = PluginSpecHelper.valid_plugin @plugin.stubs(:repository_root).returns(%w(trunk tags)) @plugin.stubs(:repository_tags).returns(%w(rel-0.1 rel-0.2 rel-0.3)) @plugin.save end specify "should have four releases" do @plugin.should_have(4).releases end specify "should have a release for every tag found" do @plugin.releases.collect(&:name).should_include 'rel-0.1' @plugin.releases.collect(&:name).should_include 'rel-0.2' @plugin.releases.collect(&:name).should_include 'rel-0.3' end specify "should have a bleeding edge release for the trunk" do @plugin.bleeding_edge.should_be_an_instance_of Release @plugin.bleeding_edge.name.should_equal "bleeding_edge" @plugin.bleeding_edge.source_url.should_equal @plugin.root + "trunk" end end context "Plugin with root that has a standard subversion layout but no tags" do setup do @plugin = PluginSpecHelper.valid_plugin @plugin.stubs(:repository_root).returns(%w(trunk)) @plugin.save end specify "should only have a bleeding edge release for the trunk" do @plugin.should_have(1).releases @plugin.releases.first.should_equal @plugin.bleeding_edge end end context "Plugin with root that doesn't have a standard subversion layout" do setup do @plugin = PluginSpecHelper.valid_plugin @plugin.stubs(:repository_root).returns(%w(lib README init.rb)) @plugin.save end specify "should only have a bleeding edge release for the plugin root" do @plugin.should_have(1).releases @plugin.releases.first.should_equal @plugin.bleeding_edge end end # TODO: fix this spec. Had to comment it out because of the # new implementation of repository_root/repository_tags. Need # to find a way of having the same stub return different values # on subsequent calls. context "Plugin with existing releases" do setup do @plugin = PluginSpecHelper.valid_plugin @plugin.stubs(:repository_root).returns(%w(trunk tags)) @plugin.stubs(:repository_tags).returns(%w(rel-0.1)) @plugin.save end specify "should not add releases which already exist when updating" do @plugin.should_have(2).releases # the hope being that this would 're-stub' the plugin # @plugin.stubs(:repository_tags).returns(%w(rel-0.1 rel-0.2)) # # @plugin.scan_root_for_releases # @plugin.should_have(3).releases # @plugin.latest_release.name.should_equal 'rel-0.2' end end context "Plugin with a release that doesn't have an about.yml" do setup do Release.any_instance.stubs(:get_revision_number_from_repository).returns(true) RemoteResources.stubs(:remote_yaml_document).raises(Exception) @plugin = Plugin.new(PluginSpecHelper.valid_parameters) @plugin.stubs(:repository_root).returns(%w(trunk tags)) @plugin.stubs(:repository_tags).returns(%w(rel-0.1 rel-0.2 rel-0.3)) end specify "should disable release meta scanning and resave the release" do @plugin.save.should_be true end end context "Plugin with test results" do setup do @plugin = PluginSpecHelper.valid_plugin_with_stubbed_scan @plugin.test_results.create(SpecFixtures.valid_test_result_parameters) end specify "should have access to its associated results" do @plugin.should_have(1).test_results @plugin.test_results.first.should_be_an_instance_of TestResult end end