summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-05 16:24:29 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-11 11:39:05 -0300
commitecf4c10e9c395604583820ad01167db34d09d4aa (patch)
tree7734ebceb1167832606dcc5463caacc9d0bb4460
parentb4b8e0ec9405c4b5d17b53552612397e847e734d (diff)
downloadgitlab-ce-ecf4c10e9c395604583820ad01167db34d09d4aa.tar.gz
Add index action to Projects::BoardsController to return project boards
-rw-r--r--app/controllers/projects/boards_controller.rb15
-rw-r--r--app/views/projects/boards/index.html.haml0
-rw-r--r--config/routes/project.rb2
-rw-r--r--spec/controllers/projects/boards_controller_spec.rb47
-rw-r--r--spec/fixtures/api/schemas/board.json12
-rw-r--r--spec/fixtures/api/schemas/boards.json4
6 files changed, 76 insertions, 4 deletions
diff --git a/app/controllers/projects/boards_controller.rb b/app/controllers/projects/boards_controller.rb
index 0035633b774..56bc54fbd1c 100644
--- a/app/controllers/projects/boards_controller.rb
+++ b/app/controllers/projects/boards_controller.rb
@@ -1,9 +1,18 @@
class Projects::BoardsController < Projects::ApplicationController
include IssuableCollections
-
- respond_to :html
- before_action :authorize_read_board!, only: [:show]
+ before_action :authorize_read_board!, only: [:index, :show]
+
+ def index
+ @boards = ::Boards::ListService.new(project, current_user).execute
+
+ respond_to do |format|
+ format.html
+ format.json do
+ render json: @boards.as_json(only: [:id, :name])
+ end
+ end
+ end
def show
::Boards::CreateService.new(project, current_user).execute
diff --git a/app/views/projects/boards/index.html.haml b/app/views/projects/boards/index.html.haml
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/app/views/projects/boards/index.html.haml
diff --git a/config/routes/project.rb b/config/routes/project.rb
index e8807ef06a7..3a7c4f86301 100644
--- a/config/routes/project.rb
+++ b/config/routes/project.rb
@@ -416,7 +416,7 @@ resources :namespaces, path: '/', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only:
end
end
- resource :board, only: [:show] do
+ resources :boards, only: [:index, :show] do
scope module: :boards do
resources :issues, only: [:update]
diff --git a/spec/controllers/projects/boards_controller_spec.rb b/spec/controllers/projects/boards_controller_spec.rb
index 6f6e608e1f3..d7698afd141 100644
--- a/spec/controllers/projects/boards_controller_spec.rb
+++ b/spec/controllers/projects/boards_controller_spec.rb
@@ -9,6 +9,53 @@ describe Projects::BoardsController do
sign_in(user)
end
+ describe 'GET index' do
+ it 'creates a new project board when project does not have one' do
+ expect { list_boards }.to change(project.boards, :count).by(1)
+ end
+
+ context 'when format is HTML' do
+ it 'renders template' do
+ list_boards
+
+ expect(response).to render_template :index
+ expect(response.content_type).to eq 'text/html'
+ end
+ end
+
+ context 'when format is JSON' do
+ it 'returns a list of project boards' do
+ create_list(:board, 2, project: project)
+
+ list_boards format: :json
+
+ parsed_response = JSON.parse(response.body)
+
+ expect(response).to match_response_schema('boards')
+ expect(parsed_response.length).to eq 2
+ end
+ end
+
+ context 'with unauthorized user' do
+ before do
+ allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true)
+ allow(Ability).to receive(:allowed?).with(user, :read_board, project).and_return(false)
+ end
+
+ it 'returns a not found 404 response' do
+ list_boards
+
+ expect(response).to have_http_status(404)
+ end
+ end
+
+ def list_boards(format: :html)
+ get :index, namespace_id: project.namespace.to_param,
+ project_id: project.to_param,
+ format: format
+ end
+ end
+
describe 'GET show' do
it 'creates a new board when project does not have one' do
expect { read_board }.to change(Board, :count).by(1)
diff --git a/spec/fixtures/api/schemas/board.json b/spec/fixtures/api/schemas/board.json
new file mode 100644
index 00000000000..6c6e2bee8cb
--- /dev/null
+++ b/spec/fixtures/api/schemas/board.json
@@ -0,0 +1,12 @@
+{
+ "type": "object",
+ "required" : [
+ "id",
+ "name"
+ ],
+ "properties" : {
+ "id": { "type": "integer" },
+ "name": { "type": "string" }
+ },
+ "additionalProperties": false
+}
diff --git a/spec/fixtures/api/schemas/boards.json b/spec/fixtures/api/schemas/boards.json
new file mode 100644
index 00000000000..117564ef77a
--- /dev/null
+++ b/spec/fixtures/api/schemas/boards.json
@@ -0,0 +1,4 @@
+{
+ "type": "array",
+ "items": { "$ref": "board.json" }
+}