diff --git a/app/controllers/targets_controller.rb b/app/controllers/targets_controller.rb index fb97aa3..0a81187 100644 --- a/app/controllers/targets_controller.rb +++ b/app/controllers/targets_controller.rb @@ -56,7 +56,7 @@ class TargetsController < ApplicationController end def toggle_exposure - @goal.target_exposures.toggle!(@quantity) + @goal.exposures.toggle!(@quantity) prepare_targets end diff --git a/app/models/goal.rb b/app/models/goal.rb index a211ae2..29899b8 100644 --- a/app/models/goal.rb +++ b/app/models/goal.rb @@ -2,9 +2,9 @@ class Goal < ActiveRecord::Base belongs_to :project, required: true has_many :targets, -> { order effective_from: :desc }, inverse_of: :goal, dependent: :destroy, extend: BodyTracking::ItemsWithQuantities - has_many :target_exposures, as: :view, dependent: :destroy, + has_many :exposures, as: :view, dependent: :destroy, class_name: 'Exposure', extend: BodyTracking::TogglableExposures - has_many :quantities, -> { order "lft" }, through: :target_exposures + has_many :quantities, -> { order "lft" }, through: :exposures accepts_nested_attributes_for :targets, allow_destroy: true validates :is_binding, uniqueness: {scope: :project_id}, if: :is_binding? @@ -19,7 +19,7 @@ class Goal < ActiveRecord::Base end before_save do - quantities << targets.map(&:quantity)[0..5] if target_exposures.empty? + quantities << targets.map(&:quantity)[0..5] if exposures.empty? end before_destroy prepend: true do diff --git a/test/system/targets_test.rb b/test/system/targets_test.rb index 182bb13..802f286 100644 --- a/test/system/targets_test.rb +++ b/test/system/targets_test.rb @@ -45,11 +45,13 @@ class TargetsTest < BodyTrackingSystemTestCase end def test_index_table_header_close_exposure + quantity = @project.goals.binding.exposures.sample.quantity + visit goal_targets_path(@project.goals.binding) - within 'table#targets thead th', text: quantities(:quantities_energy).name do + within 'table#targets thead th', text: quantity.name do click_link class: 'icon-close' end - assert_no_selector 'table#targets thead th', text: quantities(:quantities_energy).name + assert_no_selector 'table#targets thead th', text: quantity.name assert_selector 'table#targets thead th' end