Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cleaning-portalmec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Richard Fernando Heise Ferreira
cleaning-portalmec
Commits
949d46b8
Commit
949d46b8
authored
8 years ago
by
bfs15
Browse files
Options
Downloads
Plain Diff
Merge branch 'rspec' of gitlab.c3sl.ufpr.br:portalmec/portalmec into rspec
parents
f4617a78
c4f2eaef
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/controllers/v1/statistics_controller.rb
+13
-10
13 additions, 10 deletions
app/controllers/v1/statistics_controller.rb
spec/shared/contexts.rb
+2
-1
2 additions, 1 deletion
spec/shared/contexts.rb
with
15 additions
and
11 deletions
app/controllers/v1/statistics_controller.rb
+
13
−
10
View file @
949d46b8
class
V1::StatisticsController
<
ApplicationController
# GET v1/statistics
# GET v1/statistics.json
def
index
statistics
=
{
:
count
=>
count_learning_objects
,
:
month_publications
=>
month_publications
,
:
month_downloads
=>
month_downloads
}
statistics
=
{
count
:
count_learning_objects
,
month_publications
:
month_publications
,
month_downloads
:
month_downloads
}
render
json:
statistics
end
private
def
count_learning_objects
LearningObject
.
where
(
'state = ?'
,
LearningObject
.
states
[
:published
]).
count
end
def
month_publication
s
LearningObject
.
where
(
'
extract (month from published_at) = ? and extract (year from published_at) = ?'
,
Time
.
now
.
month
,
Time
.
now
.
year
).
count
end
def
count_learning_object
s
LearningObject
.
where
(
'
state = ?'
,
LearningObject
.
states
[
:published
]
).
count
end
def
month_downloads
end
def
month_publications
LearningObject
.
where
(
'extract (month from published_at) = ? and extract (year from published_at) = ?'
,
Time
.
current
.
month
,
Time
.
current
.
year
).
count
end
def
month_downloads
Download
.
where
(
'extract (month from created_at) = ? and extract (year from created_at) = ?'
,
Time
.
current
.
month
,
Time
.
current
.
year
).
count
end
end
This diff is collapsed.
Click to expand it.
spec/shared/contexts.rb
+
2
−
1
View file @
949d46b8
...
...
@@ -7,9 +7,10 @@ RSpec.shared_context "authenticate_user", shared_context: :metadata do
let
(
:auth_client
)
{
@auth_headers
[
'client'
]
}
let
(
:uid
)
{
@auth_headers
[
'uid'
]
}
let
(
:access_token
)
{
@auth_headers
[
'access-token'
]
}
let
(
:role
)
{
Role
.
all
}
before
do
@user
=
create
(
:user
)
@user
=
create
(
:user
,
roles:
[
role
.
find_by
(
name:
'teacher'
)]
)
@auth_headers
=
@user
.
create_new_auth_token
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment