-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f7fbfb
commit d90065f
Showing
8 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,51 @@ | ||
class QueriesController < ApplicationController | ||
before_action :set_query, only: %i[ show update destroy ] | ||
|
||
# GET /queries | ||
def index | ||
@queries = Query.all | ||
|
||
render json: @queries | ||
end | ||
|
||
# GET /queries/1 | ||
def show | ||
render json: @query | ||
end | ||
|
||
# POST /queries | ||
def create | ||
@query = Query.new(query_params) | ||
|
||
if @query.save | ||
render json: @query, status: :created, location: @query | ||
else | ||
render json: @query.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# PATCH/PUT /queries/1 | ||
def update | ||
if @query.update(query_params) | ||
render json: @query | ||
else | ||
render json: @query.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# DELETE /queries/1 | ||
def destroy | ||
@query.destroy! | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_query | ||
@query = Query.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def query_params | ||
params.require(:query).permit(:description) | ||
end | ||
end |
This file contains 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,2 @@ | ||
class Query < ApplicationRecord | ||
end |
This file contains 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 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,9 @@ | ||
class CreateQueries < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :queries do |t| | ||
t.text :description | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,38 @@ | ||
require "test_helper" | ||
|
||
class QueriesControllerTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@query = queries(:one) | ||
end | ||
|
||
test "should get index" do | ||
get queries_url, as: :json | ||
assert_response :success | ||
end | ||
|
||
test "should create query" do | ||
assert_difference("Query.count") do | ||
post queries_url, params: { query: { description: @query.description } }, as: :json | ||
end | ||
|
||
assert_response :created | ||
end | ||
|
||
test "should show query" do | ||
get query_url(@query), as: :json | ||
assert_response :success | ||
end | ||
|
||
test "should update query" do | ||
patch query_url(@query), params: { query: { description: @query.description } }, as: :json | ||
assert_response :success | ||
end | ||
|
||
test "should destroy query" do | ||
assert_difference("Query.count", -1) do | ||
delete query_url(@query), as: :json | ||
end | ||
|
||
assert_response :no_content | ||
end | ||
end |
This file contains 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,7 @@ | ||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
one: | ||
description: MyText | ||
|
||
two: | ||
description: MyText |
This file contains 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,7 @@ | ||
require "test_helper" | ||
|
||
class QueryTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |