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