From 0b45910511a6a50a70445d0923647ef774c544ab Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Sat, 30 Nov 2024 17:11:12 +0100 Subject: [PATCH 1/2] Allow passing a user class to the test app generator Currently, solidus_auth_devise is tested with a dummy app that specifies `Spree::LegacyUser` in its `spree.rb initializer. That's not great, but there's no way of fixing it if the rake task install does not pass through the user class option. The way to use this feature would be in an extension's Rakefile: ```rb SolidusDevSupport::RakeTasks.install(user_class: "Spree::User") ``` --- lib/solidus_dev_support/rake_tasks.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/solidus_dev_support/rake_tasks.rb b/lib/solidus_dev_support/rake_tasks.rb index 4d9295e0..7fefc13e 100644 --- a/lib/solidus_dev_support/rake_tasks.rb +++ b/lib/solidus_dev_support/rake_tasks.rb @@ -7,14 +7,15 @@ module SolidusDevSupport class RakeTasks include Rake::DSL - def self.install(*args) - new(*args).tap(&:install) + def self.install(**args) + new(**args).tap(&:install) end - def initialize(root: Dir.pwd) + def initialize(root: Dir.pwd, user_class: "Spree::LegacyUser") @root = Pathname(root) @test_app_path = @root.join(ENV.fetch('DUMMY_PATH', 'spec/dummy')) @gemspec = Bundler.load_gemspec(@root.glob("{,*}.gemspec").first) + @user_class = user_class end attr_reader :test_app_path, :root, :gemspec @@ -39,12 +40,12 @@ def install_test_app_task # We need to go back to the gem root since the upstream # extension:test_app changes the working directory to be the dummy app. task :test_app do - Rake::Task['extension:test_app'].invoke + Rake::Task['extension:test_app'].invoke(@user_class) cd root end directory ENV.fetch('DUMMY_PATH', nil) do - Rake::Task['extension:test_app'].invoke + Rake::Task['extension:test_app'].invoke(@user_class) end end end From a498d161e7190e0c6bbc648c9470274572dabcec Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 3 Dec 2024 15:11:16 +0100 Subject: [PATCH 2/2] Extension template: Use Spree::User for dummy app The Gemfile that's generated for testing extensions contains solidus_auth_devise, which sets the user class for the app to Spree::User. The generator in this Rakefile should be set up to do the same. --- lib/solidus_dev_support/templates/extension/Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/solidus_dev_support/templates/extension/Rakefile b/lib/solidus_dev_support/templates/extension/Rakefile index a6562a8d..30e2d3f5 100644 --- a/lib/solidus_dev_support/templates/extension/Rakefile +++ b/lib/solidus_dev_support/templates/extension/Rakefile @@ -2,6 +2,6 @@ require "bundler/gem_tasks" require 'solidus_dev_support/rake_tasks' -SolidusDevSupport::RakeTasks.install +SolidusDevSupport::RakeTasks.install(user_class: "Spree::User") task default: 'extension:specs'