Commit 4635d815 authored by Andy Soiron's avatar Andy Soiron

Merge branch '336792-fj-add-encoding-field-to-wiki-api' into 'master'

Add `encoding` field to the wiki page entity

See merge request gitlab-org/gitlab!81150
parents 72874d8b 05fd6cb1
......@@ -7,7 +7,8 @@ type: reference, api
# Group wikis API **(PREMIUM)**
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/212199) in GitLab 13.5.
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/212199) in GitLab 13.5.
> - The `encoding` field was [added](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/81150) in GitLab 14.9.
The [group wikis](../user/project/wiki/group.md) API is available only in APIv4.
An API for [project wikis](wikis.md) is also available.
......@@ -37,18 +38,21 @@ Example response:
"content" : "Here is an instruction how to deploy this project.",
"format" : "markdown",
"slug" : "deploy",
"title" : "deploy"
"title" : "deploy",
"encoding": "UTF-8"
},
{
"content" : "Our development process is described here.",
"format" : "markdown",
"slug" : "development",
"title" : "development"
"title" : "development",
"encoding": "UTF-8"
},{
"content" : "* [Deploy](deploy)\n* [Development](development)",
"format" : "markdown",
"slug" : "home",
"title" : "home"
"title" : "home",
"encoding": "UTF-8"
}
]
```
......@@ -77,7 +81,8 @@ Example response:
"content" : "home page",
"format" : "markdown",
"slug" : "home",
"title" : "home"
"title" : "home",
"encoding": "UTF-8"
}
```
......@@ -109,7 +114,8 @@ Example response:
"content" : "Hello world",
"format" : "markdown",
"slug" : "Hello",
"title" : "Hello"
"title" : "Hello",
"encoding": "UTF-8"
}
```
......@@ -142,7 +148,8 @@ Example response:
"content" : "documentation",
"format" : "markdown",
"slug" : "Docs",
"title" : "Docs"
"title" : "Docs",
"encoding": "UTF-8"
}
```
......
......@@ -6,6 +6,8 @@ info: To determine the technical writer assigned to the Stage/Group associated w
# Project wikis API **(FREE)**
> The `encoding` field was [added](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/81150) in GitLab 14.9.
The project [wikis](../user/project/wiki/index.md) API is available only in APIv4.
An API for [group wikis](group_wikis.md) is also available.
......@@ -34,18 +36,21 @@ Example response:
"content" : "Here is an instruction how to deploy this project.",
"format" : "markdown",
"slug" : "deploy",
"title" : "deploy"
"title" : "deploy",
"encoding": "UTF-8"
},
{
"content" : "Our development process is described here.",
"format" : "markdown",
"slug" : "development",
"title" : "development"
"title" : "development",
"encoding": "UTF-8"
},{
"content" : "* [Deploy](deploy)\n* [Development](development)",
"format" : "markdown",
"slug" : "home",
"title" : "home"
"title" : "home",
"encoding": "UTF-8"
}
]
```
......@@ -74,7 +79,8 @@ Example response:
"content" : "home page",
"format" : "markdown",
"slug" : "home",
"title" : "home"
"title" : "home",
"encoding": "UTF-8"
}
```
......@@ -105,7 +111,8 @@ Example response:
"content" : "Hello world",
"format" : "markdown",
"slug" : "Hello",
"title" : "Hello"
"title" : "Hello",
"encoding": "UTF-8"
}
```
......@@ -137,7 +144,8 @@ Example response:
"content" : "documentation",
"format" : "markdown",
"slug" : "Docs",
"title" : "Docs"
"title" : "Docs",
"encoding": "UTF-8"
}
```
......
......@@ -21,7 +21,7 @@ RSpec.describe API::Wikis do
let(:group) { create(:group, :internal, :wiki_repo) }
let(:wiki) { create(:group_wiki, container: group, user: user) }
let(:payload) { { content: 'content', format: 'rdoc', title: 'title' } }
let(:expected_keys_with_content) { %w(content format slug title) }
let(:expected_keys_with_content) { %w(content format slug title encoding) }
let(:expected_keys_without_content) { %w(format slug title) }
before do
......
......@@ -4,6 +4,10 @@ module API
module Entities
class WikiPage < WikiPageBasic
expose :content
expose :encoding do |wiki_page|
wiki_page.content.encoding.name
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe API::Entities::WikiPage do
let_it_be_with_reload(:wiki_page) { create(:wiki_page) }
let(:entity) { described_class.new(wiki_page) }
it 'returns the proper encoding for the wiki page content' do
expect(entity.as_json[:encoding]).to eq 'UTF-8'
wiki_page.update_attributes(content: 'new_content'.encode('ISO-8859-1')) # rubocop:disable Rails/ActiveRecordAliases, Rails/SaveBang
expect(entity.as_json[:encoding]).to eq 'ISO-8859-1'
end
end
......@@ -31,7 +31,7 @@ RSpec.describe API::Wikis do
let(:project_wiki) { create(:project_wiki, project: project, user: user) }
let(:payload) { { content: 'content', format: 'rdoc', title: 'title' } }
let(:expected_keys_with_content) { %w(content format slug title) }
let(:expected_keys_with_content) { %w(content format slug title encoding) }
let(:expected_keys_without_content) { %w(format slug title) }
let(:wiki) { project_wiki }
......
......@@ -46,11 +46,12 @@ end
RSpec.shared_examples_for 'wikis API returns wiki page' do
it 'returns the wiki page' do
expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to eq(4)
expect(json_response.size).to eq(5)
expect(json_response.keys).to match_array(expected_keys_with_content)
expect(json_response['content']).to eq(page.content)
expect(json_response['slug']).to eq(page.slug)
expect(json_response['title']).to eq(page.title)
expect(json_response['encoding']).to eq('UTF-8')
end
end
......@@ -59,12 +60,13 @@ RSpec.shared_examples_for 'wikis API creates wiki page' do
post(api(url, user), params: payload)
expect(response).to have_gitlab_http_status(:created)
expect(json_response.size).to eq(4)
expect(json_response.size).to eq(5)
expect(json_response.keys).to match_array(expected_keys_with_content)
expect(json_response['content']).to eq(payload[:content])
expect(json_response['slug']).to eq(payload[:title].tr(' ', '-'))
expect(json_response['title']).to eq(payload[:title])
expect(json_response['rdoc']).to eq(payload[:rdoc])
expect(json_response['encoding']).to eq('UTF-8')
end
[:title, :content].each do |part|
......@@ -85,7 +87,7 @@ RSpec.shared_examples_for 'wikis API updates wiki page' do
put(api(url, user), params: payload)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to eq(4)
expect(json_response.size).to eq(5)
expect(json_response.keys).to match_array(expected_keys_with_content)
expect(json_response['content']).to eq(payload[:content])
expect(json_response['slug']).to eq(payload[:title].tr(' ', '-'))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment