Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6650787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:56:01+00:00 2026-05-26T00:56:01+00:00

I am trying to build a rails login process with devise that will allow

  • 0

I am trying to build a rails login process with devise that will allow the user to signin/signout through a mobile application.

I created a SessionsController like that :

class SessionsController < Devise::SessionsController

  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)

    respond_to do |format|  
      format.html { super }  
      format.json {  
        render :status => 200, :json => { :error => "Success", :user =>  resource}.to_json  
      }  
    end  
  end

  def destroy  
    super  
  end
end

My routes :

devise_for :users, :controllers => {:sessions => "sessions"}
resources :users

Then I have the following spec to test the process :

require 'spec_helper'

describe SessionsController do

  describe "POST 'signin'" do

    before (:each) do
      @user = Factory(:user)
    end

    it "should login with json request" do
      @expected = @user.to_json

      post :create, :user => {:email => 'user@test.com', :password => 'please'}, :content_type => 'application/json', :format => :json
      response.body.should == @expected
    end

  end

end

And I get the following error :

Failure/Error: post :create, :user => {:email => 'user@test.com', :password => 'please'}, :content_type => 'application/json', :format => :json
     AbstractController::ActionNotFound:
       Could not find devise mapping for path "/users/sign_in.json?content_type=application%2Fjson&user%5Bemail%5D=user%40test.com&user%5Bpassword%5D=please".
       Maybe you forgot to wrap your route inside the scope block?

[EDIT]
It seems like the functionality is ok but only the test is broken ; because if I run this small script :

require 'rest_client'
require "active_support/core_ext"

RestClient.post "http://localhost:3000/users/sign_in", {:user => {:email => 'user@test.com', :password => 'please'}}.to_json, :content_type => :json, :accept => :json

I get the following result :

"{\"error\":\"Success\",\"user\":{\"email\":\"user@test.com\",\"name\":\"First User\"}}"

which is the expected one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:56:02+00:00Added an answer on May 26, 2026 at 12:56 am

    I do not know if it is the best solution but here is how I successfully test my json login process through webservices on devise :

    require 'spec_helper'
    require 'rest_client'
    require 'active_support/core_ext'
    
    describe "sign up / sign out / sign in edit / cancel account" do
    
    before (:each) do
      @user = {:name => "tester", :email =>"tester@test.biz"}
    end
    
    describe "POST 'sign up'" do
    
      it "should sign up with json request" do
        response_json = RestClient.post "http://localhost:3000/sign_up", {:user=>{:name=>"tester", :email => "tester@test.biz", :password => "FILTERED", :password_confirmation => "FILTERED"}}.to_json, :content_type => :json, :accept => :json
        response = ActiveSupport::JSON.decode(response_json)
        response["response"].should == "ok"
        response["user"].should == @user.as_json
        @@token = response["token"]
        @@token.should_not == nil
      end
    
    end
    
    
    describe "DELETE 'sign out'" do
    
      it "should logout with json request" do
        response_json = RestClient.delete "http://localhost:3000/users/sign_out?auth_token=#{@@token}", :accept => :json
        response = ActiveSupport::JSON.decode(response_json)
        response["response"].should == "ok"
      end
    
    end
    
    
    describe "POST 'sign in'" do
    
      it "should login with json request" do
        response_json = RestClient.post "http://localhost:3000/users/sign_in", {:user => {:email => "tester@test.biz", :password => "FILTERED"}}.to_json, :content_type => :json, :accept => :json
        response = ActiveSupport::JSON.decode(response_json)
        response["response"].should == "ok"
        response["user"].should == @user.as_json
        @@token = response["token"]
        @@token.should_not == nil
      end
    
    end
    
    
    describe "PUT 'edit'" do
    
      it "should edit user name with json request" do
        response_json = RestClient.put "http://localhost:3000/users?auth_token=#{@@token}", {:user => {:name => "tester2", :email => "tester@test.biz", :current_password => "FILTERED"}}.to_json, :content_type => :json, :accept => :json
        response = ActiveSupport::JSON.decode(response_json)
        response["response"].should == "ok"
        response["user"]["email"].should == "tester@test.biz"
        response["user"]["name"].should == "tester2"
        @@token = response["token"]
        @@token.should_not == nil
      end
    
    end
    
    
    describe "DELETE 'account'" do
    
      it "should logout with json request" do
        response_json = RestClient.delete "http://localhost:3000/users?auth_token=#{@@token}", :accept => :json
        response = ActiveSupport::JSON.decode(response_json)
        response["response"].should == "ok"
      end
    
    end
    end
    

    With that I can create a new user, log out, log in again, edit the account and delete the account. Everything through 5 webservices in json. This order of execution allows the tests to be played every time, but I think there is missing a real rollback process to be executed at the end of the campaign.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a very simple rails application. When user submits a
I'm trying to build a Rails application that auto-corrects the spelling of a Rails
I'm trying to build a simple product backlog application to teach myself Rails. For
What are rails smart collections? If I am trying to build a view that
I'm trying to build something (ultimately a gem but for now an application) that
I am trying to build a rails app that's basically just a text-editor (with
I am trying to build a free web application using ruby/rails It should be
I am trying to build a rails application which requires a server push functionality
I'm trying to build an app in Ruby on Rails that stores specified tweets
I am trying to build a rails API for an iphone app. Devise works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.