Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit a97a93f

Browse files
committed
closes #86
1 parent 57828c3 commit a97a93f

File tree

7 files changed

+55
-35
lines changed

7 files changed

+55
-35
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ spec/test_app/Gemfile.lock
1717
/Gemfile.lock
1818
/examples/action-cable/rails_cache_dir/
1919
rails_cache_dir/
20+
react_prerendering_src.js
2021

2122
.bundle/
2223
log/*.log

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
source 'https://rubygems.org'
22
gem "opal-jquery", git: "https://github.com/opal/opal-jquery.git", branch: "master"
3+
# gem 'hyper-react', path: '../hyper-react'
4+
# gem 'hyper-operation', path: '../hyper-operation'
5+
# gem 'hyperloop-config', path: '../hyperloop-config'
36
gemspec

lib/active_record_base.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ def __hyperloop_secure_attributes(acting_user)
318318
Hyperloop::InternalPolicy.accessible_attributes_for(self, acting_user)
319319
attributes.select { |attr| accessible_attributes.include? attr.to_sym }
320320
end
321+
322+
# regulate built in scopes so they are accesible from the client
323+
%i[limit offset].each do |scope|
324+
regulate_scope(scope) {}
325+
end
321326
end
322327
end
323328

react_prerendering_src.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

spec/batch3/edge_cases_spec.rb

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,54 @@
6464
end.to eq(1)
6565
end
6666

67-
xit "fetches data during prerendering" do # server_only not working!
68-
# test for fix in prerendering fetch which was causing security violations
67+
it "fetches data during prerendering" do
6968
5.times do |i|
7069
FactoryBot.create(:todo, title: "Todo #{i}")
7170
end
71+
# cause spec to fail if there are attempts to fetch data after prerendering
72+
hide_const 'ReactiveRecord::Operations::Fetch'
7273
mount "TestComponent77", {}, render_on: :both do
7374
class TestComponent77 < Hyperloop::Component
7475
render(UL) do
75-
puts "Todo defined? #{defined? Todo} class? #{Todo.class}"
76-
LI { "fred" }
77-
#Todo.each do |todo|
78-
# # try Todo.find_by_title ... as well
79-
# LI { todo.title }
80-
# end
76+
Todo.each do |todo|
77+
LI { todo.title }
78+
end
8179
end
8280
end
8381
end
84-
binding.pry
82+
Todo.all.each do |todo|
83+
page.should have_content(todo.title)
84+
end
85+
end
86+
87+
it "prerenders a belongs to relationship" do
88+
user_item = User.create(name: 'Fred')
89+
todo_item = TodoItem.create(title: 'test-todo', user: user_item)
90+
mount "PrerenderTest", {}, render_on: :server_only do
91+
class PrerenderTest < Hyperloop::Component
92+
render(DIV) do
93+
TodoItem.first.user.name
94+
end
95+
end
96+
end
97+
page.should have_content("Fred")
98+
end
99+
100+
it "the limit and offset predefined scopes work" do
101+
5.times do |i|
102+
FactoryBot.create(:todo, title: "Todo #{i}")
103+
end
104+
mount "TestComponent77" do
105+
class TestComponent77 < Hyperloop::Component
106+
render(UL) do
107+
Todo.limit(2).offset(3).each do |todo|
108+
LI { todo.title }
109+
end
110+
end
111+
end
112+
end
113+
Todo.limit(2).offset(3).each do |todo|
114+
page.should have_content(todo.title)
115+
end
85116
end
86117
end

spec/spec_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def self.should_immediately_generate(opts={}, &block)
135135

136136
module React
137137
module IsomorphicHelpers
138-
def self.load_context(ctx, controller, name = nil)
138+
def self.xxxload_context(ctx, controller, name = nil)
139139
@context = Context.new("#{controller.object_id}-#{Time.now.to_i}", ctx, controller, name)
140140
end
141141
end
@@ -307,7 +307,7 @@ class JavaScriptError < StandardError; end
307307
elsif client_options[:raise_on_js_errors] != :off && errors.present?
308308
raise JavaScriptError, errors.join("\n\n")
309309
end
310-
end
310+
end
311311

312312
config.include Capybara::DSL
313313

spec/support/component_helpers.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,9 @@ def build_test_url_for(controller)
130130
javascript = render_params.delete(:javascript)
131131
code = render_params.delete(:code)
132132
page = "<%= react_component @component_name, @component_params, { prerender: #{render_on != :client_only} } %>" # false should be: "#{render_on != :client_only} } %>" but its not working in the gem testing harness
133-
page = "<script type='text/javascript'>\n#{TOP_LEVEL_COMPONENT_PATCH}\n</script>\n#{page}"
134-
135-
if code
136-
page = "<script type='text/javascript'>\n#{code}\n</script>\n"+page
133+
unless render_on == :server_only
134+
page = "<script type='text/javascript'>\n#{TOP_LEVEL_COMPONENT_PATCH}\n</script>\n#{page}"
135+
page = "<script type='text/javascript'>\n#{code}\n</script>\n"+page if code
137136
end
138137

139138
#TODO figure out how to auto insert this line???? something like:
@@ -159,7 +158,7 @@ def build_test_url_for(controller)
159158
page = "<script type='text/javascript'>go = function() {window.hyper_spec_waiting_for_go = false}</script>\n#{page}"
160159
title = view_context.escape_javascript(ComponentTestHelpers.current_example.description)
161160
title = "#{title}...continued." if ComponentTestHelpers.description_displayed
162-
page = "<script type='text/javascript'>console.log(console.log('%c#{title}','color:green; font-weight:bold; font-size: 200%'))</script>\n#{page}"
161+
page = "<script type='text/javascript'>console.log('%c#{title}','color:green; font-weight:bold; font-size: 200%')</script>\n#{page}"
163162
ComponentTestHelpers.description_displayed = true
164163
render_params[:inline] = page
165164
render render_params

0 commit comments

Comments
 (0)