Commit 3cecaeb5 authored by Mateus Rambo Strey's avatar Mateus Rambo Strey

clean tests and add score calculator service test

parent b552d798
......@@ -94,7 +94,7 @@ gem 'stackprof'
#Awesome font icons
gem "font-awesome-rails"
group :development, :test do
group :development do
# profiler
gem 'rack-mini-profiler'
gem 'flamegraph'
......@@ -111,11 +111,8 @@ group :development, :test do
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'sqlite3'
#JavaScript runtime
gem 'execjs'
end
group :test do
......
......@@ -14,6 +14,8 @@ class ScoreCalculatorService
def reputation(values = nil)
values = reputation_hash if values.nil?
values = values.with_indifferent_access
sum = 0
Score.all.find_each do |score|
......@@ -24,7 +26,7 @@ class ScoreCalculatorService
sum += (values[score.code].to_f / max) * score.weight.to_f
end
sum.to_f / sum_weights.to_f
(sum.to_f / sum_weights.to_f).round(3)
end
private
......
require 'test_helper'
class FeedbackControllerTest < ActionController::TestCase
test "should get new_feedback" do
get :new_feedback
assert_response :success
end
test "should get new_bug" do
get :new_bug
assert_response :success
end
test "should get create" do
get :create
assert_response :success
end
test "should get report_bug" do
get :report_bug
assert_response :success
end
end
require 'test_helper'
class LearningObject::ChunksControllerTest < ActionController::TestCase
test "should get show" do
get :show
assert_response :success
end
test "should get create" do
get :create
assert_response :success
end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
<% 1.upto(5000) do |i| %>
bookmark_top_<%= i %>:
user: user_<%= i %>
bookmarkable: lo_top (LearningObject)
<% end %>
<% 1.upto(3000) do |i| %>
bookmark_joao_<%= i %>:
user: joao
bookmarkable: lo_test_<%= i %> (LearningObject)
<% end %>
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
title: MyString
url: MyText
two:
title: MyString
url: MyText
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
<% 1.upto(20000) do |i| %>
collection_test_<%= i %>:
name: 'lo_test_<%= i %>'
description: 'hue hue hue test <%= i %>'
created_at: 2016-01-28 09:51:07
views: <% 1.upto(9999) do |i| %>view_<%= i %>,<% end %>view_10000
likes: <% 1.upto(2799) do |i| %>like_<%= i %>,<% end %>like_2800
downloads: <% 1.upto(5999) do |i| %>download_<%= i %>,<% end %>download_6000
shares: <% 1.upto(2999) do |i| %>share_<%= i %>,<% end %>share_3000
<% end %>
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
reason: MyText
two:
reason: MyText
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
description: MyText
two:
description: MyText
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
<% 1.upto(10000) do |i| %>
download_<%= i %>:
date: 2016-01-28 09:51:07
<% end %>
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
two:
name: MyString
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
user_id:
message: MyText
two:
user_id:
message: MyText
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
<% 1.upto(20000) do |i| %>
follow_<%= i %>:
user:
followable:
<% end %>
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
address: MyString
city: MyString
country: MyString
description: MyText
two:
name: MyString
address: MyString
city: MyString
country: MyString
description: MyText
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
link: MyString
retrieve_link: MyString
description: MyText
format: MyString
mime_type: MyString
size: 1
bundle_name: MyString
learning_object_id:
two:
name: MyString
link: MyString
retrieve_link: MyString
description: MyText
format: MyString
mime_type: MyString
size: 1
bundle_name: MyString
learning_object_id:
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
lo1:
name: 'lo1'
description: 'hue hue hue 1'
reviews:
thumbnail: ''
score: 0.0
created_at: 2016-01-28 09:51:07
views: <% 1.upto(9999) do |i| %>view_<%= i %>,<% end %>view_10000
likes: <% 1.upto(2799) do |i| %>like_<%= i %>,<% end %>like_2800
downloads: <% 1.upto(5999) do |i| %>download_<%= i %>,<% end %>download_6000
shares: <% 1.upto(2999) do |i| %>share_<%= i %>,<% end %>share_3000
lo_top:
name: 'lo_top'
description: 'hue hue hue top'
reviews:
thumbnail: ''
score: 0.0
created_at: 2016-01-28 09:51:07
views: <% 1.upto(19999) do |i| %>view_<%= i %>,<% end %>view_20000
likes: <% 1.upto(3499) do |i| %>like_<%= i %>,<% end %>like_3500
downloads: <% 1.upto(7999) do |i| %>download_<%= i %>,<% end %>download_8000
shares: <% 1.upto(3999) do |i| %>share_<%= i %>,<% end %>share_4000
<% 1.upto(10000) do |i| %>
lo_test_<%= i %>:
name: 'lo_test_<%= i %>'
description: 'hue hue hue test <%= i %>'
thumbnail: ''
created_at: 2016-01-28 09:51:07
views: <% 1.upto(9999) do |i| %>view_<%= i %>,<% end %>view_10000
likes: <% 1.upto(2799) do |i| %>like_<%= i %>,<% end %>like_2800
downloads: <% 1.upto(5999) do |i| %>download_<%= i %>,<% end %>download_6000
shares: <% 1.upto(2999) do |i| %>share_<%= i %>,<% end %>share_3000
<% end %>
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
<% 1.upto(10000) do |i| %>
like_<%= i %>:
date: 2016-01-28 09:51:07
<% end %>
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
key: MyString
value: MyText
language: MyString
two:
key: MyString
value: MyText
language: MyString
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
approves: false
user_id:
review_id:
two:
approves: false
user_id:
review_id:
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
two:
name: MyString
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
review:
rating:
two:
review:
rating:
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
description: MyText
pros: MyText
cons: MyText
reviewable_id:
two:
name: MyString
description: MyText
pros: MyText
cons: MyText
reviewable_id:
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
admin:
name: admin
description: MyText
teacher:
name: teacher
description: MyText
curator:
name: curator
description: MyText
\ No newline at end of file
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
<%
values = [
[ 0, 0, 0, 0, 0, 0, 0, 0, 0], # Iniciante
[ 25, 3.0, 10, 500, 250, 70, 50, 5, 400], # Novato
[ 50, 3.8, 20, 550, 350, 85, 250, 15, 600], # Amador
[ 100, 4.2, 40, 600, 450, 90, 1000, 25, 750], # Profissional
[ 250, 4.9, 80, 680, 550, 95, 5000, 35, 800] # Expert
]
%>
one:
score_id:
user_category_id:
value: 1
two:
score_id:
user_category_id:
value: 1
<% 1.upto(values.first.size) do |i| %>
<% 1.upto(values.size) do |j| %>
<%= i %>_<%= j %>:
score: <%= i %>
user_category: <%= j %>
value: <%= values[j-1][i-1] %>
<% end %>
<% end %>
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
code: MyString
weight: 1
active: false
two:
name: MyString
code: MyString
weight: 1
active: false
1:
name: 'Quantidade de envio de objetos'
code: 'reputation_submitted'
weight: 4
active: true
2:
name: 'Avaliação média dos seus objetos'
code: 'reputation_reviews_average_score'
weight: 9
active: true
3:
name: 'Adições a coleções bem avaliadas'
code: 'reputation_added_in_best_collections'
weight: 7
active: true
4:
name: 'Melhor score'
code: 'reputation_best_score'
weight: 3
active: true
5:
name: 'Score médio'
code: 'reputation_average_score'
weight: 7
active: true
6:
name: 'Aprovação das avaliações em objetos de terceiros (% de sim)'
code: 'reputation_reviews_rate'
weight: 10
active: true
# reputation_confirmed_complaints:
# name: 'Denúncias confirmadas'
# code: 'reputation_confirmed_complaints'
# weight: 0
# active: true
7:
name: 'Quantidade de seguidores'
code: 'reputation_followers'
weight: 6
active: true
8:
name: 'Submissões recentes'
code: 'reputation_submitted_recently'
weight: 4
active: true
9:
name: 'Score das coleções públicas'
code: 'reputation_collection_score'
weight: 3
active: true
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
<% 1.upto(10000) do |i| %>
share_<%= i %>:
date: 2016-01-28 09:51:07
<% end %>
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
two:
name: MyString
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
subject_id:
learning_object_id:
two:
subject_id:
learning_object_id:
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
1:
name: 'Iniciante'
reference: 0.0
one:
name: MyString
2:
name: 'Novato'
reference: 0.408919891329286
two:
name: MyString
3:
name: 'Amador'
reference: 0.558910604053845
4:
name: 'Profissional'
reference: 0.708149893070887
5:
name: 'Expert'
reference: 1.0
joao:
name: 'João'
email: 'joao@teste.br'
score: '0.0'
learning_objects: lo1, lo2, lo3
<% 1.upto(10000) do |i| %>
user_<%= i %>:
name: 'user test <%= i %>'
email: 'user_test_<%= i %>@test.com'
<% end %>
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
<% 1.upto(20000) do |i| %>
view_<%= i %>:
date: 2016-01-28 09:51:07
<% end %>
require 'test_helper'
class ComplaintMessageTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class FeedbackRatingTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class FeedbackTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class MetadatumTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class RoleTest < ActiveSupport::TestCase
should have_and_belong_to_many(:users)
should validate_uniqueness_of(:name)
should validate_presence_of(:name)
# should have_and_belong_to_many(:users)
# should validate_uniqueness_of(:name)
# should validate_presence_of(:name)
end
require 'test_helper'
class SubjectTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class UserTest < ActiveSupport::TestCase
should have_and_belong_to_many(:roles)
should validate_uniqueness_of(:email)
# should have_and_belong_to_many(:roles)
# should validate_uniqueness_of(:email)
end
require 'test_helper'
class ScoreCalculatorServiceTest < ActiveSupport::TestCase
# def setup
#
# end
test 'reputation calculation' do
hash_stub = {
'reputation_submitted': 60,
'reputation_reviews_average_score': 4.8,
'reputation_added_in_best_collections': 4,
'reputation_best_score': 736,
'reputation_average_score': 680,
'reputation_reviews_rate': 98,
# 'reputation_confirmed_complaints': ,
'reputation_followers': 300,
'reputation_submitted_recently': 5,
'reputation_collection_score': 700
}
calculator = ScoreCalculatorService.new(mock)
calculator.stub :reputation_hash, hash_stub do
p Score.all.each {|s| p "#{s.score_user_categories.map(&:value).inspect}\n\n" }
assert_equal 0.677, calculator.reputation
end
end
end
......@@ -3,12 +3,14 @@ require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'shoulda-callback-matchers'
require 'minitest/mock'
require 'repository/not_persisted_record_error'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# load seeds
# Rails.application.load_seed
# Add more helper methods to be used by all tests here...
def assert_count(expected, actual = 0)
......@@ -19,4 +21,8 @@ class ActiveSupport::TestCase
MiniTest::Mock.new
end
# config.after :all do
# ActiveRecord::Base.subclasses.each(&:delete_all)