From 471110d33d1291322b605f3d76a0e88c596a6583 Mon Sep 17 00:00:00 2001 From: Nandinii Yeleswarapu Date: Wed, 2 Oct 2024 14:24:15 -0500 Subject: [PATCH 1/6] create basic stubbed game controller --- app/controllers/games_controller.rb | 75 ++++++++++++++++++++++ app/helpers/games_helper.rb | 2 + app/models/game.rb | 2 + app/views/games/_form.html.erb | 27 ++++++++ app/views/games/_game.html.erb | 12 ++++ app/views/games/_game.json.jbuilder | 2 + app/views/games/_games.html.erb | 22 +++++++ app/views/games/demo_game.html.erb | 5 ++ app/views/games/edit.html.erb | 12 ++++ app/views/games/index.html.erb | 5 ++ app/views/games/index.json.jbuilder | 1 + app/views/games/new.html.erb | 11 ++++ app/views/games/show.html.erb | 8 +++ app/views/games/show.json.jbuilder | 1 + config/routes.rb | 11 ++-- db/migrate/20241002002856_create_games.rb | 9 +++ db/schema.rb | 20 ++++++ db/seeds.rb | 10 +++ features/.DS_Store | Bin 0 -> 6148 bytes test/controllers/games_controller_test.rb | 48 ++++++++++++++ test/system/games_test.rb | 43 +++++++++++++ 21 files changed, 322 insertions(+), 4 deletions(-) create mode 100644 app/controllers/games_controller.rb create mode 100644 app/helpers/games_helper.rb create mode 100644 app/models/game.rb create mode 100644 app/views/games/_form.html.erb create mode 100644 app/views/games/_game.html.erb create mode 100644 app/views/games/_game.json.jbuilder create mode 100644 app/views/games/_games.html.erb create mode 100644 app/views/games/demo_game.html.erb create mode 100644 app/views/games/edit.html.erb create mode 100644 app/views/games/index.html.erb create mode 100644 app/views/games/index.json.jbuilder create mode 100644 app/views/games/new.html.erb create mode 100644 app/views/games/show.html.erb create mode 100644 app/views/games/show.json.jbuilder create mode 100644 db/migrate/20241002002856_create_games.rb create mode 100644 db/schema.rb create mode 100644 features/.DS_Store create mode 100644 test/controllers/games_controller_test.rb create mode 100644 test/system/games_test.rb diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb new file mode 100644 index 00000000..63dddf2f --- /dev/null +++ b/app/controllers/games_controller.rb @@ -0,0 +1,75 @@ +class GamesController < ApplicationController + before_action :set_game, only: %i[ show edit update destroy ] + + # GET /games or /games.json + def index + @games = Game.all + end + + # GET /games/1 or /games/1.json + def show + @game = Game.find(params[:id]) + redirect_to send(@game.game_path) + end + + def demo_game + end + + # GET /games/new + def new + @game = Game.new + end + + # GET /games/1/edit + def edit + end + + # POST /games or /games.json + def create + @game = Game.new(game_params) + + respond_to do |format| + if @game.save + format.html { redirect_to @game, notice: "Game was successfully created." } + format.json { render :show, status: :created, location: @game } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @game.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /games/1 or /games/1.json + def update + respond_to do |format| + if @game.update(game_params) + format.html { redirect_to @game, notice: "Game was successfully updated." } + format.json { render :show, status: :ok, location: @game } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @game.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /games/1 or /games/1.json + def destroy + @game.destroy! + + respond_to do |format| + format.html { redirect_to games_path, status: :see_other, notice: "Game was successfully destroyed." } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_game + @game = Game.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def game_params + params.require(:game).permit(:name, :game_path) + end +end diff --git a/app/helpers/games_helper.rb b/app/helpers/games_helper.rb new file mode 100644 index 00000000..2ef8c1f4 --- /dev/null +++ b/app/helpers/games_helper.rb @@ -0,0 +1,2 @@ +module GamesHelper +end diff --git a/app/models/game.rb b/app/models/game.rb new file mode 100644 index 00000000..56c90b19 --- /dev/null +++ b/app/models/game.rb @@ -0,0 +1,2 @@ +class Game < ActiveRecord::Base +end \ No newline at end of file diff --git a/app/views/games/_form.html.erb b/app/views/games/_form.html.erb new file mode 100644 index 00000000..e9f5d203 --- /dev/null +++ b/app/views/games/_form.html.erb @@ -0,0 +1,27 @@ +<%= form_with(model: game) do |form| %> + <% if game.errors.any? %> +
+

<%= pluralize(game.errors.count, "error") %> prohibited this game from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :name, style: "display: block" %> + <%= form.text_field :name %> +
+ +
+ <%= form.label :game_path, style: "display: block" %> + <%= form.text_field :game_path %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/games/_game.html.erb b/app/views/games/_game.html.erb new file mode 100644 index 00000000..5bd20154 --- /dev/null +++ b/app/views/games/_game.html.erb @@ -0,0 +1,12 @@ +
+

+ Name: + <%= game.name %> +

+ +

+ Game path: + <%= game.game_path %> +

+ +
diff --git a/app/views/games/_game.json.jbuilder b/app/views/games/_game.json.jbuilder new file mode 100644 index 00000000..d8eea494 --- /dev/null +++ b/app/views/games/_game.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! game, :id, :name, :game_path, :created_at, :updated_at +json.url game_url(game, format: :json) diff --git a/app/views/games/_games.html.erb b/app/views/games/_games.html.erb new file mode 100644 index 00000000..4d00c1be --- /dev/null +++ b/app/views/games/_games.html.erb @@ -0,0 +1,22 @@ +

<%= notice %>

+<% content_for :title, "Games" %> + +

Games

+ +
+ + + <% @games.each_slice(4) do |row| %> + + <% row.each do |game| %> + + <% end %> + + <% end %> + +
+ <%= game.name %> +
+ <%= link_to "Play", game_path(game) %> +
+
\ No newline at end of file diff --git a/app/views/games/demo_game.html.erb b/app/views/games/demo_game.html.erb new file mode 100644 index 00000000..a73fa041 --- /dev/null +++ b/app/views/games/demo_game.html.erb @@ -0,0 +1,5 @@ +

<%= notice %>

+ +
+ Demo Game Page +
diff --git a/app/views/games/edit.html.erb b/app/views/games/edit.html.erb new file mode 100644 index 00000000..287b0a9f --- /dev/null +++ b/app/views/games/edit.html.erb @@ -0,0 +1,12 @@ +<% content_for :title, "Editing game" %> + +

Editing game

+ +<%= render "form", game: @game %> + +
+ +
+ <%= link_to "Show this game", @game %> | + <%= link_to "Back to games", games_path %> +
diff --git a/app/views/games/index.html.erb b/app/views/games/index.html.erb new file mode 100644 index 00000000..0e8e5401 --- /dev/null +++ b/app/views/games/index.html.erb @@ -0,0 +1,5 @@ +

<%= notice %>

+ +<% content_for :title, "Games" %> + +<%= render "games" %> \ No newline at end of file diff --git a/app/views/games/index.json.jbuilder b/app/views/games/index.json.jbuilder new file mode 100644 index 00000000..e6305a05 --- /dev/null +++ b/app/views/games/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @games, partial: "games/game", as: :game diff --git a/app/views/games/new.html.erb b/app/views/games/new.html.erb new file mode 100644 index 00000000..47228e5d --- /dev/null +++ b/app/views/games/new.html.erb @@ -0,0 +1,11 @@ +<% content_for :title, "New game" %> + +

New game

+ +<%= render "form", game: @game %> + +
+ +
+ <%= link_to "Back to games", games_path %> +
diff --git a/app/views/games/show.html.erb b/app/views/games/show.html.erb new file mode 100644 index 00000000..0ac3785d --- /dev/null +++ b/app/views/games/show.html.erb @@ -0,0 +1,8 @@ +

<%= notice %>

+ +
+ <%= link_to "Edit this game", edit_game_path(@game) %> | + <%= link_to "Back to games", games_path %> + + <%= button_to "Destroy this game", @game, method: :delete %> +
diff --git a/app/views/games/show.json.jbuilder b/app/views/games/show.json.jbuilder new file mode 100644 index 00000000..c04bffe0 --- /dev/null +++ b/app/views/games/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "games/game", game: @game diff --git a/config/routes.rb b/config/routes.rb index e1e77031..6d80d75f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,10 @@ 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. + resources :games, only: [:show, :demo_game, :index] get "up" => "rails/health#show", as: :rails_health_check + root :to => redirect('/games') + + ## stub paths to demo game landing page + get '/spellingbee/:id', to: 'games#demo_game', as: 'spellingbee' + get '/wordle/:id', to: 'games#demo_game', as: 'wordle' + get '/letterboxed/:id', to: 'games#demo_game', as: 'letterboxed' end diff --git a/db/migrate/20241002002856_create_games.rb b/db/migrate/20241002002856_create_games.rb new file mode 100644 index 00000000..f07419e5 --- /dev/null +++ b/db/migrate/20241002002856_create_games.rb @@ -0,0 +1,9 @@ +class CreateGames < ActiveRecord::Migration[7.2] + def change + create_table :games do |t| + t.string 'name' + t.string 'game_path' + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 00000000..d43b0b5c --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,20 @@ +# 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.2].define(version: 2024_10_02_002856) do + create_table "games", force: :cascade do |t| + t.string "name" + t.string "game_path" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end +end diff --git a/db/seeds.rb b/db/seeds.rb index 4fbd6ed9..a2f9563a 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,3 +7,13 @@ # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| # MovieGenre.find_or_create_by!(name: genre_name) # end + +initial_games = [ + {:name => 'Spelling Bee', :game_path => 'spellingbee_path'}, + {:name => 'Wordle', :game_path => 'wordle_path'}, + {:name => 'Letter Boxed', :game_path => 'letterboxed_path'} +] + +initial_games.each do |game| + Game.find_or_create_by!(game) +end \ No newline at end of file diff --git a/features/.DS_Store b/features/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c5cf507b1e44bb99dca76277d70cdaa54ed90624 GIT binary patch literal 6148 zcmeHK!EVz)5S>i}aa1AYP^4Zet<-B&(iVXtE+#Dpt_^|%pkT+YYSnn7*j5fvB%k49 zxbh|Z4!qgjAkqN0B0w|J>>H2gt?jqAcbACNs7{WFdPEe!8CzX6KQTVfzGW?+X#D&^sBt^-a zS6Pvm#mLk}Qd;iVod~)?chcKmE>DKXeSJE7yz1-a@MO@}4^JPhR^8zK;e#g^lk5C_ zVLq@(_*C$%Si9$O4IkHmpeP^;hyu5)fd3B#ySIED>0T5N1^zt+`2V2cjG@QIq5XBB zv0DHjFC(oX=A|KXw8zk6;}Ba`3R5X=hm%<gj<*f>N6CJO;8gEXSRA64KRUR-oK literal 0 HcmV?d00001 diff --git a/test/controllers/games_controller_test.rb b/test/controllers/games_controller_test.rb new file mode 100644 index 00000000..90bfc200 --- /dev/null +++ b/test/controllers/games_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class GamesControllerTest < ActionDispatch::IntegrationTest + setup do + @game = games(:one) + end + + test "should get index" do + get games_url + assert_response :success + end + + test "should get new" do + get new_game_url + assert_response :success + end + + test "should create game" do + assert_difference("Game.count") do + post games_url, params: { game: { game_path: @game.game_path, name: @game.name } } + end + + assert_redirected_to game_url(Game.last) + end + + test "should show game" do + get game_url(@game) + assert_response :success + end + + test "should get edit" do + get edit_game_url(@game) + assert_response :success + end + + test "should update game" do + patch game_url(@game), params: { game: { game_path: @game.game_path, name: @game.name } } + assert_redirected_to game_url(@game) + end + + test "should destroy game" do + assert_difference("Game.count", -1) do + delete game_url(@game) + end + + assert_redirected_to games_url + end +end diff --git a/test/system/games_test.rb b/test/system/games_test.rb new file mode 100644 index 00000000..1b7d1439 --- /dev/null +++ b/test/system/games_test.rb @@ -0,0 +1,43 @@ +require "application_system_test_case" + +class GamesTest < ApplicationSystemTestCase + setup do + @game = games(:one) + end + + test "visiting the index" do + visit games_url + assert_selector "h1", text: "Games" + end + + test "should create game" do + visit games_url + click_on "New game" + + fill_in "Game path", with: @game.game_path + fill_in "Name", with: @game.name + click_on "Create Game" + + assert_text "Game was successfully created" + click_on "Back" + end + + test "should update Game" do + visit game_url(@game) + click_on "Edit this game", match: :first + + fill_in "Game path", with: @game.game_path + fill_in "Name", with: @game.name + click_on "Update Game" + + assert_text "Game was successfully updated" + click_on "Back" + end + + test "should destroy Game" do + visit game_url(@game) + click_on "Destroy this game", match: :first + + assert_text "Game was successfully destroyed" + end +end From f3f7e52ff3d23bb5050bb592f260eaf05b45608d Mon Sep 17 00:00:00 2001 From: Junchao Wu Date: Wed, 2 Oct 2024 14:24:58 -0500 Subject: [PATCH 2/6] basic landing page --- Gemfile | 1 - Gemfile.lock | 11 +-- app/assets/stylesheets/pages.css | 92 +++++++++++++++++++++++ app/controllers/pages_controller.rb | 5 ++ app/helpers/pages_helper.rb | 2 + app/models/game.rb | 4 + app/views/pages/index.html.erb | 33 ++++++++ config/routes.rb | 1 + db/migrate/20241002170741_create_games.rb | 10 +++ db/schema.rb | 20 +++++ db/seeds.rb | 3 + test/controllers/pages_controller_test.rb | 8 ++ test/fixtures/games.yml | 9 +++ test/models/game_test.rb | 7 ++ 14 files changed, 198 insertions(+), 8 deletions(-) create mode 100644 app/assets/stylesheets/pages.css create mode 100644 app/controllers/pages_controller.rb create mode 100644 app/helpers/pages_helper.rb create mode 100644 app/models/game.rb create mode 100644 app/views/pages/index.html.erb create mode 100644 db/migrate/20241002170741_create_games.rb create mode 100644 db/schema.rb create mode 100644 test/controllers/pages_controller_test.rb create mode 100644 test/fixtures/games.yml create mode 100644 test/models/game_test.rb diff --git a/Gemfile b/Gemfile index 79802f3d..5ea6f9ba 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,4 @@ source "https://rubygems.org" -ruby "3.3.4" # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" gem "rails", "~> 7.2.1" diff --git a/Gemfile.lock b/Gemfile.lock index 79eeeb21..32da4b67 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -176,7 +176,9 @@ GEM zeitwerk (~> 2.6) erubi (1.13.0) execjs (2.9.1) - ffi (1.17.0) + ffi (1.17.0-aarch64-linux-gnu) + ffi (1.17.0-arm64-darwin) + ffi (1.17.0-x86_64-darwin) ffi (1.17.0-x86_64-linux-gnu) flay (2.13.3) erubi (~> 1.10) @@ -224,7 +226,6 @@ GEM marcel (1.0.4) matrix (0.4.2) mini_mime (1.1.5) - mini_portile2 (2.8.7) minitest (5.25.1) msgpack (1.7.2) multi_test (1.1.0) @@ -400,8 +401,7 @@ GEM actionpack (>= 6.1) activesupport (>= 6.1) sprockets (>= 3.0.0) - sqlite3 (2.0.4) - mini_portile2 (~> 2.8.0) + sqlite3 (2.0.4-aarch64-linux-gnu) sqlite3 (2.0.4-arm64-darwin) sqlite3 (2.0.4-x86_64-darwin) sqlite3 (2.0.4-x86_64-linux-gnu) @@ -478,8 +478,5 @@ DEPENDENCIES tzinfo-data uglifier -RUBY VERSION - ruby 3.3.4p94 - BUNDLED WITH 2.5.18 diff --git a/app/assets/stylesheets/pages.css b/app/assets/stylesheets/pages.css new file mode 100644 index 00000000..ecd60743 --- /dev/null +++ b/app/assets/stylesheets/pages.css @@ -0,0 +1,92 @@ +/* app/assets/stylesheets/pages.css */ + +.container { + padding: 20px; +} + +.header { + display: flex; + justify-content: space-between; + align-items: center; +} + +h2 { + font-size: 24px; +} + +.btn-login { + background-color: #4caf50; + color: white; + padding: 10px 20px; + text-align: center; + border: none; + border-radius: 5px; + cursor: pointer; +} + +.dropdown { + position: relative; + display: inline-block; +} + +.dropbtn { + background-color: #4caf50; + color: white; + padding: 10px 20px; + font-size: 16px; + border: none; + cursor: pointer; + border-radius: 5px; +} + +.dropdown-content { + display: none; + position: absolute; + background-color: #f9f9f9; + min-width: 160px; + box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); + z-index: 1; +} + +.dropdown-content a { + color: black; + padding: 12px 16px; + text-decoration: none; + display: block; +} + +.dropdown-content a:hover { + background-color: #f1f1f1; +} + +.dropdown:hover .dropdown-content { + display: block; +} + +.dropdown:hover .dropbtn { + background-color: #3e8e41; +} + +.game-list { + display: grid; + grid-template-columns: repeat(3, 1fr); + gap: 20px; + margin-top: 20px; +} + +.game-item { + padding: 15px; + border: 1px solid #ddd; + text-align: center; + border-radius: 8px; +} + +.btn-play { + background-color: #4caf50; + color: white; + padding: 10px 20px; + text-align: center; + border: none; + border-radius: 5px; + cursor: pointer; +} diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb new file mode 100644 index 00000000..6a000b92 --- /dev/null +++ b/app/controllers/pages_controller.rb @@ -0,0 +1,5 @@ +class PagesController < ApplicationController + def index + @games = Game.all + end +end diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb new file mode 100644 index 00000000..2c057fd0 --- /dev/null +++ b/app/helpers/pages_helper.rb @@ -0,0 +1,2 @@ +module PagesHelper +end diff --git a/app/models/game.rb b/app/models/game.rb new file mode 100644 index 00000000..eeb2a1df --- /dev/null +++ b/app/models/game.rb @@ -0,0 +1,4 @@ +class Game < ApplicationRecord + validates :name, presence: true + validates :description, presence: true +end diff --git a/app/views/pages/index.html.erb b/app/views/pages/index.html.erb new file mode 100644 index 00000000..f2b6efa3 --- /dev/null +++ b/app/views/pages/index.html.erb @@ -0,0 +1,33 @@ + +
+ +
+

Hello, <%="Guest" %>!

+ + <% if true %> + + + <% else %> + + <%= link_to 'Log In', '#', class: 'btn btn-login' %> + <% end %> +
+ + +
+ <% @games.each do |game| %> +
+

<%= game.name %>

+

<%= game.description %>

+ <%= link_to 'Play', '#', class: 'btn btn-play' %> +
+ <% end %> +
+
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index e1e77031..6b94d400 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + root "pages#index" # Set this as the homepage route # 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. diff --git a/db/migrate/20241002170741_create_games.rb b/db/migrate/20241002170741_create_games.rb new file mode 100644 index 00000000..da67109f --- /dev/null +++ b/db/migrate/20241002170741_create_games.rb @@ -0,0 +1,10 @@ +class CreateGames < ActiveRecord::Migration[7.2] + def change + create_table :games do |t| + t.string :name + t.text :description + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 00000000..b3a109c2 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,20 @@ +# 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.2].define(version: 2024_10_02_170741) do + create_table "games", force: :cascade do |t| + t.string "name" + t.text "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end +end diff --git a/db/seeds.rb b/db/seeds.rb index 4fbd6ed9..5167da55 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,3 +7,6 @@ # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| # MovieGenre.find_or_create_by!(name: genre_name) # end +Game.create(name: "Space Invaders", description: "Defend the earth from alien invaders!") +Game.create(name: "Pac-Man", description: "Navigate the maze and eat all the dots!") +Game.create(name: "Tetris", description: "Arrange the falling blocks to complete lines!") diff --git a/test/controllers/pages_controller_test.rb b/test/controllers/pages_controller_test.rb new file mode 100644 index 00000000..d975bb19 --- /dev/null +++ b/test/controllers/pages_controller_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class PagesControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get pages_index_url + assert_response :success + end +end diff --git a/test/fixtures/games.yml b/test/fixtures/games.yml new file mode 100644 index 00000000..382f6d84 --- /dev/null +++ b/test/fixtures/games.yml @@ -0,0 +1,9 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + description: MyText + +two: + name: MyString + description: MyText diff --git a/test/models/game_test.rb b/test/models/game_test.rb new file mode 100644 index 00000000..6628fae0 --- /dev/null +++ b/test/models/game_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class GameTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From a4852ea9694ca3224e8efb8097c9c065bf81e71d Mon Sep 17 00:00:00 2001 From: Nandinii Yeleswarapu Date: Wed, 2 Oct 2024 14:48:48 -0500 Subject: [PATCH 3/6] initial base scrum9+4 for integration --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 84cf45fb..2f892a45 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Rails.application.routes.draw do resources :games - root "games#index" + root :to => redirect('/games') ## stub paths to demo game landing page get '/spellingbee/:id', to: 'games#demo_game', as: 'spellingbee' From 0fe1e36d0d6b863cbf88a157ea5fe70fddc4af00 Mon Sep 17 00:00:00 2001 From: Junchao Wu Date: Wed, 2 Oct 2024 15:05:26 -0500 Subject: [PATCH 4/6] remove unused attribute for the db --- app/models/game.rb | 1 - db/schema.rb | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/game.rb b/app/models/game.rb index 436341d9..a58d4f13 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -1,4 +1,3 @@ class Game < ApplicationRecord validates :name, presence: true - validates :description, presence: true end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 46288bee..d43b0b5c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -14,6 +14,7 @@ create_table "games", force: :cascade do |t| t.string "name" t.string "game_path" - t.timestamps + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end end From 2c19bd3c023eb03b6885e5f2eb11a99381c60cf2 Mon Sep 17 00:00:00 2001 From: Nandinii Yeleswarapu Date: Wed, 2 Oct 2024 15:20:34 -0500 Subject: [PATCH 5/6] add back deleted health check route --- config/routes.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index 2f892a45..8391605a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,6 +2,8 @@ resources :games root :to => redirect('/games') + get "up" => "rails/health#show", as: :rails_health_check + ## stub paths to demo game landing page get '/spellingbee/:id', to: 'games#demo_game', as: 'spellingbee' get '/wordle/:id', to: 'games#demo_game', as: 'wordle' From 04b45dfe56f49f0bf923bcc1a8d50a51c77f6079 Mon Sep 17 00:00:00 2001 From: Junchao Wu Date: Wed, 2 Oct 2024 19:42:29 -0500 Subject: [PATCH 6/6] remove duplicate files, add basic front-end functions to main page --- .../stylesheets/{pages.css => games.css} | 6 ++++ app/helpers/pages_helper.rb | 2 -- app/views/games/_games.html.erb | 24 +++++--------- app/views/games/index.html.erb | 16 ++++++--- app/views/pages/index.html.erb | 33 ------------------- 5 files changed, 26 insertions(+), 55 deletions(-) rename app/assets/stylesheets/{pages.css => games.css} (94%) delete mode 100644 app/helpers/pages_helper.rb delete mode 100644 app/views/pages/index.html.erb diff --git a/app/assets/stylesheets/pages.css b/app/assets/stylesheets/games.css similarity index 94% rename from app/assets/stylesheets/pages.css rename to app/assets/stylesheets/games.css index ecd60743..b126a87e 100644 --- a/app/assets/stylesheets/pages.css +++ b/app/assets/stylesheets/games.css @@ -24,6 +24,10 @@ h2 { cursor: pointer; } +.btn-admin { + background-color: red; +} + .dropdown { position: relative; display: inline-block; @@ -72,6 +76,8 @@ h2 { grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 20px; + max-width: 1600px; + margin: 0 auto; } .game-item { diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb deleted file mode 100644 index 2c057fd0..00000000 --- a/app/helpers/pages_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module PagesHelper -end diff --git a/app/views/games/_games.html.erb b/app/views/games/_games.html.erb index 4d00c1be..83e94078 100644 --- a/app/views/games/_games.html.erb +++ b/app/views/games/_games.html.erb @@ -3,20 +3,12 @@

Games

-
- - - <% @games.each_slice(4) do |row| %> - - <% row.each do |game| %> - - <% end %> - - <% end %> - -
- <%= game.name %> -
- <%= link_to "Play", game_path(game) %> -
+
+ <% @games.each do |game| %> +
+

<%= game.name %>

+ <%= link_to 'Play', game_path(game), class: 'btn btn-play' %> +
+ <% end %> +
\ No newline at end of file diff --git a/app/views/games/index.html.erb b/app/views/games/index.html.erb index c2267d30..98a709b9 100644 --- a/app/views/games/index.html.erb +++ b/app/views/games/index.html.erb @@ -3,20 +3,28 @@

Hello, <%="Guest" %>!

- <% if true %> +
+ <%# <% if true %> + <%# TODO, using if-else to display login button or account info button %> - <% else %> + <%# <% else %> <%= link_to 'Log In', '#', class: 'btn btn-login' %> - <% end %> + <%# <% end %> + + <% if true %> + <%# TODO, only appear if the user is admin %> + <%= link_to 'All Users for Admin', '#', class: 'btn btn-login btn-admin' %> + <% end%> +
diff --git a/app/views/pages/index.html.erb b/app/views/pages/index.html.erb deleted file mode 100644 index f2b6efa3..00000000 --- a/app/views/pages/index.html.erb +++ /dev/null @@ -1,33 +0,0 @@ - -
- -
-

Hello, <%="Guest" %>!

- - <% if true %> - - - <% else %> - - <%= link_to 'Log In', '#', class: 'btn btn-login' %> - <% end %> -
- - -
- <% @games.each do |game| %> -
-

<%= game.name %>

-

<%= game.description %>

- <%= link_to 'Play', '#', class: 'btn btn-play' %> -
- <% end %> -
-
\ No newline at end of file