happy-commander 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +18 -0
- data/bin/commander +7 -0
- data/commander.gemspec +24 -0
- data/lib/commander.rb +3 -0
- data/lib/commander/client.rb +90 -0
- data/lib/commander/exceptions.rb +3 -0
- data/lib/commander/helpers.rb +11 -0
- data/lib/commander/runner.rb +156 -0
- data/lib/commander/setup.rb +145 -0
- data/lib/commander/trello.rb +63 -0
- data/lib/commander/vacations.rb +38 -0
- data/lib/commander/version.rb +4 -0
- data/spec/client_spec.rb +121 -0
- data/spec/fixtures/trello.txt +1 -0
- data/spec/fixtures/users.txt +12 -0
- data/spec/fixtures/vacations.txt +1 -0
- data/spec/helpers_spec.rb +13 -0
- data/spec/runner_spec.rb +262 -0
- data/spec/setup_spec.rb +87 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/input_stubbing.rb +3 -0
- data/spec/support/request_stubbing.rb +23 -0
- data/spec/trello_spec.rb +113 -0
- data/spec/vacations_spec.rb +13 -0
- metadata +133 -0
data/spec/setup_spec.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Commander::Setup do
|
4
|
+
|
5
|
+
subject { Commander::Setup }
|
6
|
+
|
7
|
+
describe '.get_user_input' do
|
8
|
+
|
9
|
+
it 'gets user input' do
|
10
|
+
expect($stdin).to receive_message_chain(:gets, :chomp)
|
11
|
+
subject.get_user_input
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.pick_cron_day' do
|
16
|
+
|
17
|
+
it 'translates literal day names into integers' do
|
18
|
+
expect_user_input 'Tuesday'
|
19
|
+
expect(subject.pick_cron_day).to eq(2)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'asks to correct invalid inputs' do
|
23
|
+
expect_user_input 'Invalid'
|
24
|
+
expect_user_input 'Sunday'
|
25
|
+
expect(subject.pick_cron_day).to eq(0)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'translates "Sunday" into the integer 0' do
|
29
|
+
expect_user_input 'Sunday'
|
30
|
+
expect(subject.pick_cron_day).to eq(0)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'translates "Saturday" into the integer 6' do
|
34
|
+
expect_user_input 'Saturday'
|
35
|
+
expect(subject.pick_cron_day).to eq(6)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '.pick_cron_time' do
|
40
|
+
|
41
|
+
it 'takes hours from the users input' do
|
42
|
+
expect_user_input '14'
|
43
|
+
expect(subject.pick_cron_time).to eq(14)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'ensure valid range of integers' do
|
47
|
+
expect_user_input '25'
|
48
|
+
expect_user_input '7'
|
49
|
+
expect(subject.pick_cron_time).to eq(7)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '.configure' do
|
54
|
+
|
55
|
+
it 'outputs / prompts instructions' do
|
56
|
+
expect(subject).to receive(:puts).at_least(:once)
|
57
|
+
expect_user_input 'board_id'
|
58
|
+
expect_user_input 'key'
|
59
|
+
expect_user_input 'secret'
|
60
|
+
expect_user_input 'token'
|
61
|
+
expect_user_input 'card'
|
62
|
+
expect_user_input 'syntax_selection'
|
63
|
+
subject.configure
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '.choice' do
|
68
|
+
|
69
|
+
it 'outputs cron syntax based on user input (1)' do
|
70
|
+
expect(subject).to receive(:pick_cron_time)
|
71
|
+
expect(subject).to receive(:pick_cron_day)
|
72
|
+
subject.choose(1)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'outputs cron syntax based on user input (2)' do
|
76
|
+
expect(subject).to receive(:puts).at_least(:once)
|
77
|
+
expect_user_input('* * * * *')
|
78
|
+
subject.choose(2)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'outputs cron syntax based on user input (3)' do
|
82
|
+
expect(subject).to receive(:write_to_file)
|
83
|
+
expect(subject).to receive(:exit).with('Success')
|
84
|
+
subject.choose(3)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
$:.unshift(File.expand_path(File.dirname(__FILE__))) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
require 'simplecov'
|
4
|
+
|
5
|
+
SimpleCov.minimum_coverage 60
|
6
|
+
SimpleCov.start do
|
7
|
+
add_filter '/spec/'
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec.configure do |c|
|
11
|
+
c.order = :random
|
12
|
+
c.before { allow($stdout).to receive(:puts) }
|
13
|
+
c.before { allow($stdin).to receive(:gets) }
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'webmock/rspec'
|
17
|
+
require 'support/request_stubbing'
|
18
|
+
require 'support/input_stubbing'
|
19
|
+
require 'commander'
|
20
|
+
require 'rspec'
|
21
|
+
require 'trello'
|
22
|
+
require 'commander/trello'
|
23
|
+
require 'commander/runner'
|
24
|
+
require 'commander/client'
|
25
|
+
require 'commander/version'
|
26
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Helper for stubbing
|
2
|
+
module Helpers
|
3
|
+
def self.boards_details
|
4
|
+
[{
|
5
|
+
id: 'abcdef123456789123456789',
|
6
|
+
name: 'Test',
|
7
|
+
desc: 'This is a test board',
|
8
|
+
closed: false,
|
9
|
+
idOrganization: 'abcdef123456789123456789',
|
10
|
+
url: 'https://trello.com/board/test/abcdef123456789123456789'
|
11
|
+
}]
|
12
|
+
end
|
13
|
+
|
14
|
+
def boards_payload
|
15
|
+
JSON.generate(boards_details)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def stub_boards_call
|
20
|
+
trello_config = Commander::CONFIG
|
21
|
+
stub_request(:get, "https://api.trello.com/1/boards/#{trello_config['board_id']}?key=#{trello_config['consumerkey']}&token=#{trello_config['oauthtoken']}")
|
22
|
+
.to_return(status: 200, body: Helpers.boards_details.first.to_json)
|
23
|
+
end
|
data/spec/trello_spec.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Commander::TrelloConnection do
|
4
|
+
|
5
|
+
subject { Commander::TrelloConnection }
|
6
|
+
|
7
|
+
describe '.new' do
|
8
|
+
|
9
|
+
it 'sets up trello' do
|
10
|
+
allow(Trello::Board).to receive(:find).and_return nil
|
11
|
+
config = Commander::CONFIG
|
12
|
+
expect_any_instance_of(Trello::Configuration).to receive(:developer_public_key=).with(config['consumerkey']).and_call_original
|
13
|
+
subject.new
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets up trello' do
|
17
|
+
allow(Trello::Board).to receive(:find).and_return nil
|
18
|
+
config = Commander::CONFIG
|
19
|
+
expect_any_instance_of(Trello::Configuration).to receive(:member_token=).with(config['oauthtoken']).and_call_original
|
20
|
+
subject.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#find_member_by_id' do
|
25
|
+
let( :trello_connection ) { subject.new }
|
26
|
+
|
27
|
+
before do
|
28
|
+
allow_any_instance_of(subject).to receive(:configure_trello).and_return true
|
29
|
+
allow(subject).to receive(:find_member_by_id).and_return :id
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'finds the right member based on the trello id and returns a trello member object' do
|
33
|
+
board = double('board')
|
34
|
+
trello_connection.board = board
|
35
|
+
expect(board).to receive_message_chain(:members, :find)
|
36
|
+
trello_connection.send(:find_member_by_id, 42)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#find_member_by_username' do
|
41
|
+
let( :trello_connection ) { subject.new }
|
42
|
+
|
43
|
+
before do
|
44
|
+
allow_any_instance_of(subject).to receive(:configure_trello).and_return true
|
45
|
+
allow(subject).to receive(:find_member_by_username).and_return :username
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'finds a member based on a username and returns a trello member object' do
|
49
|
+
board = double('board')
|
50
|
+
trello_connection.board = board
|
51
|
+
expect(board).to receive_message_chain(:members, :find)
|
52
|
+
trello_connection.send(:find_member_by_username, 'art')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#comment_on_card' do
|
57
|
+
let ( :trello_connection ) { subject.new }
|
58
|
+
|
59
|
+
before do
|
60
|
+
allow_any_instance_of(subject).to receive(:configure_trello).and_return true
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'comments on the assigned trello card ' do
|
64
|
+
card = double('card')
|
65
|
+
allow(card).to receive(:add_comment).with('username').and_return true
|
66
|
+
expect(trello_connection.comment_on_card('username', card)).to eq true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#add_commander_to_card' do
|
71
|
+
let ( :trello_connection ) { subject.new }
|
72
|
+
|
73
|
+
before do
|
74
|
+
allow_any_instance_of(subject).to receive(:configure_trello).and_return true
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'adds the valid member to the trello card and comments it' do
|
78
|
+
card = double('card')
|
79
|
+
allow(card).to receive(:add_member).and_return true
|
80
|
+
expect(trello_connection.add_commander_to_card('asd', card)).to eq true
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#list_of_assigned_members' do
|
85
|
+
let ( :trello_connection ) { subject.new }
|
86
|
+
|
87
|
+
before do
|
88
|
+
allow_any_instance_of(subject).to receive(:configure_trello).and_return true
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'list all the assigned members of the specified card ' do
|
92
|
+
card = double('card')
|
93
|
+
expect(card).to receive_message_chain(:assignees, :map)
|
94
|
+
trello_connection.list_of_assigned_members(card)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#find_member_by_id(id)' do
|
99
|
+
let( :trello_connection ) { subject.new }
|
100
|
+
|
101
|
+
before do
|
102
|
+
allow_any_instance_of(subject).to receive(:configure_trello).and_return true
|
103
|
+
allow(subject).to receive(:find_card_by_id).and_return :id
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'finds the right card based on the trello id' do
|
107
|
+
board = double('board')
|
108
|
+
trello_connection.board = board
|
109
|
+
expect(board).to receive_message_chain(:cards, :find)
|
110
|
+
trello_connection.send(:find_card_by_id, 42)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: happy-commander
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jschmid1
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby-trello
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.7.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.7.7
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: colorize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.7.3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.7.3
|
55
|
+
description: Easy, fair and trackable labor division in your team.
|
56
|
+
email:
|
57
|
+
- jschmid@suse.de
|
58
|
+
executables:
|
59
|
+
- commander
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/commander
|
71
|
+
- commander.gemspec
|
72
|
+
- config/.trello.yml
|
73
|
+
- config/members.yml
|
74
|
+
- lib/commander.rb
|
75
|
+
- lib/commander/client.rb
|
76
|
+
- lib/commander/exceptions.rb
|
77
|
+
- lib/commander/helpers.rb
|
78
|
+
- lib/commander/runner.rb
|
79
|
+
- lib/commander/setup.rb
|
80
|
+
- lib/commander/trello.rb
|
81
|
+
- lib/commander/vacations.rb
|
82
|
+
- lib/commander/version.rb
|
83
|
+
- rubocop.yml
|
84
|
+
- spec/client_spec.rb
|
85
|
+
- spec/fixtures/trello.txt
|
86
|
+
- spec/fixtures/users.txt
|
87
|
+
- spec/fixtures/vacations.txt
|
88
|
+
- spec/helpers_spec.rb
|
89
|
+
- spec/runner_spec.rb
|
90
|
+
- spec/setup_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
- spec/support/input_stubbing.rb
|
93
|
+
- spec/support/request_stubbing.rb
|
94
|
+
- spec/trello_spec.rb
|
95
|
+
- spec/vacations_spec.rb
|
96
|
+
homepage: http://rubygems.org/gems/happy-commander
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.2.2
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Automatically sets a Commanding officer of the Week.
|
120
|
+
test_files:
|
121
|
+
- spec/client_spec.rb
|
122
|
+
- spec/fixtures/trello.txt
|
123
|
+
- spec/fixtures/users.txt
|
124
|
+
- spec/fixtures/vacations.txt
|
125
|
+
- spec/helpers_spec.rb
|
126
|
+
- spec/runner_spec.rb
|
127
|
+
- spec/setup_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
- spec/support/input_stubbing.rb
|
130
|
+
- spec/support/request_stubbing.rb
|
131
|
+
- spec/trello_spec.rb
|
132
|
+
- spec/vacations_spec.rb
|
133
|
+
has_rdoc:
|