mode 0.0.10 → 0.0.11
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.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.travis.yml +1 -0
- data/bin/mode +3 -8
- data/lib/connect.rb +13 -0
- data/lib/mode.rb +18 -5
- data/lib/mode/api/link.rb +4 -0
- data/lib/mode/api/request.rb +20 -10
- data/lib/mode/auth/access_token.rb +16 -0
- data/lib/mode/cli/connect.rb +1 -1
- data/lib/mode/commands/analyze_field.rb +1 -3
- data/lib/mode/commands/connect.rb +24 -49
- data/lib/mode/commands/helpers.rb +23 -18
- data/lib/mode/commands/import.rb +2 -4
- data/lib/mode/commands/login.rb +88 -25
- data/lib/mode/config.rb +60 -2
- data/lib/mode/connector/connect.rb +11 -0
- data/lib/mode/connector/daemon.rb +54 -12
- data/lib/mode/connector/daemonizer.rb +107 -0
- data/lib/mode/connector/data_source.rb +36 -9
- data/lib/mode/connector/scheduler.rb +6 -5
- data/lib/mode/connector/uploader.rb +3 -4
- data/lib/mode/version.rb +1 -1
- data/mode.gemspec +7 -4
- data/spec/api/request_spec.rb +9 -6
- data/spec/commands/connect_spec.rb +45 -59
- data/spec/commands/helpers_spec.rb +9 -22
- data/spec/commands/import_spec.rb +5 -0
- data/spec/commands/login_spec.rb +87 -76
- data/spec/config_spec.rb +9 -0
- data/spec/connector/daemon_spec.rb +11 -6
- data/spec/connector/daemonizer_spec.rb +106 -0
- data/spec/connector/data_source_spec.rb +15 -17
- data/spec/connector/registrar_spec.rb +5 -6
- data/spec/connector/scheduler_spec.rb +3 -2
- data/spec/connector/uploader_spec.rb +9 -9
- metadata +65 -65
- data/lib/mode/configurable.rb +0 -46
- data/lib/mode/connector/config.rb +0 -31
- data/spec/connector/config_spec.rb +0 -46
@@ -10,14 +10,12 @@ module Mode
|
|
10
10
|
def initialize(data_sources, options = {})
|
11
11
|
@data_sources = data_sources
|
12
12
|
@scheduler = Rufus::Scheduler.new
|
13
|
-
@max_jobs = options[:max_jobs] || 4
|
13
|
+
@max_jobs = (options[:max_jobs] || 4).to_i
|
14
14
|
end
|
15
15
|
|
16
16
|
def start!
|
17
|
-
data_sources.each(&:connection)
|
18
|
-
|
19
|
-
|
20
|
-
scheduler.every('5s') { tick }
|
17
|
+
data_sources.each(&:connection) # Keep outside the scheduler loop
|
18
|
+
scheduler.interval('5s') { tick }
|
21
19
|
scheduler.join
|
22
20
|
end
|
23
21
|
|
@@ -39,6 +37,9 @@ module Mode
|
|
39
37
|
if processors.length < max_jobs
|
40
38
|
scheduler.in(0, :tag => 'processor') { tock }
|
41
39
|
end
|
40
|
+
rescue => err
|
41
|
+
Mode::Logger.instance.error(
|
42
|
+
"Connector::Scheduler", err.message, err.backtrace)
|
42
43
|
end
|
43
44
|
|
44
45
|
def tock
|
@@ -10,9 +10,8 @@ module Mode
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def perform!
|
13
|
-
Mode::API::Request.put(
|
14
|
-
|
15
|
-
:execution => {
|
13
|
+
Mode::API::Request.put(path,
|
14
|
+
:report_run => {
|
16
15
|
:dataset => {
|
17
16
|
:count => count,
|
18
17
|
:content => content,
|
@@ -25,7 +24,7 @@ module Mode
|
|
25
24
|
class << self
|
26
25
|
def error!(path, message, detail = nil)
|
27
26
|
Mode::API::Request.put(path,
|
28
|
-
:
|
27
|
+
:report_run => {
|
29
28
|
:error => {
|
30
29
|
:detail => detail,
|
31
30
|
:message => message
|
data/lib/mode/version.rb
CHANGED
data/mode.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_runtime_dependency "thor"
|
23
23
|
spec.add_runtime_dependency "terminal-table"
|
24
24
|
|
25
|
-
# Data Packaging
|
25
|
+
# Data Packaging (In Development)
|
26
26
|
spec.add_runtime_dependency "data_kit"
|
27
27
|
spec.add_runtime_dependency "data_package"
|
28
28
|
|
@@ -34,14 +34,17 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_runtime_dependency "sequel"
|
35
35
|
|
36
36
|
# Concurrency & Processes
|
37
|
-
spec.add_runtime_dependency "
|
37
|
+
spec.add_runtime_dependency "spoon"
|
38
38
|
spec.add_runtime_dependency "rufus-scheduler"
|
39
|
-
|
39
|
+
|
40
|
+
# Web Management
|
41
|
+
# spec.add_runtime_dependency "launchy"
|
42
|
+
|
40
43
|
# Development Dependencies
|
41
44
|
spec.add_development_dependency "bundler", "~> 1.3"
|
42
45
|
spec.add_development_dependency "rake"
|
43
46
|
spec.add_development_dependency "profile"
|
44
47
|
spec.add_development_dependency "rspec"
|
45
|
-
spec.add_development_dependency "ruby-prof"
|
46
48
|
spec.add_development_dependency "simplecov"
|
49
|
+
spec.add_development_dependency "warbler"
|
47
50
|
end
|
data/spec/api/request_spec.rb
CHANGED
@@ -2,13 +2,16 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mode::API::Request do
|
4
4
|
let(:username) { 'besquared' }
|
5
|
-
let(:
|
5
|
+
let(:password) { 'token_password '}
|
6
6
|
|
7
7
|
before do
|
8
8
|
Mode::API::Request.configure(:test, {
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
'credentials' => {
|
10
|
+
'username' => username,
|
11
|
+
'password' => password
|
12
|
+
}, 'access_token' => {
|
13
|
+
'token' => 'token123',
|
14
|
+
'password' => 'password123'
|
12
15
|
}
|
13
16
|
})
|
14
17
|
end
|
@@ -63,10 +66,10 @@ describe Mode::API::Request do
|
|
63
66
|
'/api/besquared/data_source_connections'
|
64
67
|
|
65
68
|
Mode::API::Request.data_source_connection_path.should == \
|
66
|
-
'/api/besquared/data_source_connections/
|
69
|
+
'/api/besquared/data_source_connections/token123'
|
67
70
|
|
68
71
|
Mode::API::Request.data_source_connection_messages_path.should == \
|
69
|
-
'/api/besquared/data_source_connections/
|
72
|
+
'/api/besquared/data_source_connections/token123/messages'
|
70
73
|
end
|
71
74
|
|
72
75
|
it 'has http object' do
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Mode::Commands::Connect do
|
4
4
|
let(:tmpdir) { Dir.mktmpdir }
|
5
5
|
let(:config) { Mode::Config.init(tmpdir) }
|
6
|
-
let(:
|
6
|
+
let(:daemon) { double(:daemon) }
|
7
7
|
|
8
8
|
let(:data_source) {
|
9
9
|
Mode::Connector::DataSource.new('testdb', {
|
@@ -19,75 +19,61 @@ describe Mode::Commands::Connect do
|
|
19
19
|
initialize_logger
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
connect
|
24
|
-
|
25
|
-
connect.command.should == 'start'
|
26
|
-
connect.concurrency.should == 4
|
27
|
-
end
|
28
|
-
|
29
|
-
it "registers connector" do
|
30
|
-
connect = Mode::Commands::Connect.new('start')
|
31
|
-
|
32
|
-
registrar = double(:registrar, :perform! => true)
|
33
|
-
Mode::Connector::Registrar.should_receive(:new).and_return(registrar)
|
34
|
-
|
35
|
-
connect.send(:register!)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "starts the daemon" do
|
39
|
-
connect = Mode::Commands::Connect.new('start')
|
40
|
-
|
41
|
-
Mode::Connector::Daemon.should_receive(:spawn!).and_return(true)
|
42
|
-
|
43
|
-
connect.send(:spawn_command!, 'start')
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'restarts the daemon' do
|
47
|
-
connect = Mode::Commands::Connect.new('start')
|
22
|
+
describe "starting" do
|
23
|
+
let(:connect) { Mode::Commands::Connect.new('start') }
|
48
24
|
|
49
|
-
|
25
|
+
it "initializes with command and connect config" do
|
26
|
+
connect.command.should == 'start'
|
27
|
+
connect.concurrency.should == 4
|
28
|
+
end
|
50
29
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
it 'spawns with the start command' do
|
55
|
-
connect = Mode::Commands::Connect.new('start')
|
56
|
-
|
57
|
-
Mode::Connector::Daemon.should_receive(:spawn!).and_return(true)
|
58
|
-
|
59
|
-
connect.send(:spawn!)
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'spawns with the restart command' do
|
63
|
-
connect = Mode::Commands::Connect.new('restart')
|
64
|
-
|
65
|
-
Mode::Connector::Daemon.should_receive(:spawn!).twice.and_return(true)
|
30
|
+
it "registers connector" do
|
31
|
+
connect.should_receive(:configuration).and_return(config)
|
66
32
|
|
67
|
-
|
33
|
+
registrar = double(:registrar, :perform! => true)
|
34
|
+
Mode::Connector::Registrar.should_receive(:new).and_return(registrar)
|
35
|
+
connect.send(:register!)
|
36
|
+
end
|
68
37
|
end
|
69
38
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
39
|
+
describe "controlling the daemon" do
|
40
|
+
it "starts" do
|
41
|
+
connect = Mode::Commands::Connect.new('start')
|
42
|
+
connect.should_receive(:daemon).and_return(daemon)
|
43
|
+
|
44
|
+
daemon.should_receive(:start).and_return(true)
|
45
|
+
connect.send(:run_command!)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'stops' do
|
49
|
+
connect = Mode::Commands::Connect.new('stop')
|
50
|
+
connect.should_receive(:daemon).and_return(daemon)
|
51
|
+
|
52
|
+
daemon.should_receive(:stop).and_return(true)
|
53
|
+
connect.send(:run_command!)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'restarts' do
|
57
|
+
connect = Mode::Commands::Connect.new('restart')
|
58
|
+
connect.should_receive(:daemon).and_return(daemon)
|
59
|
+
|
60
|
+
daemon.should_receive(:restart).and_return(true)
|
61
|
+
connect.send(:run_command!)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'raises on if the command is unrecognized' do
|
65
|
+
connect = Mode::Commands::Connect.new('fake')
|
66
|
+
daemon.should_not_receive(:start)
|
67
|
+
expect { connect.send(:run_command!) }.to raise_error
|
68
|
+
end
|
84
69
|
end
|
85
70
|
|
86
71
|
it 'executes the connector' do
|
87
72
|
connect = Mode::Commands::Connect.new('start')
|
88
73
|
|
89
74
|
connect.should_receive(:register!)
|
90
|
-
connect.should_receive(:
|
75
|
+
connect.should_receive(:run_command!)
|
76
|
+
connect.should_receive(:validate_config!)
|
91
77
|
|
92
78
|
connect.execute
|
93
79
|
end
|
@@ -7,6 +7,7 @@ end
|
|
7
7
|
describe Mode::Commands::Helpers do
|
8
8
|
let(:tmpdir) { Dir.mktmpdir }
|
9
9
|
let(:command) { CommandClass.new }
|
10
|
+
let(:config) { Mode::Config.init(tmpdir) }
|
10
11
|
|
11
12
|
before do
|
12
13
|
initialize_logger
|
@@ -16,18 +17,10 @@ describe Mode::Commands::Helpers do
|
|
16
17
|
command.config_dir.should == File.expand_path("~/.mode/")
|
17
18
|
end
|
18
19
|
|
19
|
-
it "provides a config path" do
|
20
|
-
command.config_path.should == Mode::Config.full_path("~/.mode/")
|
21
|
-
end
|
22
|
-
|
23
20
|
it "provides config validation" do
|
24
|
-
command.stub(:
|
21
|
+
command.stub(:config_exists).and_return(false)
|
25
22
|
|
26
23
|
expect { command.require_config! }.to raise_error
|
27
|
-
|
28
|
-
config = Mode::Config.init(tmpdir)
|
29
|
-
|
30
|
-
command.require_config!
|
31
24
|
end
|
32
25
|
|
33
26
|
it "provides credential validation" do
|
@@ -36,8 +29,6 @@ describe Mode::Commands::Helpers do
|
|
36
29
|
# raise for no config
|
37
30
|
expect { command.require_credentials! }.to raise_error
|
38
31
|
|
39
|
-
config = Mode::Config.init(tmpdir)
|
40
|
-
|
41
32
|
# raise for credentials not found
|
42
33
|
expect { command.require_credentials! }.to raise_error
|
43
34
|
|
@@ -49,21 +40,17 @@ describe Mode::Commands::Helpers do
|
|
49
40
|
end
|
50
41
|
|
51
42
|
it "provides api request configuration" do
|
43
|
+
command.stub(:config).and_return(config)
|
44
|
+
|
52
45
|
command.configure_api_requests!
|
53
46
|
Mode::API::Request.valid?.should == true
|
54
47
|
end
|
55
48
|
|
56
|
-
it
|
57
|
-
command.
|
58
|
-
|
59
|
-
|
60
|
-
expect { command.require_connect_config! }.to raise_error
|
61
|
-
|
62
|
-
config = Mode::Connector::Config.init(tmpdir)
|
63
|
-
|
64
|
-
config.data_sources << Mode::Connector::DataSource.new('test', {})
|
65
|
-
config.save
|
49
|
+
it 'validates a configuration' do
|
50
|
+
command.should_receive(:require_config!)
|
51
|
+
command.should_receive(:require_credentials!)
|
52
|
+
command.should_receive(:configure_api_requests!)
|
66
53
|
|
67
|
-
command.
|
54
|
+
command.validate_config!
|
68
55
|
end
|
69
56
|
end
|
@@ -2,6 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mode::Commands::Import do
|
4
4
|
let(:tmpdir) { Dir.mktmpdir }
|
5
|
+
let(:config) { Mode::Config.init(tmpdir) }
|
5
6
|
let(:packages_path) { Mode::API::Request.packages_path }
|
6
7
|
|
7
8
|
before do
|
@@ -129,6 +130,8 @@ describe Mode::Commands::Import do
|
|
129
130
|
import_params = { 'table_name' => 'espn_draft' }
|
130
131
|
import.should_receive(:parse_uploaded_response).with(:package).and_return(resource)
|
131
132
|
import.should_receive(:submit_import_form).with(resource, import_params).and_return(true)
|
133
|
+
|
134
|
+
import.should_receive(:validate_config!).and_return(true)
|
132
135
|
|
133
136
|
import.execute
|
134
137
|
end
|
@@ -149,6 +152,8 @@ describe Mode::Commands::Import do
|
|
149
152
|
import.should_receive(:parse_uploaded_response).with(:package).and_return(resource)
|
150
153
|
import.should_receive(:submit_import_form).with(resource, import_params).and_return(true)
|
151
154
|
|
155
|
+
import.should_receive(:validate_config!).and_return(true)
|
156
|
+
|
152
157
|
import.execute
|
153
158
|
end
|
154
159
|
end
|
data/spec/commands/login_spec.rb
CHANGED
@@ -5,57 +5,42 @@ describe Mode::Commands::Login do
|
|
5
5
|
let(:username) { 'besquared' }
|
6
6
|
let(:password) { 'password' }
|
7
7
|
|
8
|
-
let(:
|
8
|
+
let(:token_repr) {
|
9
9
|
{
|
10
10
|
'name' => 'personal',
|
11
11
|
'token' => 'token123',
|
12
|
-
'
|
12
|
+
'password' => 'password123',
|
13
|
+
'account_name' => 'besquared',
|
14
|
+
'_links' => {
|
15
|
+
'verify' => {
|
16
|
+
'href' => 'verification_url{?password}'
|
17
|
+
}
|
18
|
+
}
|
13
19
|
}
|
14
20
|
}
|
15
21
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
'token' => 'token567',
|
20
|
-
'account_name' => 'besquared'
|
21
|
-
}
|
22
|
+
|
23
|
+
let(:token_resource) {
|
24
|
+
Mode::API::Resource.new(token_repr)
|
22
25
|
}
|
23
26
|
|
24
|
-
let(:
|
25
|
-
Mode::
|
26
|
-
'_embedded' => {
|
27
|
-
'access_tokens' => [
|
28
|
-
personal_repr,
|
29
|
-
secondary_repr
|
30
|
-
]
|
31
|
-
}
|
32
|
-
})
|
27
|
+
let(:token) {
|
28
|
+
Mode::Auth::AccessToken.new(token_resource)
|
33
29
|
}
|
34
30
|
|
35
|
-
let(:
|
31
|
+
let(:tokens_resource) {
|
36
32
|
Mode::API::Resource.new({
|
37
33
|
'_embedded' => {
|
38
|
-
'access_tokens' => [
|
39
|
-
personal_repr
|
40
|
-
]
|
34
|
+
'access_tokens' => [token_repr]
|
41
35
|
}
|
42
36
|
})
|
43
37
|
}
|
44
38
|
|
45
|
-
let(:
|
46
|
-
Mode::Auth::AccessToken.new(
|
47
|
-
Mode::API::Resource.new(personal_repr)
|
48
|
-
)
|
49
|
-
}
|
50
|
-
|
51
|
-
let(:secondary_token) {
|
52
|
-
Mode::Auth::AccessToken.new(
|
53
|
-
Mode::API::Resource.new(secondary_repr)
|
54
|
-
)
|
55
|
-
}
|
39
|
+
let(:command) { Mode::Commands::Login.new(:test => true) }
|
56
40
|
|
57
41
|
before do
|
58
42
|
initialize_logger
|
43
|
+
command.stub(:say)
|
59
44
|
end
|
60
45
|
|
61
46
|
it "initializes with each environment" do
|
@@ -65,65 +50,52 @@ describe Mode::Commands::Login do
|
|
65
50
|
end
|
66
51
|
|
67
52
|
it "executes a login process with a new config" do
|
68
|
-
command = Mode::Commands::Login.new
|
69
|
-
|
70
|
-
command.stub(:say)
|
71
53
|
command.stub(:config_dir).and_return(tmpdir)
|
72
54
|
|
73
55
|
command.should_receive(:configure_credentials).and_return([username, password])
|
74
|
-
command.should_receive(:choose_access_token).and_return(
|
56
|
+
command.should_receive(:choose_access_token).and_return(token)
|
75
57
|
|
76
58
|
command.execute
|
77
59
|
|
78
60
|
config = Mode::Config.new(tmpdir)
|
79
61
|
|
80
62
|
config.username.should == 'besquared'
|
81
|
-
config.access_token.should == 'token123'
|
63
|
+
config.access_token['token'].should == 'token123'
|
64
|
+
config.access_token['password'].should == 'password123'
|
82
65
|
end
|
83
66
|
|
84
67
|
it "executes a login process with an existing config" do
|
85
|
-
command = Mode::Commands::Login.new
|
86
|
-
|
87
|
-
command.stub(:say)
|
88
68
|
command.stub(:config_dir).and_return(tmpdir)
|
89
69
|
|
90
70
|
Mode::Config.init(tmpdir)
|
91
71
|
|
92
72
|
command.should_receive(:configure_credentials).and_return([username, password])
|
93
|
-
command.should_receive(:choose_access_token).and_return(
|
73
|
+
command.should_receive(:choose_access_token).and_return(token)
|
94
74
|
|
95
75
|
command.execute
|
96
76
|
|
97
77
|
config = Mode::Config.new(tmpdir)
|
98
78
|
|
99
79
|
config.username.should == 'besquared'
|
100
|
-
config.access_token.should == 'token123'
|
80
|
+
config.access_token['token'].should == 'token123'
|
81
|
+
config.access_token['password'].should == 'password123'
|
101
82
|
end
|
102
83
|
|
103
84
|
it "rescues and displays errors during the login process" do
|
104
|
-
command = Mode::Commands::Login.new
|
105
|
-
|
106
85
|
command.stub(:config_dir).and_return(tmpdir)
|
107
86
|
|
108
87
|
error = StandardError.new("Expected Break")
|
109
88
|
command.should_receive(:configure_credentials).and_raise(error)
|
110
|
-
|
111
89
|
command.should_receive(:say).with("Expected Break")
|
112
|
-
|
113
90
|
command.execute
|
114
91
|
end
|
115
92
|
|
116
93
|
it "configures API with credentials" do
|
117
|
-
command = Mode::Commands::Login.new(:test => true)
|
118
|
-
|
119
94
|
command.send(:configure_api, 'besquared', 'password')
|
120
|
-
|
121
95
|
Mode::API::Request.environment.should == :test
|
122
96
|
end
|
123
97
|
|
124
98
|
it "requests credentials and configures API" do
|
125
|
-
command = Mode::Commands::Login.new(:test => true)
|
126
|
-
|
127
99
|
command.should_receive(:configure_api)
|
128
100
|
command.should_receive(:ask).and_return('besquared', 'password')
|
129
101
|
|
@@ -134,46 +106,85 @@ describe Mode::Commands::Login do
|
|
134
106
|
end
|
135
107
|
|
136
108
|
it "raises when credentials are invalid" do
|
137
|
-
command = Mode::Commands::Login.new(:test => true)
|
138
|
-
|
139
109
|
response = double(:response, :status => 401)
|
140
|
-
Mode::API::Request.should_receive(:get).with(
|
110
|
+
Mode::API::Request.should_receive(:get).with(
|
111
|
+
:access_tokens).and_return(response)
|
112
|
+
|
141
113
|
expect { command.send(:fetch_access_tokens) }.to raise_error
|
142
114
|
end
|
143
115
|
|
144
|
-
it "fetches access tokens
|
145
|
-
|
146
|
-
|
116
|
+
it "fetches access tokens" do
|
117
|
+
Mode::API::Request.should_receive(:get).with(
|
118
|
+
:access_tokens).and_return(tokens_resource)
|
119
|
+
|
120
|
+
command.send(:fetch_access_tokens).first.token.should == 'token123'
|
121
|
+
end
|
147
122
|
|
148
|
-
|
123
|
+
it "creates a new access token" do
|
124
|
+
Mode::API::Request.should_receive(:post).with(:access_tokens, {
|
125
|
+
:access_token => { :name => "Token Name" } }).and_return(token_resource)
|
149
126
|
|
150
|
-
|
151
|
-
|
152
|
-
tokens.last.token.should == 'token567'
|
127
|
+
command.should_receive(:ask).and_return("Token Name")
|
128
|
+
command.send(:create_access_token).token.should == 'token123'
|
153
129
|
end
|
154
130
|
|
155
|
-
it "
|
156
|
-
|
157
|
-
|
131
|
+
it "verifies an access token password with success" do
|
132
|
+
Mode::API::Request.should_receive(:get).with(
|
133
|
+
'verification_url?password=password').and_return(token_resource)
|
134
|
+
|
135
|
+
command.send(:verify_access_token, token, 'password').token.should == token.token
|
136
|
+
end
|
158
137
|
|
159
|
-
|
138
|
+
describe "when there are no access tokens" do
|
139
|
+
it "prompts the user to create an access token" do
|
140
|
+
command.should_receive(:fetch_access_tokens).and_return([])
|
141
|
+
command.should_receive(:prompt_create_access_token).and_return(token)
|
142
|
+
command.send(:choose_access_token).should == token
|
143
|
+
end
|
160
144
|
|
161
|
-
|
145
|
+
it "creates a new token upon user request" do
|
146
|
+
command.should_receive(:yes?).and_return(true)
|
147
|
+
command.should_receive(:create_access_token).and_return(token)
|
148
|
+
command.send(:prompt_create_access_token).token.should == 'token123'
|
149
|
+
end
|
162
150
|
|
163
|
-
|
164
|
-
|
151
|
+
it "raises an error if the user doesn't create a token" do
|
152
|
+
command.should_receive(:yes?).and_return(false)
|
153
|
+
expect { command.send(:prompt_create_access_token) }.to raise_error
|
154
|
+
end
|
165
155
|
end
|
166
156
|
|
167
|
-
|
168
|
-
|
169
|
-
|
157
|
+
describe "when there are one or more access tokens" do
|
158
|
+
it "prompts the user to choose an access token" do
|
159
|
+
command.should_receive(:fetch_access_tokens).and_return([token])
|
160
|
+
command.should_receive(:prompt_choose_access_token).with([token]).and_return(token)
|
161
|
+
command.send(:choose_access_token).should == token
|
162
|
+
end
|
170
163
|
|
171
|
-
|
172
|
-
|
164
|
+
it "asks the user to make a token choice" do
|
165
|
+
command.should_receive(:ask).and_return("2")
|
166
|
+
command.should_receive(:ask).and_return("1")
|
167
|
+
command.send(:ask_for_access_token_choice, [token]).should == "1"
|
168
|
+
end
|
173
169
|
|
174
|
-
|
170
|
+
it "verifies the chosen access token" do
|
171
|
+
command.should_receive(:ask).and_return(:fake)
|
172
|
+
command.should_receive(:ask).and_return(:secret)
|
173
|
+
command.should_receive(:verify_access_token).with(token, :fake).and_return(false)
|
174
|
+
command.should_receive(:verify_access_token).with(token, :secret).and_return(true)
|
175
|
+
command.send(:verify_access_token_secret, token).should == true
|
176
|
+
end
|
175
177
|
|
176
|
-
|
177
|
-
|
178
|
+
it "verifies the access token after prompted choice" do
|
179
|
+
command.should_receive(:ask_for_access_token_choice).and_return("1")
|
180
|
+
command.should_receive(:verify_access_token_secret).and_return(token)
|
181
|
+
command.send(:prompt_choose_access_token, [token]).should == token
|
182
|
+
end
|
183
|
+
|
184
|
+
it "creates a new token if the user skips token choice" do
|
185
|
+
command.should_receive(:ask_for_access_token_choice).and_return("")
|
186
|
+
command.should_receive(:create_access_token).and_return(token)
|
187
|
+
command.send(:prompt_choose_access_token, [token]).should == token
|
188
|
+
end
|
178
189
|
end
|
179
190
|
end
|