Dictionary show action for letters, alphabetical links helper
This commit is contained in:
		
							
								
								
									
										36
									
								
								spec/helpers/dictionary_helper_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								spec/helpers/dictionary_helper_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user