diff --git a/assets/javascripts/contracts.js b/assets/javascripts/contracts.js index e69de29..62aff96 100644 --- a/assets/javascripts/contracts.js +++ b/assets/javascripts/contracts.js @@ -0,0 +1,17 @@ +jQuery(function($) { + toggleSpecificDeliverableFields = function() { + var deliverableType = $('select#deliverable_type option:selected').val(); + + if (deliverableType == 'FixedDeliverable') { + $('#deliverable_total').show(); + } else { + $('#deliverable_total').hide(); + } + }, + + toggleSpecificDeliverableFields(); + + $('select#deliverable_type').change(function() { + toggleSpecificDeliverableFields(); + }); +}); diff --git a/init.rb b/init.rb index 375aad6..2b5f920 100644 --- a/init.rb +++ b/init.rb @@ -1,5 +1,11 @@ config.gem 'formtastic', :version => '0.9.10' +if Rails.env.test? + config.gem "stackdeck" + config.gem "johnson", :version => '2.0.0.pre3' + config.gem "holygrail" +end + require 'redmine' Redmine::Plugin.register :redmine_contracts do diff --git a/test/integration/deliverables_new_test.rb b/test/integration/deliverables_new_test.rb index 62bc59e..d58da0a 100644 --- a/test/integration/deliverables_new_test.rb +++ b/test/integration/deliverables_new_test.rb @@ -57,6 +57,8 @@ class DeliverablesNewTest < ActionController::IntegrationTest fill_in "End Date", :with => '2010-12-31' fill_in "Notes", :with => 'Some notes on the deliverable' fill_in "Total", :with => '1,000.00' + # TODO: webrat can't trigger DOM events so it can't appear + # assert js("jQuery('#deliverable_total').is(':visible')"), "Total is hidden when it should be visible" click_button "Save" @@ -89,6 +91,9 @@ class DeliverablesNewTest < ActionController::IntegrationTest fill_in "End Date", :with => '2010-12-31' fill_in "Notes", :with => 'Some notes on the deliverable' + assert js("jQuery('#deliverable_total').is(':hidden')"), + "Total is visible when it should be hidden" + click_button "Save" assert_response :success diff --git a/test/test_helper.rb b/test/test_helper.rb index 38fcc4a..c239301 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -10,6 +10,26 @@ Webrat.configure do |config| config.mode = :rails end +require 'holygrail' + +module HolyGrail + module Extensions + # Need to rewrite the javascript for the engine too + def rewrite_script_paths(body) + body. + gsub(%r%src=("|')/?plugin_assets/redmine_contracts/javascripts/(.*)("|')%) { %|src=#{$1}%s#{$1}"| % Rails.root.join("vendor/plugins/redmine_contracts/assets/javascripts/#{$2}") }. + gsub(%r%src=("|')/?javascripts/(.*)("|')%) { %|src=#{$1}%s#{$1}"| % Rails.root.join("public/javascripts/#{$2}") } + end + end +end + +class ActionController::TestCase + include HolyGrail::Extensions +end +class ActionController::IntegrationTest + include HolyGrail::Extensions +end + def User.add_to_project(user, project, role) Member.generate!(:principal => user, :project => project, :roles => [role]) end