diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-10-28 17:32:45 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-10-28 17:32:45 -0400 |
commit | 141f8b1a7e42928e94cccd0c8f89fdd56f8e2efe (patch) | |
tree | 234bc2a3ccd234b576330061db8a17ad785135ed | |
parent | cfc41eb3ccc99b92220115b0710fb821525e1075 (diff) | |
download | wittle-141f8b1a7e42928e94cccd0c8f89fdd56f8e2efe.tar.gz wittle-141f8b1a7e42928e94cccd0c8f89fdd56f8e2efe.tar.bz2 wittle-141f8b1a7e42928e94cccd0c8f89fdd56f8e2efe.zip |
created puzzle and score tables
-rw-r--r-- | Gemfile.lock | 3 | ||||
-rw-r--r-- | app/models/wittle/puzzle.rb | 12 | ||||
-rw-r--r-- | app/models/wittle/score.rb | 8 | ||||
-rw-r--r-- | db/migrate/20231028205751_create_wittle_puzzles.rb | 11 | ||||
-rw-r--r-- | db/migrate/20231028210722_create_wittle_scores.rb | 12 | ||||
-rw-r--r-- | lib/wittle/engine.rb | 1 | ||||
-rw-r--r-- | test/dummy/db/schema.rb | 33 | ||||
-rw-r--r-- | test/fixtures/wittle/puzzles.yml | 11 | ||||
-rw-r--r-- | test/fixtures/wittle/scores.yml | 13 | ||||
-rw-r--r-- | test/models/wittle/puzzle_test.rb | 9 | ||||
-rw-r--r-- | test/models/wittle/score_test.rb | 9 | ||||
-rw-r--r-- | wittle.gemspec | 1 |
12 files changed, 123 insertions, 0 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index 2fd1efc..86422fe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock | |||
@@ -2,6 +2,7 @@ PATH | |||
2 | remote: . | 2 | remote: . |
3 | specs: | 3 | specs: |
4 | wittle (0.1.0) | 4 | wittle (0.1.0) |
5 | enumerize | ||
5 | haml | 6 | haml |
6 | rails (>= 7.1.1) | 7 | rails (>= 7.1.1) |
7 | rice | 8 | rice |
@@ -91,6 +92,8 @@ GEM | |||
91 | date (3.3.3) | 92 | date (3.3.3) |
92 | drb (2.1.1) | 93 | drb (2.1.1) |
93 | ruby2_keywords | 94 | ruby2_keywords |
95 | enumerize (2.7.0) | ||
96 | activesupport (>= 3.2) | ||
94 | erubi (1.12.0) | 97 | erubi (1.12.0) |
95 | globalid (1.2.1) | 98 | globalid (1.2.1) |
96 | activesupport (>= 6.1) | 99 | activesupport (>= 6.1) |
diff --git a/app/models/wittle/puzzle.rb b/app/models/wittle/puzzle.rb new file mode 100644 index 0000000..e118d8a --- /dev/null +++ b/app/models/wittle/puzzle.rb | |||
@@ -0,0 +1,12 @@ | |||
1 | module Wittle | ||
2 | class Puzzle < ApplicationRecord | ||
3 | extend Enumerize | ||
4 | |||
5 | has_many :scores | ||
6 | |||
7 | validates :data, presence: true | ||
8 | |||
9 | validates :category, presence: true | ||
10 | enumerize :category, in: [:normal, :hard, :expert], scope: :shallow | ||
11 | end | ||
12 | end | ||
diff --git a/app/models/wittle/score.rb b/app/models/wittle/score.rb new file mode 100644 index 0000000..be00fda --- /dev/null +++ b/app/models/wittle/score.rb | |||
@@ -0,0 +1,8 @@ | |||
1 | module Wittle | ||
2 | class Score < ApplicationRecord | ||
3 | belongs_to :puzzle | ||
4 | |||
5 | validates :name, presence: true | ||
6 | validates :ip, presence: true | ||
7 | end | ||
8 | end | ||
diff --git a/db/migrate/20231028205751_create_wittle_puzzles.rb b/db/migrate/20231028205751_create_wittle_puzzles.rb new file mode 100644 index 0000000..ebe0bf7 --- /dev/null +++ b/db/migrate/20231028205751_create_wittle_puzzles.rb | |||
@@ -0,0 +1,11 @@ | |||
1 | class CreateWittlePuzzles < ActiveRecord::Migration[7.1] | ||
2 | def change | ||
3 | create_table :wittle_puzzles do |t| | ||
4 | t.text :data | ||
5 | t.text :solved_data | ||
6 | t.string :category | ||
7 | |||
8 | t.timestamps | ||
9 | end | ||
10 | end | ||
11 | end | ||
diff --git a/db/migrate/20231028210722_create_wittle_scores.rb b/db/migrate/20231028210722_create_wittle_scores.rb new file mode 100644 index 0000000..9ae6413 --- /dev/null +++ b/db/migrate/20231028210722_create_wittle_scores.rb | |||
@@ -0,0 +1,12 @@ | |||
1 | class CreateWittleScores < ActiveRecord::Migration[7.1] | ||
2 | def change | ||
3 | create_table :wittle_scores do |t| | ||
4 | t.references :puzzle, null: false, foreign_key: true | ||
5 | t.string :name | ||
6 | t.string :ip | ||
7 | t.integer :seconds_taken | ||
8 | |||
9 | t.timestamps | ||
10 | end | ||
11 | end | ||
12 | end | ||
diff --git a/lib/wittle/engine.rb b/lib/wittle/engine.rb index f0ec682..6b4feca 100644 --- a/lib/wittle/engine.rb +++ b/lib/wittle/engine.rb | |||
@@ -1,3 +1,4 @@ | |||
1 | require "enumerize" | ||
1 | require "haml" | 2 | require "haml" |
2 | require "wittle_generator/wittle_generator" | 3 | require "wittle_generator/wittle_generator" |
3 | 4 | ||
diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb new file mode 100644 index 0000000..928cc3c --- /dev/null +++ b/test/dummy/db/schema.rb | |||
@@ -0,0 +1,33 @@ | |||
1 | # This file is auto-generated from the current state of the database. Instead | ||
2 | # of editing this file, please use the migrations feature of Active Record to | ||
3 | # incrementally modify your database, and then regenerate this schema definition. | ||
4 | # | ||
5 | # This file is the source Rails uses to define your schema when running `bin/rails | ||
6 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to | ||
7 | # be faster and is potentially less error prone than running all of your | ||
8 | # migrations from scratch. Old migrations may fail to apply correctly if those | ||
9 | # migrations use external dependencies or application code. | ||
10 | # | ||
11 | # It's strongly recommended that you check this file into your version control system. | ||
12 | |||
13 | ActiveRecord::Schema[7.1].define(version: 2023_10_28_210722) do | ||
14 | create_table "wittle_puzzles", force: :cascade do |t| | ||
15 | t.text "data" | ||
16 | t.text "solved_data" | ||
17 | t.string "category" | ||
18 | t.datetime "created_at", null: false | ||
19 | t.datetime "updated_at", null: false | ||
20 | end | ||
21 | |||
22 | create_table "wittle_scores", force: :cascade do |t| | ||
23 | t.integer "puzzle_id", null: false | ||
24 | t.string "name" | ||
25 | t.string "ip" | ||
26 | t.integer "seconds_taken" | ||
27 | t.datetime "created_at", null: false | ||
28 | t.datetime "updated_at", null: false | ||
29 | t.index ["puzzle_id"], name: "index_wittle_scores_on_puzzle_id" | ||
30 | end | ||
31 | |||
32 | add_foreign_key "wittle_scores", "puzzles" | ||
33 | end | ||
diff --git a/test/fixtures/wittle/puzzles.yml b/test/fixtures/wittle/puzzles.yml new file mode 100644 index 0000000..75f9eab --- /dev/null +++ b/test/fixtures/wittle/puzzles.yml | |||
@@ -0,0 +1,11 @@ | |||
1 | # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
2 | |||
3 | one: | ||
4 | data: MyText | ||
5 | solved_data: MyText | ||
6 | category: MyString | ||
7 | |||
8 | two: | ||
9 | data: MyText | ||
10 | solved_data: MyText | ||
11 | category: MyString | ||
diff --git a/test/fixtures/wittle/scores.yml b/test/fixtures/wittle/scores.yml new file mode 100644 index 0000000..1f21c4c --- /dev/null +++ b/test/fixtures/wittle/scores.yml | |||
@@ -0,0 +1,13 @@ | |||
1 | # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
2 | |||
3 | one: | ||
4 | puzzle: one | ||
5 | name: MyString | ||
6 | ip: MyString | ||
7 | seconds_taken: 1 | ||
8 | |||
9 | two: | ||
10 | puzzle: two | ||
11 | name: MyString | ||
12 | ip: MyString | ||
13 | seconds_taken: 1 | ||
diff --git a/test/models/wittle/puzzle_test.rb b/test/models/wittle/puzzle_test.rb new file mode 100644 index 0000000..f826aa3 --- /dev/null +++ b/test/models/wittle/puzzle_test.rb | |||
@@ -0,0 +1,9 @@ | |||
1 | require "test_helper" | ||
2 | |||
3 | module Wittle | ||
4 | class PuzzleTest < ActiveSupport::TestCase | ||
5 | # test "the truth" do | ||
6 | # assert true | ||
7 | # end | ||
8 | end | ||
9 | end | ||
diff --git a/test/models/wittle/score_test.rb b/test/models/wittle/score_test.rb new file mode 100644 index 0000000..0d5e4a3 --- /dev/null +++ b/test/models/wittle/score_test.rb | |||
@@ -0,0 +1,9 @@ | |||
1 | require "test_helper" | ||
2 | |||
3 | module Wittle | ||
4 | class ScoreTest < ActiveSupport::TestCase | ||
5 | # test "the truth" do | ||
6 | # assert true | ||
7 | # end | ||
8 | end | ||
9 | end | ||
diff --git a/wittle.gemspec b/wittle.gemspec index e182456..0c467e3 100644 --- a/wittle.gemspec +++ b/wittle.gemspec | |||
@@ -18,4 +18,5 @@ Gem::Specification.new do |s| | |||
18 | s.add_dependency "rails", ">= 7.1.1" | 18 | s.add_dependency "rails", ">= 7.1.1" |
19 | s.add_dependency "rice" | 19 | s.add_dependency "rice" |
20 | s.add_dependency "haml" | 20 | s.add_dependency "haml" |
21 | s.add_dependency "enumerize" | ||
21 | end | 22 | end |