Permalink
Browse files

Model cleanup for the issues feature.

  • Loading branch information...
1 parent c510f9e commit a8971f5cbe8545fff087907e062e1216c749391b @pwnall committed Apr 1, 2012
View
@@ -1,7 +1,35 @@
+# Entity that needs to be tracked (e.g. bug or feature) associated with a repo.
class Issue < ActiveRecord::Base
+ # The repository that this issue refers to.
belongs_to :repository, :inverse_of => :issues
- belongs_to :profile, :inverse_of => :issues
+ validates :repository, :presence => true
+ # The profile of the user who opened this issue.
+ belongs_to :author, :class_name => 'Profile', :inverse_of => :issues
+ validates :author, :presence => true
+
+ # One-line summary of the issue.
+ validates :title, :length => 1..160, :presence => true
+
+ # Full description of the issue, including repro steps, desired behavior, etc.
+ validates :description, :length => { :maximum => 1.kilobyte },
+ :exclusion => [nil]
+
+ # True for issues that still require attention.
+ validates :open, :inclusion => { :in => [true, false] }
+end
+
+# :nodoc: access control
+class Issue
+ # TODO(christy13): Verify this is the logic desired
+ def can_edit?(author_profile)
+ @repository.can_edit?(author_profile) or @profile == author_profile
+ end
+end
+
+
+# :nodoc: activity feed integration
+class Issue
# Profiles following this issue.
has_many :subscribers, :through => :subscriber_feed_subscriptions,
:source => :profile
@@ -23,18 +51,6 @@ class Issue < ActiveRecord::Base
has_many :feed_item_topic, :as => :topic, :dependent => :destroy,
:inverse_of => :topic
- validates :title, :length => 1..32, :presence => true
-
- # TODO: Verify this is the logic desired
- def can_edit?(author_profile)
- @repository.can_edit? author_profile or @profile == author_profile
- end
-
- # Virtual attribute, backed by profile_id.
- def profile_name
- @profile_name ||= profile && profile.name
- end
-
# Updates feeds to reflect that this issue was created.
def publish_creation(author_profile)
# Duplicating the profile and issue title because the issue record
@@ -52,4 +68,4 @@ def publish_deletion(author_profile)
:repo_name => self.repository,
:issue_title => self.title }
end
-end
+end
@@ -12,8 +12,9 @@ class Profile < ActiveRecord::Base
:dependent => :destroy,
:inverse_of => :principal
- # Issues
- has_many :issues, :inverse_of => :profile, :dependent => :destroy
+ # The issues opened by the user behind this profile.
+ has_many :issues, :inverse_of => :author, :foreign_key => 'author_id',
+ :dependent => :destroy
# The ACL entries shown in the ACL editing UI.
def acl_entries
@@ -30,7 +30,7 @@ def profile_name=(new_profile_name)
has_many :acl_entries, :as => :subject, :dependent => :destroy,
:inverse_of => :subject
- # Issues
+ # The issues created against this repository.
has_many :issues, :inverse_of => :repository, :dependent => :destroy
# The repository name.
@@ -1,13 +1,16 @@
class CreateIssues < ActiveRecord::Migration
def change
create_table :issues do |t|
- t.integer :profile_id, :null => false
- t.integer :repository_id, :null => false
- t.boolean :open, :default => true
- t.string :title, :length => 32
- t.text :description, :length => 1.kilobyte
+ t.references :repository, :null => false
+ t.references :author, :null => false
+ t.boolean :open, :default => true, :null => false
+ t.string :title, :length => 160, :null => false
+ t.text :description, :length => 1.kilobyte, :null => false
t.timestamps
end
+
+ add_index :issues, [:author_id, :open], :unique => false, :null => false
+ add_index :issues, [:repository_id, :open], :unique => false, :null => false
end
end
View
@@ -139,15 +139,18 @@
add_index "feed_subscriptions", ["topic_id", "topic_type", "profile_id"], :name => "index_feed_subscriptions_on_topic_profile", :unique => true
create_table "issues", :force => true do |t|
- t.integer "profile_id", :null => false
+ t.integer "author_id", :null => false
t.integer "repository_id", :null => false
- t.boolean "open", :default => true
- t.string "title"
- t.text "description"
+ t.boolean "open", :default => true, :null => false
+ t.string "title", :null => false
+ t.text "description", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
+ add_index "issues", ["author_id", "open"], :name => "index_issues_on_author_id_and_open"
+ add_index "issues", ["repository_id", "open"], :name => "index_issues_on_repository_id_and_open"
+
create_table "profiles", :force => true do |t|
t.string "name", :limit => 32, :null => false
t.string "display_name", :limit => 128, :null => false
@@ -1,15 +1,6 @@
-# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
-
-one:
- profile_id: 1
- repository_id: 1
- open: false
- title: MyString
- description: MyText
-
-two:
- profile_id: 1
- repository_id: 1
- open: false
- title: MyString
- description: MyText
+costan_ghost_translated:
+ author: dexter
+ repository: costan_ghost
+ open: true
+ title: Missing translation
+ description: The text files in this project are English-only. It would be nice if they had translations.
@@ -1,7 +1,54 @@
require 'test_helper'
class IssueTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
+ setup do
+ @repo = repositories(:costan_ghost)
+ @issue = Issue.new :repository => @repo, :author => profiles(:dexter),
+ :open => true, :title => 'Crashes on OSX',
+ :description => 'Running Lion 10.7'
+ end
+
+ test 'setup' do
+ assert @issue.valid?
+ end
+
+ test 'requires repository' do
+ @issue.repository = nil
+ assert !@issue.valid?
+ end
+
+ test 'requires author' do
+ @issue.author = nil
+ assert !@issue.valid?
+ end
+
+ test 'requires title' do
+ @issue.title = nil
+ assert !@issue.valid?
+ end
+
+ test 'requires non-empty title' do
+ @issue.title = ''
+ assert !@issue.valid?
+ end
+
+ test 'requires description' do
+ @issue.description = nil
+ assert !@issue.valid?
+ end
+
+ test 'accepts empty description' do
+ @issue.description = ''
+ assert @issue.valid?
+ end
+
+ test 'requires open' do
+ @issue.open = nil
+ assert !@issue.valid?
+ end
+
+ test 'accepts open=false' do
+ @issue.open = false
+ assert @issue.valid?
+ end
end

0 comments on commit a8971f5

Please sign in to comment.