diff --git a/db/migrate/001_create_schema.rb b/db/migrate/001_create_schema.rb index 9b65382..807f14d 100644 --- a/db/migrate/001_create_schema.rb +++ b/db/migrate/001_create_schema.rb @@ -1,4 +1,5 @@ -class CreateSchema < ActiveRecord::Migration +class CreateSchema < + (Rails::VERSION::MAJOR < 5 ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]) def change create_table :quantities do |t| t.references :project diff --git a/db/migrate/002_load_defaults.rb b/db/migrate/002_load_defaults.rb index 639e3be..38ab92f 100644 --- a/db/migrate/002_load_defaults.rb +++ b/db/migrate/002_load_defaults.rb @@ -1,4 +1,5 @@ -class LoadDefaults < ActiveRecord::Migration +class LoadDefaults < + (Rails::VERSION::MAJOR < 5 ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]) def change reversible do |dir| dir.up do diff --git a/init.rb b/init.rb index 7baa7d7..dc9c1cf 100644 --- a/init.rb +++ b/init.rb @@ -1,6 +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' 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 new file mode 100644 index 0000000..c6a78d8 --- /dev/null +++ b/lib/body_tracking/plugin_fixtures_loader.rb @@ -0,0 +1,10 @@ +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) + end + end + end +end diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 0000000..44cff58 --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,96 @@ +# Required for Puma to start in test env for system tests +# (RAILS_ENV=test does not work) +ENV["RACK_ENV"] = "test" + +# Load the Redmine helper +require File.expand_path('../../../../test/application_system_test_case', __FILE__) + +class BodyTrackingSystemTestCase < ApplicationSystemTestCase + profile = Selenium::WebDriver::Firefox::Profile.new + profile['browser.download.dir'] = DOWNLOADS_PATH + profile['browser.download.folderList'] = 2 + profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf" + profile['pdfjs.disabled'] = true + + driven_by :selenium, using: :headless_firefox, screen_size: [1280, 720], options: { + profile: profile + } + + Capybara.configure do |config| + config.save_path = './tmp/screenshots/' + end + + fixtures :projects +# fixtures :users, :email_addresses, :trackers, :projects, +# :roles, :members, :member_roles, :enabled_modules + plugin_fixtures :targets + + include AbstractController::Translation + + def logout_user + click_link t(:label_logout) + assert_current_path home_path + assert_link t(:label_login) + end + + def create_recurrence(issue=issues(:issue_01), **attributes) + #attributes[:mode] ||= :weekly + t_base = 'issues.recurrences.form' + + visit issue_path(issue) + assert_difference ['all("#recurrences tr").length', 'IssueRecurrence.count'], 1 do + within '#issue_recurrences' do + click_link t(:button_add) + attributes.each do |k, v| + value = case k + when :mode + interval = t("#{t_base}.mode_intervals.#{v}") + description = t("#{t_base}.mode_descriptions.#{v}") + "#{interval}(s)" + (description.present? ? ", #{description}" : '') + when :anchor_to_start + t("#{t_base}.#{k.to_s}.#{v}") + else + t("#{t_base}.#{k.to_s.pluralize}.#{v}") + end + select strip_tags(value), from: "recurrence_#{k}" + end + click_button t(:button_add) + end + # status_code not supported by Selenium + assert_current_path issue_path(issue) + assert_selector '#recurrence-errors', visible: :all, exact_text: '' + end + IssueRecurrence.last + end + + def destroy_recurrence(recurrence) + visit issue_path(recurrence.issue) + + assert_difference ['all("#recurrences tr").length', 'IssueRecurrence.count'], -1 do + within "#recurrences tr[id=recurrence-#{recurrence.id}]" do + click_link t(:button_delete) + end + # status_code not supported by Selenium + assert_current_path issue_path(recurrence.issue) + assert_selector '#recurrence-errors', visible: :all, exact_text: '' + end + end + + def close_issue(issue) + assert !issue.closed? + closed_on = issue.closed_on + status = IssueStatus.all.where(is_closed: true).first + + visit edit_issue_path(issue) + within 'form#issue-form' do + select status.name, from: t(:field_status) + click_button t(:button_submit) + end + issue.reload + + assert_equal status.id, issue.status_id + assert_not_nil issue.closed_on + assert_not_equal closed_on, issue.closed_on + assert issue.closed? + end +end diff --git a/test/fixtures/targets.yml b/test/fixtures/targets.yml new file mode 100644 index 0000000..c8862f7 --- /dev/null +++ b/test/fixtures/targets.yml @@ -0,0 +1,2 @@ +targets_01: + condition: '==' diff --git a/test/system/targets_test.rb b/test/system/targets_test.rb new file mode 100644 index 0000000..baa4746 --- /dev/null +++ b/test/system/targets_test.rb @@ -0,0 +1,27 @@ +require File.expand_path('../../application_system_test_case', __FILE__) + +class TargetsTest < BodyTrackingSystemTestCase + def setup + super + + @project1 = projects(:projects_001) + + log_user 'alice', 'foo' + end + + def teardown + logout_user + super + end + + def test_index + assert_not_equal 0, @project1.targets.count + visit project_targets_path(@project1) + assert_current_path project_targets_path(@project1) + end + + def test_index_without_targets + #assert_equal 0, @project1.targets.count + #assert_selector 'div#targets', visible: :yes, exact_text: l(:label_no_data) + end +end