Attempt without adding engine to application

This commit is contained in:
David Henry
2014-05-08 00:46:19 +01:00
parent c7099ac5b0
commit 426560a4db
24 changed files with 62 additions and 247 deletions

View File

@@ -51,55 +51,35 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
end
end
test 'user with valid confirmation token where the token has expired and the mapping is in the non-default engine it should raise an error' do
swap Devise, confirm_within: 3.days do
user = create_user(confirm: false, confirmation_sent_at: 4.days.ago)
assert_raise ActionView::Template::Error do
visit rails_engine.without_router_confirmation_path(confirmation_token: user.raw_confirmation_token)
end
end
end
test 'user with valid confirmation token where the token has expired and the mapping is in the non-default engine and a router_name has been specified it returns the confirmation path' do
swap Devise, confirm_within: 3.days do
user = create_user(confirm: false, confirmation_sent_at: 4.days.ago)
visit rails_engine.with_router_confirmation_path(confirmation_token: user.raw_confirmation_token)
assert_current_url "/rails_engine/with_router/confirmation?confirmation_token=#{user.raw_confirmation_token}"
end
end
test 'user with valid confirmation token where the token has expired and the mapping is in the non-default engine and the application router points to that engine it returns the path' do
swap Devise, confirm_within: 3.days, router_name: :rails_engine do
user = create_engine_user(confirm: false, confirmation_sent_at: 4.days.ago)
visit rails_engine.without_router_confirmation_path(confirmation_token: user.raw_confirmation_token)
assert_current_url "/rails_engine/without_router/confirmation?confirmation_token=#{user.raw_confirmation_token}"
end
end
test 'user with valid confirmation token where the token has expired and the mapping is in the main app and the application router points at the engine it raises an error' do
swap Devise, confirm_within: 3.days, router_name: :rails_engine do
user = create_engine_user(confirm: false, confirmation_sent_at: 4.days.ago)
test 'user with valid confirmation token where the token has expired and with application router_name set to a different engine it should raise an error' do
user = create_user(confirm: false, confirmation_sent_at: 4.days.ago)
swap Devise, confirm_within: 3.days, router_name: :fake_engine do
assert_raise ActionView::Template::Error do
visit_user_confirmation_with_token(user.raw_confirmation_token)
end
end
end
test 'user with valid confirmation token where the token has expired and the mapping points to the main app and the application router points at the engine it returns the path' do
test 'user with valid confirmation token where the token has expired and with application router_name set to a different engine and route overrides back to main it shows the path' do
user = create_user(confirm: false, confirmation_sent_at: 4.days.ago)
swap Devise, confirm_within: 3.days, router_name: :rails_engine do
visit user_with_router_confirmation_path(confirmation_token: user.raw_confirmation_token)
swap Devise, confirm_within: 3.days, router_name: :fake_engine do
visit user_on_main_app_confirmation_path(confirmation_token: user.raw_confirmation_token)
assert_current_url "/user_with_routers/confirmation?confirmation_token=#{user.raw_confirmation_token}"
assert_current_url "/user_on_main_apps/confirmation?confirmation_token=#{user.raw_confirmation_token}"
end
end
test 'user with valid confirmation token where the token has expired with router overrides different engine it shows the path' do
user = create_user(confirm: false, confirmation_sent_at: 4.days.ago)
swap Devise, confirm_within: 3.days do
visit user_on_engine_confirmation_path(confirmation_token: user.raw_confirmation_token)
assert_current_url "/user_on_engines/confirmation?confirmation_token=#{user.raw_confirmation_token}"
end
end
test 'user with valid confirmation token should be able to confirm an account before the token has expired' do
swap Devise, confirm_within: 3.days do

View File

@@ -1,6 +1,6 @@
require 'shared_user_without_omniauth'
class UserWithoutConfirmation < ActiveRecord::Base
class UserOnEngine < ActiveRecord::Base
self.table_name = 'users'
include Shim
include SharedUserWithoutOmniauth

View File

@@ -0,0 +1,7 @@
require 'shared_user_without_omniauth'
class UserOnMainApp < ActiveRecord::Base
self.table_name = 'users'
include Shim
include SharedUserWithoutOmniauth
end

View File

@@ -7,3 +7,4 @@ class ApplicationController < ActionController::Base
before_filter :authenticate_user!, if: :devise_controller?
respond_to *Mime::SET.map(&:to_sym)
end

View File

@@ -0,0 +1,28 @@
class ApplicationWithFakeEngine < ApplicationController
helper_method :fake_engine
def fake_engine
@fake_engine ||= FakeEngine.new
end
end
class FakeEngine
def user_on_engine_confirmation_path
'/user_on_engine/confirmation'
end
def new_user_on_engine_session_path
'/user_on_engine/confirmation/new'
end
def new_user_on_engine_registration_path
'/user_on_engine/registration/new'
end
def new_user_on_engine_password_path
'/user_on_engine/password/new'
end
def new_user_on_engine_unlock_path
'/user_on_engine/unlock/new'
end
end

View File

@@ -12,7 +12,6 @@ rescue LoadError
end
require "devise"
require "rails_engine"
module RailsApp
class Application < Rails::Application

View File

@@ -12,6 +12,8 @@ Devise.setup do |config|
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
config.mailer_sender = "please-change-me@config-initializers-devise.com"
config.parent_controller = "ApplicationWithFakeEngine"
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"

View File

@@ -1,6 +1,4 @@
Rails.application.routes.draw do
mount RailsEngine::Engine => '/rails_engine', as: 'rails_engine'
# Resources for testing
resources :users, only: [:index] do
member do
@@ -22,11 +20,16 @@ Rails.application.routes.draw do
# Users scope
devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }
devise_for :user_with_routers,
class_name: 'UserWithoutConfirmation',
devise_for :user_on_main_apps,
class_name: 'UserOnMainApp',
router_name: :main_app,
module: :devise
devise_for :user_on_engines,
class_name: 'UserOnEngine',
router_name: :fake_engine,
module: :devise
as :user do
get "/as/sign_in", to: "devise/sessions#new"
end

View File

@@ -1,5 +0,0 @@
source "https://rubygems.org"
gemspec

View File

@@ -1,86 +0,0 @@
PATH
remote: .
specs:
rails_engine (0.0.1)
rails (~> 4.0.0)
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.0.4)
actionpack (= 4.0.4)
mail (~> 2.5.4)
actionpack (4.0.4)
activesupport (= 4.0.4)
builder (~> 3.1.0)
erubis (~> 2.7.0)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
activemodel (4.0.4)
activesupport (= 4.0.4)
builder (~> 3.1.0)
activerecord (4.0.4)
activemodel (= 4.0.4)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.4)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.4)
i18n (~> 0.6, >= 0.6.9)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
arel (4.0.2)
builder (3.1.4)
erubis (2.7.0)
hike (1.2.3)
i18n (0.6.9)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.25.1)
minitest (4.7.5)
multi_json (1.9.3)
polyglot (0.3.4)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
rails (4.0.4)
actionmailer (= 4.0.4)
actionpack (= 4.0.4)
activerecord (= 4.0.4)
activesupport (= 4.0.4)
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.4)
sprockets-rails (~> 2.0.0)
railties (4.0.4)
actionpack (= 4.0.4)
activesupport (= 4.0.4)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.3.1)
sprockets (2.12.1)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.0.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
sqlite3 (1.3.9)
thor (0.19.1)
thread_safe (0.3.3)
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.39)
PLATFORMS
ruby
DEPENDENCIES
rails_engine!
sqlite3

View File

@@ -1,9 +0,0 @@
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
load 'rails/tasks/engine.rake'
Bundler::GemHelper.install_tasks

View File

@@ -1,4 +0,0 @@
module RailsEngine
class ApplicationController < ActionController::Base
end
end

View File

@@ -1,8 +0,0 @@
require 'shared_user_without_omniauth'
module RailsEngine
class User < ActiveRecord::Base
self.table_name = :users
include SharedUserWithoutOmniauth
end
end

View File

@@ -1,14 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>RailsEngine</title>
<%= stylesheet_link_tag "rails_engine/application", media: "all" %>
<%= javascript_include_tag "rails_engine/application" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>

View File

@@ -1,8 +0,0 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/rails_engine/engine', __FILE__)
require 'rails/all'
require 'rails/engine/commands'

View File

@@ -1,12 +0,0 @@
RailsEngine::Engine.routes.draw do
devise_for :without_router,
class_name: 'RailsEngine::User',
module: :devise
devise_for :with_router,
class_name: 'RailsEngine::User',
router_name: :rails_engine,
module: :devise
root to: 'with_router#index'
end

View File

@@ -1,4 +0,0 @@
require "rails_engine/engine"
module RailsEngine
end

View File

@@ -1,6 +0,0 @@
require 'devise'
module RailsEngine
class Engine < ::Rails::Engine
isolate_namespace RailsEngine
end
end

View File

@@ -1,3 +0,0 @@
module RailsEngine
VERSION = "0.0.1"
end

View File

@@ -1,4 +0,0 @@
# desc "Explaining what the task does"
# task :rails_engine do
# # Task goes here
# end

View File

@@ -1,17 +0,0 @@
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "rails_engine/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "rails_engine"
s.version = RailsEngine::VERSION
s.summary = "Engine route testing."
s.authors = "David Henry"
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile"]
s.add_dependency "rails"
s.add_dependency "devise"
end

View File

@@ -21,22 +21,6 @@ class ActionDispatch::IntegrationTest
end
end
def create_engine_user(options={})
@user ||= begin
user = RailsEngine::User.create!(
username: 'usertest',
email: options[:email] || 'user@test.com',
password: options[:password] || '12345678',
password_confirmation: options[:password] || '12345678',
created_at: Time.now.utc
)
user.update_attribute(:confirmation_sent_at, options[:confirmation_sent_at]) if options[:confirmation_sent_at]
user.confirm! unless options[:confirm] == false
user.lock_access! if options[:locked] == true
user
end
end
def create_admin(options={})
@admin ||= begin
admin = Admin.create!(