lita-claims 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 732d239f96492956b6cb2bc64e1f70f466288e11
4
- data.tar.gz: 545d89715a2786c0899c85567f409de45158fd3c
3
+ metadata.gz: 0b0044d0d1c66f9d0e5420a8d51cda79bbd03dc4
4
+ data.tar.gz: 9e4156919f937a95262e078c2e9f8b2bdf46ca2c
5
5
  SHA512:
6
- metadata.gz: 181fc3798c01853634389ed24b678755ad07a274c19d6238a8ec9175794c3b2c7de2c16c297f48797da0530f8365331ef0a1becbb16f98c9a51f80c7d513ec53
7
- data.tar.gz: 3e12eeb56bcfe1844cbde5f2225dc2290ab2e32c19478799c0652f849223a61c2c31308863e3860e8c7b48c5b3507d3524141e7234ec40a81b5f9a5ad470bd66
6
+ metadata.gz: e27603ccaba2610838a5c47088513152c6eddba1fe7db65cc100df2e8c35dbad902aa34ba0fe2a38169c706fd4af853037a64249cd5a2788afbeace3694edebb
7
+ data.tar.gz: 5472a5aaeb0f0fc72b744e8474316beac5bc20dd38df3c69812c6fc9bdd443d37fbd1cadc6b62cac0b40b6aa2f69bc9160ca765de8b29aee8adbd3a6c13e9bf9
@@ -10,16 +10,56 @@ module Lita
10
10
  "claim PROPERTY" => "To claim a property by the name PROPERTY"
11
11
  })
12
12
 
13
+ route(/^who claimed\s(#{PROPERTY_OR_ENVIRONMENT.source})(?:\s(#{PROPERTY_OR_ENVIRONMENT.source}))?/i, :exists?, command: true, help: {
14
+ "who claimed PROPERTY" => "To see who claimed a property by the name PROPERTY"
15
+ })
16
+
17
+ route(/^unclaim\s(#{PROPERTY_OR_ENVIRONMENT.source})(?:\s(#{PROPERTY_OR_ENVIRONMENT.source}))?/i, :destroy, command: true, help: {
18
+ "unclaim PROPERTY" => "To remove your claim from a property by the name PROPERTY"
19
+ })
20
+
13
21
  def create(response)
14
22
  claimer = response.message.source.user.name
15
23
  property, environment = response.matches.first
16
24
  environment ||= 'default'
17
25
  environment_string = " (#{environment})" if environment != 'default'
18
26
  if property && Claim.create(property, claimer, environment)
19
- reply = "#{property}#{environment_string} was claimed by #{claimer}"
27
+ reply = "#{property}#{environment_string} was claimed by #{claimer}."
20
28
  else
21
29
  existing_claimer = Claim.read(property, environment)
22
- reply = "Could not claim #{property}#{environment_string} - already claimed by #{existing_claimer}"
30
+ reply = "Could not claim #{property}#{environment_string} - already claimed by #{existing_claimer}."
31
+ end
32
+ response.reply(reply)
33
+ end
34
+
35
+ def exists?(response)
36
+ property, environment = response.matches.first
37
+ environment ||= 'default'
38
+ environment_string = " (#{environment})" if environment != 'default'
39
+ if property && Claim.exists?(property, environment)
40
+ claimer = Claim.read(property, environment)
41
+ reply = "#{property}#{environment_string} is currently claimed by #{claimer}."
42
+ else
43
+ reply = "#{property}#{environment_string} has not been claimed."
44
+ end
45
+ response.reply(reply)
46
+ end
47
+
48
+ def destroy(response)
49
+ unclaimer = response.message.source.user.name
50
+ property, environment = response.matches.first
51
+ environment ||= 'default'
52
+ environment_string = " (#{environment})" if environment != 'default'
53
+ if property && Claim.exists?(property, environment)
54
+ claimer = Claim.read(property, environment)
55
+ if claimer == unclaimer
56
+ Claim.destroy(property, environment)
57
+ reply = "#{property}#{environment_string} is no longer claimed."
58
+ else
59
+ reply = "#{property}#{environment_string} is currently claimed by #{claimer}. Use the --force flag when you are sure to unclaim the property."
60
+ end
61
+ else
62
+ reply = "#{property}#{environment_string} has not yet been claimed."
23
63
  end
24
64
  response.reply(reply)
25
65
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-claims"
3
- spec.version = "0.0.1"
3
+ spec.version = "0.0.2"
4
4
  spec.authors = ["Hannes Fostie"]
5
5
  spec.email = ["hannes@maloik.co"]
6
6
  spec.description = %q{A Lita.io plugin to claim 'properties'. Usecases include disabling deployments for environments when they are in use'}
@@ -4,29 +4,89 @@ describe Lita::Handlers::Claims, lita_handler: true do
4
4
  describe 'routes' do
5
5
  it { routes_command('claim property').to :create }
6
6
  it { routes_command('claim property environment').to :create }
7
+
8
+ it { routes_command('who claimed property').to :exists? }
9
+ it { routes_command('who claimed property environment').to :exists? }
10
+
11
+ it { routes_command('unclaim property').to :destroy }
12
+ it { routes_command('unclaim property environment').to :destroy }
7
13
  end
8
14
 
9
15
  describe 'creating claims' do
10
16
  it 'replies that the claim was made' do
11
17
  send_command 'claim property_x'
12
- expect(replies.last).to eq('property_x was claimed by Test User')
18
+ expect(replies.last).to eq('property_x was claimed by Test User.')
19
+ expect(Claim.exists?('property_x')).to be_true
13
20
  end
14
21
 
15
22
  it 'replies that the claim was made for a non-default environment' do
16
23
  send_command 'claim property_x environment_y'
17
- expect(replies.last).to eq('property_x (environment_y) was claimed by Test User')
24
+ expect(replies.last).to eq('property_x (environment_y) was claimed by Test User.')
25
+ expect(Claim.exists?('property_x', 'environment_y')).to be_true
18
26
  end
19
27
 
20
28
  it 'replies that a claim could not be made because it already exists' do
21
29
  Claim.create('property', 'Test User')
22
30
  send_command 'claim property'
23
- expect(replies.last).to eq('Could not claim property - already claimed by Test User')
31
+ expect(replies.last).to eq('Could not claim property - already claimed by Test User.')
24
32
  end
25
33
 
26
34
  it 'replies that a claim could not be made for a non-default environment because it already exists' do
27
35
  Claim.create('property', 'Test User', 'env')
28
36
  send_command 'claim property env'
29
- expect(replies.last).to eq('Could not claim property (env) - already claimed by Test User')
37
+ expect(replies.last).to eq('Could not claim property (env) - already claimed by Test User.')
38
+ end
39
+ end
40
+
41
+ describe 'check if property has been claimed' do
42
+ it 'replies who claimed a property' do
43
+ Claim.create('property_x', 'claimer')
44
+ send_command 'who claimed property_x'
45
+ expect(replies.last).to eq('property_x is currently claimed by claimer.')
46
+ end
47
+
48
+ it 'replies who claimed a property with environment' do
49
+ Claim.create('property_x', 'claimer', 'some_env')
50
+ send_command 'who claimed property_x some_env'
51
+ expect(replies.last).to eq('property_x (some_env) is currently claimed by claimer.')
52
+ end
53
+
54
+ it 'replies that a property has not been claimed' do
55
+ send_command 'who claimed property_x'
56
+ expect(replies.last).to eq('property_x has not been claimed.')
57
+ end
58
+
59
+ it 'replies that a property has not been claimed with environment' do
60
+ send_command 'who claimed property_x some_env'
61
+ expect(replies.last).to eq('property_x (some_env) has not been claimed.')
62
+ end
63
+ end
64
+
65
+ describe 'removing your claims' do
66
+ it 'removes a claim on a property' do
67
+ Claim.create('property_x', 'Test User')
68
+ send_command 'unclaim property_x'
69
+ expect(replies.last).to eq('property_x is no longer claimed.')
70
+ expect(Claim.exists?('property_x')).to be_false
71
+ end
72
+
73
+ it 'removes a claim on a property for a certain environment' do
74
+ Claim.create('property_x', 'Test User', 'env')
75
+ send_command 'unclaim property_x env'
76
+ expect(replies.last).to eq('property_x (env) is no longer claimed.')
77
+ expect(Claim.exists?('property_x', 'env')).to be_false
78
+ end
79
+
80
+ it 'returns an error when no such claim exists' do
81
+ send_command 'unclaim property_x'
82
+ expect(replies.last).to eq('property_x has not yet been claimed.')
83
+ end
84
+
85
+ it 'returns an error when the claimer is not the person removing a claim' do
86
+ Claim.create('property_x', 'Not the test user')
87
+ send_command 'unclaim property_x'
88
+ expect(replies.last).to eq('property_x is currently claimed by Not the test user. Use the --force flag when you are sure to unclaim the property.')
89
+ expect(Claim.exists?('property_x')).to be_true
30
90
  end
31
91
  end
32
92
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-claims
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hannes Fostie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-11 00:00:00.000000000 Z
11
+ date: 2014-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita