diff --git a/Gemfile b/Gemfile
index 47759dc..a0876a1 100644
--- a/Gemfile
+++ b/Gemfile
@@ -51,6 +51,7 @@ group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri windows ]
gem "rspec-rails"
+ gem "capybara"
gem "rails-controller-testing"
gem "factory_bot_rails"
end
diff --git a/Gemfile.lock b/Gemfile.lock
index c93b401..4bc781b 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -83,6 +83,15 @@ GEM
bootsnap (1.16.0)
msgpack (~> 1.2)
builder (3.2.4)
+ capybara (3.39.2)
+ addressable
+ matrix
+ mini_mime (>= 0.1.3)
+ nokogiri (~> 1.8)
+ rack (>= 1.6.0)
+ rack-test (>= 0.6.3)
+ regexp_parser (>= 1.5, < 3.0)
+ xpath (~> 3.2)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
crass (1.0.6)
@@ -145,6 +154,7 @@ GEM
net-pop
net-smtp
marcel (1.0.2)
+ matrix (0.4.2)
mini_mime (1.1.5)
minitest (5.20.0)
msgpack (1.7.2)
@@ -216,6 +226,7 @@ GEM
rake (13.0.6)
rdoc (6.5.0)
psych (>= 4.0.0)
+ regexp_parser (2.8.2)
reline (0.3.9)
io-console (~> 0.5)
responders (3.1.1)
@@ -274,6 +285,8 @@ GEM
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
+ xpath (3.2.0)
+ nokogiri (~> 1.8)
zeitwerk (2.6.12)
PLATFORMS
@@ -283,6 +296,7 @@ PLATFORMS
DEPENDENCIES
bootsnap
+ capybara
debug
devise
factory_bot_rails
diff --git a/app/controllers/dictionary_controller.rb b/app/controllers/dictionary_controller.rb
index 4100ada..0f9ba1b 100644
--- a/app/controllers/dictionary_controller.rb
+++ b/app/controllers/dictionary_controller.rb
@@ -3,4 +3,9 @@ class DictionaryController < ApplicationController
@parts_of_speech = PartOfSpeech.all
@words = Word.all
end
+
+ def show
+ @letter = params[:id]
+ @words = Word.where('substr(word, 1, 1) = ?', @letter)
+ end
end
diff --git a/app/helpers/dictionary_helper.rb b/app/helpers/dictionary_helper.rb
index e147a98..f958701 100644
--- a/app/helpers/dictionary_helper.rb
+++ b/app/helpers/dictionary_helper.rb
@@ -1,2 +1,10 @@
module DictionaryHelper
+ LETTERS = ['i', 'u', 'e', 'o', 'a', 'm', 'n', 'p', 't', 'k', 's', 'w', 'l', 'j'].sort
+
+ def alphabetical_links
+
+ LETTERS.map do |l|
+ link_to l.to_s, dictionary_path(l)
+ end.join("\n")
+ end
end
diff --git a/app/views/dictionary/index.html.erb b/app/views/dictionary/index.html.erb
index fa6e459..3ea882c 100644
--- a/app/views/dictionary/index.html.erb
+++ b/app/views/dictionary/index.html.erb
@@ -1,6 +1,8 @@
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
diff --git a/app/views/dictionary/show.html.erb b/app/views/dictionary/show.html.erb
new file mode 100644
index 0000000..e084ee0
--- /dev/null
+++ b/app/views/dictionary/show.html.erb
@@ -0,0 +1,9 @@
+
+ <%= @letter.to_s %>
+
+
+<% @words.each do |word| %>
+
+
<%= word.word %>
+
+<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 52b101c..c59451f 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,7 +1,7 @@
Rails.application.routes.draw do
devise_for :users
#get 'dictionary/index'
- resources :dictionary, only: [:index]
+ resources :dictionary, only: [:index, :show]
resources :words, only: [:index, :show]
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
diff --git a/spec/helpers/dictionary_helper_spec.rb b/spec/helpers/dictionary_helper_spec.rb
new file mode 100644
index 0000000..ef70a5b
--- /dev/null
+++ b/spec/helpers/dictionary_helper_spec.rb
@@ -0,0 +1,36 @@
+require 'rails_helper'
+
+include Capybara::RSpecMatchers
+
+# Specs in this file have access to a helper object that includes
+# the DictionaryHelper. For example:
+#
+# describe DictionaryHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# expect(helper.concat_strings("this","that")).to eq("this that")
+# end
+# end
+# end
+RSpec.describe DictionaryHelper, type: :helper do
+
+ describe "#alphabetical_links" do
+
+ it "generates fourteen letter-links" do
+ expect(helper.alphabetical_links).to have_selector(%(a), count: 14)
+ end
+
+ it "generates links for all fourteen letters" do
+ output = helper.alphabetical_links
+ letters = ['i', 'u', 'e', 'o', 'a', 'm', 'n', 'p', 't', 'k', 's', 'w', 'l', 'j']
+
+ letters.each do |l|
+ expect(output).to have_link(l, href: dictionary_path(l))
+ end
+ end
+
+ it "sorts the toki pona alphabet" do
+ expect(DictionaryHelper::LETTERS).to eql(DictionaryHelper::LETTERS.sort)
+ end
+ end
+end
diff --git a/spec/requests/dictionary_spec.rb b/spec/requests/dictionary_spec.rb
index daed06f..8285721 100644
--- a/spec/requests/dictionary_spec.rb
+++ b/spec/requests/dictionary_spec.rb
@@ -7,4 +7,21 @@ RSpec.describe "Dictionary", type: :request do
expect(response).to render_template(:index)
end
end
+
+ describe "GET /show" do
+ it 'renders the show template' do
+ get "/dictionary/a"
+ expect(response).to render_template(:show)
+ end
+
+ it "sets @letter instance variable" do
+ get "/dictionary/a"
+ expect(assigns(:letter)).to be_a(String)
+ end
+
+ it "sets @words instance variable" do
+ get "/dictionary/a"
+ expect(assigns(:words)).to be_a(ActiveRecord::Relation)
+ end
+ end
end