sashimi 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,73 @@
1
+ $: << File.dirname(__FILE__) + "/../lib"
2
+ require 'sashimi'
3
+
4
+ class Test::Unit::TestCase
5
+ include Sashimi
6
+
7
+ def assert_not(condition, message = nil)
8
+ assert !condition, message
9
+ end
10
+
11
+ private
12
+ def initialize_repository_for_test(&block)
13
+ repository.prepare_installation
14
+ create_cache_file
15
+ create_plugin_directories
16
+ yield
17
+ remove_local_repository_path # make sure of clean up tmp dirs
18
+ end
19
+
20
+ def repository
21
+ create_repository
22
+ end
23
+
24
+ def create_repository(plugin_name = 'sashimi', url = 'git://github.com/jodosha/sashimi.git')
25
+ @repository ||= AbstractRepository.new(Plugin.new(plugin_name, url))
26
+ end
27
+
28
+ def plugin
29
+ create_plugin(nil, 'git://github.com/jodosha/sashimi.git')
30
+ end
31
+
32
+ def create_plugin(name, url = nil)
33
+ Plugin.new(name, url)
34
+ end
35
+
36
+ def cached_plugin
37
+ { 'sashimi' => {'type' => 'git'},
38
+ 'plugin' => {'type' => 'svn'},
39
+ 'plug-in' => {'type' => 'svn'} }
40
+ end
41
+
42
+ def create_plugin_directories
43
+ { 'plugin' => true, 'plug-in' => false }.each do |plugin, about|
44
+ create_plugin_directory(plugin, about)
45
+ end
46
+ end
47
+
48
+ def create_plugin_directory(plugin, about = true)
49
+ AbstractRepository.change_dir_to_local_repository
50
+ FileUtils.mkdir(plugin) unless File.exists?(plugin)
51
+ FileUtils.cd(plugin)
52
+ File.open('about.yml', 'w+'){|f| f.write({'summary' => "Plugin summary"}.to_yaml)} if about
53
+ AbstractRepository.change_dir_to_local_repository
54
+ end
55
+
56
+ def create_cache_file
57
+ File.open(repository.cache_file, 'w+'){|f| f.write(cached_plugin.to_yaml)}
58
+ end
59
+
60
+ def remove_local_repository_path
61
+ FileUtils.rm_rf(File.join(repository.class.find_home, 'sashimi_test'))
62
+ end
63
+ end
64
+
65
+ module Sashimi
66
+ class AbstractRepository
67
+ @@local_repository_sub_path = 'sashimi_test/.rails/plugins'
68
+ public :local_repository_path, :change_dir, :prepare_installation,
69
+ :cache_file, :add_to_cache, :remove_from_cache,
70
+ :cache_content, :change_dir_to_local_repository,
71
+ :change_dir_to_plugin_path, :plugins_dir, :copy_plugin_to_rails_app
72
+ end
73
+ end
@@ -0,0 +1,38 @@
1
+ require 'test/unit'
2
+ require 'test/test_helper'
3
+
4
+ class PluginTest < Test::Unit::TestCase
5
+ def test_initialize
6
+ assert plugin
7
+ assert plugin.repository
8
+ assert_nil plugin.name
9
+ end
10
+
11
+ def test_should_raise_invalid_uri_exception_on_nil_url
12
+ assert_raise(URI::InvalidURIError) { create_plugin(nil, nil) }
13
+ end
14
+
15
+ def test_should_guess_name_for_git_url
16
+ assert_equal 'sashimi', plugin.guess_name
17
+ end
18
+
19
+ def test_should_guess_name_for_svn_url
20
+ assert_equal 'sashimi', create_plugin(nil, 'http://dev.repository.com/svn/sashimi').guess_name
21
+ assert_equal 'sashimi', create_plugin(nil, 'http://dev.repository.com/svn/sashimi/trunk').guess_name
22
+ end
23
+
24
+ def test_should_instantiate_git_repository_for_git_url
25
+ assert_kind_of GitRepository, plugin.repository
26
+ end
27
+
28
+ def test_should_instantiate_svn_repository_for_not_git_url
29
+ assert_kind_of SvnRepository, create_plugin(nil, 'http://dev.repository.com/svn/sashimi/trunk').repository
30
+ end
31
+
32
+ def test_should_serialize_to_hash
33
+ initialize_repository_for_test do
34
+ expected = {'plugin' => {'type' => 'svn', 'summary' => 'Plugin summary'}}
35
+ assert_equal(expected, create_plugin('plugin', 'http://dev.repository.com/svn/plugin/trunk').to_hash)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,132 @@
1
+ require 'test/unit'
2
+ require 'test/test_helper'
3
+
4
+ class AbstractRepositoryTest < Test::Unit::TestCase
5
+ def test_initialize
6
+ assert repository
7
+ assert repository.plugin.name
8
+ assert repository.plugin.url
9
+ end
10
+
11
+ # CLASS CONSTANTS
12
+ def test_local_repository_path
13
+ assert_match(/\.rails\/plugins$/, repository.local_repository_path)
14
+ end
15
+
16
+ def test_cache_file
17
+ assert_equal(".plugins", repository.cache_file)
18
+ end
19
+
20
+ def test_plugins_dir
21
+ assert_equal('vendor/plugins', repository.plugins_dir)
22
+ end
23
+
24
+ # INSTANTIATE
25
+ def test_should_instantiate_repository_by_url
26
+ assert_kind_of(SvnRepository, AbstractRepository.instantiate_repository(create_plugin(nil, 'http://svn.com')))
27
+ assert_kind_of(GitRepository, AbstractRepository.instantiate_repository(plugin))
28
+ end
29
+
30
+ def test_should_instantiate_repository_by_cache
31
+ initialize_repository_for_test do
32
+ assert AbstractRepository.instantiate_repository(create_plugin('sashimi', ''))
33
+ end
34
+ end
35
+
36
+ def test_should_recognize_git_url
37
+ assert AbstractRepository.git_url?('git://github.com/jodosha/sashimi.git')
38
+ end
39
+
40
+ # COMMANDS
41
+ def test_should_list_all_installed_plugins
42
+ initialize_repository_for_test do
43
+ assert_equal("plug-in\t\t\nplugin\t\t\nsashimi\t\t", AbstractRepository.list)
44
+ end
45
+ end
46
+
47
+ # DIRECTORIES
48
+ def test_should_change_current_dir
49
+ repository.change_dir(repository.class.find_home)
50
+ assert_equal(repository.class.find_home, Dir.pwd)
51
+ end
52
+
53
+ def test_should_change_current_dir_with_local_repository_path
54
+ initialize_repository_for_test do
55
+ repository.change_dir_to_local_repository
56
+ assert_equal(repository.local_repository_path, Dir.pwd)
57
+ end
58
+ end
59
+
60
+ def test_should_change_current_dir_with_plugin_cache_path
61
+ initialize_repository_for_test do
62
+ FileUtils.mkdir_p(cached_plugin_path)
63
+ repository.change_dir_to_plugin_path
64
+ assert_equal(cached_plugin_path, Dir.pwd)
65
+ end
66
+ end
67
+
68
+ def _ignore_test_should_copy_plugin_to_a_rails_app
69
+ initialize_repository_for_test do
70
+ repository.change_dir_to_local_repository
71
+ create_repository('plugin', '').copy_plugin_to_rails_app
72
+ assert File.exists?(File.join('vendor', 'plugins', 'plugin', 'about.yml'))
73
+ end
74
+ end
75
+
76
+ # REPOSITORY
77
+ def test_should_prepare_installation
78
+ initialize_repository_for_test do
79
+ assert File.exists?(repository.local_repository_path)
80
+ assert_equal(repository.local_repository_path, Dir.pwd)
81
+ assert File.exists?(repository.cache_file)
82
+ end
83
+ end
84
+
85
+ # CACHE
86
+ def test_should_read_cache_content
87
+ initialize_repository_for_test do
88
+ assert_equal(cache_content, repository.cache_content)
89
+ end
90
+ end
91
+
92
+ def test_should_add_plugin_to_the_cache
93
+ initialize_repository_for_test do
94
+ expected = cache_content.merge(cached_plugin)
95
+ repository.add_to_cache(cached_plugin)
96
+ assert_equal expected, cache_content
97
+ end
98
+ end
99
+
100
+ def test_should_remove_plugin_from_cache
101
+ initialize_repository_for_test do
102
+ AbstractRepository.new(create_plugin('sashimi', '')).remove_from_cache
103
+ assert_equal({"plugin"=>{"type"=>"svn"}, "plug-in"=>{"type"=>"svn"}}, cache_content)
104
+ end
105
+ end
106
+
107
+ # ABOUT
108
+ def test_should_return_about_contents_from_about_yml
109
+ initialize_repository_for_test do
110
+ plugin = create_plugin('plugin', 'http://dev.repository.com/svn/plugin/trunk')
111
+ assert_equal({'summary' => "Plugin summary"}, plugin.about)
112
+ end
113
+ end
114
+
115
+ def test_should_return_empty_hash_for_unexstistent_about_yml
116
+ initialize_repository_for_test do
117
+
118
+ plugin = create_plugin('plug-in', 'http://dev.repository.com/svn/plug-in/trunk')
119
+ assert_equal({}, plugin.about)
120
+ end
121
+ end
122
+
123
+ private
124
+ def cache_content
125
+ FileUtils.cd(repository.local_repository_path)
126
+ YAML::load_file(repository.cache_file).to_hash
127
+ end
128
+
129
+ def cached_plugin_path
130
+ File.join(repository.local_repository_path, 'sashimi')
131
+ end
132
+ end
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+ require 'test/test_helper'
3
+
4
+ class GitRepositoryTest < Test::Unit::TestCase
5
+ def test_type
6
+ assert_equal('git', GitRepository.new(nil).scm_type)
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+ require 'test/test_helper'
3
+
4
+ class SvnRepositoryTest < Test::Unit::TestCase
5
+ def test_type
6
+ assert_equal('svn', SvnRepository.new(nil).scm_type)
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sashimi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luca Guidi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-19 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">"
21
+ - !ruby/object:Gem::Version
22
+ version: 0.0.0
23
+ version:
24
+ description: Sashimi is a local repository for Rails plugins.
25
+ email: guidi.luca@gmail.com
26
+ executables:
27
+ - sashimi
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ - CHANGELOG
33
+ files:
34
+ - CHANGELOG
35
+ - MIT-LICENSE
36
+ - Rakefile
37
+ - README
38
+ - sashimi.gemspec
39
+ - setup.rb
40
+ - bin/sashimi
41
+ - lib/sashimi/commands.rb
42
+ - lib/sashimi/plugin.rb
43
+ - lib/sashimi/repositories/abstract_repository.rb
44
+ - lib/sashimi/repositories/git_repository.rb
45
+ - lib/sashimi/repositories/svn_repository.rb
46
+ - lib/sashimi/repositories.rb
47
+ - lib/sashimi.rb
48
+ - test/test_helper.rb
49
+ - test/unit/plugin_test.rb
50
+ - test/unit/repositories/abstract_repository_test.rb
51
+ - test/unit/repositories/git_repository_test.rb
52
+ - test/unit/repositories/svn_repository_test.rb
53
+ has_rdoc: true
54
+ homepage: http://lucaguidi.com/pages/sashimi
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.1.1
76
+ signing_key:
77
+ specification_version: 2
78
+ summary: Rails plugins manager
79
+ test_files:
80
+ - test/unit/plugin_test.rb
81
+ - test/unit/repositories/abstract_repository_test.rb
82
+ - test/unit/repositories/git_repository_test.rb
83
+ - test/unit/repositories/svn_repository_test.rb