Index: Gemfile =================================================================== --- Gemfile (revision 11125) +++ Gemfile (working copy) @@ -82,6 +82,8 @@ platforms << :jruby if defined?(JRUBY_VERSION) && JRUBY_VERSION >= "1.7" gem "test-unit", :platforms => platforms gem "mocha", "0.12.3" + gem 'capybara', '~> 2.0.0' + gem 'database_cleaner' end local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local") Index: test/integration/issues_test.rb =================================================================== --- test/integration/issues_test.rb (revision 11125) +++ test/integration/issues_test.rb (working copy) @@ -17,7 +17,7 @@ require File.expand_path('../../test_helper', __FILE__) -class IssuesTest < ActionController::IntegrationTest +class IssuesTest < ActionDispatch::IntegrationTest fixtures :projects, :users, :roles, @@ -36,33 +36,54 @@ # create an issue def test_add_issue log_user('jsmith', 'jsmith') - get 'projects/1/issues/new', :tracker_id => '1' - assert_response :success - assert_template 'issues/new' + + visit new_issue_path(:project_id => 1) + + within('form#issue-form') do + + select 'Bug', :from => 'Tracker' + select 'Low', :from => 'Priority' + fill_in 'Subject', :with => 'new test issue' + fill_in 'Description', :with => 'new issue' + select '0 %', :from => 'Done' + fill_in 'Due date', :with => '' + select '', :from => 'Assignee' + fill_in 'Searchable field', :with => 'Value for field 2' + + # click_button 'Create' would match both 'Create' and 'Create and continue' buttons + find('input[name=commit]').click + end - post 'projects/1/issues', :tracker_id => "1", - :issue => { :start_date => "2006-12-26", - :priority_id => "4", - :subject => "new test issue", - :category_id => "", - :description => "new issue", - :done_ratio => "0", - :due_date => "", - :assigned_to_id => "" }, - :custom_fields => {'2' => 'Value for field 2'} # find created issue issue = Issue.find_by_subject("new test issue") assert_kind_of Issue, issue # check redirection - assert_redirected_to :controller => 'issues', :action => 'show', :id => issue - follow_redirect! - assert_equal issue, assigns(:issue) + find 'div#flash_notice', :visible => true, :text => "Issue \##{issue.id} created." + assert_equal issue_path(:id => issue), current_path # check issue attributes assert_equal 'jsmith', issue.author.login assert_equal 1, issue.project.id - assert_equal 1, issue.status.id + assert_equal IssueStatus.find_by_name('New'), issue.status + assert_equal Tracker.find_by_name('Bug'), issue.tracker + assert_equal IssuePriority.find_by_name('Low'), issue.priority + assert_equal 'Value for field 2', issue.custom_field_value(CustomField.find_by_name('Searchable field')) + end + + def test_preview_issue_description + log_user('jsmith', 'jsmith') + + visit new_issue_path(:project_id => 1) + + within('form#issue-form') do + + fill_in 'Description', :with => 'new issue description' + + click_link 'Preview' + end + + find 'div#preview fieldset', :visible => true, :text => 'new issue description' end def test_update_issue_form Index: test/test_helper.rb =================================================================== --- test/test_helper.rb (revision 11125) +++ test/test_helper.rb (working copy) @@ -20,13 +20,60 @@ require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'rails/test_help' require Rails.root.join('test', 'mocks', 'open_id_authentication_mock.rb').to_s +require 'capybara/rails' require File.expand_path(File.dirname(__FILE__) + '/object_helpers') include ObjectHelpers +# Transactional fixtures do not work with Selenium tests, because Capybara +# uses a separate server thread, which the transactions would be hidden +# from. We hence use DatabaseCleaner to truncate our test database. +DatabaseCleaner.strategy = :truncation +Capybara.default_driver = :selenium + +# Use the following driver definition to test locally using Chrome (also requires chromedriver to be in PATH) +#Capybara.register_driver :selenium do |app| +# Capybara::Selenium::Driver.new(app, :browser => :chrome) # Add :switches => %w[--lang=en] to force default browser locale to English +#end + +Capybara.register_driver :selenium do |app| + # Default for Selenium remote driver is to connect to local host on port 4444 + # This can be change using :url => 'http://localhost:9195' if necessary + # PhantomJS 1.8 now directly supports Webdriver Wire API, simply run it with 'phantomjs --webdriver 4444' + Capybara::Selenium::Driver.new(app, :browser => :remote) +end + +class ActionDispatch::IntegrationTest + # Make the Capybara DSL available in all integration tests + include Capybara::DSL + + # Overrides ActiveSupport::TestCase's + # Should not depend on locale since Redmine now displays login page + # using default browser locale which depend on system locale for "real" browsers drivers + def log_user(login, password) + User.anonymous + visit '/my/page' + assert_equal '/login', current_path + within('#login-form form') do + fill_in 'username', :with => login + fill_in 'password', :with => password + find('input[name=login]').click + end + assert_equal '/my/page', current_path + end + + # Stop ActiveRecord from wrapping tests in transactions + self.use_transactional_fixtures = false + + teardown do + DatabaseCleaner.clean # Truncate the database + Capybara.reset_sessions! # Forget the (simulated) browser state + Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver + end +end + class ActiveSupport::TestCase - include ActionDispatch::TestProcess - + # Transactional fixtures accelerate your tests by wrapping each test method # in a transaction that's rolled back on completion. This ensures that the # test database remains unchanged so your fixtures don't have to be reloaded