gritano 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. data/Gemfile +9 -17
  2. data/Gemfile.lock +78 -50
  3. data/Guardfile +9 -0
  4. data/README.rdoc +23 -24
  5. data/Rakefile +8 -12
  6. data/TODO +12 -8
  7. data/VERSION +1 -1
  8. data/bin/gritano +8 -1
  9. data/bin/gritano-remote +16 -2
  10. data/gritano.gemspec +52 -230
  11. data/lib/gritano.rb +12 -6
  12. data/lib/gritano/config.rb +11 -31
  13. data/lib/gritano/console/base.rb +6 -74
  14. data/lib/gritano/console/git.rb +29 -0
  15. data/lib/gritano/console/local.rb +131 -0
  16. data/lib/gritano/console/remote.rb +47 -93
  17. data/lib/gritano/core/key.rb +18 -0
  18. data/lib/gritano/core/user.rb +12 -0
  19. data/lib/gritano/helpers.rb +52 -0
  20. data/lib/gritano/renderer.rb +36 -0
  21. data/lib/gritano/thor.rb +27 -0
  22. data/spec/data/development.yml +2 -0
  23. data/spec/gritano/console/git_spec.rb +55 -0
  24. data/spec/gritano/console/local_spec.rb +148 -0
  25. data/spec/gritano/console/remote_spec.rb +56 -0
  26. data/spec/gritano/core/key_spec.rb +21 -0
  27. data/spec/gritano/core/user_spec.rb +43 -0
  28. data/spec/gritano/helpers_spec.rb +113 -0
  29. data/spec/gritano/thor_spec.rb +29 -0
  30. data/spec/spec_helper.rb +1 -16
  31. data/templates/local.gritano +4 -0
  32. data/templates/remote.gritano +5 -0
  33. metadata +61 -280
  34. data/.gritano/config.yml +0 -2
  35. data/.gritano/database.yml +0 -2
  36. data/.ssh/.gitignore +0 -4
  37. data/bin/gritano-pub-key +0 -15
  38. data/db/migrate/001_create_users.rb +0 -8
  39. data/db/migrate/002_create_repositories.rb +0 -9
  40. data/db/migrate/003_create_permissions.rb +0 -10
  41. data/db/migrate/004_create_keys.rb +0 -11
  42. data/db/migrate/005_add_admin_to_users.rb +0 -10
  43. data/db/migrate/006_add_email_to_users.rb +0 -10
  44. data/db/migrate/007_add_password_to_users.rb +0 -10
  45. data/db/migrate/008_remove_password_from_user.rb +0 -10
  46. data/db/migrate/009_remove_email_from_users.rb +0 -10
  47. data/features/data/config_true.yml +0 -2
  48. data/features/data/local_commands/repo_add_tmp_jeka_git.txt +0 -1
  49. data/features/data/local_commands/repo_add_tmp_p_lang_git.txt +0 -1
  50. data/features/data/local_commands/repo_add_tmp_p_lang_git_igorbonadio.txt +0 -1
  51. data/features/data/local_commands/repo_add_tmp_p_lang_git_igorbonadio_jessicaeto.txt +0 -1
  52. data/features/data/local_commands/repo_list.txt +0 -6
  53. data/features/data/local_commands/repo_read_add_tmp_gritano_git_arybonadio.txt +0 -1
  54. data/features/data/local_commands/repo_read_add_tmp_gritano_git_jessicaeto.txt +0 -1
  55. data/features/data/local_commands/repo_read_add_tmp_p_lang_git_jessicaeto.txt +0 -1
  56. data/features/data/local_commands/repo_read_rm_tmp_jeka_git_aribonadio.txt +0 -1
  57. data/features/data/local_commands/repo_read_rm_tmp_jeka_git_igorbonadio.txt +0 -1
  58. data/features/data/local_commands/repo_read_rm_tmp_p_lang_git_igorbonadio.txt +0 -1
  59. data/features/data/local_commands/repo_rm_tmp_jeka_git.txt +0 -1
  60. data/features/data/local_commands/repo_rm_tmp_p_lang_git.txt +0 -1
  61. data/features/data/local_commands/repo_user_list_tmp_jeka_git.txt +0 -6
  62. data/features/data/local_commands/repo_user_list_tmp_ruby_git.txt +0 -1
  63. data/features/data/local_commands/repo_write_add_tmp_gritano_git_arybonadio.txt +0 -1
  64. data/features/data/local_commands/repo_write_add_tmp_gritano_git_jessicaeto.txt +0 -1
  65. data/features/data/local_commands/repo_write_add_tmp_p_lang_git_jessicaeto.txt +0 -1
  66. data/features/data/local_commands/repo_write_rm_tmp_gritano_git_arybonadio.txt +0 -1
  67. data/features/data/local_commands/repo_write_rm_tmp_gritano_git_igorbonadio.txt +0 -1
  68. data/features/data/local_commands/repo_write_rm_tmp_p_lang_git_igorbonadio.txt +0 -1
  69. data/features/data/local_commands/user_add_igorbonadio.txt +0 -1
  70. data/features/data/local_commands/user_add_jose.txt +0 -1
  71. data/features/data/local_commands/user_admin_add_arybonadio.txt +0 -1
  72. data/features/data/local_commands/user_admin_add_igorbonadio.txt +0 -1
  73. data/features/data/local_commands/user_admin_rm_arybonadio.txt +0 -1
  74. data/features/data/local_commands/user_admin_rm_igorbonadio.txt +0 -1
  75. data/features/data/local_commands/user_key_add_igorbonadio_marvin.txt +0 -1
  76. data/features/data/local_commands/user_key_add_userrr_marvino.txt +0 -1
  77. data/features/data/local_commands/user_key_list_arybonadio.txt +0 -1
  78. data/features/data/local_commands/user_key_list_igorbonadio.txt +0 -5
  79. data/features/data/local_commands/user_key_rm_igorbonadio_eva.txt +0 -1
  80. data/features/data/local_commands/user_key_rm_igorbonadio_marvino.txt +0 -1
  81. data/features/data/local_commands/user_list.txt +0 -6
  82. data/features/data/local_commands/user_repo_list_arybonadio.txt +0 -1
  83. data/features/data/local_commands/user_repo_list_igorbonadio.txt +0 -6
  84. data/features/data/local_commands/user_rm_igorbonadio.txt +0 -1
  85. data/features/data/local_commands/user_rm_jose.txt +0 -1
  86. data/features/data/local_commands/version.txt +0 -1
  87. data/features/data/local_help.txt +0 -32
  88. data/features/data/remote_commands/admin_help_igorbonadio.txt +0 -32
  89. data/features/data/remote_commands/admin_help_jessicaeto.txt +0 -32
  90. data/features/data/remote_commands/admin_repo_add_tmp_jeka_git_igorbonadio.txt +0 -1
  91. data/features/data/remote_commands/admin_repo_add_tmp_jeka_git_jessicaeto.txt +0 -1
  92. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio.txt +0 -1
  93. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio_igorbonadio.txt +0 -1
  94. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio_jessicaeto.txt +0 -1
  95. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio_jessicaeto_igorbonadio.txt +0 -1
  96. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio_jessicaeto_jessicaeto.txt +0 -1
  97. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_jessicaeto.txt +0 -1
  98. data/features/data/remote_commands/admin_repo_list_igorbonadio.txt +0 -6
  99. data/features/data/remote_commands/admin_repo_list_jessicaeto.txt +0 -1
  100. data/features/data/remote_commands/admin_repo_read_add_tmp_gritano_git_arybonadio_igorbonadio.txt +0 -1
  101. data/features/data/remote_commands/admin_repo_read_add_tmp_gritano_git_arybonadio_jessicaeto.txt +0 -1
  102. data/features/data/remote_commands/admin_repo_read_add_tmp_gritano_git_jessicaeto_igorbonadio.txt +0 -1
  103. data/features/data/remote_commands/admin_repo_read_add_tmp_gritano_git_jessicaeto_jessicaeto.txt +0 -1
  104. data/features/data/remote_commands/admin_repo_read_add_tmp_p_lang_git_jessicaeto_igorbonadio.txt +0 -1
  105. data/features/data/remote_commands/admin_repo_read_add_tmp_p_lang_git_jessicaeto_jessicaeto.txt +0 -1
  106. data/features/data/remote_commands/admin_repo_read_rm_tmp_jeka_git_aribonadio_igorbonadio.txt +0 -1
  107. data/features/data/remote_commands/admin_repo_read_rm_tmp_jeka_git_aribonadio_jessicaeto.txt +0 -1
  108. data/features/data/remote_commands/admin_repo_read_rm_tmp_jeka_git_igorbonadio_igorbonadio.txt +0 -1
  109. data/features/data/remote_commands/admin_repo_read_rm_tmp_jeka_git_igorbonadio_jessicaeto.txt +0 -1
  110. data/features/data/remote_commands/admin_repo_read_rm_tmp_p_lang_git_igorbonadio_igorbonadio.txt +0 -1
  111. data/features/data/remote_commands/admin_repo_read_rm_tmp_p_lang_git_igorbonadio_jessicaeto.txt +0 -1
  112. data/features/data/remote_commands/admin_repo_rm_tmp_jeka_git_igorbonadio.txt +0 -1
  113. data/features/data/remote_commands/admin_repo_rm_tmp_jeka_git_jessicaeto.txt +0 -1
  114. data/features/data/remote_commands/admin_repo_rm_tmp_p_lang_git_igorbonadio.txt +0 -1
  115. data/features/data/remote_commands/admin_repo_rm_tmp_p_lang_git_jessicaeto.txt +0 -1
  116. data/features/data/remote_commands/admin_repo_user_list_tmp_jeka_git_igorbonadio.txt +0 -6
  117. data/features/data/remote_commands/admin_repo_user_list_tmp_jeka_git_jessicaeto.txt +0 -1
  118. data/features/data/remote_commands/admin_repo_user_list_tmp_ruby_git_igorbonadio.txt +0 -1
  119. data/features/data/remote_commands/admin_repo_user_list_tmp_ruby_git_jessicaeto.txt +0 -1
  120. data/features/data/remote_commands/admin_repo_write_add_tmp_gritano_git_arybonadio_igorbonadio.txt +0 -1
  121. data/features/data/remote_commands/admin_repo_write_add_tmp_gritano_git_arybonadio_jessicaeto.txt +0 -1
  122. data/features/data/remote_commands/admin_repo_write_add_tmp_gritano_git_jessicaeto_igorbonadio.txt +0 -1
  123. data/features/data/remote_commands/admin_repo_write_add_tmp_gritano_git_jessicaeto_jessicaeto.txt +0 -1
  124. data/features/data/remote_commands/admin_repo_write_add_tmp_p_lang_git_jessicaeto_igorbonadio.txt +0 -1
  125. data/features/data/remote_commands/admin_repo_write_add_tmp_p_lang_git_jessicaeto_jessicaeto.txt +0 -1
  126. data/features/data/remote_commands/admin_repo_write_rm_tmp_gritano_git_arybonadio_igorbonadio.txt +0 -1
  127. data/features/data/remote_commands/admin_repo_write_rm_tmp_gritano_git_arybonadio_jessicaeto.txt +0 -1
  128. data/features/data/remote_commands/admin_repo_write_rm_tmp_gritano_git_igorbonadio_igorbonadio.txt +0 -1
  129. data/features/data/remote_commands/admin_repo_write_rm_tmp_gritano_git_igorbonadio_jessicaeto.txt +0 -1
  130. data/features/data/remote_commands/admin_repo_write_rm_tmp_p_lang_git_igorbonadio_igorbonadio.txt +0 -1
  131. data/features/data/remote_commands/admin_repo_write_rm_tmp_p_lang_git_igorbonadio_jessicaeto.txt +0 -1
  132. data/features/data/remote_commands/admin_user_add_igorbonadio_igorbonadio.txt +0 -1
  133. data/features/data/remote_commands/admin_user_add_igorbonadio_jessicaeto.txt +0 -1
  134. data/features/data/remote_commands/admin_user_add_jose_igorbonadio.txt +0 -1
  135. data/features/data/remote_commands/admin_user_add_jose_jessicaeto.txt +0 -1
  136. data/features/data/remote_commands/admin_user_admin_add_arybonadio_igorbonadio.txt +0 -1
  137. data/features/data/remote_commands/admin_user_admin_add_arybonadio_jessicaeto.txt +0 -1
  138. data/features/data/remote_commands/admin_user_admin_add_igorbonadio_igorbonadio.txt +0 -1
  139. data/features/data/remote_commands/admin_user_admin_add_igorbonadio_jessicaeto.txt +0 -1
  140. data/features/data/remote_commands/admin_user_admin_rm_arybonadio_igorbonadio.txt +0 -1
  141. data/features/data/remote_commands/admin_user_admin_rm_arybonadio_jessicaeto.txt +0 -1
  142. data/features/data/remote_commands/admin_user_admin_rm_igorbonadio_igorbonadio.txt +0 -1
  143. data/features/data/remote_commands/admin_user_admin_rm_igorbonadio_jessicaeto.txt +0 -1
  144. data/features/data/remote_commands/admin_user_key_add_igorbonadio_marvin_igorbonadio.txt +0 -1
  145. data/features/data/remote_commands/admin_user_key_add_igorbonadio_marvin_jessicaeto.txt +0 -1
  146. data/features/data/remote_commands/admin_user_key_add_userrr_marvino_igorbonadio.txt +0 -1
  147. data/features/data/remote_commands/admin_user_key_add_userrr_marvino_jessicaeto.txt +0 -1
  148. data/features/data/remote_commands/admin_user_key_list_arybonadio_igorbonadio.txt +0 -1
  149. data/features/data/remote_commands/admin_user_key_list_arybonadio_jessicaeto.txt +0 -1
  150. data/features/data/remote_commands/admin_user_key_list_igorbonadio_igorbonadio.txt +0 -5
  151. data/features/data/remote_commands/admin_user_key_list_igorbonadio_jessicaeto.txt +0 -1
  152. data/features/data/remote_commands/admin_user_key_rm_igorbonadio_eva_igorbonadio.txt +0 -1
  153. data/features/data/remote_commands/admin_user_key_rm_igorbonadio_eva_jessicaeto.txt +0 -1
  154. data/features/data/remote_commands/admin_user_key_rm_igorbonadio_marvino_igorbonadio.txt +0 -1
  155. data/features/data/remote_commands/admin_user_key_rm_igorbonadio_marvino_jessicaeto.txt +0 -1
  156. data/features/data/remote_commands/admin_user_list_igorbonadio.txt +0 -6
  157. data/features/data/remote_commands/admin_user_list_jessicaeto.txt +0 -1
  158. data/features/data/remote_commands/admin_user_repo_list_arybonadio_igorbonadio.txt +0 -1
  159. data/features/data/remote_commands/admin_user_repo_list_arybonadio_jessicaeto.txt +0 -1
  160. data/features/data/remote_commands/admin_user_repo_list_igorbonadio_igorbonadio.txt +0 -6
  161. data/features/data/remote_commands/admin_user_repo_list_igorbonadio_jessicaeto.txt +0 -1
  162. data/features/data/remote_commands/admin_user_rm_igorbonadio_igorbonadio.txt +0 -1
  163. data/features/data/remote_commands/admin_user_rm_igorbonadio_jessicaeto.txt +0 -1
  164. data/features/data/remote_commands/admin_user_rm_jose_igorbonadio.txt +0 -1
  165. data/features/data/remote_commands/admin_user_rm_jose_jessicaeto.txt +0 -1
  166. data/features/data/remote_commands/admin_version_igorbonadio.txt +0 -1
  167. data/features/data/remote_commands/admin_version_jessicaeto.txt +0 -1
  168. data/features/data/remote_commands/email_get_igorbonadio.txt +0 -1
  169. data/features/data/remote_commands/email_get_jessicaeto.txt +0 -1
  170. data/features/data/remote_commands/email_update_email@server_com_igorbonadio.txt +0 -1
  171. data/features/data/remote_commands/email_update_email@server_com_jessicaeto.txt +0 -1
  172. data/features/data/remote_commands/help_igorbonadio.txt +0 -14
  173. data/features/data/remote_commands/help_jessicaeto.txt +0 -14
  174. data/features/data/remote_commands/invalid_command_igorbonadio.txt +0 -14
  175. data/features/data/remote_commands/invalid_command_jessicaeto.txt +0 -14
  176. data/features/data/remote_commands/key_add_keyname_igorbonadio.txt +0 -1
  177. data/features/data/remote_commands/key_add_keyname_jessicaeto.txt +0 -1
  178. data/features/data/remote_commands/key_list_igorbonadio.txt +0 -5
  179. data/features/data/remote_commands/key_list_jessicaeto.txt +0 -5
  180. data/features/data/remote_commands/key_rm_hal_igorbonadio.txt +0 -1
  181. data/features/data/remote_commands/key_rm_hal_jessicaeto.txt +0 -1
  182. data/features/data/remote_commands/repo_list_igorbonadio.txt +0 -6
  183. data/features/data/remote_commands/repo_list_jessicaeto.txt +0 -5
  184. data/features/data/remote_commands/version_igorbonadio.txt +0 -1
  185. data/features/data/remote_commands/version_jessicaeto.txt +0 -1
  186. data/features/data/remote_help.txt +0 -14
  187. data/features/install.feature +0 -40
  188. data/features/local.feature +0 -80
  189. data/features/pub_key.feature +0 -25
  190. data/features/remote.feature +0 -150
  191. data/features/step_definitions/background_step.rb +0 -26
  192. data/features/step_definitions/install_step.rb +0 -30
  193. data/features/step_definitions/local_step.rb +0 -25
  194. data/features/step_definitions/pub_key_step.rb +0 -15
  195. data/features/step_definitions/remote_step.rb +0 -49
  196. data/features/support/database_cleaner.rb +0 -15
  197. data/features/support/env.rb +0 -30
  198. data/lib/gritano/cli.rb +0 -49
  199. data/lib/gritano/console.rb +0 -26
  200. data/lib/gritano/console/executor.rb +0 -298
  201. data/lib/gritano/console/gritano.rb +0 -35
  202. data/lib/gritano/console/installer.rb +0 -55
  203. data/lib/gritano/models.rb +0 -7
  204. data/lib/gritano/models/key.rb +0 -37
  205. data/lib/gritano/models/permission.rb +0 -39
  206. data/lib/gritano/models/repository.rb +0 -29
  207. data/lib/gritano/models/user.rb +0 -39
  208. data/spec/cli_spec.rb +0 -26
  209. data/spec/config_spec.rb +0 -64
  210. data/spec/console_base_spec.rb +0 -61
  211. data/spec/console_executor_spec.rb +0 -183
  212. data/spec/console_gritano_spec.rb +0 -121
  213. data/spec/console_installer_spec.rb +0 -28
  214. data/spec/console_remote_spec.rb +0 -70
  215. data/spec/console_spec.rb +0 -27
  216. data/spec/data/help_command_name.txt +0 -7
  217. data/spec/model_key_spec.rb +0 -44
  218. data/spec/model_permission_spec.rb +0 -72
  219. data/spec/model_repository_spec.rb +0 -56
  220. data/spec/model_user_spec.rb +0 -96
@@ -1,29 +0,0 @@
1
- module Gritano
2
- class Repository < ActiveRecord::Base
3
- validates :name, presence: true
4
- validates_uniqueness_of :name
5
-
6
- has_many :permissions
7
- has_many :users, through: :permissions
8
-
9
- before_create :create_bare_repo
10
- after_destroy :destroy_bare_repo
11
-
12
- def create_bare_repo
13
- Grit::Repo.init_bare(full_path)
14
- end
15
-
16
- def destroy_bare_repo
17
- FileUtils.rm_r(full_path, force: true)
18
- end
19
-
20
- def full_path
21
- if path
22
- File.join(path, name)
23
- else
24
- name
25
- end
26
- end
27
-
28
- end
29
- end
@@ -1,39 +0,0 @@
1
- require 'bcrypt'
2
-
3
- module Gritano
4
- class User < ActiveRecord::Base
5
- include BCrypt
6
-
7
- validates :login, presence: true
8
- validates_uniqueness_of :login
9
-
10
- has_many :permissions
11
- has_many :repositories, through: :permissions
12
- has_many :keys
13
-
14
- def add_access(repo, access)
15
- change_access(repo, "add", access)
16
- end
17
-
18
- def remove_access(repo, access)
19
- change_access(repo, "remove", access)
20
- end
21
-
22
- def change_access(repo, op, access)
23
- permission = Permission.find_by_user_id_and_repository_id(self.id, repo.id) || Permission.new
24
- permission.user_id = self.id
25
- permission.repository_id = repo.id
26
- if permission.send("#{op}_access", access)
27
- return permission.save
28
- else
29
- return false
30
- end
31
- end
32
-
33
- def check_access(repo, access)
34
- permission = Permission.find_by_user_id_and_repository_id(self.id, repo.id)
35
- return permission.is(access) if permission
36
- return false
37
- end
38
- end
39
- end
@@ -1,26 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- module Gritano
4
- describe CLI do
5
- it "should execute local commands" do
6
- console = double()
7
- console.should_receive(:execute).and_return([true, "ok"])
8
- Gritano::Console.should_receive(:remote_console).with(false, Etc.getpwuid.dir)
9
- Gritano::Console::Gritano.should_receive(:new).and_return(console)
10
- CLI.execute(["user:list"])
11
- end
12
-
13
- it "should execute remote commands" do
14
- console = double()
15
- console.should_receive(:execute).and_return([true, "ok"])
16
- Gritano::Console.should_receive(:remote_console).with(true, Etc.getpwuid.dir)
17
- Gritano::Console::Remote.should_receive(:new).and_return(console)
18
- CLI.check(["repo:list"], "login")
19
- end
20
-
21
- it "should check public keys" do
22
- Key.should_receive(:find_by_key).and_return(nil)
23
- CLI.check_pub_key("key", ".")
24
- end
25
- end
26
- end
@@ -1,64 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- module Gritano
4
- describe Config do
5
- it "should get parameters" do
6
- config = Config.new(File.join(".gritano", "config.yml"))
7
- config.host_url.should be == "gritano.org"
8
- end
9
-
10
- it "should add parameters" do
11
- FileUtils.mkdir_p('tmp')
12
- if File.exist?(File.join("tmp", "config_test.yml"))
13
- FileUtils.rm(File.join("tmp", "config_test.yml"))
14
- end
15
- config = Config.new(File.join("tmp", "config_test.yml"))
16
- config.host_url.should be == "undefined"
17
- config.host_url = "gritano.org"
18
- config.host_url.should be == "gritano.org"
19
- end
20
-
21
- it "should remove parameters" do
22
- FileUtils.mkdir_p('tmp')
23
- if File.exist?(File.join("tmp", "config_test.yml"))
24
- FileUtils.rm(File.join("tmp", "config_test.yml"))
25
- end
26
- config = Config.new(File.join("tmp", "config_test.yml"))
27
-
28
- config.host_url = "gritano.org"
29
- config.host_url.should be == "gritano.org"
30
-
31
- config.remove(:host_url)
32
- config.host_url.should be == "undefined"
33
- end
34
-
35
- it "should modify parameters" do
36
- FileUtils.mkdir_p('tmp')
37
- if File.exist?(File.join("tmp", "config_test.yml"))
38
- FileUtils.rm(File.join("tmp", "config_test.yml"))
39
- end
40
- config = Config.new(File.join("tmp", "config_test.yml"))
41
- config.host_url.should be == "undefined"
42
- config.host_url = "gritano.org"
43
- config.host_url.should be == "gritano.org"
44
- config.host_url = "host.org"
45
- config.host_url.should be == "host.org"
46
- end
47
-
48
- it "should save a config file" do
49
- FileUtils.mkdir_p('tmp')
50
- if File.exist?(File.join("tmp", "config_test.yml"))
51
- FileUtils.rm(File.join("tmp", "config_test.yml"))
52
- end
53
- config = Config.new(File.join("tmp", "config_test.yml"))
54
- config.host_url = "gritano.org"
55
- config.email = {login: 'igor', smtp: 'smtp.igor.com'}
56
- config.save
57
-
58
- config2 = Config.new(File.join("tmp", "config_test.yml"))
59
- config2.host_url.should be == "gritano.org"
60
- config2.email[:login].should be == "igor"
61
- config2.email[:smtp].should be == "smtp.igor.com"
62
- end
63
- end
64
- end
@@ -1,61 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- module Gritano
4
- module Console
5
- describe Base do
6
- def create_base(home)
7
- stdin = double()
8
- stdin.stub(:read).and_return("Your SSHKEY here...")
9
- Base.new(stdin, home)
10
- end
11
-
12
- it "should define commands" do
13
- Base.should_receive(:define_method).with("command_name")
14
- Base.add_command "command:name", "parameters" do end
15
- end
16
-
17
- it "should execute commands" do
18
- Base.add_command "command:name", "parameters" do end
19
- base = create_base('.')
20
- base.should_receive('command_name')
21
- base.execute(['command:name'])
22
- end
23
-
24
- it "should show a help message" do
25
- Base.add_command "command:name", "parameters" do end
26
- Base.help.should == File.open("spec/data/help_command_name.txt").readlines.join.
27
- gsub('{{VERSION}}', File.open("VERSION").readlines.join)
28
- end
29
-
30
- it "should check if gritano is not installed" do
31
- FileUtils.rm_rf(File.join("tmp", ".gritano"))
32
- base = create_base('tmp')
33
- lambda { base.check_gritano }.should raise_error SystemExit
34
- end
35
-
36
- it "should check if gritano is installed" do
37
- base = create_base('.')
38
- lambda { base.check_gritano }.should_not raise_error SystemExit
39
- end
40
-
41
- it "should check if git is not installed" do
42
- base = create_base('.')
43
- base.stub(:unknown_command).and_return(true)
44
- lambda { base.check_git }.should raise_error SystemExit
45
- end
46
-
47
- it "should check if git is installed" do
48
- base = create_base('.')
49
- base.stub(:unknown_command).and_return(false)
50
- lambda { base.check_git }.should_not raise_error SystemExit
51
- end
52
-
53
- it "should check if a command exists" do
54
- base = create_base('.')
55
- base.unknown_command('ls').should be_false
56
- base.unknown_command('qwertyuioplkjhgfdsa').should be_true
57
- end
58
-
59
- end
60
- end
61
- end
@@ -1,183 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- module Gritano
4
- module Console
5
- describe Executor do
6
- def create_executor(home, repo_dir)
7
- stdin = double()
8
- stdin.stub(:read).and_return("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9UnnlDwmvid+WRAyIhVzFhIjUUxA3Wul7LN8mk18dHZDv5HSVADmM4EoqbVSbpeVIyTIchqS3y3XF1rh8dfM41f/W3lcTcFihHM6RDx45Q3Lz9hfyrT8tttlWRA7prvlXu6bUOqMmNtvFFow+bJEo/HgCZHshvoDHcnlHfziU7bDCo+p50SdafFwZRe3AWp/f4TsxiP7jpBnluQM0Dl9Om8jfW8IYAJ+WxlKBsKLMkRH/HWSuigs4AQBD4ADiQfOm2RO4yeSiVFNwGFmgG7NmEq1sNALLAQw+ijN9vyiD99ybr0pqoJX3vhyRBWvCrgQdHjh8ucaoMXI89LxyYts/ igorbonadio@marvin.local")
9
- Executor.new(stdin, home, repo_dir)
10
- end
11
-
12
- it "should list users" do
13
- User.should_receive(:all).and_return([])
14
- create_executor('.', 'tmp').execute(["user:list"])
15
- end
16
-
17
- it "should list users' keys" do
18
- user = double()
19
- user.should_receive(:keys).and_return([])
20
- User.should_receive(:find_by_login).with("login").and_return(user)
21
- create_executor('.', 'tmp').execute(["user:key:list", "login"])
22
- end
23
-
24
- it "should list users' repos" do
25
- user = double()
26
- user.should_receive(:repositories).and_return([])
27
- User.should_receive(:find_by_login).with("login").and_return(user)
28
- create_executor('.', 'tmp').execute(["user:repo:list", "login"])
29
- end
30
-
31
- it "should add users" do
32
- user = double()
33
- user.should_receive(:save).and_return(true)
34
- User.should_receive(:new).with(login: "login", admin: false).and_return(user)
35
- create_executor('.', 'tmp').execute(["user:add", "login"])
36
- end
37
-
38
- it "should remove users" do
39
- user = double()
40
- user.should_receive(:destroy).and_return(true)
41
- User.should_receive(:find_by_login).with("login").and_return(user)
42
- create_executor('.', 'tmp').execute(["user:rm", "login"])
43
- end
44
-
45
- it "should add users' keys" do
46
- user = double()
47
- keys = double()
48
- key = double()
49
- key.should_receive(:valid?).and_return(true)
50
- keys.should_receive(:create).with(name: "keyname", key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9UnnlDwmvid+WRAyIhVzFhIjUUxA3Wul7LN8mk18dHZDv5HSVADmM4EoqbVSbpeVIyTIchqS3y3XF1rh8dfM41f/W3lcTcFihHM6RDx45Q3Lz9hfyrT8tttlWRA7prvlXu6bUOqMmNtvFFow+bJEo/HgCZHshvoDHcnlHfziU7bDCo+p50SdafFwZRe3AWp/f4TsxiP7jpBnluQM0Dl9Om8jfW8IYAJ+WxlKBsKLMkRH/HWSuigs4AQBD4ADiQfOm2RO4yeSiVFNwGFmgG7NmEq1sNALLAQw+ijN9vyiD99ybr0pqoJX3vhyRBWvCrgQdHjh8ucaoMXI89LxyYts/").and_return(key)
51
- user.should_receive(:keys).and_return(keys)
52
- User.should_receive(:find_by_login).with("login").and_return(user)
53
- create_executor('.', 'tmp').execute(["user:key:add", "login", "keyname"])
54
- end
55
-
56
- it "should add users' keys" do
57
- user = double()
58
- keys = double()
59
- key = double()
60
-
61
- key.should_receive(:valid?).and_return(true)
62
- keys.should_receive(:create).with(name: "keyname", key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9UnnlDwmvid+WRAyIhVzFhIjUUxA3Wul7LN8mk18dHZDv5HSVADmM4EoqbVSbpeVIyTIchqS3y3XF1rh8dfM41f/W3lcTcFihHM6RDx45Q3Lz9hfyrT8tttlWRA7prvlXu6bUOqMmNtvFFow+bJEo/HgCZHshvoDHcnlHfziU7bDCo+p50SdafFwZRe3AWp/f4TsxiP7jpBnluQM0Dl9Om8jfW8IYAJ+WxlKBsKLMkRH/HWSuigs4AQBD4ADiQfOm2RO4yeSiVFNwGFmgG7NmEq1sNALLAQw+ijN9vyiD99ybr0pqoJX3vhyRBWvCrgQdHjh8ucaoMXI89LxyYts==").and_return(key)
63
- user.should_receive(:keys).and_return(keys)
64
- User.should_receive(:find_by_login).with("login").and_return(user)
65
-
66
- stdin = double()
67
- stdin.stub(:read).and_return("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9UnnlDwmvid+WRAyIhVzFhIjUUxA3Wul7LN8mk18dHZDv5HSVADmM4EoqbVSbpeVIyTIchqS3y3XF1rh8dfM41f/W3lcTcFihHM6RDx45Q3Lz9hfyrT8tttlWRA7prvlXu6bUOqMmNtvFFow+bJEo/HgCZHshvoDHcnlHfziU7bDCo+p50SdafFwZRe3AWp/f4TsxiP7jpBnluQM0Dl9Om8jfW8IYAJ+WxlKBsKLMkRH/HWSuigs4AQBD4ADiQfOm2RO4yeSiVFNwGFmgG7NmEq1sNALLAQw+ijN9vyiD99ybr0pqoJX3vhyRBWvCrgQdHjh8ucaoMXI89LxyYts== igorbonadio@marvin.local")
68
- Executor.new(stdin, '.', 'tmp').execute(["user:key:add", "login", "keyname"])
69
- end
70
-
71
- it "should remove users' keys" do
72
- keys = double()
73
- users = double()
74
- limit = double()
75
- key = double()
76
- key.should_receive(:destroy).and_return(true)
77
- limit.should_receive(:limit).with(1).and_return([key])
78
- users.should_receive(:where).with("users.login" => "login").and_return(limit)
79
- keys.should_receive(:includes).with(:user).and_return(users)
80
- Key.should_receive(:where).with(name: "keyname").and_return(keys)
81
- create_executor('.', 'tmp').execute(["user:key:rm", "login", "keyname"])
82
- end
83
-
84
- it "should add admin rights to user" do
85
- user = double()
86
- user.should_receive(:admin=).with(true)
87
- user.should_receive(:save).and_return(true)
88
- User.should_receive(:find_by_login).with("login").and_return(user)
89
- create_executor('.', 'tmp').execute(["user:admin:add", "login"])
90
- end
91
-
92
- it "should remove admin rights from users" do
93
- user = double()
94
- user.should_receive(:admin=).with(false)
95
- user.should_receive(:save).and_return(true)
96
- User.should_receive(:find_by_login).with("login").and_return(user)
97
- create_executor('.', 'tmp').execute(["user:admin:rm", "login"])
98
- end
99
-
100
- it "should list repos" do
101
- Repository.should_receive(:all).and_return([])
102
- create_executor('.', 'tmp').execute(["repo:list"])
103
- end
104
-
105
- it "should create repos" do
106
- repo = double()
107
- repo.should_receive(:save).and_return(true)
108
- Repository.should_receive(:new).with(name: "repo.git", path: "tmp").and_return(repo)
109
- create_executor('.', 'tmp').execute(["repo:add", "repo.git"])
110
- end
111
-
112
- it "should create repos and add a user" do
113
- repo = double()
114
- repo.should_receive(:save).and_return(true)
115
- Repository.should_receive(:new).with(name: "repo.git", path: "tmp").and_return(repo)
116
-
117
- user = double()
118
- user.should_receive(:add_access).twice
119
- User.should_receive(:find_by_login).with("login").and_return(user)
120
-
121
- create_executor('.', 'tmp').execute(["repo:add", "repo.git", "login"])
122
- end
123
-
124
- it "should list repos' users" do
125
- repo = double()
126
- repo.should_receive(:users).and_return([])
127
- Repository.should_receive(:find_by_name).with("repo.git").and_return(repo)
128
- create_executor('.', 'tmp').execute(["repo:user:list", "repo.git"])
129
- end
130
-
131
- it "should remove repos" do
132
- repo = double()
133
- repo.should_receive(:destroy).and_return(true)
134
- Repository.should_receive(:find_by_name).with("repo.git").and_return(repo)
135
- create_executor('.', 'tmp').execute(["repo:rm", "repo.git"])
136
- end
137
-
138
- it "should allow user to read a repo" do
139
- repo = double()
140
- Repository.should_receive(:find_by_name).with("repo.git").and_return(repo)
141
-
142
- user = double()
143
- user.should_receive(:add_access).with(repo, :read).and_return(true)
144
- User.should_receive(:find_by_login).with("login").and_return(user)
145
-
146
- create_executor('.', 'tmp').execute(["repo:read:add", "repo.git", "login"])
147
- end
148
-
149
- it "should allow user to write to a repo" do
150
- repo = double()
151
- Repository.should_receive(:find_by_name).with("repo.git").and_return(repo)
152
-
153
- user = double()
154
- user.should_receive(:add_access).with(repo, :write).and_return(true)
155
- User.should_receive(:find_by_login).with("login").and_return(user)
156
-
157
- create_executor('.', 'tmp').execute(["repo:write:add", "repo.git", "login"])
158
- end
159
-
160
- it "should deny user to read a repo" do
161
- repo = double()
162
- Repository.should_receive(:find_by_name).with("repo.git").and_return(repo)
163
-
164
- user = double()
165
- user.should_receive(:remove_access).with(repo, :read).and_return(true)
166
- User.should_receive(:find_by_login).with("login").and_return(user)
167
-
168
- create_executor('.', 'tmp').execute(["repo:read:rm", "repo.git", "login"])
169
- end
170
-
171
- it "should deny user to write to a repo"do
172
- repo = double()
173
- Repository.should_receive(:find_by_name).with("repo.git").and_return(repo)
174
-
175
- user = double()
176
- user.should_receive(:remove_access).with(repo, :write).and_return(true)
177
- User.should_receive(:find_by_login).with("login").and_return(user)
178
-
179
- create_executor('.', 'tmp').execute(["repo:write:rm", "repo.git", "login"])
180
- end
181
- end
182
- end
183
- end
@@ -1,121 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- module Gritano
4
- module Console
5
- describe Gritano do
6
- def create_gritano(home, repo_dir)
7
- stdin = double()
8
- stdin.stub(:read).and_return("Your SSHKEY here...")
9
- Gritano.new(stdin, home, repo_dir)
10
- end
11
-
12
- def test_console_call(console, msg)
13
- executor = double()
14
- executor.should_receive(:execute).with(msg)
15
- console.should_receive(:new).and_return(executor)
16
- create_gritano('.', 'tmp').execute(msg)
17
- end
18
-
19
- def test_executor(msg)
20
- test_console_call(Executor, msg)
21
- end
22
-
23
- def test_installer(msg)
24
- test_console_call(Installer, msg)
25
- end
26
-
27
- it "should show the complete help" do
28
- create_gritano(".", "tmp").
29
- execute(["help"])[1].
30
- should == File.open("features/data/local_help.txt").readlines.join.
31
- gsub('{{VERSION}}', File.open("VERSION").readlines.join)
32
- end
33
-
34
- it "should show the version" do
35
- create_gritano(".", "tmp").
36
- execute(["version"])[1].
37
- should == "v#{File.open("VERSION").readlines.join}"
38
- end
39
-
40
- it "should list users" do
41
- test_executor(["user:list"])
42
- end
43
-
44
- it "should list users' keys" do
45
- test_executor(["user:key:list", "login"])
46
- end
47
-
48
- it "should list users' repos" do
49
- test_executor(["user:repo:list", "login"])
50
- end
51
-
52
- it "should add users" do
53
- test_executor(["user:add", "login"])
54
- end
55
-
56
- it "should remove users" do
57
- test_executor(["user:rm", "login"])
58
- end
59
-
60
- it "should add users' keys" do
61
- test_executor(["user:key:add", "login", "keyname"])
62
- end
63
-
64
- it "should remove users' keys" do
65
- test_executor(["user:key:rm", "login", "keyname"])
66
- end
67
-
68
- it "should add admin rights to user" do
69
- test_executor(["user:admin:add", "login"])
70
- end
71
-
72
- it "should remove admin rights from users" do
73
- test_executor(["user:admin:rm", "login"])
74
- end
75
-
76
- it "should list repos" do
77
- test_executor(["repo:list"])
78
- end
79
-
80
- it "should create repos" do
81
- test_executor(["repo:add", "repo.git"])
82
- end
83
-
84
- it "should create repos and add a user" do
85
- test_executor(["repo:add", "repo.git", "login"])
86
- end
87
-
88
- it "should list repos' users" do
89
- test_executor(["repo:user:list", "repo.git"])
90
- end
91
-
92
- it "should remove repos" do
93
- test_executor(["repo:rm", "repo.git"])
94
- end
95
-
96
- it "should allow user to read a repo" do
97
- test_executor(["repo:read:add", "repo.git", "login"])
98
- end
99
-
100
- it "should allow user to write to a repo" do
101
- test_executor(["repo:write:add", "repo.git", "login"])
102
- end
103
-
104
- it "should deny user to read a repo" do
105
- test_executor(["repo:read:rm", "repo.git", "login"])
106
- end
107
-
108
- it "should deny user to write to a repo"do
109
- test_executor(["repo:write:rm", "repo.git", "login"])
110
- end
111
-
112
- it "should prepare the environment" do
113
- test_installer(["setup:prepare"])
114
- end
115
-
116
- it "should install" do
117
- test_installer(["setup:install"])
118
- end
119
- end
120
- end
121
- end