summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-08-01 15:41:30 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-08-17 12:58:58 -0300
commite1998844781b92d118f25cb8f8c0cbd293a25708 (patch)
tree006c9df0983d5d3534a522cdbfa303b1c4926f48
parentbddb2f938cea11f31dc78f0c7bf9bb203ee3a4bd (diff)
downloadgitlab-ce-e1998844781b92d118f25cb8f8c0cbd293a25708.tar.gz
Projects::BoardsController#show returns a list of board lists
-rw-r--r--app/controllers/projects/boards_controller.rb3
-rw-r--r--spec/controllers/projects/boards_controller_spec.rb39
-rw-r--r--spec/fixtures/api/schemas/list.json35
-rw-r--r--spec/support/api/schema_matcher.rb9
4 files changed, 79 insertions, 7 deletions
diff --git a/app/controllers/projects/boards_controller.rb b/app/controllers/projects/boards_controller.rb
index 3c86435d83a..b04a0efbe73 100644
--- a/app/controllers/projects/boards_controller.rb
+++ b/app/controllers/projects/boards_controller.rb
@@ -1,9 +1,10 @@
class Projects::BoardsController < Projects::ApplicationController
def show
- Boards::CreateService.new(project).execute
+ board = Boards::CreateService.new(project).execute
respond_to do |format|
format.html
+ format.json { render json: board.lists.as_json(only: [:id, :list_type, :position], methods: [:title], include: { label: { only: [:id, :title, :color] } }) }
end
end
end
diff --git a/spec/controllers/projects/boards_controller_spec.rb b/spec/controllers/projects/boards_controller_spec.rb
index e03d3519b67..2392ee18602 100644
--- a/spec/controllers/projects/boards_controller_spec.rb
+++ b/spec/controllers/projects/boards_controller_spec.rb
@@ -10,15 +10,42 @@ describe Projects::BoardsController do
end
describe 'GET #show' do
- it 'creates a new board when project does not have one' do
- expect { get :show, namespace_id: project.namespace.to_param, project_id: project.to_param }.to change(Board, :count).by(1)
+ context 'when project does not have a board' do
+ it 'creates a new board' do
+ expect { get :show, namespace_id: project.namespace.to_param, project_id: project.to_param }.to change(Board, :count).by(1)
+ end
end
- it 'renders HTML template' do
- get :show, namespace_id: project.namespace.to_param, project_id: project.to_param
+ context 'when format is HTML' do
+ it 'renders HTML template' do
+ get :show, namespace_id: project.namespace.to_param, project_id: project.to_param
- expect(response).to render_template :show
- expect(response.content_type).to eq 'text/html'
+ expect(response).to render_template :show
+ expect(response.content_type).to eq 'text/html'
+ end
+ end
+
+ context 'when format is JSON' do
+ it 'returns a successful 200 response' do
+ get :show, namespace_id: project.namespace.to_param, project_id: project.to_param, format: :json
+
+ expect(response).to have_http_status(200)
+ expect(response.content_type).to eq 'application/json'
+ end
+
+ it 'returns a list of board lists' do
+ board = project.create_board
+ create(:backlog_list, board: board)
+ create(:list, board: board)
+ create(:done_list, board: board)
+
+ get :show, namespace_id: project.namespace.to_param, project_id: project.to_param, format: :json
+
+ parsed_response = JSON.parse(response.body)
+
+ expect(response).to match_response_schema('list', array: true)
+ expect(parsed_response.length).to eq 3
+ end
end
end
end
diff --git a/spec/fixtures/api/schemas/list.json b/spec/fixtures/api/schemas/list.json
new file mode 100644
index 00000000000..21239f136cd
--- /dev/null
+++ b/spec/fixtures/api/schemas/list.json
@@ -0,0 +1,35 @@
+{
+ "type": "object",
+ "required" : [
+ "id",
+ "list_type",
+ "title",
+ "position"
+ ],
+ "properties" : {
+ "id": { "type": "integer" },
+ "list_type": {
+ "type": "string",
+ "enum": ["backlog", "label", "done"]
+ },
+ "label": {
+ "type": ["object"],
+ "required": [
+ "id",
+ "color",
+ "title"
+ ],
+ "properties": {
+ "id": { "type": "integer" },
+ "color": {
+ "type": "string",
+ "pattern": "^#[0-9A-Fa-f]{3}{1,2}+$"
+ },
+ "title": { "type": "string" }
+ }
+ },
+ "title": { "type": "string" },
+ "position": { "type": ["integer", "null"] }
+ },
+ "additionalProperties": false
+}
diff --git a/spec/support/api/schema_matcher.rb b/spec/support/api/schema_matcher.rb
new file mode 100644
index 00000000000..929b637e5eb
--- /dev/null
+++ b/spec/support/api/schema_matcher.rb
@@ -0,0 +1,9 @@
+RSpec::Matchers.define :match_response_schema do |schema, options = {}|
+ match do |response|
+ schema_directory = "#{Dir.pwd}/spec/fixtures/api/schemas"
+ schema_path = "#{schema_directory}/#{schema}.json"
+ list = options.fetch(:array, false)
+
+ JSON::Validator.validate!(schema_path, response.body, list: list)
+ end
+end