Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add background drawing slug #7280

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/api/bootcamp/drawings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class API::Bootcamp::DrawingsController < API::Bootcamp::BaseController
def update
@drawing.update(code: params[:code]) if params[:code].present?
@drawing.update(title: params[:title]) if params[:title].present?
@drawing.update(background_slug: params[:background_slug]) if params[:background_slug].present?

render json: {}, status: :ok
end
Expand Down
17 changes: 16 additions & 1 deletion app/helpers/react_components/bootcamp/drawing_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,32 @@ def data
{
drawing: {
uuid: drawing.uuid,
title: drawing.title
title: drawing.title,
background_slug: drawing.background_slug
},
code: {
code: drawing.code,
stored_at: drawing.updated_at
},
backgrounds: BACKGROUNDS,
links: {
update_code: Exercism::Routes.api_bootcamp_drawing_url(drawing),
drawings_index: Exercism::Routes.bootcamp_project_path(:drawing)
}
}
end
end

BACKGROUNDS = [
{
slug: "none",
title: "No background",
image_url: nil
},
{
slug: "room",
title: "A room to decorate",
image_url: "..."
}
].freeze
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddBackgroundSlugToDrawings < ActiveRecord::Migration[7.0]
def change
return if Rails.env.production?

add_column :bootcamp_drawings, :background_slug, :string, null: false, default: "none"
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2025_01_09_143039) do
ActiveRecord::Schema[7.0].define(version: 2025_01_10_130304) do
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
Expand Down Expand Up @@ -91,6 +91,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "title", null: false
t.string "background_slug", default: "none", null: false
t.index ["user_id"], name: "index_bootcamp_drawings_on_user_id"
end

Expand Down
10 changes: 7 additions & 3 deletions test/controllers/api/bootcamp/drawings_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,34 @@ class API::Bootcamp::DrawingsControllerTest < API::BaseTestCase
drawing = create(:bootcamp_drawing, user:)
code = "Something"
title = "New title"
background_slug = "beauty"

setup_user(user)
patch api_bootcamp_drawing_url(drawing, code:, title:), headers: @headers
patch api_bootcamp_drawing_url(drawing, code:, title:, background_slug:), headers: @headers

assert_response :ok
assert_json_response({})

assert code, drawing.reload.code
assert title, drawing.reload.title
assert background_slug, drawing.reload.background_slug
end

test "update: missing title doesn't touch code" do
user = create :user
code = "Something"
title = "Some title"
drawing = create(:bootcamp_drawing, user:, code:, title:)
background_slug = "beauty"
drawing = create(:bootcamp_drawing, user:, code:, title:, background_slug:)

setup_user(user)
patch api_bootcamp_drawing_url(drawing, title: ''), headers: @headers
patch api_bootcamp_drawing_url(drawing, title: '', background_slug: ''), headers: @headers

assert_response :ok
assert_json_response({})

assert code, drawing.reload.code
assert title, drawing.reload.title
assert background_slug, drawing.reload.background_slug
end
end
Loading