Test pass: test_index_binding_goal_without_targets
This commit is contained in:
parent
56e131af93
commit
c21c834d84
@ -1,5 +1,6 @@
|
|||||||
class Target < ActiveRecord::Base
|
class Target < ActiveRecord::Base
|
||||||
belongs_to :goal, inverse_of: :targets, required: true
|
belongs_to :goal, inverse_of: :targets, required: true
|
||||||
|
has_one :project, through: :goal, inverse_of: :targets
|
||||||
belongs_to :quantity, -> { where.not(domain: :target) }, inverse_of: :targets,
|
belongs_to :quantity, -> { where.not(domain: :target) }, inverse_of: :targets,
|
||||||
required: true
|
required: true
|
||||||
belongs_to :item, polymorphic: true, inverse_of: :targets
|
belongs_to :item, polymorphic: true, inverse_of: :targets
|
||||||
|
@ -29,7 +29,7 @@ module BodyTracking::ProjectPatch
|
|||||||
has_many :meal_quantities, -> { order "lft" }, through: :meal_exposures,
|
has_many :meal_quantities, -> { order "lft" }, through: :meal_exposures,
|
||||||
source: 'quantity'
|
source: 'quantity'
|
||||||
|
|
||||||
has_many :goals, dependent: :destroy do
|
has_many :goals, inverse_of: :project, dependent: :destroy do
|
||||||
def binding
|
def binding
|
||||||
find_or_create_by!(is_binding: true) do |goal|
|
find_or_create_by!(is_binding: true) do |goal|
|
||||||
goal.name = I18n.t('goals.binding.name')
|
goal.name = I18n.t('goals.binding.name')
|
||||||
@ -37,6 +37,6 @@ module BodyTracking::ProjectPatch
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
has_many :targets, through: :goals
|
has_many :targets, through: :goals, inverse_of: :project
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,18 +7,19 @@ class TargetsTest < BodyTrackingSystemTestCase
|
|||||||
log_user 'jsmith', 'jsmith'
|
log_user 'jsmith', 'jsmith'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_index_binding_targets
|
def test_index_binding_goal
|
||||||
goal = @project1.goals.binding
|
goal = @project1.goals.binding
|
||||||
assert_not_equal 0, goal.targets.count
|
assert_not_equal 0, goal.targets.count
|
||||||
visit goal_targets_path(goal)
|
visit goal_targets_path(goal)
|
||||||
assert_selector 'table#targets tbody tr', count: goal.targets.count
|
assert_selector 'table#targets tbody tr', count: goal.targets.count
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_index_without_targets
|
def test_index_binding_goal_without_targets
|
||||||
@project1.goals.delete_all
|
goal = @project1.goals.binding
|
||||||
assert_equal 0, @project1.targets.count
|
goal.targets.delete_all
|
||||||
visit project_targets_path(@project1)
|
assert_equal 0, goal.targets.count
|
||||||
assert_current_path project_targets_path(@project1)
|
visit goal_targets_path(goal)
|
||||||
|
assert_current_path goal_targets_path(goal)
|
||||||
assert_selector 'div#targets', visible: :yes, exact_text: t(:label_no_data)
|
assert_selector 'div#targets', visible: :yes, exact_text: t(:label_no_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user