|
| 1 | +require "test_helper" |
| 2 | + |
| 3 | +class PuzzleTest < ActiveSupport::TestCase |
| 4 | + test "validates presence of question" do |
| 5 | + puzzle = Puzzle.new( |
| 6 | + question: "What is the capital of France?", |
| 7 | + answer: "rails", |
| 8 | + explanation: "This is a test puzzle", |
| 9 | + link: "https://example.com", |
| 10 | + state: "approved", |
| 11 | + suggested_by: "test_user" |
| 12 | + ) |
| 13 | + assert puzzle.valid? |
| 14 | + end |
| 15 | + |
| 16 | + test "validates question presence - fails without question" do |
| 17 | + puzzle = Puzzle.new( |
| 18 | + answer: "rails", |
| 19 | + explanation: "This is a test puzzle", |
| 20 | + link: "https://example.com", |
| 21 | + state: "approved", |
| 22 | + suggested_by: "test_user" |
| 23 | + ) |
| 24 | + assert_not puzzle.valid? |
| 25 | + assert_includes puzzle.errors[:question], "can't be blank" |
| 26 | + end |
| 27 | + |
| 28 | + test "defines answer enum with correct values" do |
| 29 | + assert_equal 0, Puzzle.answers[:ruby] |
| 30 | + assert_equal 1, Puzzle.answers[:rails] |
| 31 | + end |
| 32 | + |
| 33 | + test "defines state enum with correct values" do |
| 34 | + assert_equal 0, Puzzle.states[:approved] |
| 35 | + assert_equal 1, Puzzle.states[:rejected] |
| 36 | + assert_equal 2, Puzzle.states[:pending] |
| 37 | + assert_equal 3, Puzzle.states[:archived] |
| 38 | + end |
| 39 | + |
| 40 | + test "defaults state to pending" do |
| 41 | + puzzle = Puzzle.new( |
| 42 | + question: "Test question", |
| 43 | + answer: "ruby", |
| 44 | + explanation: "Test explanation" |
| 45 | + ) |
| 46 | + assert_equal "pending", puzzle.state |
| 47 | + end |
| 48 | + |
| 49 | + test "has many answers" do |
| 50 | + assert_respond_to Puzzle.new, :answers |
| 51 | + end |
| 52 | +end |
0 commit comments