-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HACK: Render lazy created poll inline with article
Workarounds required to reference current page from within article content via Current.page and from within the atom feed. Also no access to the request.key_generator from within feed article rendering, so we check for presence.
- Loading branch information
Showing
8 changed files
with
50 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Share | ||
module Polls | ||
class LazyPagePoll < ApplicationComponent | ||
include Phlex::Rails::Helpers::Provide | ||
include Phlex::Rails::Helpers::Request | ||
include Phlex::Rails::Helpers::TurboRefreshesWith | ||
|
||
attr_reader :page, :title, :question_data | ||
def initialize(page, title, question_data = {}) | ||
@page = page | ||
@title = title | ||
@question_data = question_data | ||
end | ||
|
||
def view_template | ||
poll = Poll.generate_for(page, title, question_data) or return | ||
|
||
provide :head, turbo_refreshes_with(method: :morph, scroll: :preserve) | ||
render Share::Polls::PollComponent.new(poll, device_uuid: device_uuid) | ||
end | ||
|
||
def device_uuid | ||
return "" unless helpers.request.key_generator | ||
|
||
helpers.cookies.signed[:device_uuid] | ||
end | ||
end | ||
end | ||
end |
12 changes: 11 additions & 1 deletion
12
spec/system/content/what-you-need-to-know-about-sqlite_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "What you need to know about SQLite", type: :system do | ||
it "displays the article content" do | ||
it "displays the article content if primary poll author does not exist" do | ||
visit "/articles/what-you-need-to-know-about-sqlite" | ||
|
||
expect(page).to have_content "What you need to know about SQLite" | ||
end | ||
|
||
it "displays the article content with poll by primary author" do | ||
FactoryBot.create(:user, :primary_author) | ||
|
||
visit "/articles/what-you-need-to-know-about-sqlite" | ||
|
||
expect(page).to have_content "What you need to know about SQLite" | ||
|
||
expect(page).to have_content "How likely are you to use SQLite in your Rails app?" | ||
end | ||
end |