validate project if set

pull/5233/head
Markus Kahl 8 years ago
parent 9e79d02d8f
commit e257294795
  1. 6
      app/contracts/queries/base_contract.rb
  2. 2
      config/locales/en.yml
  3. 15
      spec/requests/api/v3/queries/create_query_spec.rb

@ -45,10 +45,16 @@ module Queries
attr_reader :user
validate :validate_project
def initialize(query, user)
super query
@user = user
end
def validate_project
errors.add :project, :error_not_found if project_id && !Project.exists?(project_id)
end
end
end

@ -253,6 +253,8 @@ en:
models:
"queries/create_contract":
attributes:
project:
error_not_found: "not found"
public:
error_unauthorized: "- The user has no permission to create public queries."
"relations/base_contract":

@ -134,22 +134,13 @@ describe "POST /api/v3/queries", type: :request do
JSON.parse response.body
end
it "yields a 404 error given an unknown user" do
params[:_links][:user][:href] = "/api/v3/users/#{user.id}352"
post!
expect(response.status).to eq 404
expect(json["message"]).to eq "User #{user.id}352 not found"
end
it "yields a 404 error given an unknown project" do
it "yields a 422 error given an unknown project" do
params[:_links][:project][:href] = "/api/v3/projects/#{project.id}42"
post!
expect(response.status).to eq 404
expect(json["message"]).to eq "Project #{project.id}42 not found"
expect(response.status).to eq 422
expect(json["message"]).to eq "Project not found"
end
it "yields a 422 error given an unknown operator" do

Loading…
Cancel
Save