Compare commits

..

No commits in common. "translations" and "main" have entirely different histories.

8 changed files with 3 additions and 56 deletions

View File

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

View File

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

View File

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

View File

@ -1,7 +0,0 @@
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

@ -1,7 +0,0 @@
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.
ActiveRecord::Schema[7.1].define(version: 2023_10_31_200646) do
ActiveRecord::Schema[7.1].define(version: 2023_10_25_010226) do
create_table "definitions", force: :cascade do |t|
t.string "pos"
t.string "definition"
@ -40,11 +40,7 @@ ActiveRecord::Schema[7.1].define(version: 2023_10_31_200646) do
t.datetime "created_at", null: false
t.datetime "updated_at", 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 ["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
create_table "users", force: :cascade do |t|
@ -68,6 +64,4 @@ ActiveRecord::Schema[7.1].define(version: 2023_10_31_200646) do
add_foreign_key "definitions", "languages"
add_foreign_key "definitions", "words"
add_foreign_key "part_of_speeches", "languages"
add_foreign_key "part_of_speeches", "part_of_speeches"
add_foreign_key "part_of_speeches", "users"
end

View File

@ -1,13 +1,7 @@
FactoryBot.define do
factory :part_of_speech do
sequence(:pos) { |n| "test-#{n.to_s}" }
language_id { FactoryBot.create(:language_english).id }
language_id { FactoryBot.create(:language).id }
definition { "test definition" }
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

View File

@ -23,19 +23,6 @@ RSpec.describe "Dictionary", type: :request do
get "/dictionary"
expect(response.body).to include("#{Word.count} word entries in database")
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
describe "GET /show" do