|
1311 | 1311 | FactoryGirl.create(:open_petition, { |
1312 | 1312 | signature_count: signature_count, |
1313 | 1313 | last_signed_at: 2.days.ago, |
1314 | | - updated_at: 2.days.ago |
| 1314 | + updated_at: 2.days.ago, |
| 1315 | + response_threshold_reached_at: 2.days.ago, |
| 1316 | + debate_threshold_reached_at: 2.days.ago, |
| 1317 | + debate_state: 'awaiting' |
1315 | 1318 | }) |
1316 | 1319 | end |
1317 | 1320 |
|
|
1335 | 1338 | }.not_to change{ petition.signature_count } |
1336 | 1339 | end |
1337 | 1340 | end |
| 1341 | + |
| 1342 | + context "when the signature count crosses below the threshold for a response" do |
| 1343 | + let(:signature_count) { 10 } |
| 1344 | + |
| 1345 | + before do |
| 1346 | + expect(Site).to receive(:threshold_for_response).and_return(10) |
| 1347 | + end |
| 1348 | + |
| 1349 | + it "resets the timestamp" do |
| 1350 | + petition.decrement_signature_count! |
| 1351 | + expect(petition.response_threshold_reached_at).to be_nil |
| 1352 | + end |
| 1353 | + end |
| 1354 | + |
| 1355 | + context "when the signature count crosses below the threshold for a debate" do |
| 1356 | + let(:signature_count) { 100 } |
| 1357 | + |
| 1358 | + before do |
| 1359 | + expect(Site).to receive(:threshold_for_debate).and_return(100) |
| 1360 | + end |
| 1361 | + |
| 1362 | + it "records the time it happened" do |
| 1363 | + petition.decrement_signature_count! |
| 1364 | + expect(petition.debate_threshold_reached_at).to be_nil |
| 1365 | + end |
| 1366 | + |
| 1367 | + it "sets the debate_state to 'pending'" do |
| 1368 | + petition.decrement_signature_count! |
| 1369 | + expect(petition.debate_state).to eq("pending") |
| 1370 | + end |
| 1371 | + end |
1338 | 1372 | end |
1339 | 1373 |
|
1340 | 1374 | describe "at_threshold_for_moderation?" do |
|
0 commit comments