-
Notifications
You must be signed in to change notification settings - Fork 0
Add Puzzle validation #40
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<turbo-frame id="modal"> | ||
<div data-controller="modal" data-action="modal#close" class="modal-overlay"> | ||
<div data-modal-target="content" class="modal-content" onclick="event.stopPropagation()"> | ||
<h2 class="text-xl mb-4">Edit Puzzle</h2> | ||
|
||
<%= render "form", puzzle: puzzle %> | ||
|
||
<button data-action="modal#close" class="btn close-btn">Close</button> | ||
</div> | ||
</div> | ||
</turbo-frame> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1 @@ | ||
<turbo-frame id="modal"> | ||
<div data-controller="modal" data-action="click->modal#close"class="modal-overlay"> | ||
<div data-modal-target="content" | ||
class="modal-content" | ||
onclick="event.stopPropagation()"> | ||
<h2 class="text-xl mb-4">Edit Puzzle</h2> | ||
|
||
<%= render "form", puzzle: @puzzle %> | ||
|
||
<button data-action="modal#close" | ||
class="btn close-btn">Close</button> | ||
</div> | ||
</div> | ||
</turbo-frame> | ||
<%= render "edit_modal", puzzle: @puzzle %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
one: | ||
question: "Ruby or Rails provided this method? render json: @user" | ||
answer: "rails" | ||
explanation: "This is a test puzzle" | ||
link: "https://example.com" | ||
state: "approved" | ||
sent_at: <%= 1.day.ago %> | ||
suggested_by: "test_user" | ||
|
||
two: | ||
question: "Ruby or Rails provided this method? puts 'Hello, World!'" | ||
answer: "ruby" | ||
explanation: "This is a test puzzle 2" | ||
link: "" | ||
state: "pending" | ||
sent_at: <%= 2.days.ago %> | ||
suggested_by: "test_user" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require "test_helper" | ||
|
||
class PuzzleTest < ActiveSupport::TestCase | ||
test "validates presence of question" do | ||
puzzle = Puzzle.new( | ||
question: "What is the capital of France?", | ||
answer: "rails", | ||
explanation: "This is a test puzzle", | ||
link: "https://example.com", | ||
state: "approved", | ||
suggested_by: "test_user" | ||
) | ||
assert puzzle.valid? | ||
end | ||
|
||
test "validates question presence - fails without question" do | ||
puzzle = Puzzle.new( | ||
answer: "rails", | ||
explanation: "This is a test puzzle", | ||
link: "https://example.com", | ||
state: "approved", | ||
suggested_by: "test_user" | ||
) | ||
assert_not puzzle.valid? | ||
assert_includes puzzle.errors[:question], "can't be blank" | ||
end | ||
|
||
test "defines answer enum with correct values" do | ||
assert_equal 0, Puzzle.answers[:ruby] | ||
assert_equal 1, Puzzle.answers[:rails] | ||
end | ||
|
||
test "defines state enum with correct values" do | ||
assert_equal 0, Puzzle.states[:approved] | ||
assert_equal 1, Puzzle.states[:rejected] | ||
assert_equal 2, Puzzle.states[:pending] | ||
assert_equal 3, Puzzle.states[:archived] | ||
end | ||
|
||
test "defaults state to pending" do | ||
puzzle = Puzzle.new( | ||
question: "Test question", | ||
answer: "ruby", | ||
explanation: "Test explanation" | ||
) | ||
assert_equal "pending", puzzle.state | ||
end | ||
|
||
test "has many answers" do | ||
assert_respond_to Puzzle.new, :answers | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the reason the errors didn't show up at Fiona's PR; the first element should be the turbo frame's name.
Also had to move the
edit.html.erb
view content into a partial_edit_modal.html.erb
because this turbo stream needed it to render the errors