Added test_create_binding_target
Goals (incl. binding) are required to have targets Plugin fixtures are available through accessors
This commit is contained in:
parent
13974e5e2f
commit
f9ba308072
@ -8,7 +8,8 @@ class Goal < ActiveRecord::Base
|
||||
|
||||
validates :target_exposures, presence: true
|
||||
validates :is_binding, uniqueness: {scope: :project_id}, if: :is_binding?
|
||||
validates :name, presence: true, uniqueness: {scope: :project_id}
|
||||
validates :name, presence: true, uniqueness: {scope: :project_id},
|
||||
exclusion: {in: [I18n.t('targets.form.binding_goal')], unless: :is_binding?}
|
||||
|
||||
after_initialize do
|
||||
if new_record?
|
||||
|
@ -1,4 +1,4 @@
|
||||
<% if User.current.allowed_to?(:manage_common, @project) %>
|
||||
<% if User.current.allowed_to?(:manage_body_trackers, @project) %>
|
||||
<%= link_to t(".link_import_foods"), '#', class: 'icon icon-multiple',
|
||||
onclick: '$("#import-foods").show(); $("#filename").focus(); return false;' %>
|
||||
<%= link_to t(".link_new_food"), new_project_food_path(@project, view: view),
|
||||
|
@ -1,5 +1,5 @@
|
||||
<%= fields_for 'goal', goal do |ff| %>
|
||||
<label><%= l(:field_goal) %><span class="required"> *</span></label>
|
||||
<label for="goal_id"><%= l(:field_goal) %><span class="required"> *</span></label>
|
||||
<%= ff.select :id,
|
||||
options_from_collection_for_select(@project.goals, :id, :name, goal.id),
|
||||
{required: true}, autocomplete: 'off',
|
||||
|
@ -29,7 +29,7 @@
|
||||
<li><%= link_to t(".link_sources"), project_sources_path(@project) %></li>
|
||||
<li><%= link_to t(".link_quantities"), project_quantities_path(@project) %></li>
|
||||
<li><%= link_to t(".link_units"), project_units_path(@project) %></li>
|
||||
<% if User.current.allowed_to?(:manage_common, @project) %>
|
||||
<% if User.current.allowed_to?(:manage_body_trackers, @project) %>
|
||||
<li> </li>
|
||||
<li><p><%= link_to t(".link_defaults"), defaults_project_body_trackers_path(@project),
|
||||
method: :post, data: {confirm: t(".confirm_defaults")} %></li>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<% if User.current.allowed_to?(:manage_common, @project) %>
|
||||
<% if User.current.allowed_to?(:manage_body_trackers, @project) %>
|
||||
<%= link_to t(".link_new_meal"), new_project_meal_path(@project),
|
||||
{remote: true, class: 'icon icon-add'} %>
|
||||
<% end %>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<% if User.current.allowed_to?(:manage_common, @project) %>
|
||||
<% if User.current.allowed_to?(:manage_body_trackers, @project) %>
|
||||
<%= link_to t(".link_new_measurement"),
|
||||
new_project_measurement_path(@project, @view_params),
|
||||
{remote: true, class: 'icon icon-add'} %>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<div class="contextual">
|
||||
<% if User.current.allowed_to?(:manage_common, @project) %>
|
||||
<% if User.current.allowed_to?(:manage_body_trackers, @project) %>
|
||||
<%= link_to t(".link_new_quantity"), new_project_quantity_path(@project),
|
||||
{remote: true, class: 'icon icon-add'} %>
|
||||
<% end %>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<div class="contextual">
|
||||
<% if User.current.allowed_to?(:manage_common, @project) %>
|
||||
<% if User.current.allowed_to?(:manage_body_trackers, @project) %>
|
||||
<%= link_to t(".link_new_source"), '#', class: 'icon icon-add',
|
||||
onclick: '$("#add-source").show(); $("#source_name").focus(); return false;' %>
|
||||
<% end %>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<% if User.current.allowed_to?(:manage_common, @project) %>
|
||||
<% if User.current.allowed_to?(:manage_body_trackers, @project) %>
|
||||
<%= link_to t(".link_new_target"),
|
||||
new_project_target_path(@project, @view_params),
|
||||
{remote: true, class: 'icon icon-add'} %>
|
||||
|
@ -5,7 +5,6 @@
|
||||
<div id='goal-form' class="tabular">
|
||||
<% if goal.persisted? || goal.is_binding? %>
|
||||
<p><%= render partial: 'goals/show_form', locals: {goal: goal} %></p>
|
||||
<%#= t '.effective_from' %>
|
||||
<p><%= f.date_field :effective_from, disabled: !goal.is_binding? %></p>
|
||||
<% else %>
|
||||
<%= render partial: 'goals/form', locals: {goal: goal} %>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<div class="contextual">
|
||||
<% if User.current.allowed_to?(:manage_common, @project) %>
|
||||
<% if User.current.allowed_to?(:manage_body_trackers, @project) %>
|
||||
<%= link_to t(".link_new_unit"), '#', class: 'icon icon-add',
|
||||
onclick: '$("#add-unit").show(); $("#unit_shortname").focus(); return false;' %>
|
||||
<% end %>
|
||||
|
@ -94,10 +94,10 @@ en:
|
||||
contextual:
|
||||
link_new_target: 'New target'
|
||||
form:
|
||||
choose_quantity: "Choose quantity"
|
||||
binding_goal: '- binding -'
|
||||
choose_quantity: 'Choose quantity'
|
||||
button_new_target: 'Add target'
|
||||
button_delete_target: 'Delete'
|
||||
effective_from: ', effective from:'
|
||||
new_form:
|
||||
heading_new_target: 'New target'
|
||||
index:
|
||||
|
2
init.rb
2
init.rb
@ -25,7 +25,7 @@ Redmine::Plugin.register :body_tracking do
|
||||
quantities: [:index, :parents, :filter],
|
||||
units: [:index],
|
||||
}, read: true
|
||||
permission :manage_common, {
|
||||
permission :manage_body_trackers, {
|
||||
body_trackers: [:defaults],
|
||||
goals: [:edit],
|
||||
targets: [:new, :create, :edit, :update, :destroy, :reapply, :toggle_exposure],
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -21,8 +21,11 @@ class BodyTrackingSystemTestCase < ApplicationSystemTestCase
|
||||
FileUtils.rm Dir.glob(File.join(config.save_path, '*.png'))
|
||||
end
|
||||
|
||||
fixtures :projects
|
||||
plugin_fixtures :quantities, :units, :goals, :exposures, :targets, :quantity_values
|
||||
fixtures :projects, :users, :members
|
||||
# Redmine fixtures use explicit IDs, so it's impossible to access them by name.
|
||||
# Use: 'project_id: 1' and NOT 'project: projects_001'
|
||||
plugin_fixtures :enabled_modules, :roles, :member_roles,
|
||||
:quantities, :units, :goals, :exposures, :targets, :quantity_values
|
||||
|
||||
include AbstractController::Translation
|
||||
|
||||
|
3
test/fixtures/enabled_modules.yml
vendored
Normal file
3
test/fixtures/enabled_modules.yml
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
enabled_modules_body_tracking:
|
||||
name: body_tracking
|
||||
project_id: 1
|
2
test/fixtures/goals.yml
vendored
2
test/fixtures/goals.yml
vendored
@ -1,4 +1,4 @@
|
||||
goals_binding:
|
||||
project_id: 1
|
||||
is_binding: true
|
||||
name: '- binding -'
|
||||
name: "<%= I18n.t 'targets.form.binding_goal' %>"
|
||||
|
3
test/fixtures/member_roles.yml
vendored
Normal file
3
test/fixtures/member_roles.yml
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
member_roles_jsmith_manager:
|
||||
member_id: 1
|
||||
role: roles_body_trackers_manager
|
15
test/fixtures/roles.yml
vendored
Normal file
15
test/fixtures/roles.yml
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
roles_body_trackers_manager:
|
||||
name: Manage body trackers
|
||||
builtin: false
|
||||
issues_visibility: all
|
||||
users_visibility: all
|
||||
permissions: |
|
||||
- :manage_body_trackers
|
||||
- :view_body_trackers
|
||||
roles_body_trackers_viewer:
|
||||
name: View body trackers
|
||||
builtin: false
|
||||
issues_visibility: all
|
||||
users_visibility: all
|
||||
permissions: |
|
||||
- :view_body_trackers
|
@ -6,12 +6,7 @@ class TargetsTest < BodyTrackingSystemTestCase
|
||||
|
||||
@project1 = projects(:projects_001)
|
||||
|
||||
log_user 'alice', 'foo'
|
||||
end
|
||||
|
||||
def teardown
|
||||
logout_user
|
||||
super
|
||||
log_user 'jsmith', 'jsmith'
|
||||
end
|
||||
|
||||
def test_index
|
||||
@ -29,6 +24,31 @@ class TargetsTest < BodyTrackingSystemTestCase
|
||||
assert_selector 'div#targets', visible: :yes, exact_text: t(:label_no_data)
|
||||
end
|
||||
|
||||
def test_create_saves_binding_goal_if_nonexistent
|
||||
def test_index_shows_and_hides_new_target_form
|
||||
end
|
||||
|
||||
def test_create_binding_target
|
||||
visit project_targets_path(@project1)
|
||||
assert_current_path project_targets_path(@project1)
|
||||
assert_no_selector 'form#new-target-form'
|
||||
click_link t('targets.contextual.link_new_target')
|
||||
within 'form#new-target-form' do
|
||||
assert has_select?(t(:field_goal), selected: t('targets.form.binding_goal'))
|
||||
assert has_field?(t(:field_effective_from), with: Date.current.strftime)
|
||||
within 'p.target' do
|
||||
select quantities(:quantities_energy).name
|
||||
select '=='
|
||||
fill_in with: '1750'
|
||||
select units(:units_kcal).shortname
|
||||
end
|
||||
assert_difference 'Target.count' => 1, 'Threshold.count' => 1, 'Goal.count' => 0 do
|
||||
click_on t(:button_create)
|
||||
end
|
||||
end
|
||||
assert_current_path project_targets_path(@project1)
|
||||
assert_selector 'table#targets tbody tr', count: @project1.targets.count
|
||||
end
|
||||
|
||||
def test_create_binding_target_when_binding_goal_does_not_exist
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user