glman 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ module Kernel
2
+ def dp(object, options={})
3
+ Glman::DataPresenter.show(object, options)
4
+ end
5
+ end
@@ -25,6 +25,14 @@ module Glman
25
25
  nil
26
26
  end
27
27
 
28
+ def user_name
29
+ %x[git config user.name]
30
+ end
31
+
32
+ def user_email
33
+ %x[git config user.email]
34
+ end
35
+
28
36
  def push(origin, branch)
29
37
  cmd = "git push #{origin} #{branch}"
30
38
  %x[#{cmd}]
@@ -8,7 +8,7 @@ module Glman
8
8
  class ProjectsRepo
9
9
  PER_PAGE = 10000
10
10
  def initialize(opts={})
11
- @gitlab_url = opts.fetch(:gitlab_url)
11
+ @gitlab_url = opts.fetch(:url)
12
12
  @private_token = opts.fetch(:private_token)
13
13
  end
14
14
  def list
@@ -7,7 +7,7 @@ module Glman
7
7
  class UsersRepo
8
8
  PER_PAGE = 10000
9
9
  def initialize(opts={})
10
- @gitlab_url = opts.fetch(:gitlab_url)
10
+ @gitlab_url = opts.fetch(:url)
11
11
  @private_token = opts.fetch(:private_token)
12
12
  end
13
13
  def list
@@ -1,3 +1,3 @@
1
1
  module Glman
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe Glman::Commands::Configs::AliasesConfig do
4
+ subject{ described_class.new(config_manager: config_manager) }
5
+ let(:config_manager) { double('config_manager') }
6
+
7
+ describe '#add' do
8
+ before(:each) do
9
+ config_manager.should_receive(:set).with({ aliases: set_aliases })
10
+ config_manager.should_receive(:get).and_return(get_aliases)
11
+ end
12
+ let(:alias_name) {:dj}
13
+ let(:email) {'damian@o2.pl'}
14
+ let(:input_hash) {{email: email, alias_name: alias_name}}
15
+ let(:new_alias) {{alias_name => email}}
16
+ let(:old_aliases) {{pn: 'pniemczyk@o2.pl'}}
17
+ let(:get_aliases) {{aliases: old_aliases}}
18
+ let(:set_aliases) {old_aliases.merge(new_alias)}
19
+
20
+ it 'should add new alias to existings' do
21
+ subject.add(input_hash)
22
+ end
23
+ end
24
+
25
+ describe '#delete' do
26
+ before(:each) do
27
+ config_manager.should_receive(:set).with({ aliases: set_aliases })
28
+ config_manager.should_receive(:get).and_return(get_aliases)
29
+ end
30
+
31
+ let(:alias_to_delete) {'pn'}
32
+ let(:get_aliases) {{aliases: {dj: 'damian@o2.pl', pn: 'pawel@o2.pl'}}}
33
+ let(:set_aliases) {{dj: 'damian@o2.pl'}}
34
+
35
+ it 'should delete alias from existings' do
36
+ subject.delete(alias_to_delete)
37
+ end
38
+ end
39
+
40
+
41
+ describe '#set' do
42
+ before(:each) {config_manager.should_receive(:set).with({ aliases: set_aliases })}
43
+ let(:set_aliases) {{dj: 'damian@o2.pl', pn: 'pawel@o2.pl'}}
44
+
45
+ it 'should set new aliases' do
46
+ subject.set(set_aliases)
47
+ end
48
+ end
49
+
50
+ describe '#get' do
51
+ before(:each) {config_manager.should_receive(:get).and_return(get_aliases)}
52
+ let(:current_aliasses) {{pn: 'pawel@o2.pl'}}
53
+ let(:get_aliases) {{aliases: current_aliasses}}
54
+
55
+ it 'should receive current aliases' do
56
+ subject.get.should eq current_aliasses
57
+ end
58
+
59
+ context 'when configuration is empty' do
60
+ let(:current_aliasses) {Glman::Commands::Configs::AliasesConfig::DEFAULT}
61
+
62
+ it 'should receive default aliases' do
63
+ subject.get.should eq current_aliasses
64
+ end
65
+ end
66
+ end
67
+
68
+ describe '#clear' do
69
+ before(:each) {config_manager.should_receive(:set).with({ aliases: set_aliases })}
70
+ let(:set_aliases) { nil }
71
+
72
+ it 'should set aliases to default' do
73
+ subject.clear
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Glman::Commands::Configs::GitlabConfig do
4
+ subject{ described_class.new(config_manager: config_manager) }
5
+ let(:config_manager) { double('config_manager') }
6
+
7
+ describe '#set' do
8
+ context 'error' do
9
+ it 'should raise GitlabConfigurationError when data is not Hash' do
10
+ msg = 'incorrect data'
11
+ -> {subject.set('bad')}.should raise_error(described_class::GitlabConfigurationError, msg)
12
+ end
13
+
14
+ it 'should raise GitlabConfigurationError when url is incorrect' do
15
+ msg = 'url is incorrect'
16
+ -> {subject.set(url: '@')}.should raise_error(described_class::GitlabConfigurationError, msg)
17
+ end
18
+
19
+ it 'should raise GitlabConfigurationError when private_token missing' do
20
+ msg = 'private_token missing'
21
+ -> {subject.set(url: 'http://test.com')}.should raise_error(described_class::GitlabConfigurationError, msg)
22
+ -> {subject.set(url: 'http://test.com', private_token: ' ')}.should raise_error(described_class::GitlabConfigurationError, msg)
23
+ end
24
+
25
+ end
26
+
27
+ context 'successed' do
28
+ before(:each) {config_manager.should_receive(:set).with({ gitlab: set_gitlab })}
29
+ let(:set_gitlab) {{url: 'http://localhost', private_token: '1234'}}
30
+
31
+ it 'should set new gitlab' do
32
+ subject.set(set_gitlab)
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#get' do
38
+ before(:each) {config_manager.should_receive(:get).and_return(get_gitlab)}
39
+ let(:current_config) {{url: 'http://localhost', private_token: '1234'}}
40
+ let(:get_gitlab) {{gitlab: current_config}}
41
+
42
+ it 'should receive current gitlab' do
43
+ subject.get.should eq current_config
44
+ end
45
+
46
+ context 'when configuration is empty' do
47
+ let(:current_config) {Glman::Commands::Configs::GitlabConfig::DEFAULT}
48
+
49
+ it 'should receive default gitlab' do
50
+ subject.get.should eq current_config
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#clear' do
56
+ before(:each) {config_manager.should_receive(:set).with({ gitlab: set_gitlab })}
57
+ let(:set_gitlab) { Glman::Commands::Configs::GitlabConfig::DEFAULT }
58
+
59
+ it 'should set to default' do
60
+ subject.clear
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe Glman::Commands::Configs::NotifyIrcConfig do
4
+ subject{ described_class.new(config_manager: config_manager) }
5
+ let(:config_manager) { double('config_manager') }
6
+
7
+ describe '#set' do
8
+ before(:each){ config_manager.should_receive(:get).and_return(old_config) }
9
+
10
+ let(:old_config) do
11
+ {
12
+ notify: {
13
+ email: {some: 'test'},
14
+ irc: old_irc_config
15
+ }
16
+ }
17
+ end
18
+
19
+ let(:old_irc_config) do
20
+ {
21
+ nick: 'glman_test',
22
+ channel: 'test',
23
+ server: 'irc.super.com',
24
+ port: 9999,
25
+ ssl: false
26
+ }
27
+ end
28
+
29
+ let(:set_part_config) {{ channel: 'test-new', port: 1234, ssl: false }}
30
+ let(:set_full_config) do
31
+ {
32
+ nick: 'super_man',
33
+ channel: 'heroses',
34
+ server: 'irc.cool.com',
35
+ port: 912,
36
+ ssl: true
37
+ }
38
+ end
39
+
40
+ it 'should set part configuration' do
41
+ config = old_irc_config.merge(set_part_config)
42
+ config_manager.should_receive(:set).with(notify: { email: {some: 'test'}, irc: config})
43
+ subject.set(set_part_config)
44
+ end
45
+
46
+ it 'should set full configuration' do
47
+ config_manager.should_receive(:set).with(notify: { email: {some: 'test'}, irc: set_full_config})
48
+ subject.set(set_full_config)
49
+ end
50
+ end
51
+
52
+ describe '#get' do
53
+ before(:each) {config_manager.should_receive(:get).and_return(notify: {irc: current_config})}
54
+ let(:current_config) do
55
+ {
56
+ nick: 'glman_test',
57
+ channel: 'test',
58
+ server: 'irc.super.com',
59
+ port: 9999,
60
+ ssl: false
61
+ }
62
+ end
63
+
64
+ it 'should receive current itc configuration' do
65
+ subject.get.should eq current_config
66
+ end
67
+
68
+ context 'when configuration is empty' do
69
+ let(:current_config) {Glman::Commands::Configs::NotifyIrcConfig::DEFAULT}
70
+
71
+ it 'should receive default users' do
72
+ subject.get.should eq current_config
73
+ end
74
+ end
75
+ end
76
+
77
+ describe '#clear' do
78
+ before(:each) do
79
+ config_manager.should_receive(:set).with({ notify: {irc: new_config} })
80
+ config_manager.should_receive(:get).and_return({})
81
+ end
82
+
83
+ let(:new_config) { Glman::Commands::Configs::NotifyIrcConfig::DEFAULT }
84
+
85
+ it 'should set users to default' do
86
+ subject.clear
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Glman::Commands::Configs::UsersConfig do
4
+ subject{ described_class.new(config_manager: config_manager) }
5
+ let(:config_manager) { double('config_manager') }
6
+
7
+ describe '#set' do
8
+ before(:each) {config_manager.should_receive(:set).with({ users: set_users })}
9
+ let(:set_users) {{'damian@o2.pl' => {id: 1} , 'pawel@o2.pl' => {id: 2}}}
10
+
11
+ it 'should set new users' do
12
+ subject.set(set_users)
13
+ end
14
+ end
15
+
16
+ describe '#get' do
17
+ before(:each) {config_manager.should_receive(:get).and_return(get_users)}
18
+ let(:current_users) {{'pawel@o2.pl' => {id: 2}}}
19
+ let(:get_users) {{users: current_users}}
20
+
21
+ it 'should receive current users' do
22
+ subject.get.should eq current_users
23
+ end
24
+
25
+ context 'when configuration is empty' do
26
+ let(:current_users) {Glman::Commands::Configs::UsersConfig::DEFAULT}
27
+
28
+ it 'should receive default users' do
29
+ subject.get.should eq current_users
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '#clear' do
35
+ before(:each) {config_manager.should_receive(:set).with({ users: set_users })}
36
+ let(:set_users) { nil }
37
+
38
+ it 'should set users to default' do
39
+ subject.clear
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,140 @@
1
+ require 'spec_helper'
2
+
3
+ describe Glman::Commands::Config do
4
+ subject{ described_class.new(config_manager: config_manager) }
5
+ let(:config_manager) { double('config_manager') }
6
+
7
+ describe '#show' do
8
+ let(:msg_no_configuration_yet) { 'No configuration yet' }
9
+
10
+ it 'should display message no_configuration_yet when configuration missing' do
11
+ config_manager.should_receive(:get).and_return({})
12
+ Glman::DataPresenter.should_receive(:show).with(msg_no_configuration_yet, {})
13
+ subject.show
14
+ end
15
+
16
+ it 'should display message no_configuration_yet when nested configuration missing' do
17
+ config_manager.should_receive(:get).and_return({ test: 'value' })
18
+ Glman::DataPresenter.should_receive(:show).with(msg_no_configuration_yet, {})
19
+ subject.show(['nested'])
20
+ end
21
+
22
+ it 'should display nested configuration when params present' do
23
+ expected_conf = { a: 'b'}
24
+ nested_conf = { next_level: expected_conf }
25
+ config = { test: nested_conf }
26
+ config_manager.should_receive(:get).and_return(config)
27
+ Glman::DataPresenter.should_receive(:show).with(expected_conf, {})
28
+ subject.show(['test', 'next_level'])
29
+ end
30
+
31
+ it 'should display base configuration when params missing' do
32
+ config = {test: 'test'}
33
+ config_manager.should_receive(:get).and_return(config)
34
+ Glman::DataPresenter.should_receive(:show).with(config, {})
35
+ subject.show
36
+ end
37
+ end
38
+
39
+ context 'gitlab' do
40
+ let(:gitlab_conf) { double('gitlab_conf') }
41
+ before(:each) {subject.should_receive(:gitlab_conf).and_return(gitlab_conf)}
42
+
43
+ it '#set' do
44
+ value = { url: 'url', private_token: 'token' }
45
+ gitlab_conf.should_receive(:set).with(value)
46
+ subject.set(:gitlab, value)
47
+ end
48
+
49
+ it '#clear' do
50
+ gitlab_conf.should_receive(:clear)
51
+ subject.clear(:gitlab)
52
+ end
53
+
54
+ it '#get' do
55
+ gitlab_conf.should_receive(:get)
56
+ subject.get(:gitlab)
57
+ end
58
+ end
59
+
60
+ context 'users' do
61
+ let(:users_conf) { double('users_conf') }
62
+ before(:each) {subject.should_receive(:users_conf).and_return(users_conf)}
63
+
64
+ it '#set' do
65
+ value = { 'damian@o2.pl' => {id: 1} }
66
+ users_conf.should_receive(:set).with(value)
67
+ subject.set(:users, value)
68
+ end
69
+
70
+ it '#clear' do
71
+ users_conf.should_receive(:clear)
72
+ subject.clear(:users)
73
+ end
74
+
75
+ it '#get' do
76
+ users_conf.should_receive(:get)
77
+ subject.get(:users)
78
+ end
79
+ end
80
+
81
+ context 'aliases' do
82
+ let(:aliases_conf) { double('aliases_conf') }
83
+ before(:each) {subject.should_receive(:aliases_conf).and_return(aliases_conf)}
84
+
85
+ it '#set' do
86
+ value = {pn: 'pniemczyk@o2.pl'}
87
+ aliases_conf.should_receive(:set).with(value)
88
+ subject.set(:aliases, value)
89
+ end
90
+
91
+ it '#clear' do
92
+ aliases_conf.should_receive(:clear)
93
+ subject.clear(:aliases)
94
+ end
95
+
96
+ it '#get' do
97
+ aliases_conf.should_receive(:get)
98
+ subject.get(:aliases)
99
+ end
100
+
101
+ it '#delete' do
102
+ aliases_conf.should_receive(:delete).with(:pn)
103
+ subject.delete(:aliases, :pn)
104
+ end
105
+
106
+ it '#add' do
107
+ value = {pn: 'pniemczyk@o2.pl'}
108
+ aliases_conf.should_receive(:add).with(value)
109
+ subject.add(:aliases, value)
110
+ end
111
+ end
112
+
113
+ context 'irc_notify' do
114
+ let(:irc_notify_conf) { double('irc_notify_conf') }
115
+ before(:each) {subject.should_receive(:irc_notify_conf).and_return(irc_notify_conf)}
116
+
117
+ it '#set' do
118
+ value = {
119
+ nick: 'glman_test',
120
+ channel: 'test',
121
+ server: 'irc.super.com',
122
+ port: 9999,
123
+ ssl: false
124
+ }
125
+ irc_notify_conf.should_receive(:set).with(value)
126
+ subject.set(:irc_notify, value)
127
+ end
128
+
129
+ it '#clear' do
130
+ irc_notify_conf.should_receive(:clear)
131
+ subject.clear(:irc_notify)
132
+ end
133
+
134
+ it '#get' do
135
+ irc_notify_conf.should_receive(:get)
136
+ subject.get(:irc_notify)
137
+ end
138
+ end
139
+
140
+ end