Skip to content
Browse files

Add Capybara support

  • Loading branch information...
1 parent 32286bc commit a1281215a77f12f1f6825f3939246877db83f47f @edavis10 committed Mar 21, 2011
Showing with 88 additions and 0 deletions.
  1. +88 −0 test/test_helper.rb
View
88 test/test_helper.rb
@@ -3,3 +3,91 @@
# Ensure that we are using the temporary fixture path
Engines::Testing.set_fixture_path
+
+
+require 'capybara/rails'
+
+
+def User.add_to_project(user, project, role)
+ Member.generate!(:principal => user, :project => project, :roles => [role])
+end
+
+module ChiliProjectIntegrationTestHelper
+ def login_as(user="existing", password="existing")
+ visit "/login"
+ fill_in 'Login', :with => user
+ fill_in 'Password', :with => password
+ click_button 'login'
+ assert_response :success
+ assert User.current.logged?
+ end
+
+ def visit_project(project)
+ visit '/'
+ assert_response :success
+
+ click_link 'Projects'
+ assert_response :success
+
+ click_link project.name
+ assert_response :success
+ end
+
+ def visit_issue_page(issue)
+ visit '/issues/' + issue.id.to_s
+ end
+
+ def visit_issue_bulk_edit_page(issues)
+ visit url_for(:controller => 'issues', :action => 'bulk_edit', :ids => issues.collect(&:id))
+ end
+
+
+ # Capybara doesn't set the response object so we need to glue this to
+ # it's own object but without @response
+ def assert_response(code)
+ # Rewrite human status codes to numeric
+ converted_code = case code
+ when :success
+ 200
+ when :missing
+ 404
+ when :redirect
+ 302
+ when :error
+ 500
+ when code.is_a?(Symbol)
+ ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[code]
+ else
+ code
+ end
+
+ assert_equal converted_code, page.status_code
+ end
+
+
+
+end
+
+class ActionController::IntegrationTest
+ include ChiliProjectIntegrationTestHelper
+
+ include Capybara
+
+end
+
+class ActiveSupport::TestCase
+ def assert_forbidden
+ assert_response :forbidden
+ assert_template 'common/403'
+ end
+
+ def configure_plugin(configuration_change={})
+ Setting.plugin_TODO = {
+
+ }.merge(configuration_change)
+ end
+
+ def reconfigure_plugin(configuration_change)
+ Settings['plugin_TODO'] = Setting['plugin_TODO'].merge(configuration_change)
+ end
+end

0 comments on commit a128121

Please sign in to comment.
Something went wrong with that request. Please try again.