From da49ed23f984540fe4547ad868f42f30a1fcc368 Mon Sep 17 00:00:00 2001 From: David Henry Date: Thu, 1 May 2014 23:39:05 +0100 Subject: [PATCH 01/20] Start adding code to allow devise_for to specify the engine context (router_name) to be used. --- lib/devise/controllers/helpers.rb | 11 ++++++++--- lib/devise/controllers/url_helpers.rb | 5 +++-- lib/devise/mapping.rb | 20 +++++++++++++------- lib/devise/rails/routes.rb | 2 ++ 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/devise/controllers/helpers.rb b/lib/devise/controllers/helpers.rb index 14a3dd5d..89ddc99e 100644 --- a/lib/devise/controllers/helpers.rb +++ b/lib/devise/controllers/helpers.rb @@ -101,10 +101,15 @@ module Devise # The scope root url to be used when they're signed in. By default, it first # tries to find a resource_root_path, otherwise it uses the root_path. def signed_in_root_path(resource_or_scope) - scope = Devise::Mapping.find_scope!(resource_or_scope) + scope, router_name = Devise::Mapping.find_scope!(resource_or_scope, :include_router_name) home_path = "#{scope}_root_path" - if respond_to?(home_path, true) - send(home_path) + + context = router_name ? send(router_name) : self + + if context.respond_to?(home_path, true) + context.send(home_path) + elsif context.respond_to?(:root_path) + context.root_path elsif respond_to?(:root_path) root_path else diff --git a/lib/devise/controllers/url_helpers.rb b/lib/devise/controllers/url_helpers.rb index 480687f5..80fe04dc 100644 --- a/lib/devise/controllers/url_helpers.rb +++ b/lib/devise/controllers/url_helpers.rb @@ -46,8 +46,9 @@ module Devise class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1 def #{method}(resource_or_scope, *args) - scope = Devise::Mapping.find_scope!(resource_or_scope) - _devise_route_context.send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args) + scope, router_name = Devise::Mapping.find_scope!(resource_or_scope, :include_router_name) + context = router_name ? send(router_name) : _devise_route_context + context.send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args) end URL_HELPERS end diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index 7ab377b1..02a6433b 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -23,23 +23,27 @@ module Devise # class Mapping #:nodoc: attr_reader :singular, :scoped_path, :path, :controllers, :path_names, - :class_name, :sign_out_via, :format, :used_routes, :used_helpers, :failure_app + :class_name, :sign_out_via, :format, :used_routes, :used_helpers, + :failure_app, :router_name alias :name :singular # Receives an object and find a scope for it. If a scope cannot be found, # raises an error. If a symbol is given, it's considered to be the scope. - def self.find_scope!(obj) - case obj + def self.find_scope!(obj, *flags) + include_router_name = flags.include?(:include_router_name) + mapping = case obj when String, Symbol - return obj + return obj unless include_router_name + Devise.mappings.detect { |m| obj == m.name } when Class - Devise.mappings.each_value { |m| return m.name if obj <= m.to } + Devise.mappings.detect { |m| obj <= m.to } else - Devise.mappings.each_value { |m| return m.name if obj.is_a?(m.to) } + Devise.mappings.detect { |m| obj.is_a?(m.to) } end + raise "Could not find a valid mapping for #{obj.inspect}" unless mapping - raise "Could not find a valid mapping for #{obj.inspect}" + return (include_router_name ? mapping.name : [mapping.name, mapping.router_name]) end def self.find_by_path!(path, path_type=:fullpath) @@ -60,6 +64,8 @@ module Devise @sign_out_via = options[:sign_out_via] || Devise.sign_out_via @format = options[:format] + @router_name = options[:router_name] + default_failure_app(options) default_controllers(options) default_path_names(options) diff --git a/lib/devise/rails/routes.rb b/lib/devise/rails/routes.rb index 2951b141..7f974e52 100644 --- a/lib/devise/rails/routes.rb +++ b/lib/devise/rails/routes.rb @@ -153,6 +153,8 @@ module ActionDispatch::Routing # # * defaults: works the same as Rails' defaults # + # * router_name: allows application level router name to be overwritten for the current scope + # # ==== Scoping # # Following Rails 3 routes DSL, you can nest devise_for calls inside a scope: From 9e8371c29343d9be71fb7df8b19bca8652a5ccec Mon Sep 17 00:00:00 2001 From: David Henry Date: Thu, 1 May 2014 23:46:05 +0100 Subject: [PATCH 02/20] Make after_sign_out_path_for and after_inactive_sign_up_path_for aware of router name if declared in devise_for declaration. --- app/controllers/devise/registrations_controller.rb | 4 +++- lib/devise/controllers/helpers.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/devise/registrations_controller.rb b/app/controllers/devise/registrations_controller.rb index eab982e6..7d4b736c 100644 --- a/app/controllers/devise/registrations_controller.rb +++ b/app/controllers/devise/registrations_controller.rb @@ -112,7 +112,9 @@ class Devise::RegistrationsController < DeviseController # The path used after sign up for inactive accounts. You need to overwrite # this method in your own RegistrationsController. def after_inactive_sign_up_path_for(resource) - respond_to?(:root_path) ? root_path : "/" + scope, router_name = Devise::Mapping.find_scope!(resource_or_scope, :include_router_name) + context = router_name ? send(router_name) : self + context.respond_to?(:root_path) ? context.root_path : "/" end # The default url to be used after updating a resource. You need to overwrite diff --git a/lib/devise/controllers/helpers.rb b/lib/devise/controllers/helpers.rb index 89ddc99e..b0964611 100644 --- a/lib/devise/controllers/helpers.rb +++ b/lib/devise/controllers/helpers.rb @@ -155,7 +155,9 @@ module Devise # # By default it is the root_path. def after_sign_out_path_for(resource_or_scope) - respond_to?(:root_path) ? root_path : "/" + scope, router_name = Devise::Mapping.find_scope!(resource_or_scope, :include_router_name) + context = router_name ? send(router_name) : self + context.respond_to?(:root_path) ? context.root_path : "/" end # Sign in a user and tries to redirect first to the stored location and From 38b347ac00870f61cd36678a4d688501446a57a0 Mon Sep 17 00:00:00 2001 From: David Henry Date: Fri, 2 May 2014 00:17:17 +0100 Subject: [PATCH 03/20] Fix bug in the tests --- lib/devise/mapping.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index 02a6433b..22690416 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -35,11 +35,11 @@ module Devise mapping = case obj when String, Symbol return obj unless include_router_name - Devise.mappings.detect { |m| obj == m.name } + Devise.mappings.values.detect { |m| obj == m.name } when Class - Devise.mappings.detect { |m| obj <= m.to } + Devise.mappings.values.detect { |m| obj <= m.to } else - Devise.mappings.detect { |m| obj.is_a?(m.to) } + Devise.mappings.values.detect { |m| obj.is_a?(m.to) } end raise "Could not find a valid mapping for #{obj.inspect}" unless mapping From e085526b6ea3e1144b6df32c5b814944ad7b6c9b Mon Sep 17 00:00:00 2001 From: David Henry Date: Fri, 2 May 2014 00:22:20 +0100 Subject: [PATCH 04/20] Get the logic in the right order and fix variable naming (and run the tests) --- app/controllers/devise/registrations_controller.rb | 2 +- lib/devise/mapping.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/devise/registrations_controller.rb b/app/controllers/devise/registrations_controller.rb index 7d4b736c..6adefc6a 100644 --- a/app/controllers/devise/registrations_controller.rb +++ b/app/controllers/devise/registrations_controller.rb @@ -112,7 +112,7 @@ class Devise::RegistrationsController < DeviseController # The path used after sign up for inactive accounts. You need to overwrite # this method in your own RegistrationsController. def after_inactive_sign_up_path_for(resource) - scope, router_name = Devise::Mapping.find_scope!(resource_or_scope, :include_router_name) + scope, router_name = Devise::Mapping.find_scope!(resource, :include_router_name) context = router_name ? send(router_name) : self context.respond_to?(:root_path) ? context.root_path : "/" end diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index 22690416..47d2c06f 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -43,7 +43,7 @@ module Devise end raise "Could not find a valid mapping for #{obj.inspect}" unless mapping - return (include_router_name ? mapping.name : [mapping.name, mapping.router_name]) + return (include_router_name ? [mapping.name, mapping.router_name] : mapping.name) end def self.find_by_path!(path, path_type=:fullpath) From 23761aded2a8dd03c013a0140e015369b1f08891 Mon Sep 17 00:00:00 2001 From: David Henry Date: Sat, 3 May 2014 22:37:21 +0100 Subject: [PATCH 05/20] Add find_mapping! method to return the router_name instead of overloading find_scope! --- .../devise/registrations_controller.rb | 2 +- lib/devise/controllers/helpers.rb | 5 ++-- lib/devise/controllers/url_helpers.rb | 3 +- lib/devise/mapping.rb | 29 +++++++++++++------ 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/app/controllers/devise/registrations_controller.rb b/app/controllers/devise/registrations_controller.rb index 6adefc6a..4d4c960b 100644 --- a/app/controllers/devise/registrations_controller.rb +++ b/app/controllers/devise/registrations_controller.rb @@ -112,7 +112,7 @@ class Devise::RegistrationsController < DeviseController # The path used after sign up for inactive accounts. You need to overwrite # this method in your own RegistrationsController. def after_inactive_sign_up_path_for(resource) - scope, router_name = Devise::Mapping.find_scope!(resource, :include_router_name) + router_name = Devise::Mapping.find_mapping!(resource) context = router_name ? send(router_name) : self context.respond_to?(:root_path) ? context.root_path : "/" end diff --git a/lib/devise/controllers/helpers.rb b/lib/devise/controllers/helpers.rb index b0964611..8af8a3d3 100644 --- a/lib/devise/controllers/helpers.rb +++ b/lib/devise/controllers/helpers.rb @@ -101,7 +101,8 @@ module Devise # The scope root url to be used when they're signed in. By default, it first # tries to find a resource_root_path, otherwise it uses the root_path. def signed_in_root_path(resource_or_scope) - scope, router_name = Devise::Mapping.find_scope!(resource_or_scope, :include_router_name) + scope = Devise::Mapping.find_scope!(resource_or_scope) + router_name = Devise::Mapping.find_mapping!(resource_or_scope) home_path = "#{scope}_root_path" context = router_name ? send(router_name) : self @@ -155,7 +156,7 @@ module Devise # # By default it is the root_path. def after_sign_out_path_for(resource_or_scope) - scope, router_name = Devise::Mapping.find_scope!(resource_or_scope, :include_router_name) + router_name = Devise::Mapping.find_mapping!(resource_or_scope) context = router_name ? send(router_name) : self context.respond_to?(:root_path) ? context.root_path : "/" end diff --git a/lib/devise/controllers/url_helpers.rb b/lib/devise/controllers/url_helpers.rb index 80fe04dc..28c5c45f 100644 --- a/lib/devise/controllers/url_helpers.rb +++ b/lib/devise/controllers/url_helpers.rb @@ -46,7 +46,8 @@ module Devise class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1 def #{method}(resource_or_scope, *args) - scope, router_name = Devise::Mapping.find_scope!(resource_or_scope, :include_router_name) + scope = Devise::Mapping.find_scope!(resource_or_scope) + router_name = Devise::Mapping.find_mapping!(resource_or_scope) context = router_name ? send(router_name) : _devise_route_context context.send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args) end diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index 47d2c06f..f39c431f 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -30,20 +30,31 @@ module Devise # Receives an object and find a scope for it. If a scope cannot be found, # raises an error. If a symbol is given, it's considered to be the scope. - def self.find_scope!(obj, *flags) - include_router_name = flags.include?(:include_router_name) - mapping = case obj + def self.find_scope!(obj) + case obj when String, Symbol - return obj unless include_router_name - Devise.mappings.values.detect { |m| obj == m.name } + return obj when Class - Devise.mappings.values.detect { |m| obj <= m.to } + Devise.mappings.each_value { |m| return m.name if obj <= m.to } else - Devise.mappings.values.detect { |m| obj.is_a?(m.to) } + Devise.mappings.each_value { |m| return m.name if obj.is_a?(m.to) } end - raise "Could not find a valid mapping for #{obj.inspect}" unless mapping - return (include_router_name ? [mapping.name, mapping.router_name] : mapping.name) + raise "Could not find a valid mapping for #{obj.inspect}" + end + + def self.find_mapping!(obj) + case obj + when String, Symbol + scope = obj.to_sym + Devise.mappings.each_value { |m| return m.router_name if m.name == scope } + when Class + Devise.mappings.each_value { |m| return m.router_name if obj <= m.to } + else + Devise.mappings.each_value { |m| return m.router_name if obj.is_a?(m.to) } + end + + raise "Could not find a valid mapping for #{obj.inspect}" unless mapping end def self.find_by_path!(path, path_type=:fullpath) From 2dee54bc865526ed3c12f7a848689928d2f878d1 Mon Sep 17 00:00:00 2001 From: David Henry Date: Sat, 3 May 2014 22:41:32 +0100 Subject: [PATCH 06/20] make the find_mapping! method return a mapping object --- app/controllers/devise/registrations_controller.rb | 2 +- lib/devise/controllers/helpers.rb | 7 ++++--- lib/devise/controllers/url_helpers.rb | 5 +++-- lib/devise/mapping.rb | 6 +++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/controllers/devise/registrations_controller.rb b/app/controllers/devise/registrations_controller.rb index 4d4c960b..4a350f80 100644 --- a/app/controllers/devise/registrations_controller.rb +++ b/app/controllers/devise/registrations_controller.rb @@ -112,7 +112,7 @@ class Devise::RegistrationsController < DeviseController # The path used after sign up for inactive accounts. You need to overwrite # this method in your own RegistrationsController. def after_inactive_sign_up_path_for(resource) - router_name = Devise::Mapping.find_mapping!(resource) + router_name = Devise::Mapping.find_mapping!(resource).router_name context = router_name ? send(router_name) : self context.respond_to?(:root_path) ? context.root_path : "/" end diff --git a/lib/devise/controllers/helpers.rb b/lib/devise/controllers/helpers.rb index 8af8a3d3..e82d1d0a 100644 --- a/lib/devise/controllers/helpers.rb +++ b/lib/devise/controllers/helpers.rb @@ -101,8 +101,9 @@ module Devise # The scope root url to be used when they're signed in. By default, it first # tries to find a resource_root_path, otherwise it uses the root_path. def signed_in_root_path(resource_or_scope) - scope = Devise::Mapping.find_scope!(resource_or_scope) - router_name = Devise::Mapping.find_mapping!(resource_or_scope) + mapping = Devise::Mapping.find_mapping!(resource_or_scope) + scope = mapping.name + router_name = mapping.router_name home_path = "#{scope}_root_path" context = router_name ? send(router_name) : self @@ -156,7 +157,7 @@ module Devise # # By default it is the root_path. def after_sign_out_path_for(resource_or_scope) - router_name = Devise::Mapping.find_mapping!(resource_or_scope) + router_name = Devise::Mapping.find_mapping!(resource_or_scope).router_name context = router_name ? send(router_name) : self context.respond_to?(:root_path) ? context.root_path : "/" end diff --git a/lib/devise/controllers/url_helpers.rb b/lib/devise/controllers/url_helpers.rb index 28c5c45f..4067745e 100644 --- a/lib/devise/controllers/url_helpers.rb +++ b/lib/devise/controllers/url_helpers.rb @@ -46,8 +46,9 @@ module Devise class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1 def #{method}(resource_or_scope, *args) - scope = Devise::Mapping.find_scope!(resource_or_scope) - router_name = Devise::Mapping.find_mapping!(resource_or_scope) + mapping = Devise::Mapping.find_mapping!(resource_or_scope) + scope = mapping.name + router_name = mapping.router_name context = router_name ? send(router_name) : _devise_route_context context.send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args) end diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index f39c431f..fa39dd33 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -47,11 +47,11 @@ module Devise case obj when String, Symbol scope = obj.to_sym - Devise.mappings.each_value { |m| return m.router_name if m.name == scope } + Devise.mappings.each_value { |m| return m if m.name == scope } when Class - Devise.mappings.each_value { |m| return m.router_name if obj <= m.to } + Devise.mappings.each_value { |m| return m if obj <= m.to } else - Devise.mappings.each_value { |m| return m.router_name if obj.is_a?(m.to) } + Devise.mappings.each_value { |m| return m if obj.is_a?(m.to) } end raise "Could not find a valid mapping for #{obj.inspect}" unless mapping From 1dd84a8244f3a1ce6c17aa4b5f606a3fef0fff0c Mon Sep 17 00:00:00 2001 From: David Henry Date: Sat, 3 May 2014 22:46:04 +0100 Subject: [PATCH 07/20] Don't couple the routing object to the whole system.. pass around the RoutingDetails object instead. NOTE: RoutingDetails is supposed to be a simple data transfer object. --- lib/devise/controllers/helpers.rb | 2 +- lib/devise/controllers/url_helpers.rb | 2 +- lib/devise/mapping.rb | 14 +++++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/devise/controllers/helpers.rb b/lib/devise/controllers/helpers.rb index e82d1d0a..96646d41 100644 --- a/lib/devise/controllers/helpers.rb +++ b/lib/devise/controllers/helpers.rb @@ -102,7 +102,7 @@ module Devise # tries to find a resource_root_path, otherwise it uses the root_path. def signed_in_root_path(resource_or_scope) mapping = Devise::Mapping.find_mapping!(resource_or_scope) - scope = mapping.name + scope = mapping.scope router_name = mapping.router_name home_path = "#{scope}_root_path" diff --git a/lib/devise/controllers/url_helpers.rb b/lib/devise/controllers/url_helpers.rb index 4067745e..ebc574d8 100644 --- a/lib/devise/controllers/url_helpers.rb +++ b/lib/devise/controllers/url_helpers.rb @@ -47,7 +47,7 @@ module Devise class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1 def #{method}(resource_or_scope, *args) mapping = Devise::Mapping.find_mapping!(resource_or_scope) - scope = mapping.name + scope = mapping.scope router_name = mapping.router_name context = router_name ? send(router_name) : _devise_route_context context.send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args) diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index fa39dd33..da8630be 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -1,4 +1,12 @@ module Devise + class RoutingDetails + attr_reader :scope, :router_name + + def initialize(mapping) + @scope = mapping.name + @router_name = mapping.router_name + end + end # Responsible for handling devise mappings and routes configuration. Each # resource configured by devise_for in routes is actually creating a mapping # object. You can refer to devise_for in routes for usage options. @@ -47,11 +55,11 @@ module Devise case obj when String, Symbol scope = obj.to_sym - Devise.mappings.each_value { |m| return m if m.name == scope } + Devise.mappings.each_value { |m| return RoutingDetails.new(m) if m.name == scope } when Class - Devise.mappings.each_value { |m| return m if obj <= m.to } + Devise.mappings.each_value { |m| return RoutingDetails.new(m) if obj <= m.to } else - Devise.mappings.each_value { |m| return m if obj.is_a?(m.to) } + Devise.mappings.each_value { |m| return RoutingDetails.new(m) if obj.is_a?(m.to) } end raise "Could not find a valid mapping for #{obj.inspect}" unless mapping From feff27aaeeb2988358b4a489e2659b74bfdf7fe8 Mon Sep 17 00:00:00 2001 From: David Henry Date: Sat, 3 May 2014 22:47:27 +0100 Subject: [PATCH 08/20] Add description around the new method. --- lib/devise/mapping.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index da8630be..07b8f24a 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -51,6 +51,9 @@ module Devise raise "Could not find a valid mapping for #{obj.inspect}" end + # Receives an object and find a mapping for it, then return the routing + # details associated with the mapping. If a scope cannot be found, + # raises an error. def self.find_mapping!(obj) case obj when String, Symbol From d875c01bc2bb2d5582091b4f4af2dd18e7ca9e21 Mon Sep 17 00:00:00 2001 From: David Henry Date: Sat, 3 May 2014 23:22:00 +0100 Subject: [PATCH 09/20] Extract routing context to its own file. --- lib/devise/mapping.rb | 8 -------- lib/devise/routing_details.rb | 12 ++++++++++++ 2 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 lib/devise/routing_details.rb diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index 07b8f24a..342b6a8a 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -1,12 +1,4 @@ module Devise - class RoutingDetails - attr_reader :scope, :router_name - - def initialize(mapping) - @scope = mapping.name - @router_name = mapping.router_name - end - end # Responsible for handling devise mappings and routes configuration. Each # resource configured by devise_for in routes is actually creating a mapping # object. You can refer to devise_for in routes for usage options. diff --git a/lib/devise/routing_details.rb b/lib/devise/routing_details.rb new file mode 100644 index 00000000..b53b7d81 --- /dev/null +++ b/lib/devise/routing_details.rb @@ -0,0 +1,12 @@ +module Devise + # This is a data transfer object to avoid coupling between + # Devive::Mapping and the rest of the application. + class RoutingDetails + attr_reader :scope, :router_name + + def initialize(mapping) + @scope = mapping.name + @router_name = mapping.router_name + end + end +end From 3e8fce5081b1317e03cd774f55b8e308e219edd0 Mon Sep 17 00:00:00 2001 From: David Henry Date: Sun, 4 May 2014 12:53:25 +0100 Subject: [PATCH 10/20] Make sure I include the new class into the gem --- lib/devise.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/devise.rb b/lib/devise.rb index 2b99d923..da3bab07 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -489,6 +489,7 @@ module Devise end require 'warden' +require 'devise/routing_details' require 'devise/mapping' require 'devise/models' require 'devise/modules' From 33873426ad1a3d45efb2931b024edf6342b10907 Mon Sep 17 00:00:00 2001 From: David Henry Date: Sun, 4 May 2014 22:59:29 +0100 Subject: [PATCH 11/20] Use 2.1 instead of 2.1.0 travis-ci/travis-ci#2220 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fc75ec2e..eb20a230 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ install: script/cached-bundle install --deployment --path vendor/bundle rvm: - 1.9.3 - 2.0.0 - - 2.1.0 + - 2.1 env: matrix: - DEVISE_ORM=mongoid From 1e8e8516f00637f0d451504e0820fa8caccc8cf7 Mon Sep 17 00:00:00 2001 From: David Henry Date: Mon, 5 May 2014 23:19:03 +0100 Subject: [PATCH 12/20] Simplify access to router_name using the existing scope lookup. --- .../devise/registrations_controller.rb | 3 ++- lib/devise/controllers/helpers.rb | 9 +++++---- lib/devise/controllers/url_helpers.rb | 5 ++--- lib/devise/mapping.rb | 17 ----------------- .../app/models/rails_engine/user.rb | 0 5 files changed, 9 insertions(+), 25 deletions(-) create mode 100644 test/rails_app/rails_engine/app/models/rails_engine/user.rb diff --git a/app/controllers/devise/registrations_controller.rb b/app/controllers/devise/registrations_controller.rb index 4a350f80..7c2f18a4 100644 --- a/app/controllers/devise/registrations_controller.rb +++ b/app/controllers/devise/registrations_controller.rb @@ -112,7 +112,8 @@ class Devise::RegistrationsController < DeviseController # The path used after sign up for inactive accounts. You need to overwrite # this method in your own RegistrationsController. def after_inactive_sign_up_path_for(resource) - router_name = Devise::Mapping.find_mapping!(resource).router_name + scope = Devise::Mapping.find_scope!(resource) + router_name = Devise.mappings[scope].router_name context = router_name ? send(router_name) : self context.respond_to?(:root_path) ? context.root_path : "/" end diff --git a/lib/devise/controllers/helpers.rb b/lib/devise/controllers/helpers.rb index 96646d41..48dd50e0 100644 --- a/lib/devise/controllers/helpers.rb +++ b/lib/devise/controllers/helpers.rb @@ -101,9 +101,9 @@ module Devise # The scope root url to be used when they're signed in. By default, it first # tries to find a resource_root_path, otherwise it uses the root_path. def signed_in_root_path(resource_or_scope) - mapping = Devise::Mapping.find_mapping!(resource_or_scope) - scope = mapping.scope - router_name = mapping.router_name + scope = Devise::Mapping.find_scope!(resource_or_scope) + router_name = Devise.mappings[scope].router_name + home_path = "#{scope}_root_path" context = router_name ? send(router_name) : self @@ -157,7 +157,8 @@ module Devise # # By default it is the root_path. def after_sign_out_path_for(resource_or_scope) - router_name = Devise::Mapping.find_mapping!(resource_or_scope).router_name + scope = Devise::Mapping.find_scope!(resource_or_scope) + router_name = Devise.mappings[scope].router_name context = router_name ? send(router_name) : self context.respond_to?(:root_path) ? context.root_path : "/" end diff --git a/lib/devise/controllers/url_helpers.rb b/lib/devise/controllers/url_helpers.rb index ebc574d8..465d698a 100644 --- a/lib/devise/controllers/url_helpers.rb +++ b/lib/devise/controllers/url_helpers.rb @@ -46,9 +46,8 @@ module Devise class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1 def #{method}(resource_or_scope, *args) - mapping = Devise::Mapping.find_mapping!(resource_or_scope) - scope = mapping.scope - router_name = mapping.router_name + scope = Devise::Mapping.find_scope!(resource_or_scope) + router_name = Devise.mappings[scope].router_name context = router_name ? send(router_name) : _devise_route_context context.send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args) end diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index 342b6a8a..de787dc5 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -43,23 +43,6 @@ module Devise raise "Could not find a valid mapping for #{obj.inspect}" end - # Receives an object and find a mapping for it, then return the routing - # details associated with the mapping. If a scope cannot be found, - # raises an error. - def self.find_mapping!(obj) - case obj - when String, Symbol - scope = obj.to_sym - Devise.mappings.each_value { |m| return RoutingDetails.new(m) if m.name == scope } - when Class - Devise.mappings.each_value { |m| return RoutingDetails.new(m) if obj <= m.to } - else - Devise.mappings.each_value { |m| return RoutingDetails.new(m) if obj.is_a?(m.to) } - end - - raise "Could not find a valid mapping for #{obj.inspect}" unless mapping - end - def self.find_by_path!(path, path_type=:fullpath) Devise.mappings.each_value { |m| return m if path.include?(m.send(path_type)) } raise "Could not find a valid mapping for path #{path.inspect}" diff --git a/test/rails_app/rails_engine/app/models/rails_engine/user.rb b/test/rails_app/rails_engine/app/models/rails_engine/user.rb new file mode 100644 index 00000000..e69de29b From 18da4b1effe1febb9f59f5fc3aa65a2ffa08677c Mon Sep 17 00:00:00 2001 From: David Henry Date: Mon, 5 May 2014 23:23:55 +0100 Subject: [PATCH 13/20] Stash as test have broken --- Gemfile | 1 + Gemfile.lock | 7 ++ test/rails_app/config/application.rb | 1 + test/rails_app/config/routes.rb | 2 + test/rails_app/rails_engine/Gemfile | 5 ++ test/rails_app/rails_engine/Gemfile.lock | 86 +++++++++++++++++++ test/rails_app/rails_engine/Rakefile | 13 +++ .../rails_engine/application_controller.rb | 4 + .../app/models/rails_engine/user.rb | 5 ++ .../layouts/rails_engine/application.html.erb | 14 +++ test/rails_app/rails_engine/bin/rails | 8 ++ test/rails_app/rails_engine/config/routes.rb | 5 ++ .../rails_engine/lib/rails_engine.rb | 4 + .../rails_engine/lib/rails_engine/engine.rb | 5 ++ .../rails_engine/lib/rails_engine/version.rb | 3 + .../lib/tasks/rails_engine_tasks.rake | 4 + .../rails_engine/rails_engine.gemspec | 16 ++++ 17 files changed, 183 insertions(+) create mode 100644 test/rails_app/rails_engine/Gemfile create mode 100644 test/rails_app/rails_engine/Gemfile.lock create mode 100644 test/rails_app/rails_engine/Rakefile create mode 100644 test/rails_app/rails_engine/app/controllers/rails_engine/application_controller.rb create mode 100644 test/rails_app/rails_engine/app/views/layouts/rails_engine/application.html.erb create mode 100755 test/rails_app/rails_engine/bin/rails create mode 100644 test/rails_app/rails_engine/config/routes.rb create mode 100644 test/rails_app/rails_engine/lib/rails_engine.rb create mode 100644 test/rails_app/rails_engine/lib/rails_engine/engine.rb create mode 100644 test/rails_app/rails_engine/lib/rails_engine/version.rb create mode 100644 test/rails_app/rails_engine/lib/tasks/rails_engine_tasks.rake create mode 100644 test/rails_app/rails_engine/rails_engine.gemspec diff --git a/Gemfile b/Gemfile index 7cb4e7ba..d6944bea 100644 --- a/Gemfile +++ b/Gemfile @@ -12,6 +12,7 @@ group :test do gem "omniauth-openid", "~> 1.0.1" gem "webrat", "0.7.3", require: false gem "mocha", "~> 1.0.0", require: false + gemspec path: "test/rails_app/rails_engine" end platforms :jruby do diff --git a/Gemfile.lock b/Gemfile.lock index e481eec3..3582c659 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -19,6 +19,12 @@ PATH thread_safe (~> 0.1) warden (~> 1.2.3) +PATH + remote: test/rails_app/rails_engine + specs: + rails_engine (0.0.1) + rails + GEM remote: https://rubygems.org/ specs: @@ -161,6 +167,7 @@ DEPENDENCIES omniauth-oauth2 (~> 1.0.0) omniauth-openid (~> 1.0.1) rails (~> 4.0.0) + rails_engine! rdoc sqlite3 webrat (= 0.7.3) diff --git a/test/rails_app/config/application.rb b/test/rails_app/config/application.rb index 91c75cb9..fb60bae7 100644 --- a/test/rails_app/config/application.rb +++ b/test/rails_app/config/application.rb @@ -12,6 +12,7 @@ rescue LoadError end require "devise" +require "rails_engine" module RailsApp class Application < Rails::Application diff --git a/test/rails_app/config/routes.rb b/test/rails_app/config/routes.rb index 0e710b49..136f0418 100644 --- a/test/rails_app/config/routes.rb +++ b/test/rails_app/config/routes.rb @@ -1,4 +1,6 @@ Rails.application.routes.draw do + mount RailsEngine::Engine => '/rails_engine', as: 'rails_engine' + # Resources for testing resources :users, only: [:index] do member do diff --git a/test/rails_app/rails_engine/Gemfile b/test/rails_app/rails_engine/Gemfile new file mode 100644 index 00000000..7e2c3dff --- /dev/null +++ b/test/rails_app/rails_engine/Gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gemspec + + diff --git a/test/rails_app/rails_engine/Gemfile.lock b/test/rails_app/rails_engine/Gemfile.lock new file mode 100644 index 00000000..aecb5fa0 --- /dev/null +++ b/test/rails_app/rails_engine/Gemfile.lock @@ -0,0 +1,86 @@ +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 diff --git a/test/rails_app/rails_engine/Rakefile b/test/rails_app/rails_engine/Rakefile new file mode 100644 index 00000000..834f9e76 --- /dev/null +++ b/test/rails_app/rails_engine/Rakefile @@ -0,0 +1,13 @@ +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 + + diff --git a/test/rails_app/rails_engine/app/controllers/rails_engine/application_controller.rb b/test/rails_app/rails_engine/app/controllers/rails_engine/application_controller.rb new file mode 100644 index 00000000..249809d8 --- /dev/null +++ b/test/rails_app/rails_engine/app/controllers/rails_engine/application_controller.rb @@ -0,0 +1,4 @@ +module RailsEngine + class ApplicationController < ActionController::Base + end +end diff --git a/test/rails_app/rails_engine/app/models/rails_engine/user.rb b/test/rails_app/rails_engine/app/models/rails_engine/user.rb index e69de29b..846acf9b 100644 --- a/test/rails_app/rails_engine/app/models/rails_engine/user.rb +++ b/test/rails_app/rails_engine/app/models/rails_engine/user.rb @@ -0,0 +1,5 @@ +module RailsEngine + class User + table_name :user + end +end diff --git a/test/rails_app/rails_engine/app/views/layouts/rails_engine/application.html.erb b/test/rails_app/rails_engine/app/views/layouts/rails_engine/application.html.erb new file mode 100644 index 00000000..d78fccfb --- /dev/null +++ b/test/rails_app/rails_engine/app/views/layouts/rails_engine/application.html.erb @@ -0,0 +1,14 @@ + + + + RailsEngine + <%= stylesheet_link_tag "rails_engine/application", media: "all" %> + <%= javascript_include_tag "rails_engine/application" %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/test/rails_app/rails_engine/bin/rails b/test/rails_app/rails_engine/bin/rails new file mode 100755 index 00000000..258ac128 --- /dev/null +++ b/test/rails_app/rails_engine/bin/rails @@ -0,0 +1,8 @@ +#!/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' diff --git a/test/rails_app/rails_engine/config/routes.rb b/test/rails_app/rails_engine/config/routes.rb new file mode 100644 index 00000000..65ca8605 --- /dev/null +++ b/test/rails_app/rails_engine/config/routes.rb @@ -0,0 +1,5 @@ +RailsEngine::Engine.routes.draw do + # devise_for :engine_users, class_name: RailsEngine::User + + # devise_for :engine_users_with_router_name, router_name: :rails_engine +end diff --git a/test/rails_app/rails_engine/lib/rails_engine.rb b/test/rails_app/rails_engine/lib/rails_engine.rb new file mode 100644 index 00000000..45ab5d52 --- /dev/null +++ b/test/rails_app/rails_engine/lib/rails_engine.rb @@ -0,0 +1,4 @@ +require "rails_engine/engine" + +module RailsEngine +end diff --git a/test/rails_app/rails_engine/lib/rails_engine/engine.rb b/test/rails_app/rails_engine/lib/rails_engine/engine.rb new file mode 100644 index 00000000..f73fea45 --- /dev/null +++ b/test/rails_app/rails_engine/lib/rails_engine/engine.rb @@ -0,0 +1,5 @@ +module RailsEngine + class Engine < ::Rails::Engine + isolate_namespace RailsEngine + end +end diff --git a/test/rails_app/rails_engine/lib/rails_engine/version.rb b/test/rails_app/rails_engine/lib/rails_engine/version.rb new file mode 100644 index 00000000..ef5d8b72 --- /dev/null +++ b/test/rails_app/rails_engine/lib/rails_engine/version.rb @@ -0,0 +1,3 @@ +module RailsEngine + VERSION = "0.0.1" +end diff --git a/test/rails_app/rails_engine/lib/tasks/rails_engine_tasks.rake b/test/rails_app/rails_engine/lib/tasks/rails_engine_tasks.rake new file mode 100644 index 00000000..c179de9d --- /dev/null +++ b/test/rails_app/rails_engine/lib/tasks/rails_engine_tasks.rake @@ -0,0 +1,4 @@ +# desc "Explaining what the task does" +# task :rails_engine do +# # Task goes here +# end diff --git a/test/rails_app/rails_engine/rails_engine.gemspec b/test/rails_app/rails_engine/rails_engine.gemspec new file mode 100644 index 00000000..b5c65758 --- /dev/null +++ b/test/rails_app/rails_engine/rails_engine.gemspec @@ -0,0 +1,16 @@ +$:.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" +end From 2d3ca4dc31f7c6edf531d0e64c7c44ac176bab59 Mon Sep 17 00:00:00 2001 From: David Henry Date: Mon, 5 May 2014 23:50:26 +0100 Subject: [PATCH 14/20] get everything working with the engine included and devise routes declared within it. --- Gemfile.lock | 1 + test/rails_app/rails_engine/app/models/rails_engine/user.rb | 4 ++-- test/rails_app/rails_engine/config/routes.rb | 2 +- test/rails_app/rails_engine/lib/rails_engine/engine.rb | 1 + test/rails_app/rails_engine/rails_engine.gemspec | 1 + 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3582c659..6e8369fc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,6 +23,7 @@ PATH remote: test/rails_app/rails_engine specs: rails_engine (0.0.1) + devise rails GEM diff --git a/test/rails_app/rails_engine/app/models/rails_engine/user.rb b/test/rails_app/rails_engine/app/models/rails_engine/user.rb index 846acf9b..f97fcc8d 100644 --- a/test/rails_app/rails_engine/app/models/rails_engine/user.rb +++ b/test/rails_app/rails_engine/app/models/rails_engine/user.rb @@ -1,5 +1,5 @@ module RailsEngine - class User - table_name :user + class User < ActiveRecord::Base + self.table_name = :user end end diff --git a/test/rails_app/rails_engine/config/routes.rb b/test/rails_app/rails_engine/config/routes.rb index 65ca8605..f0145199 100644 --- a/test/rails_app/rails_engine/config/routes.rb +++ b/test/rails_app/rails_engine/config/routes.rb @@ -1,5 +1,5 @@ RailsEngine::Engine.routes.draw do - # devise_for :engine_users, class_name: RailsEngine::User + devise_for :engine_users, class_name: 'RailsEngine::User' # devise_for :engine_users_with_router_name, router_name: :rails_engine end diff --git a/test/rails_app/rails_engine/lib/rails_engine/engine.rb b/test/rails_app/rails_engine/lib/rails_engine/engine.rb index f73fea45..c2503961 100644 --- a/test/rails_app/rails_engine/lib/rails_engine/engine.rb +++ b/test/rails_app/rails_engine/lib/rails_engine/engine.rb @@ -1,3 +1,4 @@ +require 'devise' module RailsEngine class Engine < ::Rails::Engine isolate_namespace RailsEngine diff --git a/test/rails_app/rails_engine/rails_engine.gemspec b/test/rails_app/rails_engine/rails_engine.gemspec index b5c65758..8ce0a3e6 100644 --- a/test/rails_app/rails_engine/rails_engine.gemspec +++ b/test/rails_app/rails_engine/rails_engine.gemspec @@ -13,4 +13,5 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile"] s.add_dependency "rails" + s.add_dependency "devise" end From ceafc710ef2e412161d2377b52eab9135bc972b3 Mon Sep 17 00:00:00 2001 From: David Henry Date: Tue, 6 May 2014 00:56:58 +0100 Subject: [PATCH 15/20] Start adding tests to the engine routing tests. --- test/integration/confirmable_test.rb | 21 +++++++++++++++++++ .../app/models/rails_engine/user.rb | 6 +++++- test/rails_app/rails_engine/config/routes.rb | 11 ++++++++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/test/integration/confirmable_test.rb b/test/integration/confirmable_test.rb index ee3fe19e..a7049cf0 100644 --- a/test/integration/confirmable_test.rb +++ b/test/integration/confirmable_test.rb @@ -47,6 +47,27 @@ class ConfirmationTest < ActionDispatch::IntegrationTest assert_have_selector '#error_explanation' assert_contain /needs to be confirmed within 3 days/ assert_not user.reload.confirmed? + assert_current_url "/users/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 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 should not raise an error' 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 diff --git a/test/rails_app/rails_engine/app/models/rails_engine/user.rb b/test/rails_app/rails_engine/app/models/rails_engine/user.rb index f97fcc8d..e60087ff 100644 --- a/test/rails_app/rails_engine/app/models/rails_engine/user.rb +++ b/test/rails_app/rails_engine/app/models/rails_engine/user.rb @@ -1,5 +1,9 @@ module RailsEngine class User < ActiveRecord::Base - self.table_name = :user + self.table_name = :users + + devise :database_authenticatable, :confirmable, :lockable, :recoverable, + :registerable, :rememberable, :timeoutable, + :trackable, :validatable end end diff --git a/test/rails_app/rails_engine/config/routes.rb b/test/rails_app/rails_engine/config/routes.rb index f0145199..d36a4246 100644 --- a/test/rails_app/rails_engine/config/routes.rb +++ b/test/rails_app/rails_engine/config/routes.rb @@ -1,5 +1,12 @@ RailsEngine::Engine.routes.draw do - devise_for :engine_users, class_name: 'RailsEngine::User' + devise_for :without_router, + class_name: 'RailsEngine::User', + module: :devise - # devise_for :engine_users_with_router_name, router_name: :rails_engine + devise_for :with_router, + class_name: 'RailsEngine::User', + router_name: :rails_engine, + module: :devise + + root to: 'with_router#index' end From b5da4e82d05207f478ac49a82c574e3cb1e19da7 Mon Sep 17 00:00:00 2001 From: David Henry Date: Tue, 6 May 2014 23:07:24 +0100 Subject: [PATCH 16/20] Add full tests around confirmation when using devise_for with router_name --- test/integration/confirmable_test.rb | 32 ++++++++++++++++++- .../user_without_confirmation.rb | 14 ++++++++ test/rails_app/config/routes.rb | 5 +++ .../app/models/rails_engine/user.rb | 5 +++ test/support/integration.rb | 16 ++++++++++ 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 test/rails_app/app/active_record/user_without_confirmation.rb diff --git a/test/integration/confirmable_test.rb b/test/integration/confirmable_test.rb index a7049cf0..6b72980f 100644 --- a/test/integration/confirmable_test.rb +++ b/test/integration/confirmable_test.rb @@ -61,7 +61,7 @@ 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 and a router_name has been specified it should not raise an error' do + 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) @@ -71,6 +71,36 @@ 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 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) + + 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 + 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) + + assert_current_url "/user_with_routers/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 user = create_user(confirm: false, confirmation_sent_at: 2.days.ago) diff --git a/test/rails_app/app/active_record/user_without_confirmation.rb b/test/rails_app/app/active_record/user_without_confirmation.rb new file mode 100644 index 00000000..58ac544f --- /dev/null +++ b/test/rails_app/app/active_record/user_without_confirmation.rb @@ -0,0 +1,14 @@ +require 'shared_user' + +class UserWithoutConfirmation < ActiveRecord::Base + self.table_name = 'users' + include Shim + + devise :database_authenticatable, :confirmable, :lockable, :recoverable, + :registerable, :rememberable, :timeoutable, + :trackable, :validatable + + def raw_confirmation_token + @raw_confirmation_token + end +end diff --git a/test/rails_app/config/routes.rb b/test/rails_app/config/routes.rb index 136f0418..4384d9aa 100644 --- a/test/rails_app/config/routes.rb +++ b/test/rails_app/config/routes.rb @@ -22,6 +22,11 @@ Rails.application.routes.draw do # Users scope devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" } + devise_for :user_with_routers, + class_name: 'UserWithoutConfirmation', + router_name: :main_app, + module: :devise + as :user do get "/as/sign_in", to: "devise/sessions#new" end diff --git a/test/rails_app/rails_engine/app/models/rails_engine/user.rb b/test/rails_app/rails_engine/app/models/rails_engine/user.rb index e60087ff..03c8ebfe 100644 --- a/test/rails_app/rails_engine/app/models/rails_engine/user.rb +++ b/test/rails_app/rails_engine/app/models/rails_engine/user.rb @@ -5,5 +5,10 @@ module RailsEngine devise :database_authenticatable, :confirmable, :lockable, :recoverable, :registerable, :rememberable, :timeoutable, :trackable, :validatable + + def raw_confirmation_token + @raw_confirmation_token + end + end end diff --git a/test/support/integration.rb b/test/support/integration.rb index 245b0e42..d16cc65e 100644 --- a/test/support/integration.rb +++ b/test/support/integration.rb @@ -21,6 +21,22 @@ 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!( From bec913fc07168b3767430b6e6cd2c1f66bbdeec0 Mon Sep 17 00:00:00 2001 From: David Henry Date: Tue, 6 May 2014 23:31:59 +0100 Subject: [PATCH 17/20] Clean up the code. --- lib/devise.rb | 1 - lib/devise/routing_details.rb | 12 ------------ .../app/active_record/user_without_confirmation.rb | 11 ++--------- test/rails_app/lib/shared_user_without_omniauth.rb | 13 +++++++++++++ test/rails_app/rails_engine/Rakefile | 6 +----- .../rails_engine/app/models/rails_engine/user.rb | 12 +++--------- 6 files changed, 19 insertions(+), 36 deletions(-) delete mode 100644 lib/devise/routing_details.rb create mode 100644 test/rails_app/lib/shared_user_without_omniauth.rb diff --git a/lib/devise.rb b/lib/devise.rb index da3bab07..2b99d923 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -489,7 +489,6 @@ module Devise end require 'warden' -require 'devise/routing_details' require 'devise/mapping' require 'devise/models' require 'devise/modules' diff --git a/lib/devise/routing_details.rb b/lib/devise/routing_details.rb deleted file mode 100644 index b53b7d81..00000000 --- a/lib/devise/routing_details.rb +++ /dev/null @@ -1,12 +0,0 @@ -module Devise - # This is a data transfer object to avoid coupling between - # Devive::Mapping and the rest of the application. - class RoutingDetails - attr_reader :scope, :router_name - - def initialize(mapping) - @scope = mapping.name - @router_name = mapping.router_name - end - end -end diff --git a/test/rails_app/app/active_record/user_without_confirmation.rb b/test/rails_app/app/active_record/user_without_confirmation.rb index 58ac544f..974bca13 100644 --- a/test/rails_app/app/active_record/user_without_confirmation.rb +++ b/test/rails_app/app/active_record/user_without_confirmation.rb @@ -1,14 +1,7 @@ -require 'shared_user' +require 'shared_user_without_omniauth' class UserWithoutConfirmation < ActiveRecord::Base self.table_name = 'users' include Shim - - devise :database_authenticatable, :confirmable, :lockable, :recoverable, - :registerable, :rememberable, :timeoutable, - :trackable, :validatable - - def raw_confirmation_token - @raw_confirmation_token - end + include SharedUserWithoutOmniauth end diff --git a/test/rails_app/lib/shared_user_without_omniauth.rb b/test/rails_app/lib/shared_user_without_omniauth.rb new file mode 100644 index 00000000..df145e35 --- /dev/null +++ b/test/rails_app/lib/shared_user_without_omniauth.rb @@ -0,0 +1,13 @@ +module SharedUserWithoutOmniauth + extend ActiveSupport::Concern + + included do + devise :database_authenticatable, :confirmable, :lockable, :recoverable, + :registerable, :rememberable, :timeoutable, + :trackable, :validatable + end + + def raw_confirmation_token + @raw_confirmation_token + end +end diff --git a/test/rails_app/rails_engine/Rakefile b/test/rails_app/rails_engine/Rakefile index 834f9e76..e97c2e3d 100644 --- a/test/rails_app/rails_engine/Rakefile +++ b/test/rails_app/rails_engine/Rakefile @@ -6,8 +6,4 @@ end load 'rails/tasks/engine.rake' - - -Bundler::GemHelper.install_tasks - - +Bundler::GemHelper.install_tasks \ No newline at end of file diff --git a/test/rails_app/rails_engine/app/models/rails_engine/user.rb b/test/rails_app/rails_engine/app/models/rails_engine/user.rb index 03c8ebfe..a9cb6fde 100644 --- a/test/rails_app/rails_engine/app/models/rails_engine/user.rb +++ b/test/rails_app/rails_engine/app/models/rails_engine/user.rb @@ -1,14 +1,8 @@ +require 'shared_user_without_omniauth' + module RailsEngine class User < ActiveRecord::Base self.table_name = :users - - devise :database_authenticatable, :confirmable, :lockable, :recoverable, - :registerable, :rememberable, :timeoutable, - :trackable, :validatable - - def raw_confirmation_token - @raw_confirmation_token - end - + include SharedUserWithoutOmniauth end end From 426560a4db59e9a9d5744197bae9aca7effff885 Mon Sep 17 00:00:00 2001 From: David Henry Date: Thu, 8 May 2014 00:46:19 +0100 Subject: [PATCH 18/20] Attempt without adding engine to application --- Gemfile | 1 - Gemfile.lock | 8 -- test/integration/confirmable_test.rb | 52 ++++------- ...hout_confirmation.rb => user_on_engine.rb} | 2 +- .../app/active_record/user_on_main_app.rb | 7 ++ .../app/controllers/application_controller.rb | 1 + .../application_with_fake_engine.rb | 28 ++++++ test/rails_app/config/application.rb | 1 - test/rails_app/config/initializers/devise.rb | 2 + test/rails_app/config/routes.rb | 11 ++- test/rails_app/rails_engine/Gemfile | 5 -- test/rails_app/rails_engine/Gemfile.lock | 86 ------------------- test/rails_app/rails_engine/Rakefile | 9 -- .../rails_engine/application_controller.rb | 4 - .../app/models/rails_engine/user.rb | 8 -- .../layouts/rails_engine/application.html.erb | 14 --- test/rails_app/rails_engine/bin/rails | 8 -- test/rails_app/rails_engine/config/routes.rb | 12 --- .../rails_engine/lib/rails_engine.rb | 4 - .../rails_engine/lib/rails_engine/engine.rb | 6 -- .../rails_engine/lib/rails_engine/version.rb | 3 - .../lib/tasks/rails_engine_tasks.rake | 4 - .../rails_engine/rails_engine.gemspec | 17 ---- test/support/integration.rb | 16 ---- 24 files changed, 62 insertions(+), 247 deletions(-) rename test/rails_app/app/active_record/{user_without_confirmation.rb => user_on_engine.rb} (70%) create mode 100644 test/rails_app/app/active_record/user_on_main_app.rb create mode 100644 test/rails_app/app/controllers/application_with_fake_engine.rb delete mode 100644 test/rails_app/rails_engine/Gemfile delete mode 100644 test/rails_app/rails_engine/Gemfile.lock delete mode 100644 test/rails_app/rails_engine/Rakefile delete mode 100644 test/rails_app/rails_engine/app/controllers/rails_engine/application_controller.rb delete mode 100644 test/rails_app/rails_engine/app/models/rails_engine/user.rb delete mode 100644 test/rails_app/rails_engine/app/views/layouts/rails_engine/application.html.erb delete mode 100755 test/rails_app/rails_engine/bin/rails delete mode 100644 test/rails_app/rails_engine/config/routes.rb delete mode 100644 test/rails_app/rails_engine/lib/rails_engine.rb delete mode 100644 test/rails_app/rails_engine/lib/rails_engine/engine.rb delete mode 100644 test/rails_app/rails_engine/lib/rails_engine/version.rb delete mode 100644 test/rails_app/rails_engine/lib/tasks/rails_engine_tasks.rake delete mode 100644 test/rails_app/rails_engine/rails_engine.gemspec diff --git a/Gemfile b/Gemfile index e6d6fe8a..85667cc8 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,6 @@ group :test do gem "omniauth-openid", "~> 1.0.1" gem "webrat", "0.7.3", require: false gem "mocha", "~> 1.0.0", require: false - gemspec path: "test/rails_app/rails_engine" end platforms :jruby do diff --git a/Gemfile.lock b/Gemfile.lock index bc7dfb89..52518b52 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -19,13 +19,6 @@ PATH thread_safe (~> 0.1) warden (~> 1.2.3) -PATH - remote: test/rails_app/rails_engine - specs: - rails_engine (0.0.1) - devise - rails - GEM remote: https://rubygems.org/ specs: @@ -175,7 +168,6 @@ DEPENDENCIES omniauth-oauth2 (~> 1.1.0) omniauth-openid (~> 1.0.1) rails (~> 4.1.0) - rails_engine! rdoc sqlite3 webrat (= 0.7.3) diff --git a/test/integration/confirmable_test.rb b/test/integration/confirmable_test.rb index 6b72980f..d04b00c9 100644 --- a/test/integration/confirmable_test.rb +++ b/test/integration/confirmable_test.rb @@ -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 diff --git a/test/rails_app/app/active_record/user_without_confirmation.rb b/test/rails_app/app/active_record/user_on_engine.rb similarity index 70% rename from test/rails_app/app/active_record/user_without_confirmation.rb rename to test/rails_app/app/active_record/user_on_engine.rb index 974bca13..21eb3050 100644 --- a/test/rails_app/app/active_record/user_without_confirmation.rb +++ b/test/rails_app/app/active_record/user_on_engine.rb @@ -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 diff --git a/test/rails_app/app/active_record/user_on_main_app.rb b/test/rails_app/app/active_record/user_on_main_app.rb new file mode 100644 index 00000000..54ef1f80 --- /dev/null +++ b/test/rails_app/app/active_record/user_on_main_app.rb @@ -0,0 +1,7 @@ +require 'shared_user_without_omniauth' + +class UserOnMainApp < ActiveRecord::Base + self.table_name = 'users' + include Shim + include SharedUserWithoutOmniauth +end diff --git a/test/rails_app/app/controllers/application_controller.rb b/test/rails_app/app/controllers/application_controller.rb index a3153ffa..d5a26090 100644 --- a/test/rails_app/app/controllers/application_controller.rb +++ b/test/rails_app/app/controllers/application_controller.rb @@ -7,3 +7,4 @@ class ApplicationController < ActionController::Base before_filter :authenticate_user!, if: :devise_controller? respond_to *Mime::SET.map(&:to_sym) end + diff --git a/test/rails_app/app/controllers/application_with_fake_engine.rb b/test/rails_app/app/controllers/application_with_fake_engine.rb new file mode 100644 index 00000000..3f60c54d --- /dev/null +++ b/test/rails_app/app/controllers/application_with_fake_engine.rb @@ -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 diff --git a/test/rails_app/config/application.rb b/test/rails_app/config/application.rb index fb60bae7..91c75cb9 100644 --- a/test/rails_app/config/application.rb +++ b/test/rails_app/config/application.rb @@ -12,7 +12,6 @@ rescue LoadError end require "devise" -require "rails_engine" module RailsApp class Application < Rails::Application diff --git a/test/rails_app/config/initializers/devise.rb b/test/rails_app/config/initializers/devise.rb index 81d7a248..1f994802 100644 --- a/test/rails_app/config/initializers/devise.rb +++ b/test/rails_app/config/initializers/devise.rb @@ -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" diff --git a/test/rails_app/config/routes.rb b/test/rails_app/config/routes.rb index 4384d9aa..7438114b 100644 --- a/test/rails_app/config/routes.rb +++ b/test/rails_app/config/routes.rb @@ -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 diff --git a/test/rails_app/rails_engine/Gemfile b/test/rails_app/rails_engine/Gemfile deleted file mode 100644 index 7e2c3dff..00000000 --- a/test/rails_app/rails_engine/Gemfile +++ /dev/null @@ -1,5 +0,0 @@ -source "https://rubygems.org" - -gemspec - - diff --git a/test/rails_app/rails_engine/Gemfile.lock b/test/rails_app/rails_engine/Gemfile.lock deleted file mode 100644 index aecb5fa0..00000000 --- a/test/rails_app/rails_engine/Gemfile.lock +++ /dev/null @@ -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 diff --git a/test/rails_app/rails_engine/Rakefile b/test/rails_app/rails_engine/Rakefile deleted file mode 100644 index e97c2e3d..00000000 --- a/test/rails_app/rails_engine/Rakefile +++ /dev/null @@ -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 \ No newline at end of file diff --git a/test/rails_app/rails_engine/app/controllers/rails_engine/application_controller.rb b/test/rails_app/rails_engine/app/controllers/rails_engine/application_controller.rb deleted file mode 100644 index 249809d8..00000000 --- a/test/rails_app/rails_engine/app/controllers/rails_engine/application_controller.rb +++ /dev/null @@ -1,4 +0,0 @@ -module RailsEngine - class ApplicationController < ActionController::Base - end -end diff --git a/test/rails_app/rails_engine/app/models/rails_engine/user.rb b/test/rails_app/rails_engine/app/models/rails_engine/user.rb deleted file mode 100644 index a9cb6fde..00000000 --- a/test/rails_app/rails_engine/app/models/rails_engine/user.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'shared_user_without_omniauth' - -module RailsEngine - class User < ActiveRecord::Base - self.table_name = :users - include SharedUserWithoutOmniauth - end -end diff --git a/test/rails_app/rails_engine/app/views/layouts/rails_engine/application.html.erb b/test/rails_app/rails_engine/app/views/layouts/rails_engine/application.html.erb deleted file mode 100644 index d78fccfb..00000000 --- a/test/rails_app/rails_engine/app/views/layouts/rails_engine/application.html.erb +++ /dev/null @@ -1,14 +0,0 @@ - - - - RailsEngine - <%= stylesheet_link_tag "rails_engine/application", media: "all" %> - <%= javascript_include_tag "rails_engine/application" %> - <%= csrf_meta_tags %> - - - -<%= yield %> - - - diff --git a/test/rails_app/rails_engine/bin/rails b/test/rails_app/rails_engine/bin/rails deleted file mode 100755 index 258ac128..00000000 --- a/test/rails_app/rails_engine/bin/rails +++ /dev/null @@ -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' diff --git a/test/rails_app/rails_engine/config/routes.rb b/test/rails_app/rails_engine/config/routes.rb deleted file mode 100644 index d36a4246..00000000 --- a/test/rails_app/rails_engine/config/routes.rb +++ /dev/null @@ -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 diff --git a/test/rails_app/rails_engine/lib/rails_engine.rb b/test/rails_app/rails_engine/lib/rails_engine.rb deleted file mode 100644 index 45ab5d52..00000000 --- a/test/rails_app/rails_engine/lib/rails_engine.rb +++ /dev/null @@ -1,4 +0,0 @@ -require "rails_engine/engine" - -module RailsEngine -end diff --git a/test/rails_app/rails_engine/lib/rails_engine/engine.rb b/test/rails_app/rails_engine/lib/rails_engine/engine.rb deleted file mode 100644 index c2503961..00000000 --- a/test/rails_app/rails_engine/lib/rails_engine/engine.rb +++ /dev/null @@ -1,6 +0,0 @@ -require 'devise' -module RailsEngine - class Engine < ::Rails::Engine - isolate_namespace RailsEngine - end -end diff --git a/test/rails_app/rails_engine/lib/rails_engine/version.rb b/test/rails_app/rails_engine/lib/rails_engine/version.rb deleted file mode 100644 index ef5d8b72..00000000 --- a/test/rails_app/rails_engine/lib/rails_engine/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module RailsEngine - VERSION = "0.0.1" -end diff --git a/test/rails_app/rails_engine/lib/tasks/rails_engine_tasks.rake b/test/rails_app/rails_engine/lib/tasks/rails_engine_tasks.rake deleted file mode 100644 index c179de9d..00000000 --- a/test/rails_app/rails_engine/lib/tasks/rails_engine_tasks.rake +++ /dev/null @@ -1,4 +0,0 @@ -# desc "Explaining what the task does" -# task :rails_engine do -# # Task goes here -# end diff --git a/test/rails_app/rails_engine/rails_engine.gemspec b/test/rails_app/rails_engine/rails_engine.gemspec deleted file mode 100644 index 8ce0a3e6..00000000 --- a/test/rails_app/rails_engine/rails_engine.gemspec +++ /dev/null @@ -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 diff --git a/test/support/integration.rb b/test/support/integration.rb index d16cc65e..245b0e42 100644 --- a/test/support/integration.rb +++ b/test/support/integration.rb @@ -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!( From c5c360cdd93f8c43e76d30f2b7d0727d0bc7f4de Mon Sep 17 00:00:00 2001 From: David Henry Date: Thu, 15 May 2014 18:59:51 +0100 Subject: [PATCH 19/20] Add classes for mongoid based tests --- test/rails_app/app/mongoid/user_on_engine.rb | 39 +++++++++++++++++++ .../rails_app/app/mongoid/user_on_main_app.rb | 39 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 test/rails_app/app/mongoid/user_on_engine.rb create mode 100644 test/rails_app/app/mongoid/user_on_main_app.rb diff --git a/test/rails_app/app/mongoid/user_on_engine.rb b/test/rails_app/app/mongoid/user_on_engine.rb new file mode 100644 index 00000000..e68b096f --- /dev/null +++ b/test/rails_app/app/mongoid/user_on_engine.rb @@ -0,0 +1,39 @@ +require 'shared_user_without_omniauth' + +class UserOnEngine + include Mongoid::Document + include Shim + include SharedUserWithoutOmniauth + + field :username, type: String + field :facebook_token, type: String + + ## Database authenticatable + field :email, type: String, default: "" + field :encrypted_password, type: String, default: "" + + ## Recoverable + field :reset_password_token, type: String + field :reset_password_sent_at, type: Time + + ## Rememberable + field :remember_created_at, type: Time + + ## Trackable + field :sign_in_count, type: Integer, default: 0 + field :current_sign_in_at, type: Time + field :last_sign_in_at, type: Time + field :current_sign_in_ip, type: String + field :last_sign_in_ip, type: String + + ## Confirmable + field :confirmation_token, type: String + field :confirmed_at, type: Time + field :confirmation_sent_at, type: Time + # field :unconfirmed_email, type: String # Only if using reconfirmable + + ## Lockable + field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts + field :unlock_token, type: String # Only if unlock strategy is :email or :both + field :locked_at, type: Time +end diff --git a/test/rails_app/app/mongoid/user_on_main_app.rb b/test/rails_app/app/mongoid/user_on_main_app.rb new file mode 100644 index 00000000..a35f2336 --- /dev/null +++ b/test/rails_app/app/mongoid/user_on_main_app.rb @@ -0,0 +1,39 @@ +require 'shared_user_without_omniauth' + +class UserOnMainApp + include Mongoid::Document + include Shim + include SharedUserWithoutOmniauth + + field :username, type: String + field :facebook_token, type: String + + ## Database authenticatable + field :email, type: String, default: "" + field :encrypted_password, type: String, default: "" + + ## Recoverable + field :reset_password_token, type: String + field :reset_password_sent_at, type: Time + + ## Rememberable + field :remember_created_at, type: Time + + ## Trackable + field :sign_in_count, type: Integer, default: 0 + field :current_sign_in_at, type: Time + field :last_sign_in_at, type: Time + field :current_sign_in_ip, type: String + field :last_sign_in_ip, type: String + + ## Confirmable + field :confirmation_token, type: String + field :confirmed_at, type: Time + field :confirmation_sent_at, type: Time + # field :unconfirmed_email, type: String # Only if using reconfirmable + + ## Lockable + field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts + field :unlock_token, type: String # Only if unlock strategy is :email or :both + field :locked_at, type: Time +end From 6a628724eabf369c1ad35f99fdc1e311ad2ca558 Mon Sep 17 00:00:00 2001 From: David Henry Date: Thu, 15 May 2014 19:42:08 +0100 Subject: [PATCH 20/20] Ensure I don't leave public methods around that break the test suit.. --- test/rails_app/app/controllers/application_with_fake_engine.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/rails_app/app/controllers/application_with_fake_engine.rb b/test/rails_app/app/controllers/application_with_fake_engine.rb index 3f60c54d..c77d67f1 100644 --- a/test/rails_app/app/controllers/application_with_fake_engine.rb +++ b/test/rails_app/app/controllers/application_with_fake_engine.rb @@ -1,4 +1,6 @@ class ApplicationWithFakeEngine < ApplicationController + private + helper_method :fake_engine def fake_engine @fake_engine ||= FakeEngine.new