Test title helpers for custom anon display names
This commit is contained in:
parent
d1ad34eb9c
commit
0196a9ea10
|
@ -1,81 +1,95 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require "rails_helper"
|
||||||
|
|
||||||
describe ApplicationHelper::TitleMethods, :type => :helper do
|
describe ApplicationHelper::TitleMethods, type: :helper do
|
||||||
let(:user) { FactoryBot.create(:user) }
|
let(:user) { FactoryBot.create(:user) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_const("APP_CONFIG", {
|
stub_const("APP_CONFIG", {
|
||||||
'site_name' => 'Waschmaschine',
|
"site_name" => "Waschmaschine",
|
||||||
'anonymous_name' => 'Anonymous',
|
"anonymous_name" => "Anonymous",
|
||||||
'https' => true,
|
"https" => true,
|
||||||
'items_per_page' => 5,
|
"items_per_page" => 5,
|
||||||
'sharing' => {}
|
"sharing" => {}
|
||||||
})
|
})
|
||||||
|
|
||||||
user.profile.display_name = 'Cool Man'
|
user.profile.display_name = "Cool Man"
|
||||||
user.profile.save!
|
user.profile.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#generate_title" do
|
describe "#generate_title" do
|
||||||
it 'should generate a proper title' do
|
it "should generate a proper title" do
|
||||||
expect(generate_title('Simon', 'says:', 'Nice!')).to eq('Simon says: Nice! | Waschmaschine')
|
expect(generate_title("Simon", "says:", "Nice!")).to eq("Simon says: Nice! | Waschmaschine")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should only append a single quote to names that end with s' do
|
it "should only append a single quote to names that end with s" do
|
||||||
expect(generate_title('Andreas', 'says:', 'Cool!', true)).to eq('Andreas\' says: Cool! | Waschmaschine')
|
expect(generate_title("Andreas", "says:", "Cool!", true)).to eq("Andreas' says: Cool! | Waschmaschine")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should cut content that is too long' do
|
it "should cut content that is too long" do
|
||||||
expect(generate_title('A title', 'with', 'a' * 50)).to eq('A title with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa… | Waschmaschine')
|
expect(generate_title("A title", "with", "a" * 50)).to eq("A title with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa… | Waschmaschine")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#question_title" do
|
describe "#question_title" do
|
||||||
let(:question) { FactoryBot.create(:question) }
|
let(:question) { FactoryBot.create(:question, direct: true) }
|
||||||
|
|
||||||
it 'should generate a proper title for the question' do
|
it "should generate a proper title for the question" do
|
||||||
expect(question_title(question)).to eq("Anonymous asked #{question.content} | Waschmaschine")
|
expect(question_title(question)).to eq("Anonymous asked #{question.content} | Waschmaschine")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "user has custom anonymous display name" do
|
||||||
|
before do
|
||||||
|
FactoryBot.create(:answer, question: question, user: user)
|
||||||
|
user.profile.anon_display_name = "Amogus"
|
||||||
|
user.profile.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should generate a proper title for the question with a custom anonymous display name" do
|
||||||
|
expect(question_title(question)).to eq("Amogus asked #{question.content} | Waschmaschine")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#answer_title" do
|
describe "#answer_title" do
|
||||||
let(:answer) { FactoryBot.create(:answer, user: user,
|
let(:answer) do
|
||||||
content: 'a',
|
FactoryBot.create(:answer, user: user,
|
||||||
question_content: 'q') }
|
content: "a",
|
||||||
|
question_content: "q")
|
||||||
|
end
|
||||||
|
|
||||||
it 'should generate a proper title' do
|
it "should generate a proper title" do
|
||||||
expect(answer_title(answer)).to eq('Cool Man answered q | Waschmaschine')
|
expect(answer_title(answer)).to eq("Cool Man answered q | Waschmaschine")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#user_title" do
|
describe "#user_title" do
|
||||||
it 'should generate a proper title' do
|
it "should generate a proper title" do
|
||||||
expect(user_title(user)).to eq("Cool Man | Waschmaschine")
|
expect(user_title(user)).to eq("Cool Man | Waschmaschine")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#questions_title" do
|
describe "#questions_title" do
|
||||||
it 'should generate a proper title' do
|
it "should generate a proper title" do
|
||||||
expect(questions_title(user)).to eq("Cool Man's questions | Waschmaschine")
|
expect(questions_title(user)).to eq("Cool Man's questions | Waschmaschine")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#answers_title" do
|
describe "#answers_title" do
|
||||||
it 'should generate a proper title' do
|
it "should generate a proper title" do
|
||||||
expect(answers_title(user)).to eq("Cool Man's answers | Waschmaschine")
|
expect(answers_title(user)).to eq("Cool Man's answers | Waschmaschine")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#smiles_title" do
|
describe "#smiles_title" do
|
||||||
it 'should generate a proper title' do
|
it "should generate a proper title" do
|
||||||
expect(smiles_title(user)).to eq("Cool Man's smiles | Waschmaschine")
|
expect(smiles_title(user)).to eq("Cool Man's smiles | Waschmaschine")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#comments_title" do
|
describe "#comments_title" do
|
||||||
it 'should generate a proper title' do
|
it "should generate a proper title" do
|
||||||
expect(comments_title(user)).to eq("Cool Man's comments | Waschmaschine")
|
expect(comments_title(user)).to eq("Cool Man's comments | Waschmaschine")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -83,8 +97,8 @@ describe ApplicationHelper::TitleMethods, :type => :helper do
|
||||||
describe "#list_title" do
|
describe "#list_title" do
|
||||||
let(:list) { FactoryBot.create(:list) }
|
let(:list) { FactoryBot.create(:list) }
|
||||||
|
|
||||||
it 'should generate a proper title' do
|
it "should generate a proper title" do
|
||||||
expect(list_title(list)).to eq("#{list.name} | Waschmaschine")
|
expect(list_title(list)).to eq("#{list.name} | Waschmaschine")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue