Skip to content

Commit

Permalink
Order contributor's projects by update date;
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomaiavieira committed Nov 29, 2011
1 parent 09c20b4 commit b47d79e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/models/comment.rb
@@ -1,5 +1,5 @@
class Comment < ActiveRecord::Base
belongs_to :task
belongs_to :task, :touch => true # TODO: Test the touch
belongs_to :contributor
end

2 changes: 1 addition & 1 deletion app/models/contributor.rb
Expand Up @@ -20,7 +20,7 @@ class Contributor < ActiveRecord::Base
validates_format_of :username, :with => /^\w*$/

def projects
own_projects + contributions
(own_projects + contributions).sort { |x, y| y[:updated_at] <=> x[:updated_at] }
end

protected
Expand Down
2 changes: 1 addition & 1 deletion app/models/task.rb
@@ -1,5 +1,5 @@
class Task < ActiveRecord::Base
belongs_to :project
belongs_to :project, :touch => true # TODO: Test the touch
belongs_to :category
has_and_belongs_to_many :contributors, :join_table => :contributors_tasks
has_many :comments, :dependent => :delete_all
Expand Down
19 changes: 11 additions & 8 deletions app/views/contributors/dashboard.html.slim
@@ -1,13 +1,16 @@
.page-header
h1 Your projects

ul
- current_contributor.projects.each do |project|
li
= link_to project.name, project_board_path(project)
br
= project.description
- if current_contributor.projects.empty?
p You don't have projects yet. #{link_to 'Create your first project!', new_project_path}
br
- else
ul
- current_contributor.projects.each do |project|
li
= link_to project.name, project_board_path(project)
br
= project.description

p
= link_to 'New project', new_project_path, :class => 'btn primary'
= link_to 'New project', new_project_path, :class => 'btn primary'

2 changes: 2 additions & 0 deletions app/views/layouts/application.html.erb
Expand Up @@ -24,6 +24,8 @@
<% current_contributor.projects.each do |project| %>
<li><%= link_to project.name, project_board_path(project) %></li>
<% end %>
<li class="divider"></li>
<li><%= link_to 'New project', new_project_path %></li>
</ul>
</li>
<li><%= link_to 'Sign out', destroy_contributor_session_path, :method => :delete %></li>
Expand Down
2 changes: 1 addition & 1 deletion app/views/projects/_form.html.slim
Expand Up @@ -7,7 +7,7 @@
li= msg

= f.input :name, :input_html => { :autofocus => true }
= f.input :description
= f.input :description, :input_html => {:class => :span7}
= f.input :contributor_tokens, :label => 'Contributors', \
:input_html => { 'data-pre' => @project.contributors_for_token_input }

Expand Down
7 changes: 5 additions & 2 deletions spec/models/contributor_spec.rb
Expand Up @@ -10,15 +10,18 @@
lambda { project_1.reload }.should raise_error ActiveRecord::RecordNotFound
end

it 'should return all projects, including his own and others the he contribute' do
it 'should return all projects, including his own and others the he contribute, ordered by update date' do
hugo = Factory.create :contributor
rodrigo = Factory.create :contributor
my_project = Factory.create :project, :owner => hugo
our_project = Factory.create :project, :owner => rodrigo, :contributors => [hugo]
other_project = Factory.create :project, :owner => rodrigo
hugo.reload
hugo.projects.should include(my_project, our_project)
hugo.projects.should_not include(other_project)
hugo.projects.should == [our_project, my_project]
my_project.update_attribute(:name, 'Changed name')
hugo.reload
hugo.projects.should == [my_project, our_project]
end

context 'validates' do
Expand Down

0 comments on commit b47d79e

Please sign in to comment.