From 21445b6905ed42049ba9858fe89120367a0c3c54 Mon Sep 17 00:00:00 2001 From: maddiebaka Date: Fri, 13 Oct 2023 21:40:49 -0400 Subject: [PATCH] Add dictionary controller specs and factories --- spec/controllers/dictionary_spec.rb | 22 ++++++++++++++++++++++ spec/factories/part_of_speech.rb | 6 ++++++ spec/factories/word.rb | 5 +++++ 3 files changed, 33 insertions(+) create mode 100644 spec/controllers/dictionary_spec.rb create mode 100644 spec/factories/part_of_speech.rb create mode 100644 spec/factories/word.rb diff --git a/spec/controllers/dictionary_spec.rb b/spec/controllers/dictionary_spec.rb new file mode 100644 index 0000000..45e6e69 --- /dev/null +++ b/spec/controllers/dictionary_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +RSpec.describe DictionaryController, type: :controller do + describe "GET :index" do + it 'renders the index template' do + get :index + expect(response).to render_template(:index) + end + + it 'sets @parts_of_speech instance variable' do + get :index + FactoryBot.create(:part_of_speech) + expect(assigns(:parts_of_speech)).to be_a(ActiveRecord::Relation) + end + + it 'sets @words instance variable' do + get :index + FactoryBot.create(:word) + expect(assigns(:words)).to be_a(ActiveRecord::Relation) + end + end +end diff --git a/spec/factories/part_of_speech.rb b/spec/factories/part_of_speech.rb new file mode 100644 index 0000000..4f47522 --- /dev/null +++ b/spec/factories/part_of_speech.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :part_of_speech do + sequence(:pos) { |n| "test-#{n.to_s}" } + definition { "test definition" } + end +end diff --git a/spec/factories/word.rb b/spec/factories/word.rb new file mode 100644 index 0000000..b1fc339 --- /dev/null +++ b/spec/factories/word.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :word do + sequence(:word) { |n| "test-#{n.to_s}" } + end +end