errs_controller_spec.rb
2.54 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require 'spec_helper'
describe ErrsController do
let(:project) { Factory(:project) }
let(:err) { Factory(:err, :project => project) }
describe "GET /errs" do
it "gets a paginated list of unresolved errors" do
errors = WillPaginate::Collection.new(1,30)
3.times { errors << Factory(:err) }
Err.should_receive(:unresolved).and_return(
mock('proxy', :ordered => mock('proxy', :paginate => errors))
)
get :index
assigns(:errs).should == errors
end
end
describe "GET /projects/:project_id/errs/:id" do
before do
3.times { Factory(:notice, :err => err)}
end
it "finds the project" do
get :show, :project_id => project.id, :id => err.id
assigns(:project).should == project
end
it "finds the err" do
get :show, :project_id => project.id, :id => err.id
assigns(:err).should == err
end
it "paginates the notices, 1 at a time" do
Project.stub(:find).with(project.id).and_return(project)
project.errs.stub(:find).with(err.id).and_return(err)
err.notices.should_receive(:ordered).and_return(proxy = stub('proxy'))
proxy.should_receive(:paginate).with(:page => 3, :per_page => 1).
and_return(WillPaginate::Collection.new(1,1) << err.notices.first)
get :show, :project_id => project.id, :id => err.id
end
end
describe "PUT /projects/:project_id/errs/:id/resolve" do
before do
@err = Factory(:err)
Project.stub(:find).with(@err.project.id).and_return(@err.project)
@err.project.errs.stub(:unresolved).
and_return(stub('proxy', :find => @err))
@err.stub(:resolve!)
end
it 'finds the project and the err' do
Project.should_receive(:find).with(@err.project.id).and_return(@err.project)
@err.project.errs.should_receive(:unresolved).
and_return(mock('proxy', :find => @err))
put :resolve, :project_id => @err.project.id, :id => @err.id
assigns(:project).should == @err.project
assigns(:err).should == @err
end
it "should resolve the issue" do
@err.should_receive(:resolve!).and_return(true)
put :resolve, :project_id => @err.project.id, :id => @err.id
end
it "should display a message" do
put :resolve, :project_id => @err.project.id, :id => @err.id
request.flash[:success].should match(/Great news/)
end
it "should redirect do the errs page" do
put :resolve, :project_id => @err.project.id, :id => @err.id
response.should redirect_to(errs_path)
end
end
end