resource_finder_spec.rb
1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'rails_helper'
describe ResourceFinder, type: :controller do
describe 'find_resource' do
let(:klass) { mock('Resource') }
let(:id) { 1 }
let!(:projects_controller) {ProjectsController.new}
before do
projects_controller.extend(ResourceFinder)
end
context 'when the resource exists' do
let!(:resource) { mock('resource') }
before :each do
klass.expects(:find).with(id).returns(resource)
end
it 'is expect to return the resource' do
expect(projects_controller.find_resource(klass, id)).to eq(resource)
end
end
context 'when the resource does not exists' do
before :each do
klass.expects(:find).with(id).raises(KalibroClient::Errors::RecordNotFound)
end
# FIXME: this is not the best test, but it it's the closest we can think of
# full coverage is achieved through projects_controller_spec.rb
it 'is expected to render the 404 page' do
projects_controller.expects(:respond_to)
projects_controller.find_resource(klass, id)
end
end
end
end