spade 0.0.2 → 0.0.3

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
- spade (0.0.1)
4
+ spade (0.0.2)
5
5
  eventmachine (~> 0.12.10)
6
6
  gemcutter (~> 0.6.1)
7
7
  highline (~> 1.6.1)
@@ -13,10 +13,6 @@ module Spade::CLI
13
13
  :aliases => ['-V'],
14
14
  :desc => 'Show additional debug information while running'
15
15
 
16
- class_option :version, :type => :string,
17
- :aliases => ['-v'],
18
- :desc => 'Package version'
19
-
20
16
  class_option :require, :type => :array, :required => false,
21
17
  :aliases => ['-r'],
22
18
  :desc => "optional JS files to require before invoking main command"
@@ -204,11 +200,17 @@ module Spade::CLI
204
200
  end
205
201
 
206
202
  desc "yank", "Remove a specific package version release from SproutCutter"
203
+ method_option :version, :type => :string, :default => nil, :aliases => ['-v'], :desc => 'Specify a version to yank'
204
+ method_option :undo, :type => :boolean, :default => false, :desc => 'Unyank package'
207
205
  def yank(package)
208
206
  if options[:version]
209
207
  remote = Spade::Remote.new
210
208
  if remote.logged_in?
211
- say remote.yank(package, options[:version])
209
+ if options[:undo]
210
+ say remote.unyank(package, options[:version])
211
+ else
212
+ say remote.yank(package, options[:version])
213
+ end
212
214
  else
213
215
  say LOGIN_MESSAGE
214
216
  end
data/lib/spade/remote.rb CHANGED
@@ -39,6 +39,13 @@ module Spade
39
39
  end
40
40
  end
41
41
 
42
+ def unyank(package, version)
43
+ request :put, "api/v1/gems/unyank" do |req|
44
+ req.set_form_data 'gem_name' => package, 'version' => version
45
+ req.add_field "Authorization", creds.api_key
46
+ end
47
+ end
48
+
42
49
  def add_owner(package, email)
43
50
  request :post, "api/v1/gems/#{package}/owners" do |req|
44
51
  req.set_form_data 'email' => email
data/lib/spade/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spade
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -0,0 +1,74 @@
1
+ require "spec_helper"
2
+
3
+ describe "spade unyank" do
4
+ let(:api_key) { "deadbeef" }
5
+ let(:creds) { spade_dir("credentials") }
6
+
7
+ before do
8
+ cd(home)
9
+ env["HOME"] = home.to_s
10
+ env["RUBYGEMS_HOST"] = "http://localhost:9292"
11
+ start_fake(FakeGemcutter.new(api_key))
12
+ end
13
+
14
+ context "with a good api key" do
15
+ before do
16
+ write_api_key(api_key)
17
+ end
18
+
19
+ it "unyanks a gem when sent with the right api key" do
20
+ spade "yank", "core-test", "--undo", "-v", "1.4.3"
21
+
22
+ stdout.read.should include("Successfully unyanked gem: core-test (1.4.3)")
23
+ end
24
+
25
+ it "must unyank a valid gem" do
26
+ spade "yank", "blahblah", "--undo", "-v", "0.0.1"
27
+
28
+ stdout.read.should include("This gem could not be found")
29
+ end
30
+
31
+ it "does not unyank and indexed gem" do
32
+ spade "yank", "core-test", "--undo", "-v", "2.4.3"
33
+
34
+ stdout.read.should include("The version 2.4.3 is already indexed.")
35
+ end
36
+ end
37
+
38
+ it "shows rejection message if wrong api key is supplied" do
39
+ write_api_key("beefbeef")
40
+
41
+ spade "yank", "core-test", "--undo", "-v", "1.4.3"
42
+
43
+ stdout.read.should include("One cannot simply walk into Mordor!")
44
+ end
45
+ end
46
+
47
+ describe "spade unyank with invalid api key" do
48
+ before do
49
+ cd(home)
50
+ env["HOME"] = home.to_s
51
+ env["RUBYGEMS_HOST"] = "http://localhost:9292"
52
+ write_api_key("beefbeef")
53
+ end
54
+
55
+ it "must require a version" do
56
+ spade "yank", "core-test", "--undo"
57
+
58
+ stdout.read.should include("Version required")
59
+ end
60
+ end
61
+
62
+ describe "spade unyank without api key" do
63
+ before do
64
+ cd(home)
65
+ env["HOME"] = home.to_s
66
+ env["RUBYGEMS_HOST"] = "http://localhost:9292"
67
+ end
68
+
69
+ it "asks for login first if api key does not exist" do
70
+ spade "yank", "core-test", "-v", "1.4.3", "--undo"
71
+
72
+ stdout.read.should include("Please login first with `spade login`")
73
+ end
74
+ end
@@ -27,6 +27,12 @@ describe "spade yank" do
27
27
 
28
28
  stdout.read.should include("This gem could not be found")
29
29
  end
30
+
31
+ it "does not yank a yanked gem" do
32
+ spade "yank", "core-test", "-v", "2.4.3"
33
+
34
+ stdout.read.should include("The version 2.4.3 has already been yanked.")
35
+ end
30
36
  end
31
37
 
32
38
  it "shows rejection message if wrong api key is supplied" do
@@ -15,10 +15,22 @@ class FakeGemcutter
15
15
  elsif request.path == "/api/v1/gems" && request.post?
16
16
  respond 200, "Successfully registered rake (0.8.7)"
17
17
  elsif request.path == "/api/v1/gems/yank" && request.delete?
18
- if request.params["version"].to_i > 0
18
+ version = request.params["version"].to_i
19
+ if version < 1
20
+ respond 404, "This gem could not be found"
21
+ elsif version < 2
19
22
  respond 200, "Successfully yanked gem: #{request.params["gem_name"]} (#{request.params["version"]})"
20
23
  else
24
+ respond 500, "The version #{request.params["version"]} has already been yanked."
25
+ end
26
+ elsif request.path == "/api/v1/gems/unyank" && request.put?
27
+ version = request.params["version"].to_i
28
+ if version < 1
21
29
  respond 404, "This gem could not be found"
30
+ elsif version < 2
31
+ respond 200, "Successfully unyanked gem: #{request.params["gem_name"]} (#{request.params["version"]})"
32
+ else
33
+ respond 500, "The version #{request.params["version"]} is already indexed."
22
34
  end
23
35
  elsif request.path == "/api/v1/gems/rake/owners"
24
36
  if request.post?
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: spade
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Charles Jolley
@@ -429,6 +429,7 @@ files:
429
429
  - spec/cli/push_spec.rb
430
430
  - spec/cli/uninstall_spec.rb
431
431
  - spec/cli/unpack_spec.rb
432
+ - spec/cli/unyank_spec.rb
432
433
  - spec/cli/yank_spec.rb
433
434
  - spec/credentials_spec.rb
434
435
  - spec/fixtures/badrake-0.8.7.gem
@@ -514,6 +515,7 @@ test_files:
514
515
  - spec/cli/push_spec.rb
515
516
  - spec/cli/uninstall_spec.rb
516
517
  - spec/cli/unpack_spec.rb
518
+ - spec/cli/unyank_spec.rb
517
519
  - spec/cli/yank_spec.rb
518
520
  - spec/credentials_spec.rb
519
521
  - spec/fixtures/badrake-0.8.7.gem