simple_command 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: 8847792f86f2c4162d832d2603abfb7f0f40208110ad339484851dfaeeb99cf4
4
- data.tar.gz: ba9e8c0e1d46fb25d8408f430ba462e14e2ca386e5cd7b4c611d7787523448a0
3
+ metadata.gz: 249c45e067f58dd59ee7a290622613123271bf8a484aecab8df78eac08877c72
4
+ data.tar.gz: 8fccb81df727ae775e638a2777b362aa551c7240591f22d76e703f1652daa010
5
5
  SHA512:
6
- metadata.gz: d4fa95128f6e3fcd15419705bf36d56c33b8da0ced34b068940a3ee3fe066feeada465f8257f5076a87f3e237bd0adfd83b377a1d68bf9e81a09240bae5be243
7
- data.tar.gz: 8cc7cea6c22b3af310b039eee0f041f0ac5c48597d8cc13122771ffdef67a54dcf2ce8f2b77172ad3c6425e5598024d2ef48d95a7562083c94c3d1419348a7e0
6
+ metadata.gz: 3343d18527c57e54204a0f7610c9574632918a8964d4bf85429f13ac918700741952e2c8401616ae37098ccd03a22968afe5b195459583cd339277d656fd0eb8
7
+ data.tar.gz: 9e416787a1e7b8a19d92071ae662a76a301e184a73e8d34c70398eb7d5130b97689afa9b792425b96b32540ecabfe3dae2514f4421f7f8ac2429ce110df59cb9
@@ -10,7 +10,7 @@ module SimpleCommand
10
10
 
11
11
  def add_multiple_errors(errors_hash)
12
12
  errors_hash.each do |key, values|
13
- values.each { |value| add key, value }
13
+ SimpleCommand::Utils.array_wrap(values).each { |value| add key, value }
14
14
  end
15
15
  end
16
16
 
@@ -0,0 +1,14 @@
1
+ module SimpleCommand
2
+ module Utils
3
+ # Borrowed from active_support/core_ext/array/wrap
4
+ def self.array_wrap(object)
5
+ if object.nil?
6
+ []
7
+ elsif object.respond_to?(:to_ary)
8
+ object.to_ary || [object]
9
+ else
10
+ [object]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module SimpleCommand
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'simple_command/version'
2
+ require 'simple_command/utils'
2
3
  require 'simple_command/errors'
3
4
 
4
5
  module SimpleCommand
@@ -19,21 +19,33 @@ describe SimpleCommand::Errors do
19
19
  end
20
20
 
21
21
  describe '#add_multiple_errors' do
22
- let(:errors_list) do
23
- {
22
+ it 'populates itself with the added errors' do
23
+ errors_list = {
24
24
  some_error: ['some error description'],
25
25
  another_error: ['another error description']
26
26
  }
27
- end
28
27
 
29
- before do
30
28
  errors.add_multiple_errors errors_list
31
- end
32
29
 
33
- it 'populates itself with the added errors' do
34
30
  expect(errors[:some_error]).to eq(errors_list[:some_error])
35
31
  expect(errors[:another_error]).to eq(errors_list[:another_error])
36
32
  end
33
+
34
+ it 'copies errors from another SimpleCommand::Errors object' do
35
+ command_errors = SimpleCommand::Errors.new
36
+ command_errors.add :some_error, "was found"
37
+ command_errors.add :some_error, "happened again"
38
+
39
+ errors.add_multiple_errors command_errors
40
+
41
+ expect(errors[:some_error]).to eq(["was found", "happened again"])
42
+ end
43
+
44
+ it "ignores nil values" do
45
+ errors.add_multiple_errors({:foo => nil})
46
+
47
+ expect(errors[:foo]).to eq nil
48
+ end
37
49
  end
38
50
 
39
51
  describe '#each' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_command
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrea Pavoni
@@ -69,6 +69,7 @@ files:
69
69
  - Rakefile
70
70
  - lib/simple_command.rb
71
71
  - lib/simple_command/errors.rb
72
+ - lib/simple_command/utils.rb
72
73
  - lib/simple_command/version.rb
73
74
  - simple_command.gemspec
74
75
  - spec/factories/missed_call_command.rb