Merge pull request #248 from Retrospring/feature/answer-theme

Extend theme helper to show themes on answer pages
This commit is contained in:
Karina Kwiatek 2021-12-31 19:46:21 +01:00 committed by GitHub
commit 552f7373e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 0 deletions

View File

@ -76,6 +76,16 @@ module ThemeHelper
else
@user.theme
end
elsif @answer&.user&.theme
if user_signed_in?
if current_user&.show_foreign_themes?
@answer.user.theme
else
current_user&.theme
end
else
@answer.user.theme
end
elsif current_user&.theme
current_user.theme
end

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