aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-11-08 18:37:47 +0100
committercedricnjanga2017-11-13 17:52:54 +0100
commit89f518891cff138643eaa14977aa20a3ef01930d (patch)
tree7eef684875ba54e6853ad5d6b32b9ea89fdafb0e
parent80f932d417744488c7dadc53d7369ca573f1fc61 (diff)
downloadchouette-core-89f518891cff138643eaa14977aa20a3ef01930d.tar.bz2
ComplianceCheckSets#validated: Add response body
On successful status update, respond with the `ComplianceCheckSet` object attributes. Otherwise, respond with an error JSON. Refs #4757
-rw-r--r--app/controllers/api/v1/compliance_check_sets_controller.rb10
-rw-r--r--app/views/api/v1/compliance_check_sets/validated.rabl11
-rw-r--r--spec/controllers/api/v1/compliance_check_sets_controller_spec.rb27
3 files changed, 46 insertions, 2 deletions
diff --git a/app/controllers/api/v1/compliance_check_sets_controller.rb b/app/controllers/api/v1/compliance_check_sets_controller.rb
index e34d269ee..acb38c834 100644
--- a/app/controllers/api/v1/compliance_check_sets_controller.rb
+++ b/app/controllers/api/v1/compliance_check_sets_controller.rb
@@ -1,6 +1,14 @@
class Api::V1::ComplianceCheckSetsController < Api::V1::IbooController
def validated
@compliance_check_set = ComplianceCheckSet.find(params[:id])
- @compliance_check_set.update_status
+
+ if @compliance_check_set.update_status
+ render :validated
+ else
+ render json: {
+ status: "error",
+ messages: @compliance_check_set.errors.full_messages
+ }
+ end
end
end
diff --git a/app/views/api/v1/compliance_check_sets/validated.rabl b/app/views/api/v1/compliance_check_sets/validated.rabl
new file mode 100644
index 000000000..1368a8014
--- /dev/null
+++ b/app/views/api/v1/compliance_check_sets/validated.rabl
@@ -0,0 +1,11 @@
+object @compliance_check_set
+
+attributes(
+ :id,
+ :referential_id,
+ :name,
+ :creator,
+ :status,
+ :started_at,
+ :ended_at
+)
diff --git a/spec/controllers/api/v1/compliance_check_sets_controller_spec.rb b/spec/controllers/api/v1/compliance_check_sets_controller_spec.rb
index e8e24b530..1c3784807 100644
--- a/spec/controllers/api/v1/compliance_check_sets_controller_spec.rb
+++ b/spec/controllers/api/v1/compliance_check_sets_controller_spec.rb
@@ -2,11 +2,36 @@ RSpec.describe Api::V1::ComplianceCheckSetsController, type: :controller do
include_context 'iboo authenticated api user'
describe "POST #validate" do
+ let(:check_set) { create(:compliance_check_set) }
+
it "calls #update_status on the ComplianceCheckSet" do
- check_set = create(:compliance_check_set)
expect_any_instance_of(ComplianceCheckSet).to receive(:update_status)
patch :validated, id: check_set.id
end
+
+ context "responds with" do
+ render_views
+
+ it "object JSON on #update_status true" do
+ allow_any_instance_of(
+ ComplianceCheckSet
+ ).to receive(:update_status).and_return(true)
+
+ patch :validated, id: check_set.id
+
+ expect(JSON.parse(response.body)['id']).to eq(check_set.id)
+ end
+
+ it "error JSON on #update_status false" do
+ allow_any_instance_of(
+ ComplianceCheckSet
+ ).to receive(:update_status).and_return(false)
+
+ patch :validated, id: check_set.id
+
+ expect(response.body).to include('error')
+ end
+ end
end
end