Skip to content
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

Ran command scaffold #2

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/controllers/language_lookups_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class LanguageLookupsController < ApplicationController
before_action :set_language_lookup, only: %i[ show edit update destroy ]

# TODO show the user the results of the lookup
def show
end

# TODO show the user the form to upload the marcxml/xml
def new
end

# TODO run the translation between marcxml and iso codes
def create
respond_to do |format|
format.json { render :show, status: :created, location: @language_lookup }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/language_lookups_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module LanguageLookupsHelper
end
2 changes: 2 additions & 0 deletions app/models/language_lookup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class LanguageLookup < ApplicationRecord
end
17 changes: 17 additions & 0 deletions app/views/language_lookups/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= form_with(model: language_lookup) do |form| %>
<% if language_lookup.errors.any? %>
<div style="color: red">
<h2><%= pluralize(language_lookup.errors.count, "error") %> prohibited this language_lookup from being saved:</h2>

<ul>
<% language_lookup.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div>
<%= form.submit %>
</div>
<% end %>
2 changes: 2 additions & 0 deletions app/views/language_lookups/_language_lookup.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div id="<%= dom_id language_lookup %>">
</div>
2 changes: 2 additions & 0 deletions app/views/language_lookups/_language_lookup.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! language_lookup, :id, :created_at, :updated_at
json.url language_lookup_url(language_lookup, format: :json)
10 changes: 10 additions & 0 deletions app/views/language_lookups/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>Editing language lookup</h1>

<%= render "form", language_lookup: @language_lookup %>

<br>

<div>
<%= link_to "Show this language lookup", @language_lookup %> |
<%= link_to "Back to language lookups", language_lookups_path %>
</div>
14 changes: 14 additions & 0 deletions app/views/language_lookups/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p style="color: green"><%= notice %></p>

<h1>Language lookups</h1>

<div id="language_lookups">
<% @language_lookups.each do |language_lookup| %>
<%= render language_lookup %>
<p>
<%= link_to "Show this language lookup", language_lookup %>
</p>
<% end %>
</div>

<%= link_to "New language lookup", new_language_lookup_path %>
1 change: 1 addition & 0 deletions app/views/language_lookups/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @language_lookups, partial: "language_lookups/language_lookup", as: :language_lookup
9 changes: 9 additions & 0 deletions app/views/language_lookups/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1>New language lookup</h1>

<%= render "form", language_lookup: @language_lookup %>

<br>

<div>
<%= link_to "Back to language lookups", language_lookups_path %>
</div>
10 changes: 10 additions & 0 deletions app/views/language_lookups/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p style="color: green"><%= notice %></p>

<%= render @language_lookup %>

<div>
<%= link_to "Edit this language lookup", edit_language_lookup_path(@language_lookup) %> |
<%= link_to "Back to language lookups", language_lookups_path %>

<%= button_to "Destroy this language lookup", @language_lookup, method: :delete %>
</div>
1 change: 1 addition & 0 deletions app/views/language_lookups/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "language_lookups/language_lookup", language_lookup: @language_lookup
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
Rails.application.routes.draw do
get "language_lookup" => "language_lookups#show", as: :language_lookups_results

get "language_lookup/new" => "language_lookups#new", as: :language_lookups_form

post "language_lookup/create" => "language_lookups#create", as: :language_lookup
# 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.
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20240812182140_create_language_lookups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateLanguageLookups < ActiveRecord::Migration[7.1]
def change
create_table :language_lookups do |t|

t.timestamps
end
end
end
7 changes: 6 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions test/controllers/language_lookups_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require "test_helper"

class LanguageLookupsControllerTest < ActionDispatch::IntegrationTest
setup do
@language_lookup = language_lookups(:one)
end

test "should get index" do
get language_lookups_url
assert_response :success
end

test "should get new" do
get new_language_lookup_url
assert_response :success
end

test "should create language_lookup" do
assert_difference("LanguageLookup.count") do
post language_lookups_url, params: { language_lookup: { } }
end

assert_redirected_to language_lookup_url(LanguageLookup.last)
end

test "should show language_lookup" do
get language_lookup_url(@language_lookup)
assert_response :success
end

test "should get edit" do
get edit_language_lookup_url(@language_lookup)
assert_response :success
end

test "should update language_lookup" do
patch language_lookup_url(@language_lookup), params: { language_lookup: { } }
assert_redirected_to language_lookup_url(@language_lookup)
end

test "should destroy language_lookup" do
assert_difference("LanguageLookup.count", -1) do
delete language_lookup_url(@language_lookup)
end

assert_redirected_to language_lookups_url
end
end
11 changes: 11 additions & 0 deletions test/fixtures/language_lookups.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

# This model initially had no columns defined. If you add columns to the
# model remove the "{}" from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
7 changes: 7 additions & 0 deletions test/models/language_lookup_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class LanguageLookupTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
39 changes: 39 additions & 0 deletions test/system/language_lookups_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require "application_system_test_case"

class LanguageLookupsTest < ApplicationSystemTestCase
setup do
@language_lookup = language_lookups(:one)
end

test "visiting the index" do
visit language_lookups_url
assert_selector "h1", text: "Language lookups"
end

test "should create language lookup" do
visit language_lookups_url
click_on "New language lookup"

click_on "Create Language lookup"

assert_text "Language lookup was successfully created"
click_on "Back"
end

test "should update Language lookup" do
visit language_lookup_url(@language_lookup)
click_on "Edit this language lookup", match: :first

click_on "Update Language lookup"

assert_text "Language lookup was successfully updated"
click_on "Back"
end

test "should destroy Language lookup" do
visit language_lookup_url(@language_lookup)
click_on "Destroy this language lookup", match: :first

assert_text "Language lookup was successfully destroyed"
end
end