Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wattsworth
/
lumen-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5c9ff2b5
authored
Jul 06, 2018
by
John Doe
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
refactored tests
parent
52247d85
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
14 deletions
app/controllers/nilms_controller.rb
app/views/nilms/show.json.jbuilder
spec/controllers/nilms_controller_spec.rb
app/controllers/nilms_controller.rb
View file @
5c9ff2b5
...
...
@@ -46,11 +46,12 @@ class NilmsController < ApplicationController
@service
=
StubService
.
new
# redundant since the user must be an owner...
@role
=
current_user
.
get_nilm_permission
(
@nilm
)
if
@nilm
.
update
(
nilm_params
)
and
@nilm
.
db
.
update
(
db_params
)
if
@nilm
.
update
(
nilm_params
)
&&
@
db
.
update
(
db_params
)
@service
.
add_notice
(
'Installation Updated'
)
render
:show
,
status: :ok
else
@service
.
errors
=
@nilm
.
errors
.
full_messages
@service
.
errors
=
@nilm
.
errors
.
full_messages
+
@db
.
errors
.
full_messages
render
:show
,
status: :unprocessable_entity
end
end
...
...
app/views/nilms/show.json.jbuilder
View file @
5c9ff2b5
...
...
@@ -2,11 +2,15 @@
json.data do
json.extract! @nilm, *Nilm.json_keys
json.role @role
json.max_points_per_plot @nilm.db.max_points_per_plot
json.root_folder do
json.partial! 'db_folders/db_folder',
db_folder: @nilm.db.root_folder,
nilm: @nilm
if @nilm.db != nil
json.max_points_per_plot @nilm.db.max_points_per_plot
json.root_folder do
if @nilm.db.root_folder != nil
json.partial! 'db_folders/db_folder',
db_folder: @nilm.db.root_folder,
nilm: @nilm
end
end
end
json.jouleModules(@nilm.joule_modules) do |m|
json.extract! m, *JouleModule.json_keys
...
...
spec/controllers/nilms_controller_spec.rb
View file @
5c9ff2b5
...
...
@@ -67,22 +67,22 @@ RSpec.describe NilmsController, type: :request do
it
'returns 422 on invalid db parameters'
do
# max points must be a positive number
put
"/nilms/
#{
john_nilm
.
id
}
.json"
,
params:
{
db:
{
max_points_per_plot:
'invalid'
}
},
params:
{
max_points_per_plot:
'invalid'
},
headers:
john
.
create_new_auth_token
expect
(
response
.
status
).
to
eq
(
422
)
expect
(
response
).
to
have_error_message
(
/not a number/
)
end
it
'only allows configurable db parameters to be changed'
do
# should ignore
size
and accept max_points
url
=
john_nilm
.
db
.
url
# should ignore
url
and accept max_points
size_db
=
john_nilm
.
db
.
size_db
num_points
=
john_nilm
.
db
.
max_points_per_plot
put
"/nilms/
#{
john_nilm
.
id
}
.json"
,
params:
{
db:
{
max_points_per_plot:
num_points
+
10
,
url:
'different'
}
},
params:
{
max_points_per_plot:
num_points
+
10
,
size:
'different'
},
headers:
john
.
create_new_auth_token
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_notice_message
()
expect
(
john_nilm
.
db
.
reload
.
url
).
to
eq
(
url
)
expect
(
john_nilm
.
db
.
reload
.
size_db
).
to
eq
(
size_db
)
expect
(
john_nilm
.
db
.
max_points_per_plot
).
to
eq
(
num_points
+
10
)
end
end
...
...
@@ -113,7 +113,7 @@ RSpec.describe NilmsController, type: :request do
describe
'GET show'
do
context
'with any permissions'
do
it
'returns nilm and nested
db
as json'
do
it
'returns nilm and nested
root folder
as json'
do
# john has some permission on all 3 nilms
[
pete_nilm
,
lab_nilm
,
john_nilm
].
each
do
|
nilm
|
get
"/nilms/
#{
nilm
.
id
}
.json"
,
...
...
@@ -122,7 +122,7 @@ RSpec.describe NilmsController, type: :request do
expect
(
response
.
header
[
'Content-Type'
]).
to
include
(
'application/json'
)
body
=
JSON
.
parse
(
response
.
body
)
expect
(
body
[
'data'
][
'name'
]).
to
eq
(
nilm
.
name
)
expect
(
body
[
'data'
][
'
db'
][
'url'
]).
to
eq
(
nilm
.
db
.
url
)
expect
(
body
[
'data'
][
'
root_folder'
][
'name'
]).
to_not
be_empty
end
end
it
'returns joule modules as json'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment