show.html.haml_spec.rb
6.6 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
describe "problems/show.html.haml", type: 'view' do
let(:problem) { Fabricate(:problem) }
let(:comment) { Fabricate(:comment) }
let(:pivotal_tracker) do
Class.new(ErrbitPlugin::MockIssueTracker) do
def self.label
'pivotal'
end
def self.icons
{}
end
def configured?
true
end
end
end
let(:github_tracker) do
Class.new(ErrbitPlugin::MockIssueTracker) do
def self.label
'github'
end
def self.icons
{}
end
def configured?
true
end
end
end
let(:trackers) do
{
'github' => github_tracker,
'pivotal' => pivotal_tracker
}
end
let(:app) { AppDecorator.new(problem.app) }
before do
allow(view).to receive(:app).and_return(app)
allow(view).to receive(:problem).and_return(problem)
assign :comment, comment
assign :notices, problem.notices.page(1).per(1)
assign :notice, problem.notices.first
allow(controller).to receive(:current_user).and_return(Fabricate(:user))
end
def with_issue_tracker(tracker, _problem)
allow(ErrbitPlugin::Registry).to receive(:issue_trackers).and_return(trackers)
app.issue_tracker = IssueTrackerDecorator.new(
IssueTracker.new type_tracker: tracker, options: {
api_token: "token token token",
project_id: "1234"
})
end
describe "content_for :action_bar" do
def action_bar
view.content_for(:action_bar)
end
it "should confirm the 'resolve' link by default" do
render
expect(action_bar).to have_selector(
format(
'a.resolve[data-confirm="%s"]',
I18n.t('problems.confirm.resolve_one')
)
)
end
it "should confirm the 'resolve' link if configuration is unset" do
allow(Errbit::Config).to receive(:confirm_err_actions).and_return(nil)
render
expect(action_bar).to have_selector(
format(
'a.resolve[data-confirm="%s"]',
I18n.t('problems.confirm.resolve_one')
)
)
end
it "should not confirm the 'resolve' link if configured not to" do
allow(Errbit::Config).to receive(:confirm_err_actions).and_return(false)
render
expect(action_bar).to have_selector('a.resolve[data-confirm="null"]')
end
it "should link 'up' to HTTP_REFERER if is set" do
url = 'http://localhost:3000/problems'
controller.request.env['HTTP_REFERER'] = url
render
expect(action_bar).to have_selector("span a.up[href='#{url}']", text: 'up')
end
it "should link 'up' to app_problems_path if HTTP_REFERER isn't set'" do
controller.request.env['HTTP_REFERER'] = nil
problem = Fabricate(:problem_with_comments)
allow(view).to receive(:problem).and_return(problem)
allow(view).to receive(:app).and_return(problem.app)
render
expect(action_bar).to have_selector("span a.up[href='#{app_problems_path(problem.app)}']", text: 'up')
end
context 'create issue links' do
let(:app) { Fabricate(:app, github_repo: "test_user/test_repo") }
it 'should allow creating issue for github if application has a github tracker' do
problem = Fabricate(:problem_with_comments, app: app)
with_issue_tracker("github", problem)
allow(view).to receive(:problem).and_return(problem)
allow(view).to receive(:app).and_return(problem.app)
render
expect(action_bar).to have_selector("span a.create-issue", text: 'create issue')
end
context "without issue tracker associate on app" do
let(:problem) { Problem.new(new_record: false, app: app) }
let(:app) { App.new(new_record: false) }
it 'not see link to create issue' do
render
expect(view.content_for(:action_bar)).to_not match(/create issue/)
end
end
context "with tracker associate on app" do
before do
with_issue_tracker("pivotal", problem)
end
context "with app having github_repo" do
let(:app) { App.new(new_record: false, github_repo: 'foo/bar') }
let(:problem) { Problem.new(new_record: false, app: app) }
before do
problem.issue_link = nil
user = Fabricate(:user, github_login: 'test_user', github_oauth_token: 'abcdef')
allow(controller).to receive(:current_user).and_return(user)
end
it 'links to the associated tracker' do
render
expect(view.content_for(:action_bar)).to match(".create-issue")
end
end
context "without app having github_repo" do
context "with problem without issue link" do
before do
problem.issue_link = nil
end
it 'not see link if no issue tracker' do
render
expect(view.content_for(:action_bar)).to match(/create issue/)
end
end
context "with problem with issue link" do
before do
problem.issue_link = 'http://foo'
end
it 'not see link if no issue tracker' do
render
expect(view.content_for(:action_bar)).to_not match(/create issue/)
end
end
end
end
end
end
describe "content_for :comments" do
before do
problem = Fabricate(:problem_with_comments)
allow(view).to receive(:problem).and_return(problem)
allow(view).to receive(:app).and_return(problem.app)
allow(Errbit::Config).to receive(:use_gravatar).and_return(true)
end
it 'displays comments and new comment form' do
render
expect(view.content_for(:comments)).to include('Test comment')
expect(view.content_for(:comments)).to have_selector('img[src^="http://www.gravatar.com/avatar"]')
expect(view.content_for(:comments)).to include('Add a comment')
end
it 'displays existing comments with configured tracker' do
with_issue_tracker("pivotal", problem)
render
expect(view.content_for(:comments)).to include('Test comment')
expect(view.content_for(:comments)).to have_selector('img[src^="http://www.gravatar.com/avatar"]')
end
it 'displays comment when comment has no user' do
with_issue_tracker("pivotal", problem)
first_comment = view.problem.comments.first
first_comment.user.destroy
first_comment.reload
render
expect(view.content_for(:comments)).to include('Test comment')
expect(view.content_for(:comments)).to include('Unknown User')
expect(view.content_for(:comments)).to have_selector('img[src^="http://www.gravatar.com/avatar"]')
end
end
end