Permalink
Browse files

Add integration tests

  • Loading branch information...
1 parent aa9fcf0 commit e3e704461560b355381e16e44d5c1a5fe413633e @route route committed Oct 29, 2013
Showing with 190 additions and 66 deletions.
  1. +2 −0 .gitignore
  2. +0 −12 .travis.yml
  3. +3 −1 pjax_rails.gemspec
  4. +8 −8 test/controllers/{pjax_controller_test.rb → default_layout_controller_test.rb}
  5. +2 −2 test/controllers/with_layout_controller_test.rb
  6. +8 −0 test/dummy/app/assets/javascripts/application.js
  7. +2 −0 test/dummy/app/controllers/application_controller.rb
  8. +5 −0 test/dummy/app/controllers/capybara_controller.rb
  9. +5 −0 test/dummy/app/controllers/default_layout_controller.rb
  10. +3 −0 test/dummy/app/controllers/with_layout_controller.rb
  11. +7 −0 test/dummy/app/views/capybara/html_content.html.erb
  12. +9 −0 test/dummy/app/views/capybara/index.html.erb
  13. +1 −0 test/dummy/app/views/capybara/plain_text.html.erb
  14. +1 −0 test/dummy/app/views/capybara/prevents_pjax.html.erb
  15. +1 −0 test/dummy/app/views/default_layout/index.html.erb
  16. +1 −0 test/dummy/app/views/default_layout/prevent_pjax.html.erb
  17. +12 −0 test/dummy/app/views/layouts/application.html.erb
  18. +12 −0 test/dummy/app/views/layouts/with_layout.html.erb
  19. +1 −0 test/dummy/app/views/with_layout/index.html.erb
  20. +3 −0 test/dummy/config.ru
  21. +17 −0 test/dummy/config/application.rb
  22. +3 −0 test/dummy/config/boot.rb
  23. +5 −0 test/dummy/config/environment.rb
  24. +12 −0 test/dummy/config/environments/development.rb
  25. +17 −0 test/dummy/config/environments/test.rb
  26. +3 −0 test/dummy/config/routes.rb
  27. +33 −0 test/features/pjax_test.rb
  28. +1 −1 test/gemfiles/Gemfile.rails-3.1.x
  29. +1 −1 test/gemfiles/Gemfile.rails-3.2.x
  30. +1 −1 test/gemfiles/Gemfile.rails-4.0.x
  31. +11 −40 test/test_helper.rb
View
@@ -1,2 +1,4 @@
*.gem
Gemfile.lock
+test/dummy/tmp
+test/dummy/log
View
@@ -1,22 +1,10 @@
rvm:
- - 1.8.7
- 1.9.3
- 2.0.0
- - jruby-18mode
- jruby-19mode
- - rbx-18mode
- rbx-19mode
gemfile:
- test/gemfiles/Gemfile.rails-3.1.x
- test/gemfiles/Gemfile.rails-3.2.x
- test/gemfiles/Gemfile.rails-4.0.x
-
-matrix:
- exclude:
- - rvm: 1.8.7
- gemfile: test/gemfiles/Gemfile.rails-4.0.x
- - rvm: jruby-18mode
- gemfile: test/gemfiles/Gemfile.rails-4.0.x
- - rvm: rbx-18mode
- gemfile: test/gemfiles/Gemfile.rails-4.0.x
View
@@ -11,5 +11,7 @@ Gem::Specification.new do |s|
s.add_dependency 'jquery-rails'
s.add_development_dependency 'rake'
- s.add_development_dependency 'tzinfo'
+ s.add_development_dependency 'rails'
+ s.add_development_dependency 'capybara'
+ s.add_development_dependency 'poltergeist'
end
@@ -1,26 +1,26 @@
require 'test_helper'
-class PjaxControllerTest < ActionController::TestCase
+class DefaultLayoutControllerTest < ActionController::TestCase
test 'renders without layout' do
request.env['HTTP_X_PJAX'] = true
get :index
if Rails::VERSION::STRING >= '4.0.0'
- assert_equal 'pjax#index', response.body
+ assert_match 'default_layout#index', response.body
else
# The behavior for ~> 3.0 varies from 4.0. If there is a layout for parent
# controller and `layout` in parent controller is set to false it will be
# rendered anyway with a warning in a log file. It should be set explicit
# in child controller.
- assert_equal 'layouts/application pjax#index', response.body
+ assert_match 'layouts/application default_layout#index', response.body
end
end
test 'renders with default layout' do
get :index
- assert_equal 'layouts/application pjax#index', response.body
+ assert_match 'layouts/application default_layout#index', response.body
end
test 'prevents pjax' do
@@ -36,20 +36,20 @@ class PjaxControllerTest < ActionController::TestCase
get :index, '_pjax' => true
- assert_equal({ 'controller' => 'pjax', 'action' => 'index' }, @controller.params)
+ assert_equal({ 'controller' => 'default_layout', 'action' => 'index' }, @controller.params)
assert_equal '', request.env['QUERY_STRING']
assert_nil request.env['rack.request.query_string']
assert_nil request.env['rack.request.query_hash']
assert_nil request.env['action_dispatch.request.query_parameters']
- assert_equal '/pjax', request.original_fullpath
- assert_equal '/pjax', request.fullpath
+ assert_equal '/default_layout', request.original_fullpath
+ assert_equal '/default_layout', request.fullpath
end
test 'sets pjax url' do
request.env['HTTP_X_PJAX'] = true
get :index
- assert_equal 'http://test.host/pjax', response.headers['X-PJAX-URL']
+ assert_equal 'http://test.host/default_layout', response.headers['X-PJAX-URL']
end
end
@@ -6,12 +6,12 @@ class WithLayoutControllerTest < ActionController::TestCase
get :index
- assert_equal 'layouts/with_layout with_layout#index', response.body
+ assert_match 'layouts/with_layout with_layout#index', response.body
end
test 'renders with layout for regular request' do
get :index
- assert_equal 'layouts/with_layout with_layout#index', response.body
+ assert_match 'layouts/with_layout with_layout#index', response.body
end
end
@@ -0,0 +1,8 @@
+//= require jquery
+//= require jquery_ujs
+//= require jquery.pjax
+//= require_tree .
+
+$(function() {
+ $(document).pjax('a:not([data-skip-pjax])', '[data-pjax-container]');
+});
@@ -0,0 +1,2 @@
+class ApplicationController < ActionController::Base
+end
@@ -0,0 +1,5 @@
+class CapybaraController < ApplicationController
+ def prevents_pjax
+ prevent_pjax!
+ end
+end
@@ -0,0 +1,5 @@
+class DefaultLayoutController < ApplicationController
+ def prevent_pjax
+ prevent_pjax!
+ end
+end
@@ -0,0 +1,3 @@
+class WithLayoutController < ApplicationController
+ layout 'with_layout'
+end
@@ -0,0 +1,7 @@
+<table>
+ <tbody>
+ <tr>
+ <td>Html content</td>
+ </tr>
+ </tbody>
+</table>
@@ -0,0 +1,9 @@
+<div>Will not be touched</div>
+
+<div data-pjax-container>
+ <%= content_tag :h3, 'Pjax container' %>
+ <%= link_to 'plainText', '/capybara/plain_text' %>
+ <%= link_to 'htmlContent', '/capybara/html_content' %>
+ <%= link_to 'fullReload', '/capybara/plain_text', 'data-skip-pjax' => true %>
+ <%= link_to 'preventsPjax', '/capybara/prevents_pjax' %>
+</div>
@@ -0,0 +1 @@
+Plain text
@@ -0,0 +1 @@
+Prevents pjax
@@ -0,0 +1 @@
+default_layout#index
@@ -0,0 +1 @@
+default_layout#prevent_pjax
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Dummy</title>
+ <%= javascript_include_tag 'application' %>
+</head>
+<body>
+
+layouts/application <%= yield %>
+
+</body>
+</html>
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Dummy</title>
+ <%= javascript_include_tag 'application' %>
+</head>
+<body>
+
+layouts/with_layout <%= yield %>
+
+</body>
+</html>
@@ -0,0 +1 @@
+with_layout#index
View
@@ -0,0 +1,3 @@
+require ::File.expand_path('../config/environment', __FILE__)
+
+run Rails.application
@@ -0,0 +1,17 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails'
+require 'action_controller/railtie'
+require 'sprockets/railtie'
+
+require 'jquery-rails'
+require 'pjax_rails'
+
+Bundler.require(:default, Rails.env)
+
+module Dummy
+ class Application < Rails::Application
+ config.secret_token = 'a966a729a228e5d3edf00997e7b7eab7'
+ config.assets.enabled = true
+ end
+end
@@ -0,0 +1,3 @@
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
+# Load the Rails application.
+require File.expand_path('../application', __FILE__)
+
+# Initialize the Rails application.
+Dummy::Application.initialize!
@@ -0,0 +1,12 @@
+Dummy::Application.configure do
+ config.cache_classes = false
+
+ config.eager_load = false
+
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ config.active_support.deprecation = :log
+
+ config.assets.debug = true
+end
@@ -0,0 +1,17 @@
+Dummy::Application.configure do
+ config.cache_classes = true
+
+ config.eager_load = false
+
+ config.serve_static_assets = true
+ config.static_cache_control = "public, max-age=3600"
+
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ config.action_dispatch.show_exceptions = false
+
+ config.action_controller.allow_forgery_protection = false
+
+ config.active_support.deprecation = :notify
+end
@@ -0,0 +1,3 @@
+Dummy::Application.routes.draw do
+ get '/:controller(/:action(/:id))'
+end
View
@@ -0,0 +1,33 @@
+require 'test_helper'
+
+class PjaxTest < ActiveSupport::IntegrationCase
+ test 'loads plain text' do
+ visit '/capybara'
+ click_on 'plainText'
+ assert page.has_content?('Will not be touched')
+ assert page.has_no_content?('Pjax container')
+ assert page.has_content?('Plain text')
+ end
+
+ test 'loads html' do
+ visit '/capybara'
+ click_on 'htmlContent'
+ assert page.has_content?('Will not be touched')
+ assert page.has_no_content?('Pjax container')
+ assert_equal page.find(:xpath, '//table/tbody/tr/td').text, 'Html content'
+ end
+
+ test 'fully reloads page' do
+ visit '/capybara'
+ click_on 'fullReload'
+ assert page.has_no_content?('Will not be touched')
+ assert page.has_content?('layouts/application Plain text')
+ end
+
+ test 'prevents pjax' do
+ visit '/capybara'
+ click_on 'preventsPjax'
+ assert page.has_no_content?('Will not be touched')
+ assert page.has_content?('layouts/application Prevents pjax')
+ end
+end
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
gemspec :path => './../..'
-gem 'railties', '~> 3.1.0'
+gem 'rails', '~> 3.1.0'
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
gemspec :path => './../..'
-gem 'railties', '~> 3.2.0'
+gem 'rails', '~> 3.2.0'
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
gemspec :path => './../..'
-gem 'railties', '~> 4.0.0'
+gem 'rails', '~> 4.0.0'
View
@@ -1,46 +1,17 @@
+ENV['RAILS_ENV'] ||= 'test'
+
require 'test/unit'
-require 'rails'
-require 'action_controller'
-require 'pjax_rails'
+require 'dummy/config/environment'
require 'rails/test_help'
+require 'capybara/poltergeist'
-# Ruby 1.8 doesn't call self.inherited inside Class.new
-# Config and routes are unreacheable inside the block.
-app = Class.new(Rails::Application)
-
-app.configure do
- config.active_support.deprecation = :notify
- config.secret_token = 'a966a729a228e5d3edf00997e7b7eab7'
- config.eager_load = false
-
- routes {
- get '/:controller(/:action(/:id))'
- }
-
- routes.finalize!
-end
-
-app.initialize!
-
-require 'action_view/testing/resolvers'
+Capybara.app = Rails.application
+Capybara.default_driver = :poltergeist
+class ActiveSupport::IntegrationCase < ActiveSupport::TestCase
+ include Capybara::DSL
-class ApplicationController < ActionController::Base
- include Rails.application.routes.url_helpers
-end
-
-class PjaxController < ApplicationController
- append_view_path ActionView::FixtureResolver.new('layouts/application.html.erb' => 'layouts/application <%= yield %>')
- append_view_path ActionView::FixtureResolver.new('pjax/index.html.erb' => 'pjax#index')
- append_view_path ActionView::FixtureResolver.new('pjax/prevent_pjax.html.erb' => 'pjax#prevent_pjax')
-
- def prevent_pjax
- prevent_pjax!
+ def teardown
+ Capybara.reset_sessions!
+ Capybara.use_default_driver
end
end
-
-class WithLayoutController < ApplicationController
- layout 'with_layout'
-
- append_view_path ActionView::FixtureResolver.new('layouts/with_layout.html.erb' => 'layouts/with_layout <%= yield %>')
- append_view_path ActionView::FixtureResolver.new('with_layout/index.html.erb' => 'with_layout#index')
-end

0 comments on commit e3e7044

Please sign in to comment.