1
0

Added test_create_binding_target

Goals (incl. binding) are required to have targets
Plugin fixtures are available through accessors
This commit is contained in:
cryptogopher
2020-08-20 21:52:18 +02:00
parent 13974e5e2f
commit f9ba308072
21 changed files with 103 additions and 27 deletions

View File

@@ -2,9 +2,39 @@ module BodyTracking::PluginFixturesLoader
def self.included(base)
base.class_eval do
def self.plugin_fixtures(*symbols)
fixtures_dir = File.expand_path('../../../test/fixtures/', __FILE__)
ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, symbols)
plugin_fixtures_path = Rails.root.join('plugins', 'body_tracking', 'test', 'fixtures')
ActiveRecord::FixtureSet.create_fixtures(plugin_fixtures_path, symbols)
# ActiveRecord::TestFixtures#fixtures creates model_name(:fixture_name) accessors
fixtures *symbols
end
end
end
#private
## Load fixtures giving preference for plugin defined ones
#def load_fixtures(*args)
# # call create_fixtures directly instead of load_fixtures
# # or
# # create_fixtures in plugin_fixtures (include method in
# # ActiveRecord::TestFixtures) + load by calling #fixtures (like in issue_recurring)
# byebug
# redmine_fixture_path = self.fixture_path
# plugin_fixture_path = Rails.root.join('plugins', 'body_tracking', 'test', 'fixtures')
# all_ft_names = fixture_table_names
# plugin_ft_names, redmine_ft_names = fixture_table_names.partition do |ft_name|
# File.exists?(plugin_fixture_path.join("#{ft_name.to_s}.yml"))
# end
# self.fixture_table_names = redmine_ft_names
# fixtures = super
# ActiveSupport::TestCase.fixture_path = plugin_fixture_path
# self.fixture_table_names = plugin_ft_names
# fixtures.merge(super)
# ActiveSupport::TestCase.fixture_path = redmine_fixture_path
# self.fixture_table_names = all_ft_names
# fixtures
#end
end

View File

@@ -31,7 +31,9 @@ module BodyTracking::ProjectPatch
has_many :goals, dependent: :destroy do
def binding
find_or_initialize_by(is_binding: true) { |g| g.name = "- binding -" }
find_or_initialize_by(is_binding: true) do |goal|
goal.name = I18n.t('targets.form.binding_goal')
end
end
end
has_many :targets, through: :goals