Commit placeholder work

This commit is contained in:
maddiebaka 2023-12-06 15:53:25 -05:00
parent 60f37ece67
commit 709aa882b3
8 changed files with 56 additions and 3 deletions

View File

@ -1,6 +1,12 @@
class DictionaryController < ApplicationController class DictionaryController < ApplicationController
def index def index
@parts_of_speech = PartOfSpeech.all @english = Language.where(name: "English")
@parts_of_speech = PartOfSpeech.where(language_id: @english)
@parts_of_speech.each do |pos|
pos.translations.build
end
@words = Word.all @words = Word.all
end end

View File

@ -1,3 +1,5 @@
class PartOfSpeech < ApplicationRecord class PartOfSpeech < ApplicationRecord
belongs_to :language belongs_to :language
has_many :translations, class_name: "PartOfSpeech", foreign_key: "part_of_speech_id"
end end

View File

@ -4,11 +4,17 @@
<tr> <tr>
<td><b>Part of Speech</b></td> <td><b>Part of Speech</b></td>
<td><b>Definition</b></td> <td><b>Definition</b></td>
<% unless current_user.blank? %>
<td><b>Translation</b></td>
<% end %>
</tr> </tr>
<% parts_of_speech.each do |item| %> <% parts_of_speech.each do |item| %>
<tr> <tr>
<td><b><%= item.pos %></b></td> <td><b><%= item.pos %></b></td>
<td><%= item.definition %></td> <td><%= item.definition %></td>
<% unless current_user.blank? %>
<td><%= item.translations.first.definition %></td>
<% end %>
</tr> </tr>
<% end %> <% end %>
</table> </table>

View File

@ -0,0 +1,7 @@
class AddUserIdToPartOfSpeech < ActiveRecord::Migration[7.1]
def change
change_table :part_of_speeches do |t|
t.references :user, null: true, foreign_key: true
end
end
end

View File

@ -0,0 +1,7 @@
class AddSelfReferentialRelationshipToPartOfSpeech < ActiveRecord::Migration[7.1]
def change
change_table :part_of_speeches do |t|
t.references :part_of_speech, null: true, foreign_key: true
end
end
end

8
db/schema.rb generated
View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2023_10_25_010226) do ActiveRecord::Schema[7.1].define(version: 2023_10_31_200646) do
create_table "definitions", force: :cascade do |t| create_table "definitions", force: :cascade do |t|
t.string "pos" t.string "pos"
t.string "definition" t.string "definition"
@ -40,7 +40,11 @@ ActiveRecord::Schema[7.1].define(version: 2023_10_25_010226) do
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "language_id", null: false t.integer "language_id", null: false
t.integer "user_id"
t.integer "part_of_speech_id"
t.index ["language_id"], name: "index_part_of_speeches_on_language_id" t.index ["language_id"], name: "index_part_of_speeches_on_language_id"
t.index ["part_of_speech_id"], name: "index_part_of_speeches_on_part_of_speech_id"
t.index ["user_id"], name: "index_part_of_speeches_on_user_id"
end end
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|
@ -64,4 +68,6 @@ ActiveRecord::Schema[7.1].define(version: 2023_10_25_010226) do
add_foreign_key "definitions", "languages" add_foreign_key "definitions", "languages"
add_foreign_key "definitions", "words" add_foreign_key "definitions", "words"
add_foreign_key "part_of_speeches", "languages" add_foreign_key "part_of_speeches", "languages"
add_foreign_key "part_of_speeches", "part_of_speeches"
add_foreign_key "part_of_speeches", "users"
end end

View File

@ -1,7 +1,13 @@
FactoryBot.define do FactoryBot.define do
factory :part_of_speech do factory :part_of_speech do
sequence(:pos) { |n| "test-#{n.to_s}" } sequence(:pos) { |n| "test-#{n.to_s}" }
language_id { FactoryBot.create(:language).id } language_id { FactoryBot.create(:language_english).id }
definition { "test definition" } definition { "test definition" }
end end
factory :part_of_speech_translation, class: :part_of_speech do
sequence(:pos) { |n| "test-#{n.to_s}" }
language_id { FactoryBot.create(:language).id }
definition { "translated definition" }
end
end end

View File

@ -23,6 +23,19 @@ RSpec.describe "Dictionary", type: :request do
get "/dictionary" get "/dictionary"
expect(response.body).to include("#{Word.count} word entries in database") expect(response.body).to include("#{Word.count} word entries in database")
end end
describe "signed in" do
before :each do
sign_in FactoryBot.create(:user)
end
it "only lists the 11 parts of speech, in english" do
11.times { FactoryBot.create(:part_of_speech) }
FactoryBot.create(:part_of_speech_translation)
get "/dictionary"
expect(response.body).to have_selector(%(tr), count: 12)
end
end
end end
describe "GET /show" do describe "GET /show" do