diff --git a/spec/fake_app/engine/lib/engine.rb b/spec/fake_app/engine/lib/engine.rb new file mode 100644 index 0000000..fbca045 --- /dev/null +++ b/spec/fake_app/engine/lib/engine.rb @@ -0,0 +1,20 @@ +module Engine + class Engine < ::Rails::Engine + isolate_namespace ::Engine + end +end + +Engine::Engine.routes.draw do + resources :users +end + +# controllers +class Engine::UsersController < ::ApplicationController + def index + @users = User.page(params[:page]).per(3) + render :inline => <<-ERB +<%= @users.map(&:name).join("\n") %> +<%= paginate @users %> +ERB + end +end diff --git a/spec/fake_app/rails_app.rb b/spec/fake_app/rails_app.rb index 6180331..36b1b6a 100644 --- a/spec/fake_app/rails_app.rb +++ b/spec/fake_app/rails_app.rb @@ -17,11 +17,6 @@ app.config.root = File.dirname(__FILE__) Rails.backtrace_cleaner.remove_silencers! app.initialize! -# routes -app.routes.draw do - resources :users -end - #models require 'fake_app/active_record/models' if defined? ActiveRecord require 'fake_app/data_mapper/models' if defined? DataMapper @@ -54,3 +49,14 @@ end # helpers Object.const_set(:ApplicationHelper, Module.new) + +# routes +app.routes.draw do + resources :users + + if Rails.version > '3.1.0' + $LOAD_PATH << File.join(File.dirname(__FILE__), 'engine/lib') + require 'engine' + mount Engine::Engine => '/engine' + end +end diff --git a/spec/requests/engine_spec.rb b/spec/requests/engine_spec.rb new file mode 100644 index 0000000..ec45f09 --- /dev/null +++ b/spec/requests/engine_spec.rb @@ -0,0 +1,26 @@ +# encoding: UTF-8 +require 'spec_helper' + +feature 'Pagination properly works in mouted Engines' do + background do + 1.upto(10) {|i| User.create! :name => "user#{'%02d' % i}" } + end + scenario 'Showing normal pagination links' do + visit '/engine/users' + + within 'nav.pagination' do + within 'span.page.current' do + page.should have_content '1' + end + within 'span.next' do + click_link 'Next ›' + end + end + + within 'nav.pagination' do + within 'span.page.current' do + page.should have_content '2' + end + end + end +end if Rails.version > '3.1.0'