Merge pull request #1 from rgalanakis/master

Fix keyword argument decorators in Ruby 3.0
M .ruby-version +1 -1
@@ 1,1 1,1 @@ 
-2.7
+3.1

          
M fluent_fixtures.gemspec +1 -0
@@ 5,6 5,7 @@ Gem::Specification.new do |s|
   s.name = "fluent_fixtures".freeze
   s.version = "0.9.0.pre.20201102181742"
 
+  s.authors = [ "Michael Granger" ]
   s.required_rubygems_version = Gem::Requirement.new("> 1.3.1".freeze) if s.respond_to? :required_rubygems_version=
   s.metadata = { "changelog_uri" => "http://deveiate.org/code/fluent_fixtures/History_md.html", "documentation_uri" => "http://deveiate.org/code/fluent_fixtures", "homepage_uri" => "http://bitbucket.org/ged/fluent_fixtures" } if s.respond_to? :metadata=
   s.require_paths = ["lib".freeze]

          
M lib/fluent_fixtures/factory.rb +7 -1
@@ 190,7 190,13 @@ class FluentFixtures::Factory
 		self.apply_prelude( instance, decorator_options[:prelude] ) if decorator_options[:prelude]
 
 		instance = self.try_to_save( instance ) if decorator_options[:presave]
-		instance.instance_exec( *args, &decorator_block )
+		if args[-1].is_a?(Hash)
+			kwargs = args[-1]
+			args = args[0..-2]
+		else
+			kwargs = {}
+		end
+		instance.instance_exec( *args, **kwargs, &decorator_block )
 
 		return instance
 	end

          
M spec/fluent_fixtures/factory_spec.rb +32 -0
@@ 336,6 336,38 @@ RSpec.describe FluentFixtures::Factory d
 	end
 
 
+	it "handles keyword-only decorators" do
+		fixture_module.decorator( :set_fields ) do |name: nil, email: nil|
+			self.name = name
+			self.email = email
+		end
+
+		object = factory.set_fields( name: 'x', email: 'a@b.c' ).instance
+
+		expect( object ).to be_a( fixtured_class )
+		expect( object.name ).to eq( 'x' )
+		expect( object.email ).to eq( 'a@b.c' )
+		expect( object ).to_not be_saved
+	end
+
+
+	it "handles mixed position and keyword decorators" do
+		fixture_module.decorator( :set_fields ) do |arg1, arg2=2, kwarg: nil|
+			self.name = arg1
+			self.email = arg2
+			self.login = kwarg
+		end
+
+		object = factory.set_fields( 'x', 'a@b.c', kwarg: 'mylogin' ).instance
+
+		expect( object ).to be_a( fixtured_class )
+		expect( object.name ).to eq( 'x' )
+		expect( object.email ).to eq( 'a@b.c' )
+		expect( object.login ).to eq( 'mylogin' )
+		expect( object ).to_not be_saved
+	end
+
+
 	describe "enumerator/generator" do
 
 		it "is Enumerable" do