From 0f34cae2addc940955ec8cf3f8ff66f407172f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Fri, 16 Jun 2017 13:14:41 +0200 Subject: [PATCH] updates specs to new keyword styles --- spec/controllers/comments_controller_spec.rb | 6 +- spec/controllers/graphql_controller_spec.rb | 18 ++-- .../annotations_controller_spec.rb | 88 +++++++++++-------- .../legislation/answers_controller_spec.rb | 9 +- 4 files changed, 64 insertions(+), 57 deletions(-) diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index c267f3814..6fbcd3c7c 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -14,7 +14,7 @@ describe CommentsController do sign_in @user expect do - xhr :post, :create, comment: {commentable_id: @question.id, commentable_type: "Legislation::Question", body: "a comment"} + post :create, params: {comment: {commentable_id: @question.id, commentable_type: "Legislation::Question", body: "a comment"}}, xhr: true end.to change { @question.reload.comments_count }.by(1) end @@ -23,7 +23,7 @@ describe CommentsController do @process.update_attribute(:debate_end_date, Date.current - 1.day) expect do - xhr :post, :create, comment: {commentable_id: @question.id, commentable_type: "Legislation::Question", body: "a comment"} + post :create, params: {comment: {commentable_id: @question.id, commentable_type: "Legislation::Question", body: "a comment"}}, xhr: true end.not_to change { @question.reload.comments_count } end @@ -31,7 +31,7 @@ describe CommentsController do sign_in @unverified_user expect do - xhr :post, :create, comment: {commentable_id: @question.id, commentable_type: "Legislation::Question", body: "a comment"} + post :create, params: {comment: {commentable_id: @question.id, commentable_type: "Legislation::Question", body: "a comment"}}, xhr: true end.not_to change { @question.reload.comments_count } end end diff --git a/spec/controllers/graphql_controller_spec.rb b/spec/controllers/graphql_controller_spec.rb index 4cd6ba8c6..c975ec160 100644 --- a/spec/controllers/graphql_controller_spec.rb +++ b/spec/controllers/graphql_controller_spec.rb @@ -13,14 +13,14 @@ describe GraphqlController, type: :request do describe "handles GET request" do specify "with query string inside query params" do - get "/graphql", query: "{ proposal(id: #{proposal.id}) { title } }" + get "/graphql", params: { query: "{ proposal(id: #{proposal.id}) { title } }" } expect(response).to have_http_status(:ok) expect(JSON.parse(response.body)["data"]["proposal"]["title"]).to eq(proposal.title) end specify "with malformed query string" do - get "/graphql", query: "Malformed query string" + get "/graphql", params: { query: "Malformed query string" } expect(response).to have_http_status(:ok) expect(parser_error_raised?(response)).to be_truthy @@ -38,7 +38,7 @@ describe GraphqlController, type: :request do let(:json_headers) { { "CONTENT_TYPE" => "application/json" } } specify "with json-encoded query string inside body" do - post "/graphql", { query: "{ proposal(id: #{proposal.id}) { title } }" }.to_json, json_headers + post "/graphql", params: { query: "{ proposal(id: #{proposal.id}) { title } }" }.to_json, headers: json_headers expect(response).to have_http_status(:ok) expect(JSON.parse(response.body)["data"]["proposal"]["title"]).to eq(proposal.title) @@ -46,21 +46,21 @@ describe GraphqlController, type: :request do specify "with raw query string inside body" do graphql_headers = { "CONTENT_TYPE" => "application/graphql" } - post "/graphql", "{ proposal(id: #{proposal.id}) { title } }", graphql_headers + post "/graphql", params: "{ proposal(id: #{proposal.id}) { title } }", headers: graphql_headers expect(response).to have_http_status(:ok) expect(JSON.parse(response.body)["data"]["proposal"]["title"]).to eq(proposal.title) end specify "with malformed query string" do - post "/graphql", { query: "Malformed query string" }.to_json, json_headers + post "/graphql", params: { query: "Malformed query string" }.to_json, headers: json_headers expect(response).to have_http_status(:ok) expect(parser_error_raised?(response)).to be_truthy end it "without query string" do - post "/graphql", json_headers + post "/graphql", headers: json_headers expect(response).to have_http_status(:bad_request) expect(JSON.parse(response.body)["message"]).to eq("Query string not present") @@ -71,19 +71,19 @@ describe GraphqlController, type: :request do let(:query_string) { "{ proposal(id: #{proposal.id}) { title } }" } specify "when absent" do - get "/graphql", query: query_string + get "/graphql", params: { query: query_string } expect(response).to have_http_status(:ok) end specify "when specified as the 'null' string" do - get "/graphql", query: query_string, variables: "null" + get "/graphql", params: { query: query_string, variables: "null" } expect(response).to have_http_status(:ok) end specify "when specified as an empty string" do - get "/graphql", query: query_string, variables: "" + get "/graphql", params: { query: query_string, variables: "" } expect(response).to have_http_status(:ok) end diff --git a/spec/controllers/legislation/annotations_controller_spec.rb b/spec/controllers/legislation/annotations_controller_spec.rb index d7847d9fa..1b7f6cac0 100644 --- a/spec/controllers/legislation/annotations_controller_spec.rb +++ b/spec/controllers/legislation/annotations_controller_spec.rb @@ -13,13 +13,14 @@ describe Legislation::AnnotationsController do it "creates an ahoy event" do sign_in @user - post :create, process_id: @process.id, - draft_version_id: @draft_version.id, - legislation_annotation: { - "quote" => "ipsum", - "ranges" => [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}], - "text": "una anotacion" - } + post :create, params: { + process_id: @process.id, + draft_version_id: @draft_version.id, + legislation_annotation: { + "quote"=>"ipsum", + "ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}], + "text": "una anotacion" + }} expect(Ahoy::Event.where(name: :legislation_annotation_created).count).to eq 1 expect(Ahoy::Event.last.properties["legislation_annotation_id"]).to eq Legislation::Annotation.last.id end @@ -27,13 +28,14 @@ describe Legislation::AnnotationsController do it "does not create an annotation if the draft version is a final version" do sign_in @user - post :create, process_id: @process.id, + post :create, params: { + process_id: @process.id, draft_version_id: @final_version.id, legislation_annotation: { "quote" => "ipsum", "ranges" => [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}], "text": "una anotacion" - } + }} expect(response).to have_http_status(:not_found) end @@ -42,13 +44,15 @@ describe Legislation::AnnotationsController do sign_in @user expect do - xhr :post, :create, process_id: @process.id, - draft_version_id: @draft_version.id, - legislation_annotation: { - "quote" => "ipsum", - "ranges" => [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}], - "text": "una anotacion" - } + post :create, params: { + process_id: @process.id, + draft_version_id: @draft_version.id, + legislation_annotation: { + "quote"=>"ipsum", + "ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}], + "text": "una anotacion" + }}, + xhr: true end.to change { @draft_version.annotations.count }.by(1) end @@ -57,27 +61,31 @@ describe Legislation::AnnotationsController do @process.update_attribute(:allegations_end_date, Date.current - 1.day) expect do - xhr :post, :create, process_id: @process.id, - draft_version_id: @draft_version.id, - legislation_annotation: { - "quote" => "ipsum", - "ranges" => [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}], - "text": "una anotacion" - } - end.not_to change { @draft_version.annotations.count } + post :create, params: { + process_id: @process.id, + draft_version_id: @draft_version.id, + legislation_annotation: { + "quote"=>"ipsum", + "ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}], + "text": "una anotacion" + }}, + xhr: true + end.to_not change { @draft_version.annotations.count } end it "creates 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" => "ipsum", - "ranges" => [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}].to_json, - "text": "una anotacion" - } + post :create, params: { + process_id: @process.id, + draft_version_id: @draft_version.id, + legislation_annotation: { + "quote"=>"ipsum", + "ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}].to_json, + "text": "una anotacion" + }}, + xhr: true end.to change { @draft_version.annotations.count }.by(1) end @@ -88,14 +96,16 @@ describe Legislation::AnnotationsController do sign_in @user expect do - xhr :post, :create, process_id: @process.id, - draft_version_id: @draft_version.id, - legislation_annotation: { - "quote" => "ipsum", - "ranges" => [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}], - "text": "una anotacion" - } - end.not_to change { @draft_version.annotations.count } + post :create, params: { + process_id: @process.id, + draft_version_id: @draft_version.id, + legislation_annotation: { + "quote"=>"ipsum", + "ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}], + "text": "una anotacion" + }}, + xhr: true + end.to_not change { @draft_version.annotations.count } expect(annotation.reload.comments_count).to eq(2) expect(annotation.comments.last.body).to eq("una anotacion") diff --git a/spec/controllers/legislation/answers_controller_spec.rb b/spec/controllers/legislation/answers_controller_spec.rb index b5ef6dd96..3f2e0955f 100644 --- a/spec/controllers/legislation/answers_controller_spec.rb +++ b/spec/controllers/legislation/answers_controller_spec.rb @@ -13,8 +13,7 @@ describe Legislation::AnswersController do it "creates an ahoy event" do sign_in @user - post :create, process_id: @process.id, question_id: @question.id, - legislation_answer: { legislation_question_option_id: @question_option.id } + post :create, params: {process_id: @process.id, question_id: @question.id, legislation_answer: { legislation_question_option_id: @question_option.id }} expect(Ahoy::Event.where(name: :legislation_answer_created).count).to eq 1 expect(Ahoy::Event.last.properties["legislation_answer_id"]).to eq Legislation::Answer.last.id end @@ -23,8 +22,7 @@ describe Legislation::AnswersController do sign_in @user expect do - xhr :post, :create, process_id: @process.id, question_id: @question.id, - legislation_answer: { legislation_question_option_id: @question_option.id } + post :create, params: {process_id: @process.id, question_id: @question.id, legislation_answer: { legislation_question_option_id: @question_option.id }}, xhr: true end.to change { @question.reload.answers_count }.by(1) end @@ -33,8 +31,7 @@ describe Legislation::AnswersController do @process.update_attribute(:debate_end_date, Date.current - 1.day) expect do - xhr :post, :create, process_id: @process.id, question_id: @question.id, - legislation_answer: { legislation_question_option_id: @question_option.id } + post :create, params: {process_id: @process.id, question_id: @question.id, legislation_answer: { legislation_question_option_id: @question_option.id }}, xhr: true end.not_to change { @question.reload.answers_count } end end