Merge pull request #248 from Retrospring/feature/answer-theme
Extend theme helper to show themes on answer pages
This commit is contained in:
commit
552f7373e6
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue