Read-only patch written, frontend shows dictionary in different languages
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe WordsController, type: :controller do
|
||||
describe "GET :index" do
|
||||
it 'renders the index template' do
|
||||
get :index
|
||||
expect(response).to render_template(:index)
|
||||
end
|
||||
|
||||
it 'sets @words instance variable' do
|
||||
FactoryBot.create(:word)
|
||||
get :index
|
||||
expect(assigns(:words)).to be_a(ActiveRecord::Relation)
|
||||
end
|
||||
|
||||
it 'fetches all words into @words' do
|
||||
5.times { FactoryBot.create(:word) }
|
||||
get :index
|
||||
expect(assigns(:words).count).to eq(5)
|
||||
end
|
||||
end
|
||||
end
|
@@ -1,7 +1,7 @@
|
||||
FactoryBot.define do
|
||||
factory :part_of_speech do
|
||||
sequence(:pos) { |n| "test-#{n.to_s}" }
|
||||
language_id { FactoryBot.create(:language).id }
|
||||
language_id { FactoryBot.create(:language_english).id }
|
||||
definition { "test definition" }
|
||||
end
|
||||
end
|
||||
|
@@ -23,10 +23,6 @@ RSpec.describe ActiveLanguageHelper, type: :helper do
|
||||
expect(@tag).to have_selector(%(select))
|
||||
end
|
||||
|
||||
it "should not contain an English option" do
|
||||
expect(@tag).to_not include("English")
|
||||
end
|
||||
|
||||
it "should include css id #active_language_select_tag" do
|
||||
expect(@tag).to have_selector(%(select[id="active_language_select_tag"]))
|
||||
end
|
||||
|
@@ -14,6 +14,7 @@ RSpec.describe "Dictionary", type: :request do
|
||||
|
||||
it "shows the count of parts of speech in the database" do
|
||||
5.times { FactoryBot.create(:part_of_speech) }
|
||||
#puts PartOfSpeech.count
|
||||
get "/dictionary"
|
||||
expect(response.body).to include("#{PartOfSpeech.count} parts of speech entries in database")
|
||||
end
|
||||
|
@@ -1,106 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "Languages", type: :request do
|
||||
|
||||
describe "GET :index" do
|
||||
it "returns http success" do
|
||||
get "/admin/languages/"
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it "lists all languages" do
|
||||
language = FactoryBot.create(:language)
|
||||
get "/admin/languages/"
|
||||
expect(response.body).to include(language.name)
|
||||
end
|
||||
|
||||
it "has a new-language link" do
|
||||
get "/admin/languages/"
|
||||
expect(response.body).to have_selector(%(a[href="#{new_admin_language_path}"]))
|
||||
end
|
||||
|
||||
it "has an edit button" do
|
||||
language = FactoryBot.create(:language)
|
||||
get "/admin/languages/"
|
||||
expect(response.body).to have_link("Edit")
|
||||
end
|
||||
|
||||
it "has a delete button" do
|
||||
language = FactoryBot.create(:language)
|
||||
get "/admin/languages/"
|
||||
expect(response.body).to have_link("Delete")
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET :new" do
|
||||
it "returns http success" do
|
||||
get "/admin/languages/new"
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it "has a form for a new language" do
|
||||
get "/admin/languages/new"
|
||||
expect(response.body).to have_selector(%(input[name="language[name]"]))
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST :create" do
|
||||
it "redirect to admin_languages_path on success" do
|
||||
post "/admin/languages", params: { language: { name: "Test Name" } }
|
||||
expect(response).to redirect_to(admin_languages_path)
|
||||
end
|
||||
|
||||
it "creates a new language" do
|
||||
post "/admin/languages", params: { language: { name: "Test Name" } }
|
||||
expect(Language.count).to eq(1)
|
||||
end
|
||||
|
||||
it "requires a name for a new language" do
|
||||
post "/admin/languages", params: { language: { name: nil } }
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET :edit" do
|
||||
before :each do
|
||||
@language = FactoryBot.create(:language)
|
||||
get "/admin/languages/#{@language.id}/edit"
|
||||
end
|
||||
|
||||
it "returns http success" do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it "has a form to edit language" do
|
||||
expect(response.body).to have_selector(%(input[name="language[name]"]))
|
||||
end
|
||||
end
|
||||
|
||||
describe "PATCH :update" do
|
||||
before :each do
|
||||
@language = FactoryBot.create(:language)
|
||||
@params = { language: { name: "Test Name Update" } }
|
||||
end
|
||||
|
||||
it "updates a language" do
|
||||
patch "/admin/languages/#{@language.id}", params: @params
|
||||
expect(response).to redirect_to(admin_languages_path)
|
||||
end
|
||||
|
||||
it "requires params to update a language" do
|
||||
@params = { language: { name: nil, invalid: "oh no" } }
|
||||
patch "/admin/languages/#{@language.id}", params: @params
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "DELETE :destroy" do
|
||||
it "deletes a language" do
|
||||
language = FactoryBot.create(:language)
|
||||
language2 = FactoryBot.create(:language)
|
||||
delete "/admin/languages/#{language.id}"
|
||||
expect(Language.all).to eq([language2])
|
||||
end
|
||||
end
|
||||
end
|
@@ -13,38 +13,8 @@ RSpec.describe "Root path", type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
describe "logged out" do
|
||||
it "should have 'Register' link" do
|
||||
get root_path
|
||||
expect(response.body).to include("Register")
|
||||
end
|
||||
end
|
||||
|
||||
describe "logged in" do
|
||||
it "should have 'Sign Out' link" do
|
||||
sign_in FactoryBot.create(:user)
|
||||
get root_path
|
||||
expect(response.body).to include("Sign Out")
|
||||
end
|
||||
|
||||
it "should have the 'Languages' link" do
|
||||
sign_in FactoryBot.create(:user)
|
||||
get root_path
|
||||
expect(response.body).to have_selector(%(a[href="#{admin_languages_path}"]))
|
||||
end
|
||||
|
||||
it "should welcome user by username" do
|
||||
user = FactoryBot.create(:user)
|
||||
sign_in user
|
||||
get root_path
|
||||
expect(response.body).to include(user.username)
|
||||
end
|
||||
|
||||
it "should have a language drop-down" do
|
||||
user = FactoryBot.create(:user)
|
||||
sign_in user
|
||||
get root_path
|
||||
expect(response.body).to have_field("active_language_id")
|
||||
end
|
||||
it "should have a language drop-down" do
|
||||
get root_path
|
||||
expect(response.body).to have_field("active_language_id")
|
||||
end
|
||||
end
|
||||
|
@@ -1,39 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "Words", type: :request do
|
||||
describe "GET /index" do
|
||||
|
||||
it "renders the index template" do
|
||||
get "/words"
|
||||
expect(response).to render_template(:index)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /show/:val" do
|
||||
|
||||
before(:each) do
|
||||
@word = FactoryBot.create(:word)
|
||||
end
|
||||
|
||||
it "renders the show template" do
|
||||
get "/words/#{@word.id}"
|
||||
expect(response).to render_template(:show)
|
||||
end
|
||||
|
||||
it "sets @word instance variable" do
|
||||
get "/words/#{@word.id}"
|
||||
expect(assigns(:word)).to be_a(Word)
|
||||
end
|
||||
|
||||
it "displays the word name" do
|
||||
get "/words/#{@word.id}"
|
||||
expect(response.body).to include(@word.word)
|
||||
end
|
||||
|
||||
it "displays the definitions" do
|
||||
@definition = FactoryBot.create(:definition)
|
||||
get "/words/#{@definition.word_id}"
|
||||
expect(response.body).to include(@definition.definition)
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user