mirror of
https://github.com/TracksApp/tracks.git
synced 2025-09-21 21:40:48 +02:00

There were several problems: * Time.now returns the systems time, not the users time * fixtures do not translate dates from timezone to utc, but stores the date verbatim * calling a controller will set the timezone to the preference of the current_user. So it could be changed while you do not realize this. I fixed the failing test, but problems could be elsewhere
88 lines
1.3 KiB
Ruby
88 lines
1.3 KiB
Ruby
module Stats
|
|
class Totals
|
|
|
|
attr_reader :user
|
|
def initialize(user)
|
|
@user = user
|
|
end
|
|
|
|
def empty?
|
|
actions.empty?
|
|
end
|
|
|
|
def tags
|
|
@tags ||= tag_ids.size
|
|
end
|
|
|
|
def unique_tags
|
|
@unique_tags ||= tag_ids.uniq.size
|
|
end
|
|
|
|
def first_action_at
|
|
first_action.try(:created_at)
|
|
end
|
|
|
|
def projects
|
|
user.projects.count
|
|
end
|
|
|
|
def active_projects
|
|
user.projects.active.count
|
|
end
|
|
|
|
def hidden_projects
|
|
user.projects.hidden.count
|
|
end
|
|
|
|
def completed_projects
|
|
user.projects.completed.count
|
|
end
|
|
|
|
def contexts
|
|
user.contexts.count
|
|
end
|
|
|
|
def visible_contexts
|
|
user.contexts.active.count
|
|
end
|
|
|
|
def hidden_contexts
|
|
user.contexts.hidden.count
|
|
end
|
|
|
|
def all_actions
|
|
actions.count
|
|
end
|
|
|
|
def completed_actions
|
|
actions.completed.count
|
|
end
|
|
|
|
def incomplete_actions
|
|
actions.not_completed.count
|
|
end
|
|
|
|
def deferred_actions
|
|
actions.deferred.count
|
|
end
|
|
|
|
def blocked_actions
|
|
actions.blocked.count
|
|
end
|
|
|
|
private
|
|
|
|
def actions
|
|
user.todos
|
|
end
|
|
|
|
def first_action
|
|
@first_action ||= user.todos.reorder("created_at ASC").first
|
|
end
|
|
|
|
def tag_ids
|
|
@tag_ids ||= Stats::UserTagsQuery.new(user).result.map(&:id)
|
|
end
|
|
|
|
end
|
|
end
|