diff --git a/app/controllers/api/using_nothing/artworks_controller.rb b/app/controllers/api/using_nothing/artworks_controller.rb new file mode 100644 index 0000000..619b1cc --- /dev/null +++ b/app/controllers/api/using_nothing/artworks_controller.rb @@ -0,0 +1,10 @@ +module Api + module UsingNothing + class ArtworksController < ApplicationController + def index + artworks = Artwork.all + render json: artworks + end + end + end +end diff --git a/app/models/artwork.rb b/app/models/artwork.rb new file mode 100644 index 0000000..c803b1f --- /dev/null +++ b/app/models/artwork.rb @@ -0,0 +1,2 @@ +class Artwork < ApplicationRecord +end diff --git a/config/routes.rb b/config/routes.rb index 9f768e5..593a034 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,7 @@ Rails.application.routes.draw do - # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html - - # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. - # Can be used by load balancers and uptime monitors to verify that the app is live. - get "up" => "rails/health#show", :as => :rails_health_check - - # Defines the root path route ("/") - # root "posts#index" + namespace :api do + namespace :using_nothing do + resources :artworks + end + end end diff --git a/db/migrate/20240305151845_create_artworks.rb b/db/migrate/20240305151845_create_artworks.rb new file mode 100644 index 0000000..ccc780e --- /dev/null +++ b/db/migrate/20240305151845_create_artworks.rb @@ -0,0 +1,11 @@ +class CreateArtworks < ActiveRecord::Migration[7.1] + def change + create_table :artworks do |t| + t.string :artist_name + t.string :title + t.string :medium + t.integer :amount_cents + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..5d285d4 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,26 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[7.1].define(version: 2024_03_05_151845) do + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "artworks", force: :cascade do |t| + t.string "artist_name" + t.string "title" + t.string "medium" + t.integer "amount_cents" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/spec/factories/artwork.rb b/spec/factories/artwork.rb new file mode 100644 index 0000000..0f6a7eb --- /dev/null +++ b/spec/factories/artwork.rb @@ -0,0 +1,8 @@ +FactoryBot.define do + factory :artwork do + amount_cents { 77_000 } + artist_name { "Polly Painter" } + medium { "Very wet paint" } + title { "Just like some flowers or whatever" } + end +end diff --git a/spec/requests/using_nothing/list_artworks_spec.rb b/spec/requests/using_nothing/list_artworks_spec.rb new file mode 100644 index 0000000..0c24418 --- /dev/null +++ b/spec/requests/using_nothing/list_artworks_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +describe "/api/using_nothing/artworks" do + context "without any artworks" do + it "returns an empty array" do + get "/api/using_nothing/artworks" + expect(response.status).to eq 200 + expect(response.parsed_body).to eq [] + end + end + + context "with an artwork" do + let!(:artwork) { FactoryBot.create(:artwork) } + + it "returns that artwork" do + get "/api/using_nothing/artworks" + expect(response.status).to eq 200 + expect(response.parsed_body).to eq [artwork].as_json + end + end + + context "with a few artworks" do + before do + FactoryBot.create_list(:artwork, 3) + end + + it "returns those artworks" do + get "/api/using_nothing/artworks" + expect(response.status).to eq 200 + expect(response.parsed_body.count).to eq 3 + end + end +end