lita 3.0.3 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb14f54dba3cb206240b73763d3e026995bc06a5
4
- data.tar.gz: 45069d5cfdf40c64d531e105a8a87ea54558f2b7
3
+ metadata.gz: 72bfc92024ae2bb828d19ddaa51b6234465522d8
4
+ data.tar.gz: 6849ff7eb590365266e4fa89c8f17a5c4c075e52
5
5
  SHA512:
6
- metadata.gz: 451f67e518336c165ad40cb5a2f0016011145e51d8ec4767eb878073922219c292fe450dfaf31f2d843cd670b781fc3c2aa0a61bada976234c34019e408330a9
7
- data.tar.gz: cf03873b486d1c6a16c78f52b4f0728373c93a7eb0bce3c5aed9a14dd0b89f0f8ef22a62abb3bd534ca7c13ac96be293e1f968f4dbeb0f2a01c70550ad76ed12
6
+ metadata.gz: bd119e2dfff11a6e2bdaafe556c03fd8ab9ce2d89f760474a96588dde7c0bc6316f6fd37de78df4fc9a1bd40ce4f7ea9208cb682d3ea65bead748f843d0f44c3
7
+ data.tar.gz: 3d3b9be32bca1ed13a2dcf9b4ad3b85df51530532f4e1e89fd10749fd7b7a56bd4cda1fda1a461125c953b11ede6d864159d33325c9281fad5a3d155704171ac
@@ -8,8 +8,12 @@ ClassLength:
8
8
  Enabled: false
9
9
  Documentation:
10
10
  Enabled: false
11
+ DoubleNegation:
12
+ Enabled: false
11
13
  EndAlignment:
12
14
  AlignWith: variable
15
+ IndentHash:
16
+ Enabled: false
13
17
  LineLength:
14
18
  Max: 100
15
19
  MethodLength:
@@ -19,19 +19,19 @@ module Lita
19
19
  Process.daemon(true)
20
20
  File.open(@pid_path, "w") { |f| f.write(Process.pid) }
21
21
  set_up_logs
22
- at_exit { FileUtils.rm(@pid_path) if File.exists?(@pid_path) }
22
+ at_exit { FileUtils.rm(@pid_path) if File.exist?(@pid_path) }
23
23
  end
24
24
 
25
25
  private
26
26
 
27
27
  # Abort if Lita is already running.
28
28
  def ensure_not_running
29
- abort I18n.t("lita.daemon.pid_exists", path: @pid_path) if File.exists?(@pid_path)
29
+ abort I18n.t("lita.daemon.pid_exists", path: @pid_path) if File.exist?(@pid_path)
30
30
  end
31
31
 
32
32
  # Call the appropriate method depending on kill mode.
33
33
  def handle_existing_process
34
- if @kill_existing && File.exists?(@pid_path)
34
+ if @kill_existing && File.exist?(@pid_path)
35
35
  kill_existing_process
36
36
  else
37
37
  ensure_not_running
@@ -200,20 +200,22 @@ module Lita
200
200
  # Invokes the given block after the given number of seconds.
201
201
  # @param interval [Integer] The number of seconds to wait before invoking the block.
202
202
  # @yieldparam timer [Lita::Timer] The current {Lita::Timer} instance.
203
+ # @return [void]
203
204
  # @since 3.0.0
204
205
  def after(interval, &block)
205
- Timer.new(interval: interval, &block).start
206
+ Thread.new { Timer.new(interval: interval, &block).start }
206
207
  end
207
208
 
208
209
  # Invokes the given block repeatedly, waiting the given number of seconds between each
209
210
  # invocation.
210
211
  # @param interval [Integer] The number of seconds to wait before each invocation of the block.
211
212
  # @yieldparam timer [Lita::Timer] The current {Lita::Timer} instance.
213
+ # @return [void]
212
214
  # @note The block should call {Lita::Timer#stop} at a terminating condition to avoid infinite
213
215
  # recursion.
214
216
  # @since 3.0.0
215
217
  def every(interval, &block)
216
- Timer.new(interval: interval, recurring: true, &block).start
218
+ Thread.new { Timer.new(interval: interval, recurring: true, &block).start }
217
219
  end
218
220
 
219
221
  # Creates a new +Faraday::Connection+ for making HTTP requests.
@@ -57,7 +57,7 @@ module Lita
57
57
  end
58
58
 
59
59
  def set_description
60
- description = %{#{description_prefix} "#{event_name}"}
60
+ description = %(#{description_prefix} "#{event_name}")
61
61
  description << " to :#{expected_route}" if expected_route
62
62
  ::RSpec.current_example.metadata[:description] = description
63
63
  end
@@ -59,7 +59,7 @@ module Lita
59
59
  end
60
60
 
61
61
  def set_description
62
- description = %{#{description_prefix} "#{message_body}"}
62
+ description = %(#{description_prefix} "#{message_body}")
63
63
  description << " to :#{expected_route}" if expected_route
64
64
  ::RSpec.current_example.metadata[:description] = description
65
65
  end
@@ -32,9 +32,11 @@ module Lita
32
32
 
33
33
  # Sleep for the given interval, call the block, then run again if it's a recurring timer.
34
34
  def run
35
- sleep @interval
36
- @block.call(self) if running? && @block
37
- run if running? && recurring?
35
+ loop do
36
+ sleep @interval
37
+ @block.call(self) if running? && @block
38
+ break unless running? && recurring?
39
+ end
38
40
  end
39
41
 
40
42
  # Is the timer currently running?
@@ -8,18 +8,18 @@ module Lita
8
8
  @redis ||= Redis::Namespace.new("users", redis: Lita.redis)
9
9
  end
10
10
 
11
- # Finds or creates a user. Attempts to find a user with the given ID. If
12
- # none is found, creates a user with the provided ID and metadata.
11
+ # Creates a new user with the given ID, or merges and saves supplied
12
+ # metadata to an existing user with the given ID.
13
13
  # @param id [Integer, String] A unique identifier for the user.
14
14
  # @param metadata [Hash] An optional hash of metadata about the user.
15
15
  # @option metadata [String] name (id) The display name of the user.
16
16
  # @return [Lita::User] The user.
17
17
  def create(id, metadata = {})
18
- user = find_by_id(id)
19
- unless user
20
- user = new(id, metadata)
21
- user.save
22
- end
18
+ existing_user = find_by_id(id)
19
+ metadata = Util.stringify_keys(metadata)
20
+ metadata = existing_user.metadata.merge(metadata) if existing_user
21
+ user = new(id, metadata)
22
+ user.save
23
23
  user
24
24
  end
25
25
 
@@ -94,8 +94,8 @@ module Lita
94
94
  # @option metadata [String] name (id) The user's display name.
95
95
  def initialize(id, metadata = {})
96
96
  @id = id.to_s
97
- @metadata = metadata
98
- @name = @metadata[:name] || @metadata["name"] || @id
97
+ @metadata = Util.stringify_keys(metadata)
98
+ @name = @metadata["name"] || @id
99
99
  ensure_name_metadata_set
100
100
  end
101
101
 
@@ -126,7 +126,6 @@ module Lita
126
126
  # one value. It's not possible to store an empty hash key in Redis.
127
127
  def ensure_name_metadata_set
128
128
  username = metadata.delete("name")
129
- username = metadata.delete(:name) unless username
130
129
  metadata["name"] = username || id
131
130
  end
132
131
 
@@ -5,6 +5,15 @@ module Lita
5
5
  ACRONYM_REGEX = /(?=a)b/
6
6
 
7
7
  class << self
8
+ # Returns a hash with any symbol keys converted to strings.
9
+ # @param hash [Hash] The hash to convert.
10
+ # @return [Hash] The converted hash.
11
+ def stringify_keys(hash)
12
+ result = {}
13
+ hash.each_key { |key| result[key.to_s] = hash[key] }
14
+ result
15
+ end
16
+
8
17
  # Transforms a camel-cased string into a snaked-cased string. Taken from
9
18
  # +ActiveSupport.+
10
19
  # @param camel_cased_word [String] The word to transform.
@@ -1,4 +1,4 @@
1
1
  module Lita
2
2
  # The current version of Lita.
3
- VERSION = "3.0.3"
3
+ VERSION = "3.0.4"
4
4
  end
@@ -81,19 +81,19 @@ describe Lita::Authorization, lita: true do
81
81
 
82
82
  describe ".groups" do
83
83
  before do
84
- %i{foo bar baz}.each do |group|
84
+ %i(foo bar baz).each do |group|
85
85
  described_class.add_user_to_group(requesting_user, user, group)
86
86
  end
87
87
  end
88
88
 
89
89
  it "returns a list of all authorization groups" do
90
- expect(described_class.groups).to match_array(%i{foo bar baz})
90
+ expect(described_class.groups).to match_array(%i(foo bar baz))
91
91
  end
92
92
  end
93
93
 
94
94
  describe ".groups_with_users" do
95
95
  before do
96
- %i{foo bar baz}.each do |group|
96
+ %i(foo bar baz).each do |group|
97
97
  described_class.add_user_to_group(requesting_user, user, group)
98
98
  described_class.add_user_to_group(
99
99
  requesting_user,
@@ -108,7 +108,7 @@ describe Lita::Authorization, lita: true do
108
108
  end
109
109
 
110
110
  it "returns a hash of all authorization groups and their members" do
111
- groups = %i{foo bar baz}
111
+ groups = %i(foo bar baz)
112
112
  groups_with_users = described_class.groups_with_users
113
113
  expect(groups_with_users.keys).to match_array(groups)
114
114
  groups.each do |group|
@@ -25,7 +25,7 @@ describe Lita::Daemon do
25
25
 
26
26
  context "when the user has not requested that existing processes should be killed" do
27
27
  it "aborts if a Lita process is already running" do
28
- allow(File).to receive(:exists?).and_return(true)
28
+ allow(File).to receive(:exist?).and_return(true)
29
29
  expect(subject).to receive(:abort)
30
30
  subject.daemonize
31
31
  end
@@ -35,13 +35,13 @@ describe Lita::Daemon do
35
35
  subject { described_class.new("/tmp/lita_pid", "/tmp/lita_log", true) }
36
36
 
37
37
  it "kills existing processes" do
38
- allow(File).to receive(:exists?).and_return(true)
38
+ allow(File).to receive(:exist?).and_return(true)
39
39
  expect(Process).to receive(:kill)
40
40
  subject.daemonize
41
41
  end
42
42
 
43
43
  it "aborts if it can't kill an existing process" do
44
- allow(File).to receive(:exists?).and_return(true)
44
+ allow(File).to receive(:exist?).and_return(true)
45
45
  allow(Process).to receive(:kill).and_raise(Errno::ESRCH)
46
46
  expect(subject).to receive(:abort)
47
47
  subject.daemonize
@@ -57,6 +57,12 @@ describe Lita::Handler, lita: true do
57
57
  end
58
58
  end
59
59
 
60
+ def infinite_every_test(response)
61
+ thread = every(5) { "Looping forever!" }
62
+ response.reply("Replying after timer!")
63
+ thread
64
+ end
65
+
60
66
  def self.name
61
67
  "Lita::Handlers::Test"
62
68
  end
@@ -212,5 +218,13 @@ describe Lita::Handler, lita: true do
212
218
  expect { queue.pop(true) }.to raise_error(ThreadError)
213
219
  end
214
220
  end
221
+
222
+ context "with an infinite timer" do
223
+ it "doesn't block the handler's thread" do
224
+ expect(response).to receive(:reply)
225
+ thread = subject.infinite_every_test(response)
226
+ thread.kill
227
+ end
228
+ end
215
229
  end
216
230
  end
@@ -40,7 +40,7 @@ describe Lita::Handlers::Authorization, lita_handler: true do
40
40
  expect(replies.last).to eq("#{target_user.name} was already in bar.")
41
41
  end
42
42
 
43
- it %{replies with a warning if the group was "admins"} do
43
+ it 'replies with a warning if the group was "admins"' do
44
44
  send_command("auth add foo admins")
45
45
  expect(replies.last).to match(/Administrators can only be managed/)
46
46
  end
@@ -63,7 +63,7 @@ describe Lita::Handlers::Authorization, lita_handler: true do
63
63
  expect(replies.last).to eq("#{target_user.name} was not in bar.")
64
64
  end
65
65
 
66
- it %{replies with a warning if the group was "admins"} do
66
+ it 'replies with a warning if the group was "admins"' do
67
67
  send_command("auth add foo admins")
68
68
  expect(replies.last).to match(/Administrators can only be managed/)
69
69
  end
@@ -71,7 +71,7 @@ describe Lita::Handlers::Authorization, lita_handler: true do
71
71
 
72
72
  describe "#list" do
73
73
  context "when there are populated groups" do
74
- let(:groups) { %i{foo bar} }
74
+ let(:groups) { %i(foo bar) }
75
75
  let(:user1) { Lita::User.create(3, name: "Bongo") }
76
76
  let(:user2) { Lita::User.create(4, name: "Carl") }
77
77
 
@@ -23,9 +23,7 @@ describe Lita::Handlers::Info, lita_handler: true do
23
23
  it "returns JSON with info about the running robot" do
24
24
  subject.web(request, response)
25
25
  expect(response.headers["Content-Type"]).to eq("application/json")
26
- expect(response.body.join).to include(
27
- %{"lita_version":"#{Lita::VERSION}"}
28
- )
26
+ expect(response.body.join).to include(%("lita_version":"#{Lita::VERSION}"))
29
27
  end
30
28
  end
31
29
  end
@@ -12,11 +12,18 @@ describe Lita::User, lita: true do
12
12
 
13
13
  it "returns existing users" do
14
14
  described_class.create(1, name: "Carl")
15
- expect_any_instance_of(described_class).not_to receive(:save)
16
- user = described_class.find(1, name: "Carl")
15
+ user = described_class.find(1)
17
16
  expect(user.id).to eq("1")
18
17
  expect(user.name).to eq("Carl")
19
18
  end
19
+
20
+ it "merges and saves new metadata for existing users" do
21
+ described_class.create(1, name: "Carl")
22
+ described_class.create(1, name: "Mr. Carl", foo: "bar")
23
+ user = described_class.find_by_id(1)
24
+ expect(user.name).to eq("Mr. Carl")
25
+ expect(user.metadata["foo"]).to eq("bar")
26
+ end
20
27
  end
21
28
 
22
29
  describe ".find_by_id" do
@@ -1,6 +1,13 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Lita::Util do
4
+ describe ".stringify_keys" do
5
+ it "converts symbol hash keys to strings" do
6
+ stringified = described_class.stringify_keys(foo: "bar")
7
+ expect(stringified).to eq("foo" => "bar")
8
+ end
9
+ end
10
+
4
11
  describe ".underscore" do
5
12
  it "converts camel cased strings into snake case" do
6
13
  expect(described_class.underscore("FooBarBaz")).to eq("foo_bar_baz")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Cuadra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-01 00:00:00.000000000 Z
11
+ date: 2014-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler