Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolved #151 #267

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
14 changes: 10 additions & 4 deletions app/models/issue.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
class Issue < ActiveRecord::Base
before_save :set_sub_id

# This is to avoid conflict with the :type attribute
self.inheritance_column = nil

belongs_to :user
belongs_to :project

validates_presence_of :title, :description, :user, :project, :type, :status
validates_presence_of :sub_id, unless: :set_sub_id
validates :sub_id, uniqueness: { scope: :project }

# TODO: make a list of 5 most popular types of issues
# people can raise on design projects.
Expand Down Expand Up @@ -42,11 +46,13 @@ def show_url
File.join(project.urlbase, 'issue', sub_id.to_s)
end

def sub_id
(project.issue_ids.index(id) + 1).to_i
def self.find_from_project(project, sub_id)
project.issues.find_by_sub_id(sub_id)
end

def self.find_from_project(project, sub_id)
Issue.find(project.issue_ids[sub_id.to_i - 1])
def set_sub_id
return if sub_id
sub_id = project.issues.count + 1
update_attribute(:sub_id, sub_id)
end
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, your rubocop is failing. We use two spaces for indentation. If you are going to use tabs please configure your editor so that it uses 2 spaces as tabs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed that :)

5 changes: 5 additions & 0 deletions db/migrate/20150318141041_add_sub_id_to_issues.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddSubIdToIssues < ActiveRecord::Migration
def change
add_column :issues, :sub_id, :integer
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150312234604) do
ActiveRecord::Schema.define(version: 20150318141041) do

create_table "comments", force: true do |t|
t.text "body"
Expand Down Expand Up @@ -66,6 +66,7 @@
t.integer "type"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "sub_id"
end

create_table "notification_statuses", force: true do |t|
Expand Down