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
Open

resolved #151 #267

wants to merge 12 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Mar 18, 2015

I added the sub_id attribute on the issue model instead of calling a lot of queries to retrieve it from the project model.

@sarupbanskota
Copy link
Contributor

@AhmedZaleh could you pull from master? @rohitpaulk this addresses #151, so I'm assigning you for review.

@ghost
Copy link
Author

ghost commented Mar 18, 2015

I rebased my commit, please review and merge.

def set_sub_id
current_id = project.issues.count
update_attribute(:sub_id, current_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 :)

@rohitpaulk
Copy link
Member

There's a lot more to do here. You've added a sub_id, but you aren't using it anywhere. I'll add a few comments inline pointing to the functions

@@ -49,4 +51,9 @@ def sub_id
def self.find_from_project(project, sub_id)
Issue.find(project.issue_ids[sub_id.to_i - 1])
Copy link
Member

Choose a reason for hiding this comment

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

This should be modified, and the sub_id method should be deleted.

Also, please add validations that check the presence and uniqueness of 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
Copy link
Member

Choose a reason for hiding this comment

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

Since this is run before saving, we should set it equal to project.issues.count + 1

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that's right. Thanks a lot :)

@rohitpaulk
Copy link
Member

Please add validations too, we need to make sure that issues aren't saved to the database without a sub_id. We'll need validations for both presence and uniqueness, and a couple of tests that check that they work.

@ghost
Copy link
Author

ghost commented Mar 21, 2015

I know I must validate the presence but how can I validate the uniqueness inside project.issues ? I mean project1.issues.first.sub_id = 1 and project2.issues.first.sub_id = 1 so I cannot use validate_uniqueness_of :sub_id that way. I think I can define a method to ensure sub_id uniqueness inside project.issues but what if I have duplicates what should I set the duplicate sub_id to ? Should I just increment it by 1 or there is another different way?

@Alwahsh
Copy link
Collaborator

Alwahsh commented Mar 21, 2015

@AhmedZaleh you can use:

validates :sub_id, uniqueness: { scope: :project }

@ghost
Copy link
Author

ghost commented Mar 21, 2015

@Alwahsh Thanks a lot :)

@Alwahsh
Copy link
Collaborator

Alwahsh commented Mar 21, 2015

np :)

@rohitpaulk
Copy link
Member

This is still marked as in progress, we'll need tests before we can merge this in.

@Alwahsh
Copy link
Collaborator

Alwahsh commented Apr 9, 2015

@rohitpaulk I've created some tests that would be enough to test this change I believe in #292... I'd recommend a squash of commits though :)

@rohitpaulk rohitpaulk removed their assignment Apr 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants