+ ##
+ # test the unredaction of an old version of a way, while being
+ # authorised as a normal user.
+ def test_unredact_way_normal_user
+ way = create(:way, :with_history, :version => 2)
+ way_v1 = way.old_ways.find_by(:version => 1)
+ way_v1.redact!(create(:redaction))
+
+ basic_authorization(create(:user).email, "test")
+
+ post :redact, :params => { :id => way_v1.way_id, :version => way_v1.version }
+ assert_response :forbidden, "should need to be moderator to unredact."
+ end
+
+ ##
+ # test the unredaction of an old version of a way, while being
+ # authorised as a moderator.
+ def test_unredact_way_moderator
+ moderator_user = create(:moderator_user)
+ way = create(:way, :with_history, :version => 2)
+ way_v1 = way.old_ways.find_by(:version => 1)
+ way_v1.redact!(create(:redaction))
+
+ basic_authorization(moderator_user.email, "test")
+
+ post :redact, :params => { :id => way_v1.way_id, :version => way_v1.version }
+ assert_response :success, "should be OK to unredact old version as moderator."
+
+ # check moderator can still see the unredacted data, without passing
+ # the appropriate flag
+ get :version, :params => { :id => way_v1.way_id, :version => way_v1.version }
+ assert_response :success, "After unredaction, node should not be gone for moderator."
+
+ # and when accessed via history
+ get :history, :params => { :id => way_v1.way_id }
+ assert_response :success, "Unredaction shouldn't have stopped history working."
+ assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 1, "way #{way_v1.way_id} version #{way_v1.version} should still be present in the history for moderators."
+
+ basic_authorization(create(:user).email, "test")
+
+ # check normal user can now see the unredacted data
+ get :version, :params => { :id => way_v1.way_id, :version => way_v1.version }
+ assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
+
+ # and when accessed via history
+ get :history, :params => { :id => way_v1.way_id }
+ assert_response :success, "Redaction shouldn't have stopped history working."
+ assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 1, "way #{way_v1.way_id} version #{way_v1.version} should still be present in the history for normal users."
+ end
+
+ private
+