Commit 56ea0e91 authored by Mateus Rambo Strey's avatar Mateus Rambo Strey

fix tests?

parent 2f074fa9
......@@ -142,7 +142,7 @@ gem 'screencap'
# using while rails 5 isn't released
# gem 'rails-api'
# gem 'active_model_serializers'
gem 'active_model_serializers'
# limit the number of requests by user to api
gem 'redis-throttle', git: 'git://github.com/lelylan/redis-throttle.git'
......
......@@ -44,6 +44,11 @@ GEM
erubis (~> 2.7.0)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
active_model_serializers (0.10.2)
actionpack (>= 4.1, < 6)
activemodel (>= 4.1, < 6)
jsonapi (~> 0.1.1.beta2)
railties (>= 4.1, < 6)
activejob (5.0.0)
activesupport (= 5.0.0)
globalid (>= 0.3.6)
......@@ -234,6 +239,8 @@ GEM
activerecord (>= 3.0)
json (1.8.3)
json_pure (1.8.3)
jsonapi (0.1.1.beta2)
json (~> 1.8)
justify (1.0.2)
jwt (1.5.4)
launchy (2.4.3)
......@@ -485,6 +492,7 @@ PLATFORMS
ruby
DEPENDENCIES
active_model_serializers
activerecord-import
annotate
bcrypt (~> 3.1.7)
......
......@@ -13,7 +13,7 @@ Rails.application.configure do
config.eager_load = false
# Configure static file server for tests with Cache-Control for performance.
config.serve_static_files = true
config.public_file_server.enabled = true
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=3600'
}
......
Rails.application.config.active_record.belongs_to_required_by_default = true
ActiveSupport.halt_callback_chains_on_return_false = false
......@@ -23,9 +23,9 @@ development: &development
port: 6379
test:
host: portalmecdev1.c3sl.ufpr.br
host: localhost
port: 6379
production:
host: portalmecdev1.c3sl.ufpr.br
host: localhost
port: 6379
require 'devise'
require 'public_activity/testing'
PublicActivity.enabled = false
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
......
......@@ -10,27 +10,27 @@ class V1::CollectionsControllerTest < ActionController::TestCase
test 'should user post collection to create and return :created code' do
auth_request users(:jack)
post :create, collection: {name: 'my collection',
description: 'testing collection',
owner_type: 'User', owner_id: users(:jack).id
}
post :create, params: { collection: { name: 'my collection',
description: 'testing collection',
owner_type: 'User', owner_id: users(:jack).id }
}
assert_response :created
end
test 'should institution post collection to create and return :created code' do
auth_request users(:jack)
post :create, collection: {name: 'my collection',
post :create, params: { collection: { name: 'my collection',
description: 'testing collection',
owner_type: 'Institution', owner_id: institutions(:ufpr).id
}
owner_type: 'Institution', owner_id: institutions(:ufpr).id }
}
assert_response :created
end
test 'should user post collection to create and return :unauthorized code' do
post :create, collection: {name: 'my collection',
post :create, params: { collection: {name: 'my collection',
description: 'testing collection',
owner_type: 'Institution', owner_id: institutions(:ufpr).id
}
owner_type: 'Institution', owner_id: institutions(:ufpr).id }
}
assert_response :unauthorized
end
......@@ -38,7 +38,7 @@ class V1::CollectionsControllerTest < ActionController::TestCase
auth_request users(:jack)
tag = tags(:tag_three).name
post :tagging, id: collections(:ufpr).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' }
post :tagging, params: { id: collections(:ufpr).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' } }
assert_response :created
end
......@@ -47,7 +47,7 @@ class V1::CollectionsControllerTest < ActionController::TestCase
auth_request users(:john)
tag = tags(:tag_one).name
post :untagging, id: collections(:ufpr).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' }
post :untagging, params: { id: collections(:ufpr).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' } }
assert_response :ok
end
......@@ -58,7 +58,7 @@ class V1::CollectionsControllerTest < ActionController::TestCase
institution.users << users(:jack)
tag = tags(:tag_one).name
post :tagging, id: collections(:ufpr).id, tag: { name: tag, owner_id: institutions(:ufpr).id, owner_type: 'Institution' }
post :tagging, params: { id: collections(:ufpr).id, tag: { name: tag, owner_id: institutions(:ufpr).id, owner_type: 'Institution' } }
assert_response :created
end
......@@ -68,7 +68,7 @@ class V1::CollectionsControllerTest < ActionController::TestCase
institution.users << users(:john)
tag = tags(:tag_two).name
delete :untagging, id: collections(:ufpr).id, tag: { name: tag , owner_id: institutions(:ufpr).id, owner_type: 'Institution' }
delete :untagging, params: { id: collections(:ufpr).id, tag: { name: tag , owner_id: institutions(:ufpr).id, owner_type: 'Institution' } }
assert_response :ok
end
......
......@@ -13,13 +13,14 @@ class V1::ComplaintControllerTest < ActionController::TestCase
auth_request jack
post :create, complaint: {
post :create, params: { complaint: {
user_id: jack.id,
description: 'description of complaint',
complaintable_id: learning_objects(:one).id,
complaint_reason_id: complaint_reasons(:reason_1).id,
complaintable_type: 'LearningObject'
}
}
assert_response :created
end
......@@ -28,13 +29,14 @@ class V1::ComplaintControllerTest < ActionController::TestCase
auth_request jack
post :create, complaint: {
post :create, params: { complaint: {
user_id: nil,
description: 'description of complaint',
complaintable_id: learning_objects(:one).id,
complaint_reason_id: complaint_reasons(:reason_1).id,
complaintable_type: 'LearningObject'
}
}
assert_response :unprocessable_entity
end
......
......@@ -11,54 +11,56 @@ class V1::InstitutionControllerTest < ActionController::TestCase
test 'should user show institution' do
auth_application
ufpr = institutions(:ufpr)
get :show, id: ufpr.id
get :show, params: { id: ufpr.id }
assert_response :ok
end
test 'should user post institution to create and return :unauthorized' do
post :create, institution: {name: 'my institution',
post :create, params: { 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',
post :create, params: { 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'}
put :update, params: { 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'}
put :update, params: { 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
delete :destroy, params: { 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
delete :destroy, params: { id: ufpr.id }
assert_response :unauthorized
end
......
......@@ -7,19 +7,19 @@ class V1::LanguagesControllerTest < ActionController::TestCase
test 'should put update to language with admin user and return :ok code' do
auth_request users(:admin)
language = languages(:portuguese)
put :update, language: {
put :update, params: { language: {
name: 'English',
code: 'en'
}, id: language.id
}, id: language.id }
assert_response :ok
end
test 'should not put update to language if user is not logged in and then return :unauthorized code' do
language = languages(:portuguese)
put :update, language: {
put :update, params: { language: {
name: 'English',
code: 'en'
}, id: language.id
}, id: language.id }
assert_response :unauthorized
end
......
......@@ -8,7 +8,7 @@ class V1::LearningObjectsControllerTest < ActionController::TestCase
auth_request users(:jack)
tag = tags(:tag_three).name
post :tagging, id: learning_objects(:user_lo).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' }
post :tagging, params: { id: learning_objects(:user_lo).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' } }
assert_response :created
end
......@@ -16,7 +16,7 @@ class V1::LearningObjectsControllerTest < ActionController::TestCase
auth_request users(:jack)
tag = tags(:tag_three).name
post :untagging, id: learning_objects(:user_lo).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' }
post :untagging, params: { id: learning_objects(:user_lo).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' } }
assert_response :ok
end
......@@ -26,7 +26,7 @@ class V1::LearningObjectsControllerTest < ActionController::TestCase
institution.users << users(:jack)
tag = tags(:tag_one).name
post :tagging, id: learning_objects(:institution_lo).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' }
post :tagging, params: { id: learning_objects(:institution_lo).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' } }
assert_response :created
end
......@@ -36,7 +36,7 @@ class V1::LearningObjectsControllerTest < ActionController::TestCase
institution.users << users(:jack)
tag = tags(:tag_one).name
post :untagging, id: learning_objects(:institution_lo).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' }
post :untagging, params: { id: learning_objects(:institution_lo).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' } }
assert_response :ok
end
......
......@@ -19,7 +19,7 @@ class V1::LicensesControllerTest < ActionController::TestCase
auth_request users(:admin)
assert_difference('License.count') do
post :create, license: { description: @license.description, name: @license.name, url: @license.url, image_url: @license.image_url }
post :create, params: { license: { description: @license.description, name: @license.name, url: @license.url, image_url: @license.image_url } }
end
assert_response 201
......@@ -34,7 +34,7 @@ class V1::LicensesControllerTest < ActionController::TestCase
test "should update license" do
auth_request users(:admin)
put :update, id: @license, license: { description: @license.description, name: @license.name, url: @license.url, image_url: @license.image_url }
put :update, params: { id: @license, license: { description: @license.description, name: @license.name, url: @license.url, image_url: @license.image_url } }
assert_response 204
end
......@@ -42,7 +42,7 @@ class V1::LicensesControllerTest < ActionController::TestCase
auth_request users(:admin)
assert_difference('License.count', -1) do
delete :destroy, id: @license
delete :destroy, params: { id: @license }
end
assert_response 204
......
......@@ -7,19 +7,19 @@ class V1::MimeTypesControllerTest < ActionController::TestCase
test 'should put update to mime_type with admin user and return :ok code' do
auth_request users(:admin)
mime_type = mime_types(:mp4)
put :update, mime_type: {
put :update, params: { mime_type: {
extension: '.mp45',
mime_type: 'video/mp45'
}, id: mime_type.id
}, id: mime_type.id }
assert_response :ok
end
test 'should not put update to mime_type if user is not logged in and then return :unauthorized code' do
mime_type = mime_types(:mp4)
put :update, mime_type: {
put :update, params: { mime_type: {
extension: '.mp45',
mime_type: 'video/mp45'
}, id: mime_type.id
}, id: mime_type.id }
assert_response :unauthorized
end
......
......@@ -8,20 +8,20 @@ class V1::ObjectTypesControllerTest < ActionController::TestCase
auth_request users(:admin)
object_type = object_types(:image)
mime_type = mime_types(:mp4)
put :update, object_type: {
put :update, params: { object_type: {
name: 'Vídeo',
mime_types: [mime_type.id]
}, id: object_type.id
}, id: object_type.id }
assert_response :ok
end
test 'should not put update to object_type if user is not logged in and then return :unauthorized code' do
object_type = object_types(:image)
mime_type = mime_types(:mp4)
put :update, object_type: {
put :update, params: { object_type: {
name: 'Vídeo',
mime_types: [mime_type.id]
}, id: object_type.id
}, id: object_type.id }
assert_response :unauthorized
end
......
......@@ -24,7 +24,7 @@ class V1::ReviewsControllerTest < ActionController::TestCase
test 'should user delete review withou permission and return :unauthorized code' do
auth_request users(:john)
delete :destroy, collection_id: collections(:ufpr).id, id: reviews(:collection).id
delete :destroy, params: { collection_id: collections(:ufpr).id, id: reviews(:collection).id }
assert_response :unauthorized
end
......@@ -33,7 +33,7 @@ class V1::ReviewsControllerTest < ActionController::TestCase
def create_review(object)
object_param_name = "#{object.class.to_s.downcase}_id".to_sym
object_param_name = 'learning_object_id' if LearningObject == object.class
post :create, review: {
post :create, params: { review: {
name: 'Test of review',
description: 'testing',
pros: 'my pros',
......@@ -43,6 +43,6 @@ class V1::ReviewsControllerTest < ActionController::TestCase
{ rating_id: ratings(:application_context).id, value: 3 },
{ rating_id: ratings(:content).id, value: 3 }
]
}, object_param_name => object.id
}, object_param_name => object.id }
end
end
......@@ -11,31 +11,31 @@ class V1::ScoresControllerTest < ActionController::TestCase
test 'should put score to update and return :ok code' do
auth_request users(:jack)
score = scores(:score_19)
put :update, score: {name: 'testing',
put :update, params: { score: {name: 'testing',
weight: 10,
active: true,
score_type: ['LearningObject']
}, id: score.id
}, id: score.id }
assert_response :ok
end
test 'do not should put score to update if user is not authenticated and then return :unauthorized code' do
score = scores(:score_19)
put :update, score: {name: 'testing',
put :update, params: { score: {name: 'testing',
weight: 10,
active: true,
score_type: ['LearningObject']
}, id: score.id
}, id: score.id }
assert_response :unauthorized
end
test 'should put invalid score to update and return :unprocessable_entity code' do
auth_request users(:jack)
score = scores(:score_19)
put :update, score: {name: 'testing',
put :update, params: { score: {name: 'testing',
weight: 'addasd',
score_type: ['LearningObject']
}, id: score.id
}, id: score.id }
assert_response :unprocessable_entity
end
......
......@@ -10,18 +10,18 @@ class V1::SearchControllerTest < ActionController::TestCase
test 'should search return :ok' do
SearchService::SEARCH_CLASSES.each do |search_class|
get :index, search_class: search_class
get :index, params: { search_class: search_class }
assert_response :ok
end
end
test 'should search with invalid class and return :bad_request' do
get :index, search_class: 'invalid'
get :index, params: { search_class: 'invalid' }
assert_response :bad_request
end
test 'should autocomplete with invalid class and return :bad_request' do
get :autocomplete, search_class: 'invalid'
get :autocomplete, params: { search_class: 'invalid' }
assert_response :bad_request
end
......
......@@ -11,8 +11,8 @@ class V1::Users::BookmarksControllerTest < ActionController::TestCase
test 'should user append learning object in bookmarks and return :created code' do
auth_request users(:jack)
lo = learning_objects(:one)
post :create, id: users(:jack).id, bookmarks: { id: lo.id,
type: "LearningObject"
post :create, params: { id: users(:jack).id, bookmarks: { id: lo.id,
type: "LearningObject" }
}
assert_response :created
end
......@@ -20,8 +20,8 @@ class V1::Users::BookmarksControllerTest < ActionController::TestCase
test 'should user append collection in bookmarks and return :created code' do
auth_request users(:jack)
collection = collections(:ufpr)
post :create, id: users(:jack).id, bookmarks: { id: collection.id,
type: "Collection"
post :create, params: { id: users(:jack).id, bookmarks: { id: collection.id,
type: "Collection" }
}
assert_response :created
end
......@@ -29,8 +29,8 @@ class V1::Users::BookmarksControllerTest < ActionController::TestCase
test 'should user undo bookmark of learning object to destroy and return :ok' do
auth_request users(:jack)
lo = learning_objects(:one)
delete :destroy, id: users(:jack).id, bookmarks: { id: lo.id,
type: "LearningObject"
delete :destroy, params: { id: users(:jack).id, bookmarks: { id: lo.id,
type: "LearningObject" }
}
assert_response :ok
end
......@@ -38,8 +38,8 @@ class V1::Users::BookmarksControllerTest < ActionController::TestCase
test 'should user undo bookmark of collection to destroy and return :ok' do
auth_request users(:jack)
collection = collections(:ufpr)
delete :destroy, id: users(:jack).id, bookmarks: { id: collection.id,
type: "Collection"
delete :destroy, params: { id: users(:jack).id, bookmarks: { id: collection.id,
type: "Collection" }
}
assert_response :ok
end
......
......@@ -10,77 +10,77 @@ class V1::UsersControllerTest < ActionController::TestCase
test 'should post user to create and return :created code' do
auth_request users(:jack)
post :create, user: {name: 'mauricio',
post :create, params: { user: { name: 'mauricio',
email: 'testando@inf.ufpr.br',
password: 'test123455',
password_confirmation: 'test123455',
terms_of_service: '1'}
terms_of_service: '1' } }
assert_response :created
end
test 'should post invalid user to create and return :unprocessable_entity code' do
auth_request users(:jack)
post :create, user: {name: 'mauricio', email: '', password: 'test123455', password_confirmation: 'test123455',
terms_of_service: false, role_ids: []}
post :create, params: { user: { name: 'mauricio', email: '', password: 'test123455', password_confirmation: 'test123455',
terms_of_service: false, role_ids: [] } }
assert_response :unprocessable_entity
end
test 'should put user to update and return :ok code' do
auth_request users(:jack)
user = users(:john)
put :update, user: {name: 'mauricio',
put :update, params: { user: { name: 'mauricio',
email: 'testando@inf.ufpr.br',
password: 'test123455',
password_confirmation: 'test123455',
terms_of_service: '1'
}, id: user.id
}, id: user.id }
assert_response :ok
end
test 'should put invalid user to update and return :unprocessable_entity code' do
auth_request users(:jack)
user = users(:john)
put :update, user: {name: 'mauricio', email: '', password: 'test123455', password_confirmation: 'test123455',
terms_of_service: false}, id: user.id
put :update, params: { user: { name: 'mauricio', email: '', password: 'test123455', password_confirmation: 'test123455',
terms_of_service: false }, id: user.id }
assert_response :unprocessable_entity
end
test 'should delete an user and return :ok code' do
auth_request users(:jack)
user = users(:john)
delete :destroy, id: user.id
delete :destroy, params: { id: user.id }
assert_response :ok
end
test 'should not current user delete yourself' do
auth_request users(:john)
user = users(:john)
delete :destroy, id: user.id
delete :destroy, params: { id: user.id }
assert_response :forbidden
end
test 'should user follow an user jack' do
auth_request users(:john)
post :follow, id: users(:jack).id
post :follow, params: { id: users(:jack).id }
assert_response :created
end
test 'should user follow an already followed user and return :forbidden code' do
auth_request users(:john)
post :follow, id: users(:jack).id
post :follow, params: { id: users(:jack).id }
assert_response :created
post :follow, id: users(:jack).id
post :follow, params: { id: users(:jack).id }
assert_response :forbidden
end
test 'should user unfollow an user jack' do
auth_request users(:john)
post :follow, id: users(:jack).id
post :follow, params: { id: users(:jack).id }
assert_response :created
delete :unfollow, id: users(:jack).id
delete :unfollow, params: { id: users(:jack).id }
assert_response :ok
end
......
......@@ -67,16 +67,16 @@ class LearningObjectTest < ActiveSupport::TestCase
published_at: learning_object.published_at,
tags: learning_object.tags.map(&:name),