Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • portalmec/portalmec
  • rfhferreira/cleanning-portalmec
2 results
Show changes
Showing
with 113 additions and 620 deletions
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
RSpec.shared_examples "a list" do |url, object, klass|
get url do
parameter :limit, 'Limit of #{object}'
parameter :offset, 'Offset of #{object}'
let(:list) { object.all }
let(:limit) { 12 }
let(:offset) { 0 }
example_request 'Get a list of ' + klass do
expect(JSON.parse(response_body).map { |o| o['id'] }.sort).to eq(object.limit(limit).offset(offset).pluck(:id).sort)
expect(status).to eq(200)
end
end
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
require 'devise'
require 'public_activity/testing'
PublicActivity.enabled = false
PublicActivity.enabled = true
# 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
......
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
\ No newline at end of file
#!/bin/bash
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
source $PUMA_APP_DIR/config/env_vars.sh
cd $PUMA_APP_DIR
......
#!/bin/bash
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
cd $PUMA_APP_DIR
pumactl -P shared/sockets/pumactl.sock stop
require 'test_helper'
class V1::CollectionsControllerTest < ActionController::TestCase
tests V1::CollectionsController
include Devise::Test::ControllerHelpers
test 'should get index' do
skip('Unsolved issue: ArgumentError: wrong number of arguments (2 for 0)')
end
test 'should user post collection to create and return :created code' do
auth_request users(:jack)
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, params: { collection: { name: 'my collection',
description: 'testing collection',
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, params: { collection: {name: 'my collection',
description: 'testing collection',
owner_type: 'Institution', owner_id: institutions(:ufpr).id }
}
assert_response :unauthorized
end
test 'should user tagging a collection' do
auth_request users(:jack)
tag = tags(:tag_three).name
post :tagging, params: { id: collections(:ufpr).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' } }
assert_response :created
end
test 'should user untagging a collection' do
auth_request users(:john)
tag = tags(:tag_one).name
post :untagging, params: { id: collections(:ufpr).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' } }
assert_response :ok
end
test 'should institution tagging a collection' do
auth_request users(:jack)
institution = institutions(:ufpr)
institution.users << users(:jack)
tag = tags(:tag_one).name
post :tagging, params: { id: collections(:ufpr).id, tag: { name: tag, owner_id: institutions(:ufpr).id, owner_type: 'Institution' } }
assert_response :created
end
test 'should institution untagging a collection' do
auth_request users(:john)
institution = institutions(:ufpr)
institution.users << users(:john)
tag = tags(:tag_two).name
delete :untagging, params: { id: collections(:ufpr).id, tag: { name: tag , owner_id: institutions(:ufpr).id, owner_type: 'Institution' } }
assert_response :ok
end
private
def ensure_collection_is_persisted!(collection)
collection.save!
end
end
require 'test_helper'
class V1::ComplaintControllerTest < ActionController::TestCase
tests V1::ComplaintsController
include Devise::Test::ControllerHelpers
test 'should get index' do
skip('Unsolved issue: ArgumentError: wrong number of arguments (2 for 0)')
end
test 'should create complaint and return :created code' do
jack = users(:jack)
auth_request jack
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
test 'should unprocessable_entity complaint and return :created code' do
jack = users(:jack)
auth_request jack
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
end
require 'test_helper'
class V1::FeedControllerTest < ActionController::TestCase
tests V1::FeedController
include Devise::Test::ControllerHelpers
test 'should get index' do
auth_request users(:jack)
skip('Unsolved issue: ArgumentError: wrong number of arguments (2 for 0)')
end
test 'should not get index' do
skip('Unsolved issue: ArgumentError: wrong number of arguments (2 for 0)')
assert_response :unauthorized
end
end
require 'test_helper'
class V1::InstitutionControllerTest < ActionController::TestCase
tests V1::InstitutionsController
include Devise::Test::ControllerHelpers
test 'should get index' do
skip('Unsolved issue: ArgumentError: wrong number of arguments (2 for 0)')
end
test 'should user show institution' do
auth_application
ufpr = institutions(:ufpr)
get :show, params: { id: ufpr.id }
assert_response :ok
end
test 'should user post institution to create and return :unauthorized' do
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, 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, 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, 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, params: { id: ufpr.id }
assert_response :ok
end
test 'should user delete institution to destroy and return :unauthorized' do
ufpr = institutions(:ufpr)
delete :destroy, params: { id: ufpr.id }
assert_response :unauthorized
end
test 'should user show institution users' do
skip('Unsolved issue: ArgumentError: wrong number of arguments (2 for 0)')
end
end
require 'test_helper'
class V1::LanguagesControllerTest < ActionController::TestCase
tests V1::LanguagesController
include Devise::Test::ControllerHelpers
test 'should put update to language with admin user and return :ok code' do
auth_request users(:admin)
language = languages(:portuguese)
put :update, params: { language: {
name: 'English',
code: 'en'
}, 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, params: { language: {
name: 'English',
code: 'en'
}, id: language.id }
assert_response :unauthorized
end
end
require 'test_helper'
class V1::LearningObjectsControllerTest < ActionController::TestCase
tests V1::LearningObjectsController
include Devise::Test::ControllerHelpers
test 'should user tagging a learning object' do
auth_request users(:jack)
tag = tags(:tag_three).name
post :tagging, params: { id: learning_objects(:user_lo).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' } }
assert_response :created
end
test 'should user untagging a learning object' do
auth_request users(:jack)
tag = tags(:tag_three).name
post :untagging, params: { id: learning_objects(:user_lo).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' } }
assert_response :ok
end
test 'should institution tagging a learning object' do
auth_request users(:jack)
institution = institutions(:ufpr)
institution.users << users(:jack)
tag = tags(:tag_one).name
post :tagging, params: { id: learning_objects(:institution_lo).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' } }
assert_response :created
end
test 'should institution untagging a learning object' do
auth_request users(:jack)
institution = institutions(:ufpr)
institution.users << users(:jack)
tag = tags(:tag_one).name
post :untagging, params: { id: learning_objects(:institution_lo).id, tag: { name: tag, owner_id: users(:jack).id, owner_type: 'User' } }
assert_response :ok
end
end
require 'test_helper'
class V1::LicensesControllerTest < ActionController::TestCase
tests V1::LicensesController
include Devise::Test::ControllerHelpers
setup do
@license = licenses(:one)
end
test "should get index" do
skip
get :index
assert_response :success
assert_not_nil assigns(:licenses)
end
test "should create license" do
auth_request users(:admin)
assert_difference('License.count') do
post :create, params: { license: { description: @license.description, name: @license.name, url: @license.url, image_url: @license.image_url } }
end
assert_response 201
end
test "should show license" do
skip
get :show, id: @license
assert_response :success
end
test "should update license" do
auth_request users(:admin)
put :update, params: { id: @license, license: { description: @license.description, name: @license.name, url: @license.url, image_url: @license.image_url } }
assert_response 204
end
test "should destroy license" do
auth_request users(:admin)
assert_difference('License.count', -1) do
delete :destroy, params: { id: @license }
end
assert_response 204
end
end
require 'test_helper'
class V1::MimeTypesControllerTest < ActionController::TestCase
tests V1::MimeTypesController
include Devise::Test::ControllerHelpers
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, params: { mime_type: {
extension: '.mp45',
mime_type: 'video/mp45'
}, 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, params: { mime_type: {
extension: '.mp45',
mime_type: 'video/mp45'
}, id: mime_type.id }
assert_response :unauthorized
end
end
require 'test_helper'
class V1::ObjectTypesControllerTest < ActionController::TestCase
tests V1::ObjectTypesController
include Devise::Test::ControllerHelpers
test 'should put update to object_type with admin user and return :ok code' do
auth_request users(:admin)
object_type = object_types(:image)
mime_type = mime_types(:mp4)
put :update, params: { object_type: {
name: 'Vídeo',
mime_types: [mime_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, params: { object_type: {
name: 'Vídeo',
mime_types: [mime_type.id]
}, id: object_type.id }
assert_response :unauthorized
end
end
require 'test_helper'
class V1::RatingControllerTest < ActionController::TestCase
tests V1::RatingsController
include Devise::TestHelpers
test 'should get index' do
skip('Unsolved issue: ArgumentError: wrong number of arguments (2 for 0)')
end
test 'should user show rating' do
auth_application
usability = ratings(:usability)
get :show, id: usability.id
assert_response :ok
end
test 'should user post rating to create and return :unauthorized' do
post :create, rating: {name: 'my rating',description: 'testing rating'}
assert_response :unauthorized
end
test 'should user post rating to create and return :created code' do
auth_request users(:jack)
post :create, rating: {name: 'my rating',description: 'testing rating'}
assert_response :created
end
test 'should user put rating to update and return :ok' do
auth_request users(:jack)
usability = ratings(:usability)
put :update, id: usability.id , rating: { description: 'testing rating'}
assert_response :ok
end
test 'should user put rating to update and return :unauthorized' do
usability = ratings(:usability)
put :update, id: usability.id , rating: { description: 'testing rating'}
assert_response :unauthorized
end
test 'should user delete rating to destroy and return :ok' do
auth_request users(:jack)
usability = ratings(:usability)
delete :destroy, id: usability.id
assert_response :ok
end
test 'should user delete rating to destroy and return :unauthorized' do
usability = ratings(:usability)
delete :destroy, id: usability.id
assert_response :unauthorized
end
end
require 'test_helper'
class V1::ReviewsControllerTest < ActionController::TestCase
tests V1::ReviewsController
include Devise::Test::ControllerHelpers
test 'should user review a learning object and return :created code' do
auth_request users(:admin)
assert learning_objects(:user_lo).id > 0
create_review learning_objects(:user_lo)
assert_response :created
end
test 'should user review a collection and return :created code' do
auth_request users(:admin)
create_review collections(:ufpr)
assert_response :created
end
test 'should guest user review a collection and return :unauthorized code' do
create_review collections(:ufpr)
assert_response :unauthorized
end
test 'should user delete review withou permission and return :unauthorized code' do
auth_request users(:john)
delete :destroy, params: { collection_id: collections(:ufpr).id, id: reviews(:collection).id }
assert_response :unauthorized
end
private
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, params: { review: {
name: 'Test of review',
description: 'testing',
pros: 'my pros',
cons: 'my cons',
review_ratings_attributes: [
{ rating_id: ratings(:usability).id, value: 3 },
{ rating_id: ratings(:application_context).id, value: 3 },
{ rating_id: ratings(:content).id, value: 3 }
]
}, object_param_name => object.id }
end
end
require 'test_helper'
class V1::ScoresControllerTest < ActionController::TestCase
tests V1::ScoresController
include Devise::Test::ControllerHelpers
test 'should get index' do
skip
end
test 'should show score' do
auth_application
score = scores(:score_19)
get :show, params: { id: score.id }
assert_response :ok
end
test 'should put score to update and return :ok code' do
auth_request users(:jack)
score = scores(:score_19)
put :update, params: { score: {name: 'testing',
weight: 10,
active: true,
score_type: ['LearningObject']
}, 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, params: { score: {name: 'testing',
weight: 10,
active: true,
score_type: ['LearningObject']
}, 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, params: { score: {name: 'testing',
weight: 'addasd',
score_type: ['LearningObject']
}, id: score.id }
assert_response :unprocessable_entity
end
end
require 'test_helper'
class V1::SearchControllerTest < ActionController::TestCase
tests V1::SearchController
setup do
SearchService::SEARCH_CLASSES.each { |search_class| reindex search_class.constantize }
auth_application
end
test 'should search return :ok' do
SearchService::SEARCH_CLASSES.each do |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, params: { search_class: 'invalid' }
assert_response :bad_request
end
test 'should autocomplete with invalid class and return :bad_request' do
get :autocomplete, params: { search_class: 'invalid' }
assert_response :bad_request
end
private
def reindex(klass)
klass.reindex
klass.searchkick_index.refresh
end
end
require 'test_helper'
class V1::Users::BookmarksControllerTest < ActionController::TestCase
tests V1::Users::BookmarksController
include Devise::Test::ControllerHelpers
test 'should get index' do
skip('Unsolved issue: ArgumentError: wrong number of arguments (2 for 0)')
end
test 'should user append learning object in bookmarks and return :created code' do
auth_request users(:jack)
lo = learning_objects(:one)
post :create, params: { id: users(:jack).id, bookmarks: { id: lo.id,
type: "LearningObject" }
}
assert_response :created
end
test 'should user append collection in bookmarks and return :created code' do
auth_request users(:jack)
collection = collections(:ufpr)
post :create, params: { id: users(:jack).id, bookmarks: { id: collection.id,
type: "Collection" }
}
assert_response :created
end
test 'should user undo bookmark of learning object to destroy and return :ok' do
auth_request users(:jack)
lo = learning_objects(:one)
delete :destroy, params: { id: users(:jack).id, bookmarks: { id: lo.id,
type: "LearningObject" }
}
assert_response :ok
end
test 'should user undo bookmark of collection to destroy and return :ok' do
auth_request users(:jack)
collection = collections(:ufpr)
delete :destroy, params: { id: users(:jack).id, bookmarks: { id: collection.id,
type: "Collection" }
}
assert_response :ok
end
end