Added project has_one :last_event assoc. Fixed tab line-height after font-awesome. Increased projects per page on dashboard

This commit is contained in:
randx 2012-10-17 22:02:52 +03:00
parent a9a3480de9
commit e0c43c46dd
4 changed files with 10 additions and 11 deletions

View file

@ -46,6 +46,9 @@
color:#888; color:#888;
text-shadow:0 1px 1px #fff; text-shadow:0 1px 1px #fff;
} }
i[class^="icon-"] {
line-height:14px;
}
} }
&.active { &.active {
> a { > a {

View file

@ -4,7 +4,7 @@ class DashboardController < ApplicationController
def index def index
@groups = Group.where(id: current_user.projects.pluck(:group_id)) @groups = Group.where(id: current_user.projects.pluck(:group_id))
@projects = current_user.projects_with_events @projects = current_user.projects_with_events
@projects = @projects.page(params[:page]).per(20) @projects = @projects.page(params[:page]).per(30)
@events = Event.in_projects(current_user.project_ids).limit(20).offset(params[:offset] || 0) @events = Event.in_projects(current_user.project_ids).limit(20).offset(params[:offset] || 0)
@last_push = current_user.recent_push @last_push = current_user.recent_push

View file

@ -25,6 +25,7 @@ class Project < ActiveRecord::Base
has_many :hooks, dependent: :destroy, class_name: "ProjectHook" has_many :hooks, dependent: :destroy, class_name: "ProjectHook"
has_many :wikis, dependent: :destroy has_many :wikis, dependent: :destroy
has_many :protected_branches, dependent: :destroy has_many :protected_branches, dependent: :destroy
has_one :last_event, class_name: 'Event', order: 'events.created_at DESC', foreign_key: 'project_id'
delegate :name, to: :owner, allow_nil: true, prefix: true delegate :name, to: :owner, allow_nil: true, prefix: true
@ -141,15 +142,11 @@ class Project < ActiveRecord::Base
end end
def last_activity def last_activity
events.order("created_at ASC").last last_event
end end
def last_activity_date def last_activity_date
if events.last last_event.try(:created_at) || updated_at
events.last.created_at
else
updated_at
end
end end
def wiki_notes def wiki_notes

View file

@ -169,10 +169,9 @@ describe Project do
describe "last_activity" do describe "last_activity" do
let(:project) { Factory :project } let(:project) { Factory :project }
let(:last_event) { double }
before do before do
project.stub_chain(:events, :order).and_return( [ double, double, last_event ] ) project.stub(last_event: double)
end end
it { project.last_activity.should == last_event } it { project.last_activity.should == last_event }
@ -182,8 +181,8 @@ describe Project do
let(:project) { Factory :project } let(:project) { Factory :project }
it 'returns the creation date of the project\'s last event if present' do it 'returns the creation date of the project\'s last event if present' do
last_event = double(created_at: 'now') last_event = double(created_at: Time.now)
project.stub(:events).and_return( [double, double, last_event] ) project.stub(last_event: last_event)
project.last_activity_date.should == last_event.created_at project.last_activity_date.should == last_event.created_at
end end