diff --git a/app/models/score.rb b/app/models/score.rb new file mode 100644 index 0000000000000000000000000000000000000000..cd2f1acf5a3885a2a9afcfb17ce8b6d9de2a63df --- /dev/null +++ b/app/models/score.rb @@ -0,0 +1,7 @@ +class Score < ActiveRecord::Base + has_many :score_user_categories, dependent: :destroy + has_many :user_categories, through: :score_user_categories + + validates_presence_of :name, :code, :weight + validates_uniqueness_of :code +end diff --git a/app/models/score_user_category.rb b/app/models/score_user_category.rb new file mode 100644 index 0000000000000000000000000000000000000000..9d701e717f0d2be1cd40e286a8fc2fde08a0a2a4 --- /dev/null +++ b/app/models/score_user_category.rb @@ -0,0 +1,7 @@ +class ScoreUserCategory < ActiveRecord::Base + belongs_to :score + belongs_to :user_category + + validates_presence_of :score, :user_category, :value + validates_uniqueness_of :user_category, scope: :score +end diff --git a/app/models/user_category.rb b/app/models/user_category.rb new file mode 100644 index 0000000000000000000000000000000000000000..dec0e310c6de38e1cf8f8c5bad8bad87895fe2a9 --- /dev/null +++ b/app/models/user_category.rb @@ -0,0 +1,7 @@ +class UserCategory < ActiveRecord::Base + has_many :score_user_categories, dependent: :destroy + has_many :scores, through: :score_user_categories + + validates_presence_of :name + validates_uniqueness_of :name +end diff --git a/db/migrate/20160222144157_create_scores.rb b/db/migrate/20160222144157_create_scores.rb new file mode 100644 index 0000000000000000000000000000000000000000..d92548521d6b3e566eb61abc2ce27d1525257814 --- /dev/null +++ b/db/migrate/20160222144157_create_scores.rb @@ -0,0 +1,12 @@ +class CreateScores < ActiveRecord::Migration + def change + create_table :scores do |t| + t.string :name + t.string :code + t.integer :weight + t.boolean :active, default: true + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160222144216_create_user_categories.rb b/db/migrate/20160222144216_create_user_categories.rb new file mode 100644 index 0000000000000000000000000000000000000000..0b1594c62e1c516a8cae691f9d4666d0f55dcbfa --- /dev/null +++ b/db/migrate/20160222144216_create_user_categories.rb @@ -0,0 +1,9 @@ +class CreateUserCategories < ActiveRecord::Migration + def change + create_table :user_categories do |t| + t.string :name + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160222144259_create_score_user_categories.rb b/db/migrate/20160222144259_create_score_user_categories.rb new file mode 100644 index 0000000000000000000000000000000000000000..6367e0dcb79a38eada1125607d1b308a2ac5296f --- /dev/null +++ b/db/migrate/20160222144259_create_score_user_categories.rb @@ -0,0 +1,13 @@ +class CreateScoreUserCategories < ActiveRecord::Migration + def change + create_table :score_user_categories do |t| + t.references :score, index: true + t.references :user_category, index: true + t.integer :value + + t.timestamps null: false + end + add_foreign_key :score_user_categories, :scores + add_foreign_key :score_user_categories, :user_categories + end +end diff --git a/db/seeds.rb b/db/seeds.rb index ee558cb63cf5a8044867d9f75b5f6fa2fe02e358..916611b8b8e911fdc9e148324dd05c6a324f2f97 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -22,3 +22,4 @@ require_relative "seeds/complaints" require_relative "seeds/institutions" require_relative "seeds/languages" require_relative "seeds/ratings" +require_relative "seeds/scores" diff --git a/db/seeds/scores.rb b/db/seeds/scores.rb new file mode 100644 index 0000000000000000000000000000000000000000..9e1b66e1bc5abd30c2e9c4258f93fd2808eb0908 --- /dev/null +++ b/db/seeds/scores.rb @@ -0,0 +1,27 @@ +# objects + +# reputation +Score.first_or_create(name: 'Quantidade de envio de objetos', code: 'reputation_submitted', weight: 4) +Score.first_or_create(name: 'Avaliação média dos seus objetos', code: 'reputation_reviews_average_score', weight: 9) +Score.first_or_create(name: 'Adições a coleções bem avaliadas', code: 'reputation_added_in_best_collections', weight: 7) +Score.first_or_create(name: 'Melhor score', code: 'reputation_best_score', weight: 3) +Score.first_or_create(name: 'Score médio', code: 'reputation_average_score', weight: 7) +Score.first_or_create(name: 'Aprovação das avaliações em objetos de terceiros (% de sim)', code: 'reputation_reviews_rate', weight: 10) +# Score.first_or_create(name: 'Denúncias confirmadas', code: 'reputation_', weight: 0) +Score.first_or_create(name: 'Quantidade de seguidores', code: 'reputation_followers', weight: 6) +Score.first_or_create(name: 'Submissões recentes', code: 'reputation_submitted_recently', weight: 4) +Score.first_or_create(name: 'Score das coleções públicas', code: 'reputation_collection_score', weight: 3) + +# [ +# [ 25, 3.0, 10, 500, 250, 70, 50, 5, 400], # Iniciante +# [ 50, 3.8, 20, 550, 350, 85, 250, 15, 600], # Novato +# [ 100, 4.2, 40, 600, 450, 90, 1000, 25, 750], # Amador +# [ 250, 4.9, 80, 680, 550, 95, 5000, 35, 800] # Expert +# ] + +# reputation categories +UserCategory.first_or_create(name: 'Iniciante') +UserCategory.first_or_create(name: 'Novato') +UserCategory.first_or_create(name: 'Amador') +UserCategory.first_or_create(name: 'Profissional') +UserCategory.first_or_create(name: 'Expert') diff --git a/test/fixtures/score_user_categories.yml b/test/fixtures/score_user_categories.yml new file mode 100644 index 0000000000000000000000000000000000000000..8b48ec7eac837b9208529a5480b336b045e3a0a0 --- /dev/null +++ b/test/fixtures/score_user_categories.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + score_id: + user_category_id: + value: 1 + +two: + score_id: + user_category_id: + value: 1 diff --git a/test/fixtures/scores.yml b/test/fixtures/scores.yml new file mode 100644 index 0000000000000000000000000000000000000000..bd103ffc7b605d6340700a90e69a8e3750ad9d49 --- /dev/null +++ b/test/fixtures/scores.yml @@ -0,0 +1,13 @@ +# 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 diff --git a/test/fixtures/user_categories.yml b/test/fixtures/user_categories.yml new file mode 100644 index 0000000000000000000000000000000000000000..56066c68af42f307f5780e9ac146e3651cea3979 --- /dev/null +++ b/test/fixtures/user_categories.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + +two: + name: MyString diff --git a/test/models/score_test.rb b/test/models/score_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..d38cb0a3c55492dad6707691aa49fa19fb9b7987 --- /dev/null +++ b/test/models/score_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ScoreTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/score_user_category_test.rb b/test/models/score_user_category_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..bd5bf9f3167904855c052af49b181f97a25019aa --- /dev/null +++ b/test/models/score_user_category_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ScoreUserCategoryTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/user_category_test.rb b/test/models/user_category_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..4cdbac46363829d8f97cff9140dd589eb4ba466b --- /dev/null +++ b/test/models/user_category_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserCategoryTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end