Commit f61d401ec8f1d11b47a71ab590f81c7190c0c314

Authored by Fabio Teixeira
1 parent ebd4f04a
Exists in temp_ratings

Add ratings from persons to communities

Signed-off-by: DylanGuedes <djmgguedes@gmail.com>
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Filipe Ribeiro <firibeiro77@live.com>
plugins/communities_ratings/db/migrate/20150701122801_create_community_ratings.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class CreateCommunityRatings < ActiveRecord::Migration
  2 + def change
  3 + create_table :community_ratings do |t|
  4 + t.belongs_to :community
  5 + t.belongs_to :person
  6 + t.integer :value
  7 +
  8 + t.timestamps
  9 + end
  10 + end
  11 +end
... ...
plugins/communities_ratings/lib/communities_ratings_plugin.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +class CommunitiesRatingsPlugin < Noosfero::Plugin
  2 +
  3 + def self.plugin_name
  4 + # FIXME
  5 + "CommunitiesRatingsPlugin"
  6 + end
  7 +
  8 + def self.plugin_description
  9 + # FIXME
  10 + _("A plugin that does this and that.")
  11 + end
  12 +end
... ...
plugins/communities_ratings/lib/community_rating.rb 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +class CommunityRating < ActiveRecord::Base
  2 + belongs_to :person
  3 + belongs_to :community
  4 +
  5 + attr_accessible :value, :person, :community
  6 +
  7 + validates :value,
  8 + :presence => true, :inclusion => {
  9 + in: 0..5, message: _("must be between 0 and 5")
  10 + }
  11 +
  12 + validates :community_id, :person_id,
  13 + :presence => true
  14 +
  15 +end
... ...
plugins/communities_ratings/lib/ext/community.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +require_dependency 'community'
  2 +
  3 +Community.class_eval do
  4 + has_many :community_ratings
  5 +end
0 6 \ No newline at end of file
... ...
plugins/communities_ratings/lib/ext/person.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +require_dependency 'person'
  2 +
  3 +Person.class_eval do
  4 + has_many :community_ratings
  5 +end
... ...
plugins/communities_ratings/test/unit/community_rating_test.rb 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +require 'test_helper'
  2 +
  3 +class CommunityRatingTest < ActiveSupport::TestCase
  4 + test "The value must be between 0 and 5" do
  5 + cr1 = CommunityRating.new :value => -1
  6 + cr2 = CommunityRating.new :value => 6
  7 +
  8 + assert_equal false, cr1.valid?
  9 + assert_equal false, cr2.valid?
  10 +
  11 + assert_equal true, cr1.errors[:value].include?("must be between 0 and 5")
  12 + assert_equal true, cr2.errors[:value].include?("must be between 0 and 5")
  13 + end
  14 +end
... ...