Commit a67d3d93 authored by Sophie Daringer's avatar Sophie Daringer
Browse files

Add cors files and tests

parent 296c2626
......@@ -41,3 +41,5 @@ end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
gem "rack-cors", "~> 1.1"
......@@ -122,6 +122,8 @@ GEM
puma (4.3.1)
nio4r (~> 2.0)
rack (2.2.2)
rack-cors (1.1.1)
rack (>= 2.0.0)
rack-proxy (0.6.5)
rack
rack-test (1.1.0)
......@@ -255,6 +257,7 @@ DEPENDENCIES
mdl_form!
pg
puma (~> 4.1)
rack-cors (~> 1.1)
rails (~> 6.0.1)
rspec-rails (= 4.0.0.beta3)
rswag-api
......
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '/*', headers: :any, methods: :get
end
allow do
origins 'localhost:3000', '127.0.0.1:3000', 'http://www.kuhn4sports.eu/test-cors/cors.html'
resource '/api/v1/*',
methods: %i(get post put patch delete options head)
end
end
\ No newline at end of file
# frozen_string_literal: true
# file /spec/requests/api_spec.rb
require 'swagger_helper'
RSpec.describe 'Stand Alone API', type: :request do
fixtures :users
before { @user = users(:mando) }
path '/api/v1/users' do
get 'list all the users' do
produces 'abpplication/json'
response(200, 'successful') do
schema type: :object,
properties: {
data: {
type: :array,
items: {
type: :object,
properties: {
id: { type: :string },
type: { type: :string },
attributes: {
type: :object,
properties: {
name: { type: :string },
email: { type: :string }
},
required: %w[name email]
}
},
required: %w[id type attributes]
}
}
}
run_test!
end
end
end
path '/api/v1/users/{id}' do
get 'show user' do
produces 'application/json'
parameter name: 'id', in: :path, type: :string
response 200, 'successful' do
schema type: :object,
properties: {
data: {
type: :object,
properties: {
id: { type: :string },
type: { type: :string },
attributes: {
type: :object,
properties: {
name: { type: :string },
email: { type: :string }
},
required: %w[name email]
}
},
required: %w[id type attributes]
}
}
let(:id) do
u = User.create!(name: 'Luke', email: 'luke@skywalker.net', password: '1234567', password_confirmation: '1234567')
u.id
end
run_test!
end
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment