From 955125b843125e3411aea20d9e4b0be3da469e97 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Sun, 16 Aug 2020 15:27:07 +0200 Subject: [PATCH] Target system tests started to run --- app/models/goal.rb | 1 + init.rb | 2 +- lib/body_tracking/plugin_fixtures_loader.rb | 4 ++-- test/application_system_test_case.rb | 4 +--- test/fixtures/exposures.yml | 4 ++++ test/fixtures/quantities.yml | 8 ++++++++ test/fixtures/quantity_values.yml | 7 +++++++ test/fixtures/targets.yml | 2 ++ test/fixtures/units.yml | 14 ++++++++++++++ test/system/targets_test.rb | 1 + 10 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 test/fixtures/exposures.yml create mode 100644 test/fixtures/quantities.yml create mode 100644 test/fixtures/quantity_values.yml create mode 100644 test/fixtures/units.yml diff --git a/app/models/goal.rb b/app/models/goal.rb index 8b7d481..5af6f54 100644 --- a/app/models/goal.rb +++ b/app/models/goal.rb @@ -6,6 +6,7 @@ class Goal < ActiveRecord::Base class_name: 'Exposure', extend: BodyTracking::TogglableExposures has_many :quantities, -> { order "lft" }, through: :target_exposures + validates :target_exposures, presence: true validates :name, presence: true, uniqueness: {scope: :project_id} def is_binding? diff --git a/init.rb b/init.rb index dc9c1cf..fff95ad 100644 --- a/init.rb +++ b/init.rb @@ -1,7 +1,7 @@ (Rails::VERSION::MAJOR < 5 ? ActionDispatch : ActiveSupport)::Reloader.to_prepare do Project.include BodyTracking::ProjectPatch CollectiveIdea.include BodyTracking::AwesomeNestedSetPatch - ActionController::TestCase.include BodyTracking::PluginFixturesLoader if Rails.env == 'test' + ActiveSupport::TestCase.include BodyTracking::PluginFixturesLoader if Rails.env == 'test' end Redmine::Plugin.register :body_tracking do diff --git a/lib/body_tracking/plugin_fixtures_loader.rb b/lib/body_tracking/plugin_fixtures_loader.rb index c6a78d8..b381f90 100644 --- a/lib/body_tracking/plugin_fixtures_loader.rb +++ b/lib/body_tracking/plugin_fixtures_loader.rb @@ -2,8 +2,8 @@ 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::Fixtures.create_fixtures(fixtures_dir, symbols) + fixtures_dir = File.expand_path('../../../test/fixtures/', __FILE__) + ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, symbols) end end end diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index 44cff58..1899e4a 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -21,9 +21,7 @@ class BodyTrackingSystemTestCase < ApplicationSystemTestCase end fixtures :projects -# fixtures :users, :email_addresses, :trackers, :projects, -# :roles, :members, :member_roles, :enabled_modules - plugin_fixtures :targets + plugin_fixtures :quantities, :units, :exposures, :targets, :quantity_values include AbstractController::Translation diff --git a/test/fixtures/exposures.yml b/test/fixtures/exposures.yml new file mode 100644 index 0000000..ea132e3 --- /dev/null +++ b/test/fixtures/exposures.yml @@ -0,0 +1,4 @@ +exposures_01: + view_type: Goal + view_id: <%= Project.find(1).goals.binding.id %> + quantity: quantities_energy diff --git a/test/fixtures/quantities.yml b/test/fixtures/quantities.yml new file mode 100644 index 0000000..be4b47b --- /dev/null +++ b/test/fixtures/quantities.yml @@ -0,0 +1,8 @@ +quantities_energy: + project: projects_001 + domain: diet + parent: null + lft: 1 + rgt: 2 + name: Energy + description: Total energy diff --git a/test/fixtures/quantity_values.yml b/test/fixtures/quantity_values.yml new file mode 100644 index 0000000..cc0c2a2 --- /dev/null +++ b/test/fixtures/quantity_values.yml @@ -0,0 +1,7 @@ +quantity_values_001: + type: Threshold + registry_type: Target + registry: targets_01 + quantity: quantities_energy + value: 2500 + unit: units_kcal diff --git a/test/fixtures/targets.yml b/test/fixtures/targets.yml index c8862f7..9354f70 100644 --- a/test/fixtures/targets.yml +++ b/test/fixtures/targets.yml @@ -1,2 +1,4 @@ targets_01: + goal_id: <%= Project.find(1).goals.binding.id %> condition: '==' + effective_from: <%= 1.week.ago.to_s(:db) %> diff --git a/test/fixtures/units.yml b/test/fixtures/units.yml new file mode 100644 index 0000000..00f561a --- /dev/null +++ b/test/fixtures/units.yml @@ -0,0 +1,14 @@ +units_gram: + project: projects_001 + name: 'gram' + shortname: 'g' + +units_percent: + project: projects_001 + name: 'percent' + shortname: '%' + +units_kcal: + project: projects_001 + name: 'kilocalorie' + shortname: 'kcal' diff --git a/test/system/targets_test.rb b/test/system/targets_test.rb index baa4746..b0c2739 100644 --- a/test/system/targets_test.rb +++ b/test/system/targets_test.rb @@ -18,6 +18,7 @@ class TargetsTest < BodyTrackingSystemTestCase assert_not_equal 0, @project1.targets.count visit project_targets_path(@project1) assert_current_path project_targets_path(@project1) + assert_selector 'table#targets tr', count: @project1.targets.count end def test_index_without_targets