Skip to content
Snippets Groups Projects
Commit 43219d00 authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

Merge branch 'railsapi' of gitlab.c3sl.ufpr.br:portalmec/portalmec into railsapi

parents ced5aa6f a2a93a5d
No related branches found
No related tags found
No related merge requests found
class V1::InstitutionsController < ApplicationController
before_action :set_institution, only: [:show, :update, :destroy, :users]
before_action :authenticate_user!, only: [:create, :update, :destroy]
# GET v1/institutions
# GET v1/institutions.json
def index
render json: Institution.all
end
# GET v1/institutions/1
# GET v1/institutions/1.json
def show
render json: @institution
end
# POST v1/institutions
# POST v1/institutions.json
def create
institution = Institution.new(institution_params)
if institution.save
render json: institution, status: :created
else
render json: institution.errors, status: :unprocessable_entity
end
end
# PUT/PATCH /v1/institutions/1
# PUT/PATCH /v1/institutions/1.json
def update
if @institution.update(institution_params)
render json: @institution, status: :ok
else
render json: @institution.errors, status: :unprocessable_entity
end
end
# DELETE v1/institutions/1
# DELETE v1/institutions/1.json
def destroy
@institution.destroy
render nothing: true, status: :ok
end
def users
@users = @institution.users
render json: @users, status: :ok
end
private
def set_institution
@institution = Institution.find(params[:id])
end
def institution_params
params.require(:institution).permit(:name, :description, :address, :city, :country)
end
end
class InstitutionSerializer < ActiveModel::Serializer
attributes :id, :name, :description, :address, :city, :country, :created_at, :updated_at
end
......@@ -31,6 +31,12 @@ Rails.application.routes.draw do
resources :users, concerns: :followable
resources :collections, concerns: [:followable, :sociable, :reviewable]
resources :learning_objects, concerns: [:sociable, :reviewable]
resources :institutions do
member do
get :users, to: 'institutions#users'
end
end
end
end
require 'test_helper'
class V1::InstitutionControllerTest < ActionController::TestCase
tests V1::InstitutionsController
include Devise::TestHelpers
test 'should get index' do
skip('Unsolved issue: ArgumentError: wrong number of arguments (2 for 0)')
end
test 'should user show institution' do
ufpr = institutions(:ufpr)
get :show, id: ufpr.id
assert_response :ok
end
test 'should user post institution to create and return :unauthorized' do
post :create, institution: {name: 'my institution',
description: 'testing institution',
address: 'politecnico',
city: 'Curitiba',
country: 'Brasil'
}
skip assert_response :unauthorized
end
test 'should user post institution to create and return :created code' do
auth_request users(:jack)
post :create, institution: {name: 'my institution',
description: 'testing institution',
address: 'politecnico',
city: 'Curitiba',
country: 'Brasil'
}
skip assert_response :created
end
test 'should user put institution to update and return :ok' do
auth_request users(:jack)
ufpr = institutions(:ufpr)
put :update, id: ufpr.id , institution: { description: 'testing institution'}
assert_response :ok
end
test 'should user put institution to update and return :unauthorized' do
ufpr = institutions(:ufpr)
put :update, id: ufpr.id , institution: { description: 'testing institution'}
assert_response :unauthorized
end
test 'should user delete institution to destroy and return :ok' do
auth_request users(:jack)
ufpr = institutions(:ufpr)
delete :destroy, id: ufpr.id
assert_response :ok
end
test 'should user delete institution to destroy and return :unauthorized' do
ufpr = institutions(:ufpr)
delete :destroy, id: ufpr.id
assert_response :unauthorized
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment