mutations 0.9.0 → 0.9.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
  SHA256:
3
- metadata.gz: 60a9dcaccc2cded1876539ff36b62111b6bfdcec887494265fe4fa510c360ad5
4
- data.tar.gz: 7a2bd2aacb4f8b9296e7f4a638fe42a1034ee8736a24a31d811580a87e4ecbe7
3
+ metadata.gz: e8910273a1df86a4c215e9b4878698f4c74f88b1756f7df8145b116ebeff92e2
4
+ data.tar.gz: 8f8e311fe7f030469ba62e473e5bc63f45af913640e670b19d7255f8ed5f20f8
5
5
  SHA512:
6
- metadata.gz: 756a1dd30f3affd27ef111ebfbdf066e3e056767f6a08a7b69f8c39831f977bb9ee96b82e2f729cc02d4f6bffa2ea04f8ad8e405b9b6855f7a3bc06a20a4039a
7
- data.tar.gz: b18adcdba20934dda3555cb3b72d90e23cd81612e152991338dd750f2d4bbd57ced91037b9900c4d42f8d6090cf4fe662ca0e91c3dba64692a5d0f0e3f46cae3
6
+ metadata.gz: fc69d3c607ee357701a72293b9233d652017d3e9b65c3d7b59dc3c4290fafda020189e769c8dc70fbf32645e3141225f5395d05f91c9dda63f4ce10d09e5e1a3
7
+ data.tar.gz: 2e3f1114e8aaee8a264a68aa4ef90cca33bf14d5629d8b71864c238749b77c02a61d2e1651990b27e3d808e1e3808b90c2c107380a52df0988da7ed8b5b90a9c
@@ -0,0 +1,35 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+
9
+ strategy:
10
+ fail-fast: false
11
+
12
+ matrix:
13
+ ruby-version:
14
+ - 2.1
15
+ - 2.2
16
+ - 2.3
17
+ - 2.4
18
+ - 2.5
19
+ - 2.6
20
+ - 2.7
21
+ - '3.0'
22
+ - 3.1
23
+ - 3.2
24
+ - 3.3
25
+ - 3.4
26
+ - 4.0
27
+ - jruby
28
+
29
+ steps:
30
+ - uses: actions/checkout@v3
31
+ - uses: ruby/setup-ruby@v1
32
+ with:
33
+ ruby-version: ${{ matrix.ruby-version }}
34
+ bundler-cache: true
35
+ - run: bundle exec rake test
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ 0.9.2
2
+ -----------
3
+ - Optimize control char stripping (#167, @byroot)
4
+
5
+ 0.9.1
6
+ -----------
7
+ - Treat blank strings as nil when `strip` and `empty_is_nil` options are set (#148, @saverio-kantox)
8
+ - Don't use full key in nested error messages (#149, @eugeneius)
9
+ - Don't remove unknown characters in string filter (#150, @eugeneius)
10
+
1
11
  0.9.0
2
12
  -----------
3
13
  - Retain `_id` suffix in error keys (#129, @khalilovcmd)
data/Gemfile CHANGED
@@ -1,8 +1,2 @@
1
1
  source 'http://rubygems.org'
2
2
  gemspec
3
-
4
- platforms :rbx do
5
- gem 'rubysl', '~> 2.0'
6
- gem 'psych'
7
- gem 'rubinius-developer_tools'
8
- end
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Mutations
2
2
 
3
- [![Build Status](https://travis-ci.org/cypriss/mutations.svg)](https://travis-ci.org/cypriss/mutations)
3
+ [![Build Status](https://travis-ci.org/cypriss/mutations.svg?branch=master)](https://travis-ci.org/cypriss/mutations)
4
4
  [![Code Climate](https://codeclimate.com/github/cypriss/mutations.svg)](https://codeclimate.com/github/cypriss/mutations)
5
5
 
6
6
  Compose your business logic into commands that sanitize and validate input. Write safe, reusable, and maintainable code for Ruby and Rails apps.
data/Rakefile CHANGED
@@ -2,7 +2,6 @@ require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
  Rake::TestTask.new(:test) do |test|
4
4
  test.libs << "spec"
5
- # test.warning = true # Wow that outputs a lot of shit
6
5
  test.pattern = "spec/**/*_spec.rb"
7
6
  end
8
7
 
@@ -1,8 +1,7 @@
1
1
  module Mutations
2
2
  class ArrayFilter < InputFilter
3
3
  def self.register_additional_filter(type_class, type_name)
4
- define_method(type_name) do | *args, &block |
5
- options = args[0] || {}
4
+ define_method(type_name) do |options = {}, &block|
6
5
  @element_filter = type_class.new(options, &block)
7
6
  end
8
7
  end
@@ -119,7 +119,7 @@ module Mutations
119
119
  inner = path.inject(errs) do |cur_errors,part|
120
120
  cur_errors[part.to_sym] ||= ErrorHash.new
121
121
  end
122
- inner[last] = ErrorAtom.new(key, kind, :message => message)
122
+ inner[last] = ErrorAtom.new(last.to_sym, kind, :message => message)
123
123
  end
124
124
  end
125
125
 
@@ -9,10 +9,6 @@ module Mutations
9
9
  }
10
10
 
11
11
  def filter(data)
12
- if options[:empty_is_nil] && data == ""
13
- data = nil
14
- end
15
-
16
12
  # Handle nil case
17
13
  if data.nil?
18
14
  return [nil, nil] if options[:nils]
@@ -20,7 +16,13 @@ module Mutations
20
16
  end
21
17
 
22
18
  # Now check if it's empty:
23
- return [data, :empty] if "" == data
19
+ if data == ""
20
+ if options[:empty_is_nil]
21
+ return [nil, (:nils unless options[:nils])]
22
+ else
23
+ return [data, :empty]
24
+ end
25
+ end
24
26
 
25
27
  if data.is_a?(Date) # Date and DateTime
26
28
  actual_date = data
@@ -1,10 +1,7 @@
1
1
  module Mutations
2
2
  class HashFilter < InputFilter
3
3
  def self.register_additional_filter(type_class, type_name)
4
- define_method(type_name) do | *args, &block |
5
- name = args[0]
6
- options = args[1] || {}
7
-
4
+ define_method(type_name) do |name, options = {}, &block|
8
5
  @current_inputs[name.to_sym] = type_class.new(options, &block)
9
6
  end
10
7
  end
@@ -9,11 +9,6 @@ module Mutations
9
9
  }
10
10
 
11
11
  def filter(data)
12
-
13
- if options[:empty_is_nil] && data == ""
14
- data = nil
15
- end
16
-
17
12
  # Handle nil case
18
13
  if data.nil?
19
14
  return [nil, nil] if options[:nils]
@@ -21,7 +16,13 @@ module Mutations
21
16
  end
22
17
 
23
18
  # Now check if it's empty:
24
- return [data, :empty] if data == ""
19
+ if data == ""
20
+ if options[:empty_is_nil]
21
+ return [nil, (:nils unless options[:nils])]
22
+ else
23
+ return [data, :empty]
24
+ end
25
+ end
25
26
 
26
27
  # Ensure it's the correct data type (Integer)
27
28
  if !data.is_a?(Integer)
@@ -11,14 +11,13 @@ module Mutations
11
11
  :matches => nil, # Can be a regexp
12
12
  :in => nil, # Can be an array like %w(red blue green)
13
13
  :discard_empty => false, # If the param is optional, discard_empty: true drops empty fields.
14
- :allow_control_characters => false # false removes unprintable characters from the string
14
+ :allow_control_characters => false # false removes control characters from the string
15
15
  }
16
16
 
17
- def filter(data)
18
- if options[:empty_is_nil] && data == ""
19
- data = nil
20
- end
17
+ CONTROL_CHARS = ((0..31).map(&:chr) - ["\r", "\n", "\t"]).join.freeze
18
+ REPLACE = (" " * CONTROL_CHARS.bytesize).freeze
21
19
 
20
+ def filter(data)
22
21
  # Handle nil case
23
22
  if data.nil?
24
23
  return [nil, nil] if options[:nils]
@@ -31,15 +30,17 @@ module Mutations
31
30
  # Now ensure it's a string:
32
31
  return [data, :string] unless data.is_a?(String)
33
32
 
34
- # At this point, data is a string. Now remove unprintable characters from the string:
35
- data = data.gsub(/[^[:print:]\t\r\n]+/, ' ') unless options[:allow_control_characters]
33
+ # At this point, data is a string. Now remove control characters from the string:
34
+ data = data.tr_s(CONTROL_CHARS, REPLACE) unless options[:allow_control_characters]
36
35
 
37
36
  # Transform it using strip:
38
37
  data = data.strip if options[:strip]
39
38
 
40
39
  # Now check if it's blank:
41
40
  if data == ""
42
- if options[:empty]
41
+ if options[:empty_is_nil]
42
+ return [nil, (:nils unless options[:nils])]
43
+ elsif options[:empty]
43
44
  return [data, nil]
44
45
  else
45
46
  return [data, :empty]
@@ -1,3 +1,3 @@
1
1
  module Mutations
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.2"
3
3
  end
data/mutations.gemspec CHANGED
@@ -14,6 +14,6 @@ Gem::Specification.new do |s|
14
14
  s.require_path = 'lib'
15
15
 
16
16
  s.add_dependency "activesupport"
17
- s.add_development_dependency 'minitest', '~> 4'
17
+ s.add_development_dependency 'minitest'
18
18
  s.add_development_dependency 'rake'
19
19
  end
@@ -39,7 +39,7 @@ describe "Mutations::AdditionalFilter" do
39
39
  it "should recognize additional filters" do
40
40
  outcome = TestCommandUsingAdditionalFilters.run(:first_name => "John", :last_name => "Doe")
41
41
  assert outcome.success?
42
- assert_equal nil, outcome.errors
42
+ assert_nil outcome.errors
43
43
  end
44
44
 
45
45
  class TestCommandUsingAdditionalFiltersInHashes < Mutations::Command
@@ -60,7 +60,7 @@ describe "Mutations::AdditionalFilter" do
60
60
  )
61
61
 
62
62
  assert outcome.success?
63
- assert_equal nil, outcome.errors
63
+ assert_nil outcome.errors
64
64
  end
65
65
 
66
66
  class TestCommandUsingAdditionalFiltersInArrays < Mutations::Command
@@ -81,7 +81,7 @@ describe "Mutations::AdditionalFilter" do
81
81
  )
82
82
 
83
83
  assert outcome.success?
84
- assert_equal nil, outcome.errors
84
+ assert_nil outcome.errors
85
85
  end
86
86
 
87
87
  module Mutations
@@ -9,7 +9,7 @@ describe "Mutations::ArrayFilter" do
9
9
  f = Mutations::ArrayFilter.new(:arr)
10
10
  filtered, errors = f.filter([1])
11
11
  assert_equal [1], filtered
12
- assert_equal nil, errors
12
+ assert_nil errors
13
13
  end
14
14
 
15
15
  it "considers non-arrays to be invalid" do
@@ -23,7 +23,7 @@ describe "Mutations::ArrayFilter" do
23
23
  it "considers nil to be invalid" do
24
24
  f = Mutations::ArrayFilter.new(:arr, :nils => false)
25
25
  filtered, errors = f.filter(nil)
26
- assert_equal nil, filtered
26
+ assert_nil filtered
27
27
  assert_equal :nils, errors
28
28
  end
29
29
 
@@ -31,20 +31,20 @@ describe "Mutations::ArrayFilter" do
31
31
  f = Mutations::ArrayFilter.new(:arr, :nils => true)
32
32
  _filtered, errors = f.filter(nil)
33
33
  _filtered, errors = f.filter(nil)
34
- assert_equal nil, errors
34
+ assert_nil errors
35
35
  end
36
36
 
37
37
  it "lets you specify a class, and has valid elements" do
38
38
  f = Mutations::ArrayFilter.new(:arr, :class => Integer)
39
39
  filtered, errors = f.filter([1,2,3])
40
- assert_equal nil, errors
40
+ assert_nil errors
41
41
  assert_equal [1,2,3], filtered
42
42
  end
43
43
 
44
44
  it "lets you specify a class as a string, and has valid elements" do
45
45
  f = Mutations::ArrayFilter.new(:arr, :class => 'Integer')
46
46
  filtered, errors = f.filter([1,2,3])
47
- assert_equal nil, errors
47
+ assert_nil errors
48
48
  assert_equal [1,2,3], filtered
49
49
  end
50
50
 
@@ -125,7 +125,7 @@ describe "Mutations::ArrayFilter" do
125
125
 
126
126
  filtered, errors = f.filter([true, false, "1"])
127
127
  assert_equal [true, false, true], filtered
128
- assert_equal nil, errors
128
+ assert_nil errors
129
129
  end
130
130
 
131
131
  it "lets you pass model in arrays" do
@@ -133,7 +133,7 @@ describe "Mutations::ArrayFilter" do
133
133
 
134
134
  filtered, errors = f.filter(["hey"])
135
135
  assert_equal ["hey"], filtered
136
- assert_equal nil, errors
136
+ assert_nil errors
137
137
  end
138
138
 
139
139
  it "lets you pass hashes in arrays" do
@@ -153,9 +153,9 @@ describe "Mutations::ArrayFilter" do
153
153
  filtered, errors = f.filter([{:foo => "f", :bar => 3, :baz => true}, {:foo => "f", :bar => 3}, {:foo => "f"}])
154
154
  assert_equal [{:foo=>"f", :bar=>3, :baz=>true}, {:foo=>"f", :bar=>3}, {:foo=>"f"}], filtered
155
155
 
156
- assert_equal nil, errors[0]
157
- assert_equal nil, errors[1]
158
- assert_equal ({"bar"=>:required}), errors[2].symbolic
156
+ assert_nil errors[0]
157
+ assert_nil errors[1]
158
+ assert_equal({"bar"=>:required}, errors[2].symbolic)
159
159
  end
160
160
 
161
161
  it "lets you pass arrays of arrays" do
@@ -167,7 +167,7 @@ describe "Mutations::ArrayFilter" do
167
167
 
168
168
  filtered, errors = f.filter([["h", "e"], ["l"], [], ["lo"]])
169
169
  assert_equal filtered, [["h", "e"], ["l"], [], ["lo"]]
170
- assert_equal nil, errors
170
+ assert_nil errors
171
171
  end
172
172
 
173
173
  it "handles errors for arrays of arrays" do
@@ -189,14 +189,14 @@ describe "Mutations::ArrayFilter" do
189
189
  end
190
190
  filtered, errors = f.filter([1, "2", "three", "4", 5, [6]])
191
191
  assert_equal [1,2,4,5], filtered
192
- assert_equal nil, errors
192
+ assert_nil errors
193
193
  end
194
194
 
195
195
  it "considers long arrays to be valid" do
196
196
  f = Mutations::ArrayFilter.new(:arr, :min_length => 2)
197
197
  filtered, errors = f.filter([1, 2])
198
198
  assert_equal [1, 2], filtered
199
- assert_equal nil, errors
199
+ assert_nil errors
200
200
  end
201
201
 
202
202
  it "considers short arrays to be invalid" do
@@ -210,7 +210,7 @@ describe "Mutations::ArrayFilter" do
210
210
  f = Mutations::ArrayFilter.new(:arr, :max_length => 20)
211
211
  filtered, errors = f.filter([1])
212
212
  assert_equal [1], filtered
213
- assert_equal nil, errors
213
+ assert_nil errors
214
214
  end
215
215
 
216
216
  it "sets a max_length for the array of 2 with 5 as invalid" do
@@ -224,12 +224,12 @@ describe "Mutations::ArrayFilter" do
224
224
  was = Mutations.cache_constants?
225
225
  Mutations.cache_constants = true
226
226
 
227
- f = Mutations::ArrayFilter.new(:simple_models, class: "SimpleModel")
227
+ f = Mutations::ArrayFilter.new(:simple_models, :class => "SimpleModel")
228
228
 
229
229
  m = SimpleModel.new
230
230
  filtered, errors = f.filter([m])
231
231
  assert_equal [m], filtered
232
- assert_equal nil, errors
232
+ assert_nil errors
233
233
 
234
234
  Object.send(:remove_const, 'SimpleModel')
235
235
  class SimpleModel; end
@@ -246,12 +246,12 @@ describe "Mutations::ArrayFilter" do
246
246
  was = Mutations.cache_constants?
247
247
  Mutations.cache_constants = false
248
248
 
249
- f = Mutations::ArrayFilter.new(:simple_models, class: "SimpleModel")
249
+ f = Mutations::ArrayFilter.new(:simple_models, :class => "SimpleModel")
250
250
 
251
251
  m = SimpleModel.new
252
252
  filtered, errors = f.filter([m])
253
253
  assert_equal [m], filtered
254
- assert_equal nil, errors
254
+ assert_nil errors
255
255
 
256
256
  Object.send(:remove_const, 'SimpleModel')
257
257
  class SimpleModel; end
@@ -259,7 +259,7 @@ describe "Mutations::ArrayFilter" do
259
259
  m = SimpleModel.new
260
260
  filtered, errors = f.filter([m])
261
261
  assert_equal [m], filtered
262
- assert_equal nil, errors
262
+ assert_nil errors
263
263
 
264
264
  Mutations.cache_constants = was
265
265
  end
@@ -6,11 +6,11 @@ describe "Mutations::BooleanFilter" do
6
6
  f = Mutations::BooleanFilter.new
7
7
  filtered, errors = f.filter(true)
8
8
  assert_equal true, filtered
9
- assert_equal nil, errors
9
+ assert_nil errors
10
10
 
11
11
  filtered, errors = f.filter(false)
12
12
  assert_equal false, filtered
13
- assert_equal nil, errors
13
+ assert_nil errors
14
14
  end
15
15
 
16
16
  it "considers non-booleans to be invalid" do
@@ -24,15 +24,15 @@ describe "Mutations::BooleanFilter" do
24
24
  it "considers nil to be invalid" do
25
25
  f = Mutations::BooleanFilter.new(:nils => false)
26
26
  filtered, errors = f.filter(nil)
27
- assert_equal nil, filtered
27
+ assert_nil filtered
28
28
  assert_equal :nils, errors
29
29
  end
30
30
 
31
31
  it "considers nil to be valid" do
32
32
  f = Mutations::BooleanFilter.new(:nils => true)
33
33
  filtered, errors = f.filter(nil)
34
- assert_equal nil, filtered
35
- assert_equal nil, errors
34
+ assert_nil filtered
35
+ assert_nil errors
36
36
  end
37
37
 
38
38
  it "considers certain strings to be valid booleans" do
@@ -40,7 +40,7 @@ describe "Mutations::BooleanFilter" do
40
40
  [["true", true], ["TRUE", true], ["TrUe", true], ["1", true], ["false", false], ["FALSE", false], ["FalSe", false], ["0", false], [0, false], [1, true]].each do |(str, v)|
41
41
  filtered, errors = f.filter(str)
42
42
  assert_equal v, filtered
43
- assert_equal nil, errors
43
+ assert_nil errors
44
44
  end
45
45
  end
46
46
 
data/spec/command_spec.rb CHANGED
@@ -8,16 +8,16 @@ describe "Command" do
8
8
  outcome = SimpleCommand.run(:name => "John", :email => "john@gmail.com", :amount => 5)
9
9
 
10
10
  assert outcome.success?
11
- assert_equal ({:name => "John", :email => "john@gmail.com", :amount => 5}).stringify_keys, outcome.result
12
- assert_equal nil, outcome.errors
11
+ assert_equal({:name => "John", :email => "john@gmail.com", :amount => 5}.stringify_keys, outcome.result)
12
+ assert_nil outcome.errors
13
13
  end
14
14
 
15
15
  it "should filter out spurious params" do
16
16
  outcome = SimpleCommand.run(:name => "John", :email => "john@gmail.com", :amount => 5, :buggers => true)
17
17
 
18
18
  assert outcome.success?
19
- assert_equal ({:name => "John", :email => "john@gmail.com", :amount => 5}).stringify_keys, outcome.result
20
- assert_equal nil, outcome.errors
19
+ assert_equal({:name => "John", :email => "john@gmail.com", :amount => 5}.stringify_keys, outcome.result)
20
+ assert_nil outcome.errors
21
21
  end
22
22
 
23
23
  it "should discover errors in inputs" do
@@ -29,7 +29,7 @@ describe "Command" do
29
29
 
30
30
  it "shouldn't throw an exception with run!" do
31
31
  result = SimpleCommand.run!(:name => "John", :email => "john@gmail.com", :amount => 5)
32
- assert_equal ({:name => "John", :email => "john@gmail.com", :amount => 5}).stringify_keys, result
32
+ assert_equal({:name => "John", :email => "john@gmail.com", :amount => 5}.stringify_keys, result)
33
33
  end
34
34
 
35
35
  it "should throw an exception with run!" do
@@ -70,21 +70,21 @@ describe "Command" do
70
70
 
71
71
  assert !outcome.success?
72
72
  assert_equal :max_length, outcome.errors.symbolic[:name]
73
- assert_equal nil, outcome.errors.symbolic[:email]
73
+ assert_nil outcome.errors.symbolic[:email]
74
74
  end
75
75
 
76
76
  it "should merge multiple hashes" do
77
77
  outcome = SimpleCommand.run({:name => "John", :email => "john@gmail.com"}, {:email => "bob@jones.com", :amount => 5})
78
78
 
79
79
  assert outcome.success?
80
- assert_equal ({:name => "John", :email => "bob@jones.com", :amount => 5}).stringify_keys, outcome.result
80
+ assert_equal({:name => "John", :email => "bob@jones.com", :amount => 5}.stringify_keys, outcome.result)
81
81
  end
82
82
 
83
83
  it "should merge hashes indifferently" do
84
84
  outcome = SimpleCommand.run({:name => "John", :email => "john@gmail.com"}, {"email" => "bob@jones.com", "amount" => 5})
85
85
 
86
86
  assert outcome.success?
87
- assert_equal ({:name => "John", :email => "bob@jones.com", :amount => 5}).stringify_keys, outcome.result
87
+ assert_equal({:name => "John", :email => "bob@jones.com", :amount => 5}.stringify_keys, outcome.result)
88
88
  end
89
89
 
90
90
  it "shouldn't accept objects that are not hashes or directly mappable to hashes" do
@@ -104,14 +104,14 @@ describe "Command" do
104
104
  it 'should accept objects that are conceptually hashes' do
105
105
  class CustomPersonHash
106
106
  def to_hash
107
- { name: 'John', email: 'john@example.com' }
107
+ { :name => 'John', :email => 'john@example.com' }
108
108
  end
109
109
  end
110
110
 
111
111
  outcome = SimpleCommand.run(CustomPersonHash.new)
112
112
 
113
113
  assert outcome.success?
114
- assert_equal ({ name: "John", email: "john@example.com" }).stringify_keys, outcome.result
114
+ assert_equal({ :name => "John", :email => "john@example.com" }.stringify_keys, outcome.result)
115
115
  end
116
116
 
117
117
  it "should accept nothing at all" do
@@ -120,7 +120,7 @@ describe "Command" do
120
120
 
121
121
  it "should return the filtered inputs in the outcome" do
122
122
  outcome = SimpleCommand.run(:name => " John ", :email => "john@gmail.com", :amount => "5")
123
- assert_equal ({:name => "John", :email => "john@gmail.com", :amount => 5}).stringify_keys, outcome.inputs
123
+ assert_equal({:name => "John", :email => "john@gmail.com", :amount => 5}.stringify_keys, outcome.inputs)
124
124
  end
125
125
  end
126
126
 
@@ -137,7 +137,7 @@ describe "Command" do
137
137
 
138
138
  it "should define getter methods on params" do
139
139
  mutation = EigenCommand.run(:name => "John", :email => "john@gmail.com")
140
- assert_equal ({:name => "John", :email => "john@gmail.com"}), mutation.result
140
+ assert_equal({:name => "John", :email => "john@gmail.com"}, mutation.result)
141
141
  end
142
142
  end
143
143
 
@@ -155,7 +155,7 @@ describe "Command" do
155
155
 
156
156
  it "should define setter methods on params" do
157
157
  mutation = MutatatedCommand.run(:name => "John", :email => "john@gmail.com")
158
- assert_equal ({:name => "bob", :email => "bob@jones.com"}), mutation.result
158
+ assert_equal({:name => "bob", :email => "bob@jones.com"}, mutation.result)
159
159
  end
160
160
  end
161
161
 
@@ -183,8 +183,8 @@ describe "Command" do
183
183
 
184
184
  describe "CustomErrorKeyCommand" do
185
185
  class CustomErrorKeyCommand < Mutations::Command
186
- required { string :name, error_key: :other_name }
187
- optional { string :email, min_length: 4, error_key: :other_email }
186
+ required { string :name, :error_key => :other_name }
187
+ optional { string :email, :min_length => 4, :error_key => :other_email }
188
188
  end
189
189
 
190
190
  it "should return the optional error key in the error message if required" do
@@ -196,7 +196,7 @@ describe "Command" do
196
196
  end
197
197
 
198
198
  it "should return the optional error key in the error message if optional" do
199
- outcome = CustomErrorKeyCommand.run(email: "foo")
199
+ outcome = CustomErrorKeyCommand.run(:email => "foo")
200
200
 
201
201
  assert !outcome.success?
202
202
  assert_equal :min_length, outcome.errors.symbolic[:email]
@@ -223,6 +223,7 @@ describe "Command" do
223
223
  assert !outcome.success?
224
224
  assert_nil outcome.result
225
225
  assert_equal :is_a_bob, outcome.errors[:people].symbolic[:bob]
226
+ assert_equal "Bob is invalid", outcome.errors[:people].message[:bob]
226
227
  end
227
228
  end
228
229