tddium-preview 0.7.4 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tddium-preview (0.7.3)
4
+ tddium-preview (0.7.4)
5
5
  bundler
6
6
  highline
7
7
  json
@@ -0,0 +1,67 @@
1
+ @mimic
2
+ Feature: Account command
3
+ As a Tddium user
4
+ In order to use Tddium in my organization
5
+ I want to be able to see billing info and control who has access to my account
6
+
7
+ Background:
8
+ Given the user has the following memberships in his account:
9
+ | id | role | email | display |
10
+ | 1 | member | member@example.com | [member] member@example.com |
11
+ | 2 | admin | admin@example.com | [admin] admin@example.com |
12
+ | 3 | owner | owner@example.com | [owner] owner@example.com |
13
+ | 4 | admin | someone@example.com | [admin] someone@example.com |
14
+
15
+ Scenario: Display account information
16
+ Given the user is logged in
17
+ And the user has a suite for "alpha" on "master"
18
+ When I run `tddium account`
19
+ Then the output should contain "someone@example.com"
20
+ And the output should contain:
21
+ """
22
+ [member] member@example.com
23
+ [admin] admin@example.com
24
+ """
25
+
26
+ Scenario: Add member to account successfully
27
+ Given the user is logged in
28
+ And adding a member to the account will succeed
29
+ When I successfully run `tddium account:add member member2@example.com`
30
+ Then the output should contain "Added member2@example.com"
31
+
32
+ Scenario: Add member to account unsuccessfully
33
+ Given the user is logged in
34
+ And adding a member to the account will fail with error "add member error"
35
+ When I run `tddium account:add member member@example.com`
36
+ Then the output should not contain "Added member@example.com"
37
+ And the output should contain "add member error"
38
+ And the exit status should not be 0
39
+
40
+ Scenario: Fail to add to account when not logged in
41
+ When I run `tddium account:add member member@example.com`
42
+ Then it should fail with:
43
+ """
44
+ tddium must be initialized. Try 'tddium login'
45
+ """
46
+
47
+ Scenario: Remove member from account successfully
48
+ Given the user is logged in
49
+ And removing "member@example.com" from the account will succeed
50
+ When I successfully run `tddium account:remove member@example.com`
51
+ Then the output should contain "Removed member@example.com"
52
+
53
+ Scenario: Remove member to account unsuccessfully
54
+ Given the user is logged in
55
+ And removing "member@example.com" from the account will fail with error "remove member error"
56
+ When I run `tddium account:remove member@example.com`
57
+ Then the output should not contain "Removed member@example.com"
58
+ And the output should contain "remove member error"
59
+ And the exit status should not be 0
60
+
61
+ Scenario: Fail to remove from account when not logged in
62
+ When I run `tddium account:remove member@example.com`
63
+ Then it should fail with:
64
+ """
65
+ tddium must be initialized. Try 'tddium login'
66
+ """
67
+
@@ -3,7 +3,7 @@ Feature: Login command
3
3
 
4
4
  Scenario: Interactively log in successfully
5
5
  Given the user can log in and gets API key "apikey"
6
- When I run `tddium login --environment=mimic` interactively
6
+ When I run `tddium login` interactively
7
7
  And I type "foo@example.com"
8
8
  And I type "barbarbar"
9
9
  And the console session ends
@@ -12,25 +12,21 @@ Feature: Login command
12
12
  Logged in successfully
13
13
  """
14
14
  And the exit status should be 0
15
- And the file ".tddium.mimic" should contain "apikey"
16
- And the file ".gitignore" should contain ".tddium.mimic"
17
- And the file ".gitignore" should contain ".tddium-deploy-key.mimic"
15
+ And dotfiles should be updated
18
16
 
19
17
  Scenario: Non-interactively log in successfully
20
18
  Given the user can log in and gets API key "apikey"
21
- When I run `tddium login --environment=mimic --email=foo@example.com --password=barbarbar`
19
+ When I run `tddium login --email=foo@example.com --password=barbarbar`
22
20
  Then the output should contain:
23
21
  """
24
22
  Logged in successfully
25
23
  """
26
24
  And the exit status should be 0
27
- And the file ".tddium.mimic" should contain "apikey"
28
- And the file ".gitignore" should contain ".tddium.mimic"
29
- And the file ".gitignore" should contain ".tddium-deploy-key.mimic"
25
+ And dotfiles should be updated
30
26
 
31
27
  Scenario: Non-interactively log in unsuccessfully
32
28
  Given the user cannot log in
33
- When I run `tddium login --environment=mimic --email=foo@example.com --password=barbarbar`
29
+ When I run `tddium login --email=foo@example.com --password=barbarbar`
34
30
  Then the output should contain:
35
31
  """
36
32
  Access Denied
@@ -0,0 +1,24 @@
1
+ Given /^the user has the following memberships in his account:$/ do |table|
2
+ MimicServer.server.install(:get, "/1/memberships", {:status=>0, :memberships=>table.hashes})
3
+ @memberships = {}
4
+ table.hashes.each do |row|
5
+ @memberships[row['email']]=row
6
+ end
7
+ end
8
+
9
+ Given /^adding a member to the account will succeed$/ do
10
+ MimicServer.server.install(:post, "/1/memberships", {:status=>0}, :code=>201)
11
+ end
12
+
13
+ Given /^adding a member to the account will fail with error "([^"]*)"$/ do |error|
14
+ MimicServer.server.install(:post, "/1/memberships", {:status=>1, :explanation=>error}, :code=>409)
15
+ end
16
+
17
+ Given /^removing "([^"]*)" from the account will succeed$/ do |member|
18
+ MimicServer.server.install(:delete, "/1/memberships/#{member}", {:status=>0}, :code=>200)
19
+ end
20
+
21
+ Given /^removing "([^"]*)" from the account will fail with error "([^"]*)"$/ do |member, error|
22
+ MimicServer.server.install(:delete, "/1/memberships/#{member}", {:status=>1, :explanation=>error}, :code=>409)
23
+ end
24
+
@@ -1,5 +1,7 @@
1
1
  Given /^the user is logged in$/ do
2
2
  @api_key = "abcdef"
3
+ MimicServer.server.install(:get, "/1/users", SAMPLE_USER_RESPONSE)
4
+ MimicServer.server.install(:get, "/1/accounts/usage", SAMPLE_ACCOUNT_USAGE)
3
5
  steps %Q{
4
6
  Given a file named ".tddium.mimic" with:
5
7
  """
@@ -16,3 +18,10 @@ Given /^the user cannot log in$/ do
16
18
  MimicServer.server.install(:post, "/1/users/sign_in", {:status=>1, :explanation=>"Access Denied."}, :code=>403)
17
19
  end
18
20
 
21
+ Then /^dotfiles should be updated$/ do
22
+ steps %Q{
23
+ And the file ".tddium.mimic" should contain "apikey"
24
+ And the file ".gitignore" should contain ".tddium.mimic"
25
+ And the file ".gitignore" should contain ".tddium-deploy-key.mimic"
26
+ }
27
+ end
@@ -1,6 +1,6 @@
1
1
  When /^I respond to "([^"]*)" with "([^"]*)"$/ do |expect, response|
2
2
  steps %Q{
3
- Then the output from "tddium suite --environment=mimic" should contain "#{expect}"
3
+ Then the output from "tddium suite" should contain "#{expect}"
4
4
  When I type "#{response}"
5
5
  }
6
6
  end
@@ -10,15 +10,15 @@ Feature: suite command
10
10
  And the user is logged in
11
11
  And the user has no suites
12
12
  And the user can create a suite named "beta" on branch "test/foobar"
13
- When I run `tddium suite --environment=mimic` interactively
13
+ When I run `tddium suite` interactively
14
14
  And I respond to "repo name" with "beta"
15
- Then the output from "tddium suite --environment=mimic" should contain "Detected branch test/foobar"
15
+ Then the output from "tddium suite" should contain "Detected branch test/foobar"
16
16
  And I respond to "test pattern" with ""
17
17
  And I respond to "URL to pull from" with "disable"
18
18
  And I respond to "URL to push to" with "disable"
19
19
  And I respond to "Campfire subdomain" with "disable"
20
- Then the output from "tddium suite --environment=mimic" should contain "Pushing changes to Tddium..."
21
- And the output from "tddium suite --environment=mimic" should contain "Created suite..."
20
+ Then the output from "tddium suite" should contain "Pushing changes to Tddium..."
21
+ And the output from "tddium suite" should contain "Created suite..."
22
22
  When the console session ends
23
23
  Then the exit status should be 0
24
24
 
@@ -61,3 +61,4 @@ require 'aruba/api'
61
61
  "recurly_url" => SAMPLE_RECURLY_URL}}
62
62
  PASSWORD_ERROR_EXPLANATION = "bad confirmation"
63
63
  PASSWORD_ERROR_RESPONSE = {"status"=>1, "explanation"=> PASSWORD_ERROR_EXPLANATION}
64
+ SAMPLE_ACCOUNT_USAGE = {"status"=>0, "usage"=>"Usage: something"}
@@ -123,6 +123,7 @@ Before('@mimic') do
123
123
  tid = ENV['TDDIUM_TID'] || 0
124
124
  port = 8500 + tid.to_i
125
125
  ENV['TDDIUM_CLIENT_PORT'] = port.to_s
126
+ ENV['TDDIUM_CLIENT_ENVIRONMENT'] = 'mimic'
126
127
  MimicServer.start(port)
127
128
  end
128
129
 
data/lib/tddium.rb CHANGED
@@ -93,6 +93,39 @@ class Tddium < Thor
93
93
  end
94
94
  end
95
95
 
96
+ desc "account:add [ROLE] [EMAIL]", "Authorize and invite a user to use your account"
97
+ define_method "account:add" do |role, email|
98
+ set_shell
99
+ set_default_environment
100
+ user_details = user_logged_in?(true, true)
101
+ exit_failure unless user_details
102
+
103
+ params = {:role=>role, :email=>email}
104
+ begin
105
+ say Text::Process::ADDING_MEMBER % params
106
+ result = call_api(:post, Api::Path::MEMBERSHIPS, params)
107
+ say Text::Process::ADDED_MEMBER % email
108
+ rescue TddiumClient::Error::API => e
109
+ exit_failure Text::Error::ADD_MEMBER_ERROR % [email, e.message]
110
+ end
111
+ end
112
+
113
+ desc "account:remove [EMAIL]", "Remove a user from your account"
114
+ define_method "account:remove" do |email|
115
+ set_shell
116
+ set_default_environment
117
+ user_details = user_logged_in?(true, true)
118
+ exit_failure unless user_details
119
+
120
+ begin
121
+ say Text::Process::REMOVING_MEMBER % email
122
+ result = call_api(:delete, "#{Api::Path::MEMBERSHIPS}/#{email}")
123
+ say Text::Process::REMOVED_MEMBER % email
124
+ rescue TddiumClient::Error::API => e
125
+ exit_failure Text::Error::REMOVE_MEMBER_ERROR % [email, e.message]
126
+ end
127
+ end
128
+
96
129
  desc "heroku", "Connect Heroku account with Tddium"
97
130
  method_option :email, :type => :string, :default => nil
98
131
  method_option :password, :type => :string, :default => nil
@@ -676,7 +709,7 @@ class Tddium < Thor
676
709
  end
677
710
 
678
711
  def set_default_environment
679
- env = options[:environment]
712
+ env = options[:environment] || ENV['TDDIUM_CLIENT_ENVIRONMENT']
680
713
  if env.nil?
681
714
  tddium_client.environment = :development
682
715
  tddium_client.environment = :production unless File.exists?(tddium_file_name)
@@ -723,6 +756,13 @@ class Tddium < Thor
723
756
  say Text::Status::ALL_SUITES % current_suites["suites"].collect {|suite| suite["repo_name"]}.join(", ")
724
757
  end
725
758
 
759
+ memberships = call_api(:get, Api::Path::MEMBERSHIPS)
760
+ if memberships["memberships"].length > 1
761
+ say Text::Status::ACCOUNT_MEMBERS
762
+ say memberships["memberships"].collect{|x|x['display']}.join("\n")
763
+ say "\n"
764
+ end
765
+
726
766
  account_usage = call_api(:get, Api::Path::ACCOUNT_USAGE)
727
767
  say account_usage["usage"]
728
768
  rescue TddiumClient::Error::Base => e
@@ -31,6 +31,7 @@ module TddiumConstant
31
31
  START_TEST_EXECUTIONS = "#{TEST_EXECUTIONS}/start"
32
32
  REPORT_TEST_EXECUTIONS = "#{TEST_EXECUTIONS}/report"
33
33
  ACCOUNT_USAGE = "accounts/usage"
34
+ MEMBERSHIPS = "memberships"
34
35
  end
35
36
  module ErrorCode
36
37
  INVALID_INVITATION = 2
@@ -181,6 +182,10 @@ Subdomain and API token are shared by all suites that belong to you (%s).
181
182
  Set the "Campfire room name" to 'disable' to disable Campfire notifications
182
183
  for this suite.
183
184
  EOF
185
+ ADDING_MEMBER = "Adding %<email>s as %<role>s..."
186
+ ADDED_MEMBER = "Added %s"
187
+ REMOVING_MEMBER = "Removing %s. This may take a few seconds..."
188
+ REMOVED_MEMBER = "Removed %s"
184
189
  end
185
190
 
186
191
  module Status
@@ -286,6 +291,7 @@ Run 'tddium suite --edit' to edit suite settings.
286
291
 
287
292
  Run 'tddium spec' to run tests in this suite.
288
293
  EOF
294
+ ACCOUNT_MEMBERS = "\nAuthorized users in this account:\n"
289
295
  end
290
296
 
291
297
  module Error
@@ -343,7 +349,8 @@ EOF
343
349
  NOT_LOGGED_IN = "Log in to your heroku account first using 'heroku login'"
344
350
  APP_NOT_FOUND = "The app '%s' is not recognized by Heroku"
345
351
  end
346
-
352
+ ADD_MEMBER_ERROR = "Error adding %s: %s"
353
+ REMOVE_MEMBER_ERROR = "Error removing %s: %s"
347
354
  end
348
355
  end
349
356
 
@@ -3,5 +3,5 @@ Copyright (c) 2011 Solano Labs All Rights Reserved
3
3
  =end
4
4
 
5
5
  module TddiumVersion
6
- VERSION = "0.7.4"
6
+ VERSION = "0.8.0"
7
7
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: tddium-preview
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.7.4
5
+ version: 0.8.0
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-08-30 00:00:00 -07:00
13
+ date: 2011-09-02 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -151,8 +151,10 @@ files:
151
151
  - README.rdoc
152
152
  - Rakefile
153
153
  - bin/tddium
154
+ - features/account_command.feature
154
155
  - features/login_command.feature
155
156
  - features/logout_command.feature
157
+ - features/step_definitions/account_steps.rb
156
158
  - features/step_definitions/aruba_steps.rb
157
159
  - features/step_definitions/login_steps.rb
158
160
  - features/step_definitions/mimic_steps.rb