Fix and complete controller specs
This commit is contained in:
@@ -66,7 +66,7 @@ class Legislation::AnnotationsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def convert_ranges_parameters
|
def convert_ranges_parameters
|
||||||
if params[:legislation_annotation] && params[:legislation_annotation][:ranges]
|
if params[:legislation_annotation] && params[:legislation_annotation][:ranges] && params[:legislation_annotation][:ranges].is_a?(String)
|
||||||
params[:legislation_annotation][:ranges] = JSON.parse(params[:legislation_annotation][:ranges])
|
params[:legislation_annotation][:ranges] = JSON.parse(params[:legislation_annotation][:ranges])
|
||||||
end
|
end
|
||||||
rescue JSON::ParserError
|
rescue JSON::ParserError
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ describe Legislation::AnnotationsController do
|
|||||||
|
|
||||||
post :create, process_id: @process.id,
|
post :create, process_id: @process.id,
|
||||||
draft_version_id: @draft_version.id,
|
draft_version_id: @draft_version.id,
|
||||||
annotation: {
|
legislation_annotation: {
|
||||||
"quote"=>"Ordenación Territorial",
|
"quote"=>"Ordenación Territorial",
|
||||||
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}],
|
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}],
|
||||||
"text": "una anotacion"
|
"text": "una anotacion"
|
||||||
@@ -29,7 +29,7 @@ describe Legislation::AnnotationsController do
|
|||||||
|
|
||||||
post :create, process_id: @process.id,
|
post :create, process_id: @process.id,
|
||||||
draft_version_id: @final_version.id,
|
draft_version_id: @final_version.id,
|
||||||
annotation: {
|
legislation_annotation: {
|
||||||
"quote"=>"Ordenación Territorial",
|
"quote"=>"Ordenación Territorial",
|
||||||
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}],
|
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}],
|
||||||
"text": "una anotacion"
|
"text": "una anotacion"
|
||||||
@@ -44,7 +44,7 @@ describe Legislation::AnnotationsController do
|
|||||||
expect do
|
expect do
|
||||||
xhr :post, :create, process_id: @process.id,
|
xhr :post, :create, process_id: @process.id,
|
||||||
draft_version_id: @draft_version.id,
|
draft_version_id: @draft_version.id,
|
||||||
annotation: {
|
legislation_annotation: {
|
||||||
"quote"=>"Ordenación Territorial",
|
"quote"=>"Ordenación Territorial",
|
||||||
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}],
|
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}],
|
||||||
"text": "una anotacion"
|
"text": "una anotacion"
|
||||||
@@ -59,12 +59,27 @@ describe Legislation::AnnotationsController do
|
|||||||
expect do
|
expect do
|
||||||
xhr :post, :create, process_id: @process.id,
|
xhr :post, :create, process_id: @process.id,
|
||||||
draft_version_id: @draft_version.id,
|
draft_version_id: @draft_version.id,
|
||||||
annotation: {
|
legislation_annotation: {
|
||||||
"quote"=>"Ordenación Territorial",
|
"quote"=>"Ordenación Territorial",
|
||||||
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}],
|
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}],
|
||||||
"text": "una anotacion"
|
"text": "una anotacion"
|
||||||
}
|
}
|
||||||
end.to_not change { @draft_version.annotations.count }
|
end.to_not change { @draft_version.annotations.count }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should create an annotation by parsing parameters in JSON' do
|
||||||
|
sign_in @user
|
||||||
|
|
||||||
|
expect do
|
||||||
|
xhr :post, :create, process_id: @process.id,
|
||||||
|
draft_version_id: @draft_version.id,
|
||||||
|
legislation_annotation: {
|
||||||
|
"quote"=>"Ordenación Territorial",
|
||||||
|
"ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}].to_json,
|
||||||
|
"text": "una anotacion"
|
||||||
|
}
|
||||||
|
end.to change { @draft_version.annotations.count }.by(1)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user