Permalink
Browse files

Fixed bug displaying orgs with no users.

  • Loading branch information...
1 parent 573a7b5 commit ab766d731add98a91fc6a271ef904b1aabed114e @eostrom eostrom committed Apr 2, 2012
Showing with 17 additions and 6 deletions.
  1. +2 −6 app/models/organization.rb
  2. +15 −0 spec/models/organization_spec.rb
View
8 app/models/organization.rb
@@ -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
@@ -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
View
15 spec/models/organization_spec.rb
@@ -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.