Project

General

Profile

Actions

Feature #3592

closed

Add loader for plugin and core fixtures

Added by liaham 2 months ago. Updated 16 days ago.

Status:
Rejected
Priority:
Normal
Assignee:
Target version:
-
Start date:
08/04/2025
Due date:
08/04/2025
% Done:

30%

Estimated time:
Compatible Redmine Version:
6.0.z
Requires Documentation?:
No

Description

module AdvancedPluginHelper
  module FixtureLoader
   def fixtures(*table_names)
      if table_names.first == :all
        super(:all)
        create_plugin_fixtures(:all)
      else
        super(table_names)
        create_plugin_fixtures(table_names)
      end
    end

    def create_plugin_fixtures(table_names)
      plugin_fixture_path = "#{File.dirname __FILE__}/fixtures/"
      if table_names == :all
        table_names = Dir[::File.join(plugin_fixture_path, "{**,*}/*.{yml}")].uniq
        table_names.map! { |f| f[plugin_fixture_path.to_s.size..-5].delete_prefix("/") }
      end
      table_names.each do |table|
        ActiveRecord::FixtureSet.create_fixtures plugin_fixture_path, table if File.exist? "#{plugin_fixture_path}/#{table}.yml"
      end
      self.fixture_table_names |= table_names
      setup_fixture_accessors(table_names)
    end
  end
end

Usage:

module MyPlugin
 class UnitTest < ActiveSupport::TestCase
   extend AdvancedPluginHelper::FixtureLoader
 end
end

# Load all plugin and all core fixtures
module MyPlugin
  class MyModelTest < UnitTest
    fixtures :all
  end
end

# Load only listed fixtures
module MyPlugin
  class MyModelTest < UnitTest
    fixtures :core_fixture1, :core_fixture2, :plugin_fixture1, :plugin_fixture2
  end
end
Actions #1

Updated by liaham 16 days ago

  • Target version changed from unreleased to 0.6.0
Actions #2

Updated by liaham 16 days ago

  • Status changed from New to In Progress
  • Start date set to 08/04/2025
  • % Done changed from 0 to 30
  • Requires Documentation? set to No
Actions #3

Updated by liaham 16 days ago

  • Due date set to 08/04/2025
  • Status changed from In Progress to Rejected

Each plugin running with Rails 7.2 and above can set its own fixture_paths:

# test_helper.rb

module MyPlugin
  PLUGIN_FIXTURE_PATH = File.expand_path('fixtures', __dir__)
  
  class ControllerTest < ActionDispatch::IntegrationTest
    fixture_paths << PLUGIN_FIXTUE_PATH
    # further code 
  end

  # further test classes
end
Actions #4

Updated by liaham 16 days ago

  • Target version deleted (0.6.0)
Actions

Also available in: Atom PDF