From 702283322d3b46b05987676d6623fb123bd17c9e Mon Sep 17 00:00:00 2001 From: Paul Sponagl Date: Fri, 8 Jun 2012 12:52:00 +0200 Subject: [PATCH 1/2] Upgrade to devise 2.1 rspec and cucumber tests working untest within a real app --- Gemfile | 4 ++++ Gemfile.lock | 15 ++++++++++----- app/models/locomotive/account.rb | 14 ++++++++++++++ config/routes.rb | 8 ++------ lib/locomotive/devise.rb | 2 +- locomotive_cms.gemspec | 3 ++- spec/dummy/config/initializers/devise.rb | 14 +++++--------- 7 files changed, 38 insertions(+), 22 deletions(-) diff --git a/Gemfile b/Gemfile index 42cc6998..c9f0e31c 100755 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,10 @@ source :rubygems gemspec # Include gemspec dependencies +# Devise 2.1 throws an error if devise-encryptable is present in gemspec only +# TODO: Check Devise Code to remove that 'broken' existance test for devise-encryptable +gem 'devise-encryptable' + # The rest of the dependencies are for use when in the locomotive development environment group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 98af3772..1e784fec 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,7 +10,8 @@ PATH cells (~> 3.8.0) codemirror-rails (~> 2.21) custom_fields (~> 2.0.0.rc12) - devise (~> 1.5.3) + devise (~> 2.1.0) + devise-encryptable (~> 0.1.1) dragonfly (~> 0.9.8) flash_cookie_session (~> 1.1.1) fog (~> 1.3.1) @@ -126,10 +127,13 @@ GEM carrierwave-mongoid (~> 0.2.1) mongoid (~> 2.4.9) database_cleaner (0.8.0) - devise (1.5.3) + devise (2.1.0) bcrypt-ruby (~> 3.0) - orm_adapter (~> 0.0.3) - warden (~> 1.1) + orm_adapter (~> 0.0.7) + railties (~> 3.1) + warden (~> 1.1.1) + devise-encryptable (0.1.1) + devise (>= 2.1.0.rc) diff-lcs (1.1.3) dragonfly (0.9.12) rack @@ -311,7 +315,7 @@ GEM rack raindrops (~> 0.7) unidecoder (1.1.1) - warden (1.2.0) + warden (1.1.1) rack (>= 1.0) xpath (0.1.4) nokogiri (~> 1.3) @@ -325,6 +329,7 @@ DEPENDENCIES compass-rails cucumber-rails database_cleaner + devise-encryptable factory_girl_rails (~> 1.6.0) json_spec launchy diff --git a/app/models/locomotive/account.rb b/app/models/locomotive/account.rb index 352f0b53..ccedd1e4 100644 --- a/app/models/locomotive/account.rb +++ b/app/models/locomotive/account.rb @@ -5,6 +5,20 @@ module Locomotive devise *Locomotive.config.devise_modules + ## devise fields (need to be declared since 2.x) ## + field :remember_created_at, :type => Time + field :email, :type => String, :null => false + field :encrypted_password, :type => String, :null => false + field :authentication_token, :type => String + field :reset_password_token, :type => String + field :reset_password_sent_at, :type => Time + field :password_salt, :type => String + field :sign_in_count, :type => Integer + 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 + ## attributes ## field :name field :locale, :default => Locomotive.config.default_locale.to_s or 'en' diff --git a/config/routes.rb b/config/routes.rb index b6974a20..86156e9d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,12 +1,8 @@ Locomotive::Engine.routes.draw do # authentication - devise_for :locomotive_account, - :class_name => 'Locomotive::Account', - :path => '', - :path_prefix => nil, - :failure_app => 'Locomotive::Devise::FailureApp', - :controllers => { :sessions => 'locomotive/sessions', :passwords => 'locomotive/passwords' } do + devise_for :locomotive_account, :class_name => 'Locomotive::Account', :path => '', :path_prefix => nil, :failure_app => 'Locomotive::Devise::FailureApp',:controllers => { :sessions => 'locomotive/sessions', :passwords => 'locomotive/passwords' } + devise_scope :locomotive_account do match '/' => 'sessions#new' delete 'signout' => 'sessions#destroy', :as => :destroy_locomotive_session end diff --git a/lib/locomotive/devise.rb b/lib/locomotive/devise.rb index f544a6ab..22ded327 100644 --- a/lib/locomotive/devise.rb +++ b/lib/locomotive/devise.rb @@ -1 +1 @@ -# patches for devise here \ No newline at end of file +# patches for devise here diff --git a/locomotive_cms.gemspec b/locomotive_cms.gemspec index bcd745f4..faa66fb8 100755 --- a/locomotive_cms.gemspec +++ b/locomotive_cms.gemspec @@ -22,7 +22,8 @@ Gem::Specification.new do |s| s.add_dependency 'rails', '~> 3.2.5' - s.add_dependency 'devise', '~> 1.5.3' + s.add_dependency 'devise-encryptable', '~> 0.1.1' + s.add_dependency 'devise', '~> 2.1.0' s.add_dependency 'cancan', '~> 1.6.7' s.add_dependency 'mongo', '~> 1.5.2' diff --git a/spec/dummy/config/initializers/devise.rb b/spec/dummy/config/initializers/devise.rb index d2e35b76..d24f44c1 100644 --- a/spec/dummy/config/initializers/devise.rb +++ b/spec/dummy/config/initializers/devise.rb @@ -59,11 +59,11 @@ Devise.setup do |config| # ==> Configuration for :confirmable # The time you want to give your user to confirm his account. During this time # he will be able to access your application without confirming. Default is 0.days - # When confirm_within is zero, the user won't be able to sign in without confirming. + # When allow_unconfirmed_access_for is zero, the user won't be able to sign in without confirming. # You can use this to let your user access some features of your application # without confirming the account, but blocking it after a certain period # (ie 2 days). - # config.confirm_within = 2.days + # config.allow_unconfirmed_access_for = 2.days # Defines which key will be used when confirming an account # config.confirmation_keys = [ :email ] @@ -72,16 +72,9 @@ Devise.setup do |config| # The time the user will be remembered without asking for credentials again. config.remember_for = 2.weeks - # If true, a valid remember token can be re-used between multiple browsers. - # config.remember_across_browsers = true - # If true, extends the user's remember period when remembered via cookie. # config.extend_remember_period = false - # If true, uses the password salt as remember token. This should be turned - # to false if you are not using database authenticatable. - config.use_salt_as_remember_token = true - # Options to be passed to the created cookie. For instance, you can set # :secure => true in order to force SSL only cookies. # config.cookie_options = {} @@ -146,6 +139,9 @@ Devise.setup do |config| # If true, authentication through token does not store user in session and needs # to be supplied on each request. Useful if you are using the token as API token. # config.stateless_token = false + # Hint: Devise 2 + # Devise.stateless_token was removed. If you want to have stateless tokens, + # simply do config.skip_session_storage << :auth_token in your initializer; # ==> Scopes configuration # Turn scoped views on. Before rendering "sessions/new", it will first check for From a6ba124a9eadac3d7e1127c34ffb683c63ada645 Mon Sep 17 00:00:00 2001 From: Paul Sponagl Date: Sat, 9 Jun 2012 09:54:58 +0200 Subject: [PATCH 2/2] need to require devise-encryptable --- Gemfile | 4 ---- Gemfile.lock | 1 - lib/locomotive.rb | 1 + lib/locomotive/devise.rb | 1 + 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index c9f0e31c..42cc6998 100755 --- a/Gemfile +++ b/Gemfile @@ -5,10 +5,6 @@ source :rubygems gemspec # Include gemspec dependencies -# Devise 2.1 throws an error if devise-encryptable is present in gemspec only -# TODO: Check Devise Code to remove that 'broken' existance test for devise-encryptable -gem 'devise-encryptable' - # The rest of the dependencies are for use when in the locomotive development environment group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 1e784fec..0aa2d497 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -329,7 +329,6 @@ DEPENDENCIES compass-rails cucumber-rails database_cleaner - devise-encryptable factory_girl_rails (~> 1.6.0) json_spec launchy diff --git a/lib/locomotive.rb b/lib/locomotive.rb index d8d3d46d..efe3674d 100644 --- a/lib/locomotive.rb +++ b/lib/locomotive.rb @@ -1,6 +1,7 @@ require 'locomotive/version' require 'locomotive/core_ext' require 'locomotive/configuration' +require 'locomotive/devise' require 'locomotive/logger' require 'locomotive/haml' require 'locomotive/formtastic' diff --git a/lib/locomotive/devise.rb b/lib/locomotive/devise.rb index 22ded327..53a01e38 100644 --- a/lib/locomotive/devise.rb +++ b/lib/locomotive/devise.rb @@ -1 +1,2 @@ # patches for devise here +require 'devise-encryptable'