Skip to content

Commit

Permalink
Merge pull request #4 from concertmate/create_event
Browse files Browse the repository at this point in the history
create event action made also happy path and sad path testing
  • Loading branch information
clydeautin authored Sep 12, 2024
2 parents e18077c + 74c1979 commit 70369d4
Show file tree
Hide file tree
Showing 44 changed files with 3,810 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ gem "pg", "~> 1.1"
# Use the Puma web server [https://github.com/puma/puma]
gem "puma", ">= 5.0"
gem 'rspec-rails', '~> 5.0.0'
gem 'pry'

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
# gem "jbuilder"

Expand All @@ -37,12 +35,24 @@ gem "bootsnap", require: false
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin Ajax possible
# gem "rack-cors"

gem "jsonapi-serializer"
gem "faraday"
gem "factory_bot_rails"
gem 'bundler-audit', require: false
gem 'brakeman'

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri windows ]
gem "rspec"
gem "shoulda-matchers", "~> 5.0"
gem 'rswag'
gem "pry"
gem 'faker'
gem 'vcr'
gem 'webmock'
gem 'simplecov'

end

group :development do
Expand Down
71 changes: 71 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,59 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
base64 (0.2.0)
bigdecimal (3.1.8)
bootsnap (1.18.4)
msgpack (~> 1.2)
brakeman (6.2.1)
racc
builder (3.3.0)
bundler-audit (0.9.2)
bundler (>= 1.2.0, < 3)
thor (~> 1.0)
coderay (1.1.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
crack (1.0.0)
bigdecimal
rexml
crass (1.0.6)
date (3.3.4)
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
diff-lcs (1.5.1)
docile (1.4.1)
drb (2.2.1)
erubi (1.13.0)
factory_bot (6.5.0)
activesupport (>= 5.0.0)
factory_bot_rails (6.4.3)
factory_bot (~> 6.4)
railties (>= 5.0.0)
faker (3.4.2)
i18n (>= 1.8.11, < 2)
faraday (2.11.0)
faraday-net_http (>= 2.0, < 3.4)
logger
faraday-net_http (3.3.0)
net-http
globalid (1.2.1)
activesupport (>= 6.1)
hashdiff (1.1.1)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
io-console (0.7.2)
irb (1.14.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
json-schema (4.3.1)
addressable (>= 2.8)
jsonapi-serializer (2.2.0)
activesupport (>= 4.2)
logger (1.6.1)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand All @@ -113,6 +142,8 @@ GEM
minitest (5.25.1)
msgpack (1.7.2)
mutex_m (0.2.0)
net-http (0.4.1)
uri
net-imap (0.4.16)
date
net-protocol
Expand Down Expand Up @@ -141,6 +172,7 @@ GEM
method_source (~> 1.0)
psych (5.1.2)
stringio
public_suffix (6.0.1)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.8.1)
Expand Down Expand Up @@ -186,6 +218,7 @@ GEM
psych (>= 4.0.0)
reline (0.5.10)
io-console (~> 0.5)
rexml (3.3.7)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
Expand All @@ -207,13 +240,41 @@ GEM
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.13.1)
rswag (2.14.0)
rswag-api (= 2.14.0)
rswag-specs (= 2.14.0)
rswag-ui (= 2.14.0)
rswag-api (2.14.0)
activesupport (>= 5.2, < 8.0)
railties (>= 5.2, < 8.0)
rswag-specs (2.14.0)
activesupport (>= 5.2, < 8.0)
json-schema (>= 2.2, < 5.0)
railties (>= 5.2, < 8.0)
rspec-core (>= 2.14)
rswag-ui (2.14.0)
actionpack (>= 5.2, < 8.0)
railties (>= 5.2, < 8.0)
shoulda-matchers (5.3.0)
activesupport (>= 5.2.0)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
stringio (3.1.1)
thor (1.3.2)
timeout (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uri (0.13.1)
vcr (6.3.1)
base64
webmock (3.23.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.8.1)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
Expand All @@ -230,15 +291,25 @@ PLATFORMS

DEPENDENCIES
bootsnap
brakeman
bundler-audit
debug
factory_bot_rails
faker
faraday
jsonapi-serializer
pg (~> 1.1)
pry
puma (>= 5.0)
rails (~> 7.1.3, >= 7.1.3.4)
rspec
rspec-rails (~> 5.0.0)
rswag
shoulda-matchers (~> 5.0)
simplecov
tzinfo-data
vcr
webmock

RUBY VERSION
ruby 3.2.2p53
Expand Down
17 changes: 17 additions & 0 deletions app/controllers/api/v1/events_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Api::V1::EventsController < ApplicationController
def create
event = Event.new(event_params)

if event.save
render json: EventSerializer.new(event), status: :created
else
render json: { errors: event.errors }, status: :unprocessable_entity
end
end

private

def event_params
params.permit(:venue_name, :event_name, :date_time, :artist, :location)
end
end
15 changes: 15 additions & 0 deletions app/serializers/error_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class ErrorSerializer
def initialize(errors_object)
@errors_object = errors_object
end

def serialize_json
{
"errors": [
{
detail: @errors_object.message
}
]
}
end
end
4 changes: 4 additions & 0 deletions app/serializers/event_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class EventSerializer
include JSONAPI::Serializer
attributes :venue_name, :event_name, :date_time, :artist, :location
end
27 changes: 27 additions & 0 deletions bin/brakeman
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'brakeman' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("brakeman", "brakeman")
27 changes: 27 additions & 0 deletions bin/bundle-audit
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'bundle-audit' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("bundler-audit", "bundle-audit")
27 changes: 27 additions & 0 deletions bin/bundler-audit
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'bundler-audit' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("bundler-audit", "bundler-audit")
7 changes: 7 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@

# Defines the root path route ("/")
# root "posts#index"


namespace :api do
namespace :v1 do
resources :events, only: [:show, :create, :update, :destroy]
end
end
end
5 changes: 5 additions & 0 deletions coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"result": {
"line": 100.0
}
}
Loading

0 comments on commit 70369d4

Please sign in to comment.