Commit e2bfccbfc3e3762b5ff69f2b210ac8415bab1df8
1 parent
a87d750a
Exists in
master
and in
1 other branch
add tests for ErrorReport#should_keep?
Showing
3 changed files
with
32 additions
and
2 deletions
Show diff stats
app/controllers/notices_controller.rb
| ... | ... | @@ -18,7 +18,7 @@ class NoticesController < ApplicationController |
| 18 | 18 | end |
| 19 | 19 | render :xml => api_xml |
| 20 | 20 | else |
| 21 | - render :xml => "Notice for old app version ignored" | |
| 21 | + render :text => "Notice for old app version ignored" | |
| 22 | 22 | end |
| 23 | 23 | else |
| 24 | 24 | render :text => "Your API key is unknown", :status => 422 | ... | ... |
spec/controllers/notices_controller_spec.rb
| ... | ... | @@ -6,7 +6,7 @@ describe NoticesController do |
| 6 | 6 | let(:notice) { Fabricate(:notice) } |
| 7 | 7 | let(:xml) { Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read } |
| 8 | 8 | let(:app) { Fabricate(:app) } |
| 9 | - let(:error_report) { double(:valid? => true, :generate_notice! => true, :notice => notice) } | |
| 9 | + let(:error_report) { double(:valid? => true, :generate_notice! => true, :notice => notice, :should_keep? => true) } | |
| 10 | 10 | |
| 11 | 11 | context 'notices API' do |
| 12 | 12 | context "with all params" do | ... | ... |
spec/models/error_report_spec.rb
| ... | ... | @@ -230,5 +230,35 @@ describe ErrorReport do |
| 230 | 230 | end |
| 231 | 231 | end |
| 232 | 232 | |
| 233 | + describe "#should_keep?" do | |
| 234 | + context "with current app version not set" do | |
| 235 | + before do | |
| 236 | + error_report.app.current_app_version = nil | |
| 237 | + error_report.server_environment['app-version'] = '1.0' | |
| 238 | + end | |
| 239 | + | |
| 240 | + it "return true" do | |
| 241 | + expect(error_report.should_keep?).to be true | |
| 242 | + end | |
| 243 | + end | |
| 244 | + | |
| 245 | + context "with current app version set" do | |
| 246 | + before do | |
| 247 | + error_report.app.current_app_version = '1.0' | |
| 248 | + end | |
| 249 | + | |
| 250 | + it "return true if current or newer" do | |
| 251 | + error_report.server_environment['app-version'] = '1.0' | |
| 252 | + expect(error_report.should_keep?).to be true | |
| 253 | + end | |
| 254 | + | |
| 255 | + it "return false if older" do | |
| 256 | + error_report.server_environment['app-version'] = '0.9' | |
| 257 | + expect(error_report.should_keep?).to be false | |
| 258 | + end | |
| 259 | + end | |
| 260 | + | |
| 261 | + end | |
| 262 | + | |
| 233 | 263 | end |
| 234 | 264 | end | ... | ... |