aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-04-05 16:05:36 +0200
committerFabrice Bellingard <bellingard@gmail.com>2011-04-20 08:39:18 +0200
commit7cb5ce119e44197ff9fbcc3b9e804335e781a344 (patch)
tree2eb41c469d1b61623a7df71ff895f818154d4c1e
parent816e1b7fe7a090bd607928b2ee13f90a7da52467 (diff)
downloadsonarqube-7cb5ce119e44197ff9fbcc3b9e804335e781a344.tar.gz
sonarqube-7cb5ce119e44197ff9fbcc3b9e804335e781a344.zip
[SONAR-1973] Add first model of review concept
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/review.rb22
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/review_data.rb16
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/190_create_review.rb14
3 files changed, 23 insertions, 29 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
index 9f97d1a096f..c271a3115d6 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
@@ -18,18 +18,18 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
#
class Review < ActiveRecord::Base
- belongs_to :users
- belongs_to :rule_failures
- belongs_to :projects, :class_name => 'Project', :foreign_key => 'resource_id'
- has_many :review_datas, :dependent => :destroy
+ belongs_to :user
+ belongs_to :rule_failure
+ belongs_to :resource, :class_name => 'Project', :foreign_key => 'resource_id'
+ has_many :review_data, :order => created_at, :dependent => :destroy
+ validates_presence_of :user
+ validates_presence_of :review_type
+ validates_presence_of :status
+ validate :review_must_have_at_least_one_comment
-
-
- def inherited?
- inheritance=='INHERITED'
+ def review_must_have_at_least_one_comment
+ errors.add("A review must have at least one comment.") if
+ review_data.length < 1
end
- def overrides?
- inheritance=='OVERRIDES'
- end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/review_data.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/review_data.rb
index d4bb18dbc31..7933d7f8187 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/review_data.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/review_data.rb
@@ -18,16 +18,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
#
class ReviewData < ActiveRecord::Base
- belongs_to :users
- belongs_to :reviews
+ belongs_to :user
+ belongs_to :review
+ validates_presence_of :user
+ validates_presence_of :review
+ validates_length_of :review_text, :minimum => 1, :too_short => "Your review cannot be empty."
-
-
- def inherited?
- inheritance=='INHERITED'
- end
-
- def overrides?
- inheritance=='OVERRIDES'
- end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/190_create_review.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/190_create_review.rb
index 9a00f93f888..a7a03a251fd 100644
--- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/190_create_review.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/190_create_review.rb
@@ -25,10 +25,10 @@ class CreateReview < ActiveRecord::Migration
def self.up
create_table 'reviews' do |t|
- t.column 'user_id', :integer
t.column 'created_at', :datetime
- t.column 'review_type', :string, :limit => 20
- t.column 'status', :string, :limit => 20
+ t.column 'user_id', :integer, :null => true
+ t.column 'review_type', :string, :null => true, :limit => 10
+ t.column 'status', :string, :null => true, :limit => 10
t.column 'severity', :integer, :null => true
t.column 'external_link', :string, :null => true, :limit => 200
t.column 'rule_failure_id', :integer, :null => true
@@ -36,11 +36,11 @@ class CreateReview < ActiveRecord::Migration
t.column 'resource_line', :integer, :null => true
end
- create_table 'review_datas' do |t|
- t.column 'user_id', :integer
- t.column 'review_id', :integer
+ create_table 'review_data' do |t|
t.column 'created_at', :datetime
- t.column 'review_text', :string, :limit => 5000
+ t.column 'review_id', :integer
+ t.column 'user_id', :integer, :null => true
+ t.column 'review_text', :text, :null => true
end
end