Skip to content
Extraits de code Groupes Projets
Valider 43ab8cfc rédigé par Sarah Mei's avatar Sarah Mei
Parcourir les fichiers

Tell devise that :mobile is a navigational format.

parent fbf486da
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -6,22 +6,12 @@ class SessionsController < Devise::SessionsController
after_filter :enqueue_update, :only => :create
def create
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
redirect_loc = redirect_location(resource_name, resource)
respond_with resource, :location => redirect_loc do |format|
format.mobile { redirect_to root_path }
end
end
protected
def enqueue_update
if current_user
current_user.services.each{|s|
current_user.services.each do |s|
Resque.enqueue(Job::UpdateServiceUsers, s.id) if s.respond_to? :save_friends
}
end
end
end
end
......@@ -4,6 +4,15 @@
# Use this hook to configure devise mailer, warden hooks and so forth. The first
# four configuration values can also be set straight in your models.
class ActionController::Responder
def to_mobile
default_render
rescue ActionView::MissingTemplate => e
navigation_behavior(e)
end
end
Devise.setup do |config|
# Configure the e-mail address which will be shown in DeviseMailer.
if AppConfig[:smtp_sender_address]
......@@ -11,9 +20,9 @@ Devise.setup do |config|
else
unless Rails.env == 'test'
Rails.logger.warn("No smtp sender address set, mail may fail.")
puts "WARNING: No smtp sender address set, mail may fail."
puts "WARNING: No smtp sender address set, mail may fail."
end
config.mailer_sender = "please-change-me@config-initializers-devise.com"
config.mailer_sender = "please-change-me@config-initializers-devise.com"
end
# ==> ORM configuration
......@@ -27,7 +36,7 @@ Devise.setup do |config|
# authenticating an user, both parameters are required. Remember that those
# parameters are used only when authenticating and not when retrieving from
# session. If you need permissions, you should implement that in a before filter.
config.authentication_keys = [ :username ]
config.authentication_keys = [:username]
# Tell if authentication through request.params is enabled. True by default.
# config.params_authenticatable = true
......@@ -56,7 +65,7 @@ Devise.setup do |config|
# Time interval where the invitation token is valid (default: 0).
# If invite_for is 0 or nil, the invitation will never expire.
# config.invite_for = 2.weeks
# ==> 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 nil.
......@@ -130,6 +139,7 @@ Devise.setup do |config|
# If you have any extra navigational formats, like :iphone or :mobile, you
# should add them to the navigational formats lists. Default is [:html]
# config.navigational_formats = [:html, :iphone]
config.navigational_formats = [:"*/*", "*/*", :html, :mobile]
# ==> Warden configuration
# If you want to use other strategies, that are not (yet) supported by Devise,
......
......@@ -24,23 +24,39 @@ describe SessionsController do
end
describe "#create" do
it "redirects to / for a normal user" do
it "redirects to / for a non-mobile user" do
post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}}
response.should redirect_to root_path
end
it "redirects to / for a mobile user" do
@request.env['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7'
post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}}
response.should redirect_to root_path
end
it 'queues up an update job' do
service = Services::Facebook.new(:access_token => "yeah")
@user.services << service
@user.save
Resque.should_receive(:enqueue).with(Job::UpdateServiceUsers, service.id)
post :create, {"user"=>{"remember_me"=>"0", "username"=> @user.username,
"password"=>"evankorth"}}
post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}}
end
end
describe "#destroy" do
before do
sign_in :user, @user
end
it "redirects to / for a non-mobile user" do
delete :destroy
response.should redirect_to root_path
end
it "redirects to / for a mobile user" do
@request.env['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7'
delete :destroy
response.should redirect_to root_path
end
end
end
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter