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
65a1560e
authored
Feb 15, 2017
by
John Doe
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
added mocks to handle db update
parent
bd67a56d
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
20 additions
and
14 deletions
app/controllers/nilms_controller.rb
app/views/db_folders/_db_folder.json.jbuilder
config/application.rb
spec/controllers/dbs_controller_spec.rb
spec/controllers/nilms_controller_spec.rb
spec/rails_helper.rb
spec/requests/permissions_spec.rb
spec/spec_helper.rb
app/controllers/nilms_controller.rb
View file @
65a1560e
...
...
@@ -27,7 +27,7 @@ class NilmsController < ApplicationController
@service
.
add_notice
(
'NILM Updated'
)
render
status: :ok
else
@service
.
errors
=
@nilm
.
errors
@service
.
errors
=
@nilm
.
errors
.
full_messages
render
status: :unprocessable_entity
end
end
...
...
app/views/db_folders/_db_folder.json.jbuilder
View file @
65a1560e
json.extract! db_folder, :id, :name, :description, :path, :hidden,
:start_time, :end_time, :size_on_disk
json.shallow shallow
...
...
config/application.rb
View file @
65a1560e
...
...
@@ -11,10 +11,11 @@ module ControlPanel
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Add folders under the services directory
config
.
api_only
=
true
# Add folders under the services and adapters directory
%w(nilm db db_folder db_stream)
.
each
do
|
service
|
config
.
autoload_paths
<<
Rails
.
root
.
join
(
"app/services/
#{
service
}
"
)
end
config
.
autoload_paths
<<
Rails
.
root
.
join
(
"app/adapters"
)
end
end
spec/controllers/dbs_controller_spec.rb
View file @
65a1560e
...
...
@@ -57,7 +57,21 @@ RSpec.describe DbsController, type: :request do
end
context
'with owner permissions'
do
it
'refreshes db if URL is changed or refresh paramter is set'
do
# TODO: this is a mess, figure out how instance doubles work
mock_adapter
=
spy
#instance_double(DbAdapter)
allow
(
DbAdapter
).
to
receive
(
:new
).
and_return
(
mock_adapter
)
mock_service
=
spy
#---_ this line is to provide dummy messages
allow
(
mock_service
).
to
receive
(
:run
).
and_return
(
StubService
.
new
)
allow
(
UpdateDb
).
to
receive
(
:new
).
and_return
(
mock_service
)
@auth_headers
=
john
.
create_new_auth_token
put
"/dbs/
#{
john_nilm
.
db
.
id
}
.json"
,
params:
{
url:
'http://new/url'
},
headers:
@auth_headers
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
mock_service
).
to
have_received
(
:run
)
# service is stubbed so message is empty
# expect(response).to have_notice_message
end
it
'returns 422 on invalid parameters'
do
# max points must be a positive number
...
...
spec/controllers/nilms_controller_spec.rb
View file @
65a1560e
...
...
@@ -60,6 +60,7 @@ RSpec.describe NilmsController, type: :request do
params:
{
id:
john_nilm
.
id
,
name:
""
},
headers:
@auth_headers
expect
(
response
).
to
have_http_status
(
:unprocessable_entity
)
expect
(
response
).
to
have_error_message
(
/Name/
)
expect
(
john_nilm
.
reload
.
name
).
to
eq
(
"John's NILM"
)
end
end
...
...
spec/rails_helper.rb
View file @
65a1560e
...
...
@@ -35,7 +35,7 @@ RSpec.configure do |config|
config
.
include
Devise
::
Test
::
ControllerHelpers
,
type: :view
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config
.
fixture_path
=
"
#{
::
Rails
.
root
}
/spec/fixtures"
#
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
...
...
spec/requests/permissions_spec.rb
deleted
100644 → 0
View file @
bd67a56d
require
'rails_helper'
RSpec
.
describe
"Permissions"
,
type: :request
do
describe
"GET /permissions"
do
it
"works! (now write some real specs)"
do
get
permissions_path
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
spec/spec_helper.rb
View file @
65a1560e
...
...
@@ -47,6 +47,7 @@ RSpec.configure do |config|
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks
.
verify_partial_doubles
=
true
mocks
.
verify_doubled_constant_names
=
true
end
# The settings below are suggested to provide a good initial experience
...
...
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