From a03c6c5ff34f1725465800b5e4b80854cffda0fb Mon Sep 17 00:00:00 2001 From: Adam Cooke Date: Wed, 17 Feb 2021 12:46:44 +0000 Subject: [PATCH] fix: ruby 3.0 compat --- .github/workflows/ci.yml | 1 + lib/rapid/defineable.rb | 4 ++-- lib/rapid/dsls/endpoint.rb | 4 ++-- spec/specs/rapid/argument_set_spec.rb | 22 ++++++++++---------- spec/specs/rapid/definitions/field_spec.rb | 8 ++++---- spec/specs/rapid/field_set_spec.rb | 24 +++++++++++----------- 6 files changed, 32 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6f5c79..27f9873 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,6 +28,7 @@ jobs: - 2.5 - 2.6 - 2.7 + - 3.0 steps: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 diff --git a/lib/rapid/defineable.rb b/lib/rapid/defineable.rb index 87d5fd9..e897611 100644 --- a/lib/rapid/defineable.rb +++ b/lib/rapid/defineable.rb @@ -40,9 +40,9 @@ def name(new_name = nil) # Passes all other values through to the DSL for the definition if # the DSL supoprts it. - def method_missing(name, *args, &block) + def method_missing(name, *args, **kwargs, &block) if definition.dsl.respond_to?(name) - definition.dsl.send(name, *args, &block) + definition.dsl.send(name, *args, **kwargs, &block) else super end diff --git a/lib/rapid/dsls/endpoint.rb b/lib/rapid/dsls/endpoint.rb index 089dff8..d264c74 100644 --- a/lib/rapid/dsls/endpoint.rb +++ b/lib/rapid/dsls/endpoint.rb @@ -28,8 +28,8 @@ def potential_error(klass, &block) @definition.potential_errors << klass end - def argument(*args, &block) - @definition.argument_set.argument(*args, &block) + def argument(*args, **kwargs, &block) + @definition.argument_set.argument(*args, **kwargs, &block) end def action(&block) diff --git a/spec/specs/rapid/argument_set_spec.rb b/spec/specs/rapid/argument_set_spec.rb index b49f3ca..d080e91 100644 --- a/spec/specs/rapid/argument_set_spec.rb +++ b/spec/specs/rapid/argument_set_spec.rb @@ -95,7 +95,7 @@ argument :name, type: :string argument :age, type: :integer end - as_instance = as.new(name: 'Adam', age: 1234) + as_instance = as.new({ name: 'Adam', age: 1234 }) expect(as_instance[:name]).to eq 'Adam' expect(as_instance['name']).to eq 'Adam' expect(as_instance[:age]).to eq 1234 @@ -108,7 +108,7 @@ argument :age, type: :integer, required: true end expect do - as.new(name: 'Adam') + as.new({ name: 'Adam' }) end.to raise_error Rapid::MissingArgumentError end @@ -125,7 +125,7 @@ argument :name, type: :string end expect do - as.new(name: 1234) + as.new({ name: 1234 }) end.to raise_error Rapid::InvalidArgumentError do |e| expect(e.issue).to eq :invalid_scalar end @@ -136,7 +136,7 @@ argument :name, type: :date end expect do - as.new(name: '2029-22-34') + as.new({ name: '2029-22-34' }) end.to raise_error Rapid::InvalidArgumentError do |e| expect(e.issue).to eq :parse_error end @@ -151,7 +151,7 @@ end end expect do - as.new(name: 'Not Dave') + as.new({ name: 'Not Dave' }) end.to raise_error Rapid::InvalidArgumentError do |e| expect(e.argument.name).to eq :name expect(e.issue).to eq :validation_errors @@ -163,7 +163,7 @@ as = Rapid::ArgumentSet.create('ExampleSet') do argument :names, type: [:string] end - as_instance = as.new(names: %w[Adam Charlie]) + as_instance = as.new({ names: %w[Adam Charlie] }) expect(as_instance[:names]).to be_a Array expect(as_instance[:names]).to include 'Adam' expect(as_instance[:names]).to include 'Charlie' @@ -174,7 +174,7 @@ argument :names, type: [:string] end expect do - as.new(names: ['Adam', 1323]) + as.new({ names: ['Adam', 1323] }) end.to raise_error Rapid::InvalidArgumentError do |e| expect(e.argument.name).to eq :names expect(e.issue).to eq :invalid_scalar @@ -190,7 +190,7 @@ argument :title, type: :string argument :user, type: as1 end - instance = as2.new(title: 'My title', user: { name: 'Michael' }) + instance = as2.new({ title: 'My title', user: { name: 'Michael' } }) expect(instance[:title]).to eq 'My title' expect(instance[:user]).to be_a Rapid::ArgumentSet expect(instance[:user][:name]).to eq 'Michael' @@ -204,7 +204,7 @@ argument :title, type: :string argument :user, type: as1 end - instance = as2.new(title: 'My title') + instance = as2.new({ title: 'My title' }) expect(instance[:user]).to be nil end @@ -215,7 +215,7 @@ argument :premium, :boolean argument :in_debt, :boolean end - instance = as.new(active: true, premium: false) + instance = as.new({ active: true, premium: false }) expect(instance[:admin]).to eq false expect(instance[:active]).to eq true expect(instance[:premium]).to eq false @@ -235,7 +235,7 @@ argument :book, type: as2 end expect do - as3.new(age: 12, book: { title: 'Book', user: { name: 1234 } }) + as3.new({ age: 12, book: { title: 'Book', user: { name: 1234 } } }) end.to raise_error Rapid::InvalidArgumentError do |e| expect(e.index).to be nil expect(e.argument.name).to eq :name diff --git a/spec/specs/rapid/definitions/field_spec.rb b/spec/specs/rapid/definitions/field_spec.rb index a84f92e..603d158 100644 --- a/spec/specs/rapid/definitions/field_spec.rb +++ b/spec/specs/rapid/definitions/field_spec.rb @@ -135,7 +135,7 @@ field = Rapid::Definitions::Field.new(:id) field.type = :integer expect do - field.value(id: '444') + field.value({ id: '444' }) end.to raise_error(Rapid::InvalidScalarValueError) end @@ -143,7 +143,7 @@ field = Rapid::Definitions::Field.new(:names) field.type = :string field.array = true - value = field.value(names: %w[Adam Michael]) + value = field.value({ names: %w[Adam Michael] }) expect(value).to be_a Array expect(value[0]).to eq 'Adam' expect(value[1]).to eq 'Michael' @@ -158,10 +158,10 @@ field = Rapid::Definitions::Field.new(:users) field.type = type field.array = true - value = field.value(users: [ + value = field.value({ users: [ { name: 'Adam', age: 20 }, { name: 'Michael', age: 25 } - ]) + ] }) expect(value).to be_a Array expect(value[0]).to be_a Hash diff --git a/spec/specs/rapid/field_set_spec.rb b/spec/specs/rapid/field_set_spec.rb index 8f6e31c..d701b2d 100644 --- a/spec/specs/rapid/field_set_spec.rb +++ b/spec/specs/rapid/field_set_spec.rb @@ -15,7 +15,7 @@ field.null = true field_set.add field - hash = field_set.generate_hash(name: nil) + hash = field_set.generate_hash({ name: nil }) expect(hash['name']).to eq nil end @@ -29,11 +29,11 @@ field.condition = proc { |value| value[:name] == 'Sarah' } field_set.add field - hash = field_set.generate_hash(name: 'Michael', age: 123) + hash = field_set.generate_hash({ name: 'Michael', age: 123 }) expect(hash['name']).to eq 'Michael' expect(hash.keys).to_not include 'age' - hash = field_set.generate_hash(name: 'Sarah', age: 123) + hash = field_set.generate_hash({ name: 'Sarah', age: 123 }) expect(hash['age']).to eq 123 end @@ -51,7 +51,7 @@ field.type = :integer field_set.add field - hash = field_set.generate_hash(number: 99, thing: { name: 'John' }) + hash = field_set.generate_hash({ number: 99, thing: { name: 'John' } }) expect(hash['number']).to eq 99 expect(hash.keys).to_not include 'thing' end @@ -65,7 +65,7 @@ field.type = type field_set.add field - hash = field_set.generate_hash(user: { name: 'John' }) + hash = field_set.generate_hash({ user: { name: 'John' } }) expect(hash['user']['name']).to eq 'John' end @@ -74,7 +74,7 @@ field.type = :string field_set.add field - hash = field_set.generate_hash(name: :John) + hash = field_set.generate_hash({ name: :John }) expect(hash['name']).to eq 'John' end @@ -84,7 +84,7 @@ field.array = true field_set.add field - hash = field_set.generate_hash(names: %w[Matthew Mark Michael]) + hash = field_set.generate_hash({ names: %w[Matthew Mark Michael] }) expect(hash['names']).to be_a Array expect(hash['names'].size).to eq 3 expect(hash['names']).to include 'Matthew' @@ -102,7 +102,7 @@ field.array = true field_set.add field - hash = field_set.generate_hash(users: [{ name: 'Matthew' }, { name: 'Mark' }, { name: 'Michael' }]) + hash = field_set.generate_hash({ users: [{ name: 'Matthew' }, { name: 'Mark' }, { name: 'Michael' }] }) expect(hash['users']).to be_a Array expect(hash['users'].size).to eq 3 expect(hash['users'][0]['name']).to include 'Matthew' @@ -120,12 +120,12 @@ field.type = polymorph field_set.add field - hash = field_set.generate_hash(string_or_int: 'Adam') + hash = field_set.generate_hash({ string_or_int: 'Adam' }) expect(hash['string_or_int']).to be_a Hash expect(hash['string_or_int']['type']).to eq 'string' expect(hash['string_or_int']['value']).to eq 'Adam' - hash = field_set.generate_hash(string_or_int: 1234) + hash = field_set.generate_hash({ string_or_int: 1234 }) expect(hash['string_or_int']).to be_a Hash expect(hash['string_or_int']['type']).to eq 'integer' expect(hash['string_or_int']['value']).to eq 1234 @@ -142,7 +142,7 @@ field.array = true field_set.add field - hash = field_set.generate_hash(string_or_int: ['Adam', 1, 'Gavin', 2]) + hash = field_set.generate_hash({ string_or_int: ['Adam', 1, 'Gavin', 2] }) expect(hash['string_or_int']).to be_a Array expect(hash['string_or_int'][0]['type']).to eq 'string' expect(hash['string_or_int'][0]['value']).to eq 'Adam' @@ -164,7 +164,7 @@ field_set.add field expect do - field_set.generate_hash(value: 1234) + field_set.generate_hash({ value: 1234 }) end.to raise_error Rapid::InvalidPolymorphValueError do |e| expect(e.polymorph.definition.id).to eq 'MyPolymorph' end