-
- # This test ensures that token capabilities behave correctly for a method that
- # requires the terms to have been agreed.
- # (This would be better as an integration or system testcase, since the changeset_comment
- # create method is simply a stand-in for any method that requires terms agreement.
- # But writing oauth tests is hard, and so it's easier to put in a controller test.)
- def test_api_write_and_terms_agreed_via_token
- user = create(:user, :terms_agreed => nil)
- auth_header = bearer_authorization_header(user, :scopes => %w[write_api])
- changeset = create(:changeset, :closed)
-
- assert_difference "ChangesetComment.count", 0 do
- post changeset_comment_path(changeset), :params => { :text => "This is a comment" }, :headers => auth_header
- end
- assert_response :forbidden
-
- # Try again, after agreement with the terms
- user.terms_agreed = Time.now.utc
- user.save!
-
- assert_difference "ChangesetComment.count", 1 do
- post changeset_comment_path(changeset), :params => { :text => "This is a comment" }, :headers => auth_header
- end
- assert_response :success
- end