Feature #12822 » capybara.patch
| test/integration/issues_test.rb (working copy) | ||
|---|---|---|
|
require File.expand_path('../../test_helper', __FILE__)
|
||
|
class IssuesTest < ActionController::IntegrationTest
|
||
|
class IssuesTest < ActionDispatch::IntegrationTest
|
||
|
fixtures :projects,
|
||
|
:users,
|
||
|
:roles,
|
||
| ... | ... | |
|
# 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'
|
||
|
log_user_capybara('jsmith', 'jsmith')
|
||
|
|
||
|
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_capybara('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
|
||
| test/test_helper.rb (working copy) | ||
|---|---|---|
|
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
|
||
|
|
||
|
Capybara.register_driver :selenium do |app|
|
||
|
# Use the following driver definition to test locally using Chrome (also requires chromedriver to be in PATH)
|
||
|
# Capybara::Selenium::Driver.new(app, :browser => :chrome) # Add :switches => %w[--lang=en] to force default browser locale to English
|
||
|
|
||
|
# 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) # Add :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.internet_explorer) to run on Selenium Grid Hub with IE
|
||
|
end
|
||
|
|
||
|
class ActionDispatch::IntegrationTest
|
||
|
# Make the Capybara DSL available in all integration tests
|
||
|
include Capybara::DSL
|
||
|
|
||
|
# 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_capybara(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
|
||
|
|
||