Skip to content

Commit 61d865b

Browse files
committed
Added all helper and spec files for Rspec and Rswag
1 parent ae04512 commit 61d865b

File tree

12 files changed

+1401
-1
lines changed

12 files changed

+1401
-1
lines changed

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--require spec_helper

Gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ gem 'stimulus-rails'
2626
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
2727
gem 'jbuilder'
2828

29+
# Rswag
30+
gem 'rswag'
31+
2932
# Ruby Couchbase ORM
3033
gem 'couchbase-orm', git: 'https://github.com/doctolib/couchbase-orm'
3134

@@ -61,6 +64,11 @@ group :development do
6164

6265
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
6366
# gem "spring"
67+
68+
gem 'dotenv'
69+
70+
gem 'rspec-rails'
71+
gem 'rubocop', require: false
6472
end
6573

6674
group :test do

config/couchbase.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ development:
99

1010
test:
1111
<<: *common
12-
bucket: dev_bucket_test
12+
bucket: travel-sample

spec/rails_helper.rb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# This file is copied to spec/ when you run 'rails generate rspec:install'
2+
require 'spec_helper'
3+
ENV['RAILS_ENV'] ||= 'test'
4+
require_relative '../config/environment'
5+
# Prevent database truncation if the environment is production
6+
abort("The Rails environment is running in production mode!") if Rails.env.production?
7+
require 'rspec/rails'
8+
# Add additional requires below this line. Rails is not loaded until this point!
9+
10+
# Requires supporting ruby files with custom matchers and macros, etc, in
11+
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
12+
# run as spec files by default. This means that files in spec/support that end
13+
# in _spec.rb will both be required and run as specs, causing the specs to be
14+
# run twice. It is recommended that you do not name files matching this glob to
15+
# end with _spec.rb. You can configure this pattern with the --pattern
16+
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
17+
#
18+
# The following line is provided for convenience purposes. It has the downside
19+
# of increasing the boot-up time by auto-requiring all files in the support
20+
# directory. Alternatively, in the individual `*_spec.rb` files, manually
21+
# require only the support files necessary.
22+
#
23+
# Rails.root.glob('spec/support/**/*.rb').sort.each { |f| require f }
24+
25+
# Checks for pending migrations and applies them before tests are run.
26+
# If you are not using ActiveRecord, you can remove these lines.
27+
begin
28+
ActiveRecord::Migration.maintain_test_schema!
29+
rescue ActiveRecord::PendingMigrationError => e
30+
abort e.to_s.strip
31+
end
32+
RSpec.configure do |config|
33+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
34+
config.fixture_paths = [
35+
Rails.root.join('spec/fixtures')
36+
]
37+
38+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
39+
# examples within a transaction, remove the following line or assign false
40+
# instead of true.
41+
config.use_transactional_fixtures = true
42+
43+
# You can uncomment this line to turn off ActiveRecord support entirely.
44+
# config.use_active_record = false
45+
46+
# RSpec Rails can automatically mix in different behaviours to your tests
47+
# based on their file location, for example enabling you to call `get` and
48+
# `post` in specs under `spec/controllers`.
49+
#
50+
# You can disable this behaviour by removing the line below, and instead
51+
# explicitly tag your specs with their type, e.g.:
52+
#
53+
# RSpec.describe UsersController, type: :controller do
54+
# # ...
55+
# end
56+
#
57+
# The different available types are documented in the features, such as in
58+
# https://rspec.info/features/6-0/rspec-rails
59+
config.infer_spec_type_from_file_location!
60+
61+
# Filter lines from Rails gems in backtraces.
62+
config.filter_rails_from_backtrace!
63+
# arbitrary gems may also be filtered via:
64+
# config.filter_gems_from_backtrace("gem name")
65+
end
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
require 'swagger_helper'
2+
3+
describe 'Airlines API', type: :request do
4+
path '/api/v1/airlines/{id}' do
5+
get 'Retrieves an airline by ID' do
6+
tags 'Airlines'
7+
produces 'application/json'
8+
parameter name: :id, in: :path, type: :string, description: 'ID of the airline'
9+
10+
response '200', 'airline found' do
11+
schema type: :object,
12+
properties: {
13+
name: { type: :string },
14+
iata: { type: :string },
15+
icao: { type: :string },
16+
callsign: { type: :string },
17+
country: { type: :string }
18+
},
19+
required: %w[name iata icao callsign country]
20+
21+
let(:id) { 'airline_10' }
22+
run_test!
23+
end
24+
25+
response '404', 'airline not found' do
26+
let(:id) { 'invalid_id' }
27+
run_test!
28+
end
29+
end
30+
31+
post 'Creates an airline' do
32+
tags 'Airlines'
33+
consumes 'application/json'
34+
parameter name: :id, in: :path, type: :string, description: 'ID of the airline'
35+
parameter name: :airline, in: :body, schema: {
36+
type: :object,
37+
properties: {
38+
name: { type: :string },
39+
iata: { type: :string },
40+
icao: { type: :string },
41+
callsign: { type: :string },
42+
country: { type: :string }
43+
},
44+
required: %w[name iata icao callsign country]
45+
}
46+
47+
response '201', 'airline created' do
48+
let(:airline) { { name: 'Foo Airlines', iata: 'FA', icao: 'FOO', callsign: 'FOO', country: 'US' } }
49+
run_test!
50+
end
51+
52+
response '400', 'bad request' do
53+
let(:airline) { { name: 'Foo Airlines', iata: 'FA', icao: 'FOO', callsign: 'FOO' } }
54+
run_test!
55+
end
56+
57+
response '409', 'airline already exists' do
58+
let(:airline) { { name: 'Foo Airlines', iata: 'FA', icao: 'FOO', callsign: 'FOO', country: 'US' } }
59+
run_test!
60+
end
61+
end
62+
63+
put 'Updates an airline' do
64+
tags 'Airlines'
65+
consumes 'application/json'
66+
parameter name: :id, in: :path, type: :string, description: 'ID of the airline'
67+
parameter name: :airline, in: :body, schema: {
68+
type: :object,
69+
properties: {
70+
name: { type: :string },
71+
iata: { type: :string },
72+
icao: { type: :string },
73+
callsign: { type: :string },
74+
country: { type: :string }
75+
}
76+
}
77+
78+
response '200', 'airline updated' do
79+
let(:id) { 'airline_10' }
80+
let(:airline) { { name: 'Updated Airline' } }
81+
run_test!
82+
end
83+
84+
response '400', 'bad request' do
85+
let(:id) { 'airline_10' }
86+
let(:airline) { { name: '' } }
87+
run_test!
88+
end
89+
end
90+
91+
delete 'Deletes an airline' do
92+
tags 'Airlines'
93+
parameter name: :id, in: :path, type: :string, description: 'ID of the airline'
94+
95+
response '204', 'airline deleted' do
96+
let(:id) { 'airline_10' }
97+
run_test!
98+
end
99+
100+
response '404', 'airline not found' do
101+
let(:id) { 'invalid_id' }
102+
run_test!
103+
end
104+
end
105+
end
106+
107+
path '/api/v1/airlines/list' do
108+
get 'Retrieves all airlines by country' do
109+
tags 'Airlines'
110+
produces 'application/json'
111+
parameter name: :country, in: :query, type: :string, description: 'Country of the airline'
112+
parameter name: :limit, in: :query, type: :integer, description: 'Maximum number of results to return'
113+
parameter name: :offset, in: :query, type: :integer, description: 'Number of results to skip for pagination'
114+
115+
response '200', 'airlines found' do
116+
schema type: :array,
117+
items: {
118+
type: :object,
119+
properties: {
120+
name: { type: :string },
121+
iata: { type: :string },
122+
icao: { type: :string },
123+
callsign: { type: :string },
124+
country: { type: :string }
125+
},
126+
required: %w[name iata icao callsign country]
127+
}
128+
129+
let(:country) { 'United States' }
130+
let(:limit) { 10 }
131+
let(:offset) { 0 }
132+
run_test!
133+
end
134+
end
135+
end
136+
137+
path '/api/v1/airlines/to-airport' do
138+
get 'Retrieves airlines flying to a destination airport' do
139+
tags 'Airlines'
140+
produces 'application/json'
141+
parameter name: :destinationAirportCode, in: :query, type: :string,
142+
description: 'The ICAO or IATA code of the destination airport'
143+
parameter name: :limit, in: :query, type: :integer, description: 'Maximum number of results to return'
144+
parameter name: :offset, in: :query, type: :integer, description: 'Number of results to skip for pagination'
145+
146+
response '200', 'airlines found' do
147+
schema type: :array,
148+
items: {
149+
type: :object,
150+
properties: {
151+
name: { type: :string },
152+
iata: { type: :string },
153+
icao: { type: :string },
154+
callsign: { type: :string },
155+
country: { type: :string }
156+
},
157+
required: %w[name iata icao callsign country]
158+
}
159+
160+
let(:destinationAirportCode) { 'LAX' }
161+
let(:limit) { 10 }
162+
let(:offset) { 0 }
163+
run_test!
164+
end
165+
166+
response '400', 'bad request' do
167+
let(:destinationAirportCode) { '' }
168+
run_test!
169+
end
170+
end
171+
end
172+
end

0 commit comments

Comments
 (0)