From 66fc3965049f266cec8f1dfbdae496c9ab77718f Mon Sep 17 00:00:00 2001 From: maddiebaka Date: Sun, 22 Oct 2023 14:05:01 -0400 Subject: [PATCH] Clean up frontend, DRY up templates --- app/views/application/_partsofspeech.html.erb | 14 +++++++ app/views/dictionary/index.html.erb | 38 ++----------------- app/views/dictionary/show.html.erb | 5 ++- app/views/words/show.html.erb | 2 +- spec/requests/dictionary_spec.rb | 23 +++++++++++ 5 files changed, 45 insertions(+), 37 deletions(-) create mode 100644 app/views/application/_partsofspeech.html.erb diff --git a/app/views/application/_partsofspeech.html.erb b/app/views/application/_partsofspeech.html.erb new file mode 100644 index 0000000..5354fee --- /dev/null +++ b/app/views/application/_partsofspeech.html.erb @@ -0,0 +1,14 @@ +

Parts of Speech

+ + + + + +<% parts_of_speech.each do |item| %> + + + + +<% end %> +
Part of SpeechDefinition
<%= item.pos %><%= item.definition %>
+ diff --git a/app/views/dictionary/index.html.erb b/app/views/dictionary/index.html.erb index 3ea882c..9210983 100644 --- a/app/views/dictionary/index.html.erb +++ b/app/views/dictionary/index.html.erb @@ -1,39 +1,9 @@ -

Dictionary#index

-

Find me in app/views/dictionary/index.html.erb

+
+
<%= sanitize alphabetical_links, tags: ["a"] %>

<%= @parts_of_speech.count %> parts of speech entries in database

-

Parts of Speech

- - - - - -<% @parts_of_speech.each do |item| %> - - - - -<% end %> -
Part of SpeechDefinition
<%= item.pos %><%= item.definition %>
+

<%= @words.count %> word entries in database

-

Words

-<% @words.each do |word| %> -

<%= word.word %>

- <%= render "application/definitions", word: word %> - -<% end %> +<%= render "partsofspeech", parts_of_speech: @parts_of_speech %> diff --git a/app/views/dictionary/show.html.erb b/app/views/dictionary/show.html.erb index e084ee0..857e17a 100644 --- a/app/views/dictionary/show.html.erb +++ b/app/views/dictionary/show.html.erb @@ -1,9 +1,10 @@
- <%= @letter.to_s %> +

<%= @letter.to_s %>

<% @words.each do |word| %>
-

<%= word.word %>

+

<%= word.word %>

+ <%= render "definitions", word: word %>
<% end %> diff --git a/app/views/words/show.html.erb b/app/views/words/show.html.erb index f605887..91b3f31 100644 --- a/app/views/words/show.html.erb +++ b/app/views/words/show.html.erb @@ -1,3 +1,3 @@

<%= @word.word %>

-<%= render "application/definitions", word: @word %> +<%= render "definitions", word: @word %> diff --git a/spec/requests/dictionary_spec.rb b/spec/requests/dictionary_spec.rb index 8285721..266332d 100644 --- a/spec/requests/dictionary_spec.rb +++ b/spec/requests/dictionary_spec.rb @@ -6,6 +6,23 @@ RSpec.describe "Dictionary", type: :request do get "/dictionary" expect(response).to render_template(:index) end + + it "renders the parts_of_speech partial" do + get "/dictionary" + expect(response).to render_template(partial: "_partsofspeech") + end + + it "shows the count of parts of speech in the database" do + 5.times { FactoryBot.create(:part_of_speech) } + get "/dictionary" + expect(response.body).to include("#{PartOfSpeech.count} parts of speech entries in database") + end + + it "shows the count of words in the database" do + 5.times { FactoryBot.create(:word) } + get "/dictionary" + expect(response.body).to include("#{Word.count} word entries in database") + end end describe "GET /show" do @@ -23,5 +40,11 @@ RSpec.describe "Dictionary", type: :request do get "/dictionary/a" expect(assigns(:words)).to be_a(ActiveRecord::Relation) end + + it "renders the definitions partial" do + FactoryBot.create(:definition) + get "/dictionary/t" + expect(response).to render_template(partial: "_definitions") + end end end