- <% 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 %>
diff --git a/app/views/sources/index.html.erb b/app/views/sources/index.html.erb
index 55b8ca9..4ff7447 100644
--- a/app/views/sources/index.html.erb
+++ b/app/views/sources/index.html.erb
@@ -1,5 +1,5 @@
- <% 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 %>
diff --git a/app/views/targets/_contextual.html.erb b/app/views/targets/_contextual.html.erb
index a6bfd4e..c11ed80 100644
--- a/app/views/targets/_contextual.html.erb
+++ b/app/views/targets/_contextual.html.erb
@@ -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'} %>
diff --git a/app/views/targets/_form.html.erb b/app/views/targets/_form.html.erb
index 645706e..185de94 100644
--- a/app/views/targets/_form.html.erb
+++ b/app/views/targets/_form.html.erb
@@ -5,7 +5,6 @@
<% if goal.persisted? || goal.is_binding? %>
<%= render partial: 'goals/show_form', locals: {goal: goal} %>
- <%#= t '.effective_from' %>
<%= f.date_field :effective_from, disabled: !goal.is_binding? %>
<% else %>
<%= render partial: 'goals/form', locals: {goal: goal} %>
diff --git a/app/views/units/index.html.erb b/app/views/units/index.html.erb
index c92e9e0..8c5a4c5 100644
--- a/app/views/units/index.html.erb
+++ b/app/views/units/index.html.erb
@@ -1,5 +1,5 @@
- <% 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 %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 821f53b..cd05585 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -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:
diff --git a/init.rb b/init.rb
index fff95ad..e5c3870 100644
--- a/init.rb
+++ b/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],
diff --git a/lib/body_tracking/plugin_fixtures_loader.rb b/lib/body_tracking/plugin_fixtures_loader.rb
index b381f90..2f4100c 100644
--- a/lib/body_tracking/plugin_fixtures_loader.rb
+++ b/lib/body_tracking/plugin_fixtures_loader.rb
@@ -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
diff --git a/lib/body_tracking/project_patch.rb b/lib/body_tracking/project_patch.rb
index d5f82b6..9225fa2 100644
--- a/lib/body_tracking/project_patch.rb
+++ b/lib/body_tracking/project_patch.rb
@@ -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
diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb
index 6b53570..efb64b6 100644
--- a/test/application_system_test_case.rb
+++ b/test/application_system_test_case.rb
@@ -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
diff --git a/test/fixtures/enabled_modules.yml b/test/fixtures/enabled_modules.yml
new file mode 100644
index 0000000..311623e
--- /dev/null
+++ b/test/fixtures/enabled_modules.yml
@@ -0,0 +1,3 @@
+enabled_modules_body_tracking:
+ name: body_tracking
+ project_id: 1
diff --git a/test/fixtures/goals.yml b/test/fixtures/goals.yml
index 5e57cd2..635ae23 100644
--- a/test/fixtures/goals.yml
+++ b/test/fixtures/goals.yml
@@ -1,4 +1,4 @@
goals_binding:
project_id: 1
is_binding: true
- name: '- binding -'
+ name: "<%= I18n.t 'targets.form.binding_goal' %>"
diff --git a/test/fixtures/member_roles.yml b/test/fixtures/member_roles.yml
new file mode 100644
index 0000000..e58d606
--- /dev/null
+++ b/test/fixtures/member_roles.yml
@@ -0,0 +1,3 @@
+member_roles_jsmith_manager:
+ member_id: 1
+ role: roles_body_trackers_manager
diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml
new file mode 100644
index 0000000..c4d1400
--- /dev/null
+++ b/test/fixtures/roles.yml
@@ -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
diff --git a/test/system/targets_test.rb b/test/system/targets_test.rb
index 11d11c6..e9c0456 100644
--- a/test/system/targets_test.rb
+++ b/test/system/targets_test.rb
@@ -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