Project

General

Profile

Feature #12822 » capybara.patch

v2 - Etienne Massip, 2013-01-21 22:12

View differences:

test/integration/issues_test.rb (working copy)
17 17

  
18 18
require File.expand_path('../../test_helper', __FILE__)
19 19

  
20
class IssuesTest < ActionController::IntegrationTest
20
class IssuesTest < ActionDispatch::IntegrationTest
21 21
  fixtures :projects,
22 22
           :users,
23 23
           :roles,
......
35 35

  
36 36
  # create an issue
37 37
  def test_add_issue
38
    log_user('jsmith', 'jsmith')
39
    get 'projects/1/issues/new', :tracker_id => '1'
40
    assert_response :success
41
    assert_template 'issues/new'
38
    log_user_capybara('jsmith', 'jsmith')
39

  
40
    visit new_issue_path(:project_id => 1)
41

  
42
    within('form#issue-form') do
43

  
44
      select 'Bug', :from => 'Tracker'
45
      select 'Low', :from => 'Priority'
46
      fill_in 'Subject', :with => 'new test issue'
47
      fill_in 'Description', :with => 'new issue'
48
      select '0 %', :from => 'Done'
49
      fill_in 'Due date', :with => ''
50
      select '', :from => 'Assignee'
51
      fill_in 'Searchable field', :with => 'Value for field 2'
52

  
53
      # click_button 'Create' would match both 'Create' and 'Create and continue' buttons
54
      find('input[name=commit]').click
55
    end
42 56

  
43
    post 'projects/1/issues', :tracker_id => "1",
44
                                 :issue => { :start_date => "2006-12-26",
45
                                             :priority_id => "4",
46
                                             :subject => "new test issue",
47
                                             :category_id => "",
48
                                             :description => "new issue",
49
                                             :done_ratio => "0",
50
                                             :due_date => "",
51
                                             :assigned_to_id => "" },
52
                                 :custom_fields => {'2' => 'Value for field 2'}
53 57
    # find created issue
54 58
    issue = Issue.find_by_subject("new test issue")
55 59
    assert_kind_of Issue, issue
56 60

  
57 61
    # check redirection
58
    assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
59
    follow_redirect!
60
    assert_equal issue, assigns(:issue)
62
    find 'div#flash_notice', :visible => true, :text => "Issue \##{issue.id} created."
63
    assert_equal issue_path(:id => issue), current_path
61 64

  
62 65
    # check issue attributes
63 66
    assert_equal 'jsmith', issue.author.login
64 67
    assert_equal 1, issue.project.id
65
    assert_equal 1, issue.status.id
68
    assert_equal IssueStatus.find_by_name('New'), issue.status 
69
    assert_equal Tracker.find_by_name('Bug'), issue.tracker
70
    assert_equal IssuePriority.find_by_name('Low'), issue.priority
71
    assert_equal 'Value for field 2', issue.custom_field_value(CustomField.find_by_name('Searchable field'))
72
  end
73

  
74
  def test_preview_issue_description
75
    log_user_capybara('jsmith', 'jsmith')
76

  
77
    visit new_issue_path(:project_id => 1)
78

  
79
    within('form#issue-form') do
80

  
81
      fill_in 'Description', :with => 'new issue description'
82

  
83
      click_link 'Preview'
84
    end
85

  
86
    find 'div#preview fieldset', :visible => true, :text => 'new issue description'
66 87
  end
67 88

  
68 89
  def test_update_issue_form
test/test_helper.rb (working copy)
20 20
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
21 21
require 'rails/test_help'
22 22
require Rails.root.join('test', 'mocks', 'open_id_authentication_mock.rb').to_s
23
require 'capybara/rails'
23 24

  
24 25
require File.expand_path(File.dirname(__FILE__) + '/object_helpers')
25 26
include ObjectHelpers
26 27

  
28
# Transactional fixtures do not work with Selenium tests, because Capybara
29
# uses a separate server thread, which the transactions would be hidden
30
# from. We hence use DatabaseCleaner to truncate our test database.
31
DatabaseCleaner.strategy = :truncation
32
Capybara.default_driver = :selenium
33

  
34
Capybara.register_driver :selenium do |app|
35
  # Use the following driver definition to test locally using Chrome (also requires chromedriver to be in PATH)
36
  # Capybara::Selenium::Driver.new(app, :browser => :chrome) # Add :switches => %w[--lang=en] to force default browser locale to English
37

  
38
  # Default for Selenium remote driver is to connect to local host on port 4444 
39
  # This can be change using :url => 'http://localhost:9195' if necessary
40
  # PhantomJS 1.8 now directly supports Webdriver Wire API, simply run it with 'phantomjs --webdriver 4444'
41
  Capybara::Selenium::Driver.new(app, :browser => :remote) # Add :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.internet_explorer) to run on Selenium Grid Hub with IE
42
end
43

  
44
class ActionDispatch::IntegrationTest
45
  # Make the Capybara DSL available in all integration tests
46
  include Capybara::DSL
47

  
48
  # Should not depend on locale since Redmine now displays login page
49
  # using default browser locale which depend on system locale for "real" browsers drivers
50
  def log_user_capybara(login, password)
51
    User.anonymous
52
    visit '/my/page'
53
    assert_equal '/login', current_path
54
    within('#login-form form') do
55
      fill_in 'username', :with => login
56
      fill_in 'password', :with => password
57
      find('input[name=login]').click
58
    end
59
    assert_equal '/my/page', current_path
60
  end
61

  
62
  # Stop ActiveRecord from wrapping tests in transactions
63
  self.use_transactional_fixtures = false
64

  
65
  teardown do
66
    DatabaseCleaner.clean       # Truncate the database
67
    Capybara.reset_sessions!    # Forget the (simulated) browser state
68
    Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver
69
  end
70
end
71

  
27 72
class ActiveSupport::TestCase
28 73
  include ActionDispatch::TestProcess
29 74
  
(2-2/3)