Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create /user.json get route + test #367

Merged
merged 2 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class UsersController < ApplicationController
before_action :logged_in
respond_to :json

def logged_in
authenticate_user!
end

def show
respond_to do |format|
format.json { render json: current_user }
end
end
end
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
mount Blazer::Engine, at: "blazer"
end

# devise doesnt parse GET /user
resource :user, only: :show, constraints: ->(req) { req.format == :json }

resource :questionnaires, path: "apply" do
get :schools, on: :collection
end
Expand Down
19 changes: 19 additions & 0 deletions test/controllers/users_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'test_helper'

class UsersControllerTest < ActionController::TestCase
include ActiveJob::TestHelper
setup do
@user = create(:user)
end

should "allow access to user#get" do
sign_in @user
get :show, params: { format: :json }
assert_response :success
end

should "don't allow user#show if not signed in" do
get :show, params: { format: :json }
assert_response(:unauthorized)
end
end