tddium-preview 0.1.2 → 0.1.3
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.
- data/lib/tddium.rb +28 -2
- data/lib/tddium/constant.rb +5 -1
- data/lib/tddium/version.rb +1 -1
- data/spec/tddium_spec.rb +86 -2
- metadata +2 -2
data/lib/tddium.rb
CHANGED
@@ -20,6 +20,7 @@ require File.expand_path("../tddium/constant", __FILE__)
|
|
20
20
|
# tddium logout # Log out
|
21
21
|
#
|
22
22
|
# tddium account # View/Manage account information
|
23
|
+
# tddium account:password # Change password
|
23
24
|
#
|
24
25
|
# tddium dev # Enter "dev" mode, for single-test quick-turnaround debugging.
|
25
26
|
# tddium stopdev # Leave "dev" mode.
|
@@ -77,6 +78,31 @@ class Tddium < Thor
|
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
81
|
+
desc "password", "Change password"
|
82
|
+
method_option :environment, :type => :string, :default => nil
|
83
|
+
def password
|
84
|
+
set_default_environment(options[:environment])
|
85
|
+
return unless tddium_settings
|
86
|
+
user_details = user_logged_in?
|
87
|
+
return unless user_details
|
88
|
+
|
89
|
+
params = {}
|
90
|
+
params[:current_password] = HighLine.ask(Text::Prompt::CURRENT_PASSWORD) { |q| q.echo = "*" }
|
91
|
+
params[:password] = HighLine.ask(Text::Prompt::NEW_PASSWORD) { |q| q.echo = "*" }
|
92
|
+
params[:password_confirmation] = HighLine.ask(Text::Prompt::PASSWORD_CONFIRMATION) { |q| q.echo = "*" }
|
93
|
+
|
94
|
+
begin
|
95
|
+
user_id = user_details["user"]["id"]
|
96
|
+
result = call_api(:put, "#{Api::Path::USERS}/#{user_id}/", {:user=>params},
|
97
|
+
tddium_settings["api_key"], false)
|
98
|
+
say Text::Process::PASSWORD_CHANGED
|
99
|
+
rescue TddiumClient::Error::API => e
|
100
|
+
say Text::Error::PASSWORD_ERROR % e.explanation
|
101
|
+
rescue TddiumClient::Error::Base => e
|
102
|
+
say e.message
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
80
106
|
desc "login", "Log in to tddium using your email address and password"
|
81
107
|
method_option :environment, :type => :string, :default => nil
|
82
108
|
method_option :email, :type => :string, :default => nil
|
@@ -483,8 +509,8 @@ class Tddium < Thor
|
|
483
509
|
git_push
|
484
510
|
end
|
485
511
|
|
486
|
-
def user_logged_in?(active = true)
|
487
|
-
result = tddium_settings(:fail_with_message =>
|
512
|
+
def user_logged_in?(active = true, message = false)
|
513
|
+
result = tddium_settings(:fail_with_message => message) && tddium_settings["api_key"]
|
488
514
|
(result && active) ? get_user : result
|
489
515
|
end
|
490
516
|
|
data/lib/tddium/constant.rb
CHANGED
@@ -51,7 +51,9 @@ module TddiumConstant
|
|
51
51
|
SUITE_NAME = "Enter a suite name or press 'Return'. Using '%s' by default:"
|
52
52
|
LICENSE_AGREEMENT = "Type '%s' to accept the license and continue:" % Response::AGREE_TO_LICENSE
|
53
53
|
EMAIL = "Enter your email address:"
|
54
|
-
|
54
|
+
CURRENT_PASSWORD = "Enter your old password: "
|
55
|
+
PASSWORD = "Enter password: "
|
56
|
+
NEW_PASSWORD = "Enter a new password: "
|
55
57
|
PASSWORD_CONFIRMATION = "Confirm your password: "
|
56
58
|
INVITATION_TOKEN = "Enter your invitation token:"
|
57
59
|
USE_EXISTING_SUITE = "The suite name '%s' already exists. Enter '#{Response::YES}' to use it, or enter a new name:"
|
@@ -67,6 +69,7 @@ module TddiumConstant
|
|
67
69
|
EXISTING_SUITE = "Current suite: %s"
|
68
70
|
CREATING_SUITE = "Creating suite '%s'. This will take a few seconds."
|
69
71
|
PASSWORD_CONFIRMATION_INCORRECT = "Password confirmation incorrect"
|
72
|
+
PASSWORD_CHANGED = "Your password has been changed."
|
70
73
|
ACCOUNT_CREATED = "
|
71
74
|
Congratulations %s, your tddium account has been created!
|
72
75
|
|
@@ -118,6 +121,7 @@ http://blog.tddium.com/home/
|
|
118
121
|
"
|
119
122
|
NO_USER_DATA_FILE = "User data file '%s' does not exist"
|
120
123
|
NO_MATCHING_FILES = "No files match '%s'"
|
124
|
+
PASSWORD_ERROR = "Error changing password: %s"
|
121
125
|
end
|
122
126
|
end
|
123
127
|
|
data/lib/tddium/version.rb
CHANGED
data/spec/tddium_spec.rb
CHANGED
@@ -21,19 +21,23 @@ describe Tddium do
|
|
21
21
|
SAMPLE_GIT_REPO_URI = "ssh://git@api.tddium.com/home/git/repo/#{SAMPLE_APP_NAME}"
|
22
22
|
SAMPLE_LICENSE_TEXT = "LICENSE"
|
23
23
|
SAMPLE_PASSWORD = "foobar"
|
24
|
+
SAMPLE_NEW_PASSWORD = "foobar2"
|
24
25
|
SAMPLE_REPORT_URL = "http://api.tddium.com/1/sessions/1/test_executions/report"
|
25
26
|
SAMPLE_RUBYGEMS_VERSION = "1.3.7"
|
26
27
|
SAMPLE_RUBY_VERSION = "1.8.7"
|
27
28
|
SAMPLE_RECURLY_URL = "https://tddium.recurly.com/account/1"
|
28
29
|
SAMPLE_SESSION_ID = 1
|
29
30
|
SAMPLE_SUITE_ID = 1
|
31
|
+
SAMPLE_USER_ID = 1
|
30
32
|
DEFAULT_TEST_PATTERN = "**/*_spec.rb"
|
31
33
|
CUSTOM_TEST_PATTERN = "**/cat_spec.rb"
|
32
34
|
SAMPLE_SUITE_RESPONSE = {"repo_name" => SAMPLE_APP_NAME, "branch" => SAMPLE_BRANCH_NAME, "id" => SAMPLE_SUITE_ID, "ruby_version"=>SAMPLE_RUBY_VERSION, "git_repo_uri" => SAMPLE_GIT_REPO_URI}
|
33
35
|
SAMPLE_SUITES_RESPONSE = {"suites" => [SAMPLE_SUITE_RESPONSE]}
|
34
36
|
SAMPLE_TDDIUM_CONFIG_FILE = ".tddium.test"
|
35
37
|
SAMPLE_TEST_EXECUTION_STATS = "total 1, notstarted 0, started 1, passed 0, failed 0, pending 0, error 0", "start_time"
|
36
|
-
SAMPLE_USER_RESPONSE = {"user"=> {"api_key" => SAMPLE_API_KEY, "email" => SAMPLE_EMAIL, "created_at" => SAMPLE_DATE_TIME, "recurly_url" => SAMPLE_RECURLY_URL}}
|
38
|
+
SAMPLE_USER_RESPONSE = {"user"=> {"id"=>SAMPLE_USER_ID, "api_key" => SAMPLE_API_KEY, "email" => SAMPLE_EMAIL, "created_at" => SAMPLE_DATE_TIME, "recurly_url" => SAMPLE_RECURLY_URL}}
|
39
|
+
PASSWORD_ERROR_EXPLANATION = "bad confirmation"
|
40
|
+
PASSWORD_ERROR_RESPONSE = {"status"=>1, "explanation"=> PASSWORD_ERROR_EXPLANATION}
|
37
41
|
|
38
42
|
def call_api_should_receive(options = {})
|
39
43
|
params = [options[:method] || anything, options[:path] || anything, options[:params] || anything, (options[:api_key] || options[:api_key] == false) ? options[:api_key] : anything]
|
@@ -53,7 +57,7 @@ describe Tddium do
|
|
53
57
|
send("run_#{example.example_group.ancestors.map(&:description)[-2][1..-1]}", tddium, options)
|
54
58
|
end
|
55
59
|
|
56
|
-
[:suite, :spec, :status, :account, :login, :logout].each do |method|
|
60
|
+
[:suite, :spec, :status, :account, :login, :logout, :password].each do |method|
|
57
61
|
define_method("run_#{method}") do |tddium, *params|
|
58
62
|
options = params.first || {}
|
59
63
|
if method == :spec
|
@@ -339,6 +343,86 @@ describe Tddium do
|
|
339
343
|
end
|
340
344
|
end
|
341
345
|
|
346
|
+
shared_examples_for "prompting for password" do
|
347
|
+
it "should prompt for a password" do
|
348
|
+
highline = mock(HighLine)
|
349
|
+
HighLine.should_receive(:ask).with(password_prompt).and_yield(highline)
|
350
|
+
highline.should_receive(:echo=).with("*")
|
351
|
+
run(tddium)
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
describe "#password" do
|
356
|
+
before do
|
357
|
+
stub_defaults
|
358
|
+
stub_config_file(:api_key => true, :branches => true)
|
359
|
+
tddium.stub(:ask).and_return("")
|
360
|
+
HighLine.stub(:ask).and_return("")
|
361
|
+
end
|
362
|
+
|
363
|
+
it_should_behave_like ".tddium file is missing or corrupt"
|
364
|
+
|
365
|
+
context "the user is already logged in" do
|
366
|
+
before do
|
367
|
+
stub_call_api_response(:get, Tddium::Api::Path::USERS, SAMPLE_USER_RESPONSE)
|
368
|
+
end
|
369
|
+
|
370
|
+
it_should_behave_like "set the default environment"
|
371
|
+
|
372
|
+
it_should_behave_like "prompting for password" do
|
373
|
+
let(:password_prompt) {Tddium::Text::Prompt::CURRENT_PASSWORD}
|
374
|
+
end
|
375
|
+
|
376
|
+
it_should_behave_like "prompting for password" do
|
377
|
+
let(:password_prompt) {Tddium::Text::Prompt::NEW_PASSWORD}
|
378
|
+
end
|
379
|
+
|
380
|
+
it_should_behave_like "prompting for password" do
|
381
|
+
let(:password_prompt) {Tddium::Text::Prompt::PASSWORD_CONFIRMATION}
|
382
|
+
end
|
383
|
+
|
384
|
+
context "the user confirms their password correctly" do
|
385
|
+
before do
|
386
|
+
@user_path = "#{Tddium::Api::Path::USERS}/#{SAMPLE_USER_ID}/"
|
387
|
+
HighLine.stub(:ask).with(Tddium::Text::Prompt::CURRENT_PASSWORD).and_return(SAMPLE_PASSWORD)
|
388
|
+
HighLine.stub(:ask).with(Tddium::Text::Prompt::NEW_PASSWORD).and_return(SAMPLE_NEW_PASSWORD)
|
389
|
+
HighLine.stub(:ask).with(Tddium::Text::Prompt::PASSWORD_CONFIRMATION).and_return(SAMPLE_NEW_PASSWORD)
|
390
|
+
end
|
391
|
+
|
392
|
+
|
393
|
+
it "should send a 'PUT' request to user_path with passwords" do
|
394
|
+
call_api_should_receive(:method => :put,
|
395
|
+
:path => /#{@user_path}$/,
|
396
|
+
:params => {:user =>
|
397
|
+
{:current_password=>SAMPLE_PASSWORD,
|
398
|
+
:password => SAMPLE_NEW_PASSWORD,
|
399
|
+
:password_confirmation => SAMPLE_NEW_PASSWORD}},
|
400
|
+
:api_key => SAMPLE_API_KEY)
|
401
|
+
run_password(tddium)
|
402
|
+
end
|
403
|
+
|
404
|
+
context "'PUT user_path' is successful" do
|
405
|
+
before{stub_call_api_response(:put, @user_path, {"status"=>0})}
|
406
|
+
|
407
|
+
it "should show the user '#{Tddium::Text::Process::PASSWORD_CHANGED}'" do
|
408
|
+
tddium.should_receive(:say).with(Tddium::Text::Process::PASSWORD_CHANGED)
|
409
|
+
run_password(tddium)
|
410
|
+
end
|
411
|
+
end
|
412
|
+
context "'PUT user_path' is unsuccessful" do
|
413
|
+
|
414
|
+
context "invalid original password" do
|
415
|
+
before{stub_call_api_response(:put, @user_path, PASSWORD_ERROR_RESPONSE)}
|
416
|
+
it "should show the user: '#{Tddium::Text::Error::PASSWORD_ERROR}'" do
|
417
|
+
tddium.should_receive(:say).with(Tddium::Text::Error::PASSWORD_ERROR % PASSWORD_ERROR_EXPLANATION)
|
418
|
+
run_password(tddium)
|
419
|
+
end
|
420
|
+
end
|
421
|
+
end
|
422
|
+
end
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
342
426
|
describe "#account" do
|
343
427
|
before do
|
344
428
|
stub_defaults
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: tddium-preview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Solano Labs
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-02 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|