Add tests for new answer page theme logic

This commit is contained in:
Andreas Nedbal 2021-12-30 02:03:34 +01:00
parent a6dc7661ee
commit 51bb2ae425
1 changed files with 51 additions and 0 deletions

View File

@ -70,6 +70,18 @@ describe ThemeHelper, :type => :helper do
expect(helper.get_active_theme).to be_a(Theme)
end
end
context "when target answer's user has a theme" do
before(:each) do
@answer = FactoryBot.create(:answer, user: FactoryBot.create(:user))
@answer.user.theme = Theme.new
@answer.user.save!
end
it "returns a theme" do
expect(helper.get_active_theme).to be_a(Theme)
end
end
end
context "when user is signed in" do
@ -97,6 +109,20 @@ describe ThemeHelper, :type => :helper do
expect(helper.get_active_theme).to be(theme)
end
end
context "when target answer's user has a theme" do
let(:theme) { Theme.new }
before(:each) do
@answer = FactoryBot.create(:answer, user: FactoryBot.create(:user))
@answer.user.theme = theme
@answer.user.save!
end
it "returns a theme" do
expect(helper.get_active_theme).to be(theme)
end
end
end
context "when user has a theme" do
@ -138,6 +164,31 @@ describe ThemeHelper, :type => :helper do
end
end
end
context "when target answer's user has a theme" do
let(:answer_theme) { Theme.new }
before(:each) do
@answer = FactoryBot.create(:answer, user: FactoryBot.create(:user))
@answer.user.theme = answer_theme
@answer.user.save!
end
it "returns the theme of the current page" do
expect(helper.get_active_theme).to eq(answer_theme)
end
context "when user doesn't allow foreign themes" do
before(:each) do
user.show_foreign_themes = false
user.save!
end
it "should return the users theme" do
expect(helper.get_active_theme).to eq(theme)
end
end
end
end
end
end