Commit 65a1560e by John Doe

added mocks to handle db update

parent bd67a56d
......@@ -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
......
json.extract! db_folder, :id, :name, :description, :path, :hidden,
:start_time, :end_time, :size_on_disk
json.shallow shallow
......
......@@ -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
......@@ -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
......
......@@ -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
......
......@@ -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
......
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
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment