Skip to content

Commit

Permalink
Fixed bug displaying orgs with no users.
Browse files Browse the repository at this point in the history
  • Loading branch information
eostrom committed Apr 2, 2012
1 parent 573a7b5 commit ab766d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 2 additions & 6 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,13 @@ def battle_buddy_list
end

def last_activity
users.order('last_login_at DESC').first.last_activity
users.order('last_login_at DESC').first.try(:last_activity) || 'Never'
end

def declared_crisis?
crises.where(:resolved_on => nil).count == 1 ? true : false
end

def last_activity_at
users.order('created_at DESC').first.created_at
end

def todo_percentage_complete
# number_to_percentage(((completed_answers_count.to_f / answers_count.to_f)*100),:precision => 0)
((todos.completed.count.to_f / todos.count.to_f)*100).to_i rescue 0
Expand Down Expand Up @@ -120,4 +116,4 @@ def setup_initial_todo
self.todos.create(:critical_function => 'people', :description => 'Add a second manager using the Settings menu to ensure access to the ArtsReady site', :priority => 'critical', :user => users.first) if self.todos.count == 0
end

end
end
15 changes: 15 additions & 0 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,19 @@
end
end
end

describe '#last_activity' do
it 'is the activity of the last-logged-in user, or never' do
subject = Factory.create(:organization)
subject.last_activity.should == 'Never'

time = Time.zone.parse('Mon, 02 Apr 2012 04:24:14 UTC +00:00')
subject.users = [
Factory.create(:member,
:organization => subject,
:last_login_at => time)
]
subject.last_activity.should == time
end
end
end

0 comments on commit ab766d7

Please sign in to comment.