diff --git a/.gitignore b/.gitignore
index 6021c110..727fdae8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,6 +17,7 @@ spec/test_app/Gemfile.lock
/Gemfile.lock
/examples/action-cable/rails_cache_dir/
rails_cache_dir/
+react_prerendering_src.js
.bundle/
log/*.log
diff --git a/Gemfile b/Gemfile
index 41134fba..7bb6d099 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,3 +1,6 @@
source 'https://rubygems.org'
gem "opal-jquery", git: "https://github.com/opal/opal-jquery.git", branch: "master"
+# gem 'hyper-react', path: '../hyper-react'
+# gem 'hyper-operation', path: '../hyper-operation'
+# gem 'hyperloop-config', path: '../hyperloop-config'
gemspec
diff --git a/lib/active_record_base.rb b/lib/active_record_base.rb
index d350bcb5..87b55ae3 100644
--- a/lib/active_record_base.rb
+++ b/lib/active_record_base.rb
@@ -318,6 +318,11 @@ def __hyperloop_secure_attributes(acting_user)
Hyperloop::InternalPolicy.accessible_attributes_for(self, acting_user)
attributes.select { |attr| accessible_attributes.include? attr.to_sym }
end
+
+ # regulate built in scopes so they are accesible from the client
+ %i[limit offset].each do |scope|
+ regulate_scope(scope) {}
+ end
end
end
diff --git a/react_prerendering_src.js b/react_prerendering_src.js
deleted file mode 100644
index 02a954a8..00000000
--- a/react_prerendering_src.js
+++ /dev/null
@@ -1,19 +0,0 @@
-( (function () {
- if (typeof console !== "undefined" && console.history) {
- console.history = [];
-}
-
- var result = this.ReactRailsUJS.serverRender('renderToString', 'React.TopLevelRailsComponent', {"render_params":{},"component_name":"TestComponent77","controller":"ReactTest"});
- (function (history) {
- if (history && history.length > 0) {
- result += '\n';
- history.forEach(function (msg) {
- result += '\nconsole.' + msg.level + '.apply(console, ' + JSON.stringify(msg.arguments) + ');';
- });
- result += '\n';
- }
-})(console.history);
-
- return result;
- })()
-)
\ No newline at end of file
diff --git a/spec/batch3/edge_cases_spec.rb b/spec/batch3/edge_cases_spec.rb
index 37088693..d3676d5e 100644
--- a/spec/batch3/edge_cases_spec.rb
+++ b/spec/batch3/edge_cases_spec.rb
@@ -64,23 +64,54 @@
end.to eq(1)
end
- xit "fetches data during prerendering" do # server_only not working!
- # test for fix in prerendering fetch which was causing security violations
+ it "fetches data during prerendering" do
5.times do |i|
FactoryBot.create(:todo, title: "Todo #{i}")
end
+ # cause spec to fail if there are attempts to fetch data after prerendering
+ hide_const 'ReactiveRecord::Operations::Fetch'
mount "TestComponent77", {}, render_on: :both do
class TestComponent77 < Hyperloop::Component
render(UL) do
- puts "Todo defined? #{defined? Todo} class? #{Todo.class}"
- LI { "fred" }
- #Todo.each do |todo|
- # # try Todo.find_by_title ... as well
- # LI { todo.title }
- # end
+ Todo.each do |todo|
+ LI { todo.title }
+ end
end
end
end
- binding.pry
+ Todo.all.each do |todo|
+ page.should have_content(todo.title)
+ end
+ end
+
+ it "prerenders a belongs to relationship" do
+ user_item = User.create(name: 'Fred')
+ todo_item = TodoItem.create(title: 'test-todo', user: user_item)
+ mount "PrerenderTest", {}, render_on: :server_only do
+ class PrerenderTest < Hyperloop::Component
+ render(DIV) do
+ TodoItem.first.user.name
+ end
+ end
+ end
+ page.should have_content("Fred")
+ end
+
+ it "the limit and offset predefined scopes work" do
+ 5.times do |i|
+ FactoryBot.create(:todo, title: "Todo #{i}")
+ end
+ mount "TestComponent77" do
+ class TestComponent77 < Hyperloop::Component
+ render(UL) do
+ Todo.limit(2).offset(3).each do |todo|
+ LI { todo.title }
+ end
+ end
+ end
+ end
+ Todo.limit(2).offset(3).each do |todo|
+ page.should have_content(todo.title)
+ end
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 9e6985b8..c9014cf4 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -135,7 +135,7 @@ def self.should_immediately_generate(opts={}, &block)
module React
module IsomorphicHelpers
- def self.load_context(ctx, controller, name = nil)
+ def self.xxxload_context(ctx, controller, name = nil)
@context = Context.new("#{controller.object_id}-#{Time.now.to_i}", ctx, controller, name)
end
end
@@ -307,7 +307,7 @@ class JavaScriptError < StandardError; end
elsif client_options[:raise_on_js_errors] != :off && errors.present?
raise JavaScriptError, errors.join("\n\n")
end
- end
+ end
config.include Capybara::DSL
diff --git a/spec/support/component_helpers.rb b/spec/support/component_helpers.rb
index 87d300db..957085dd 100644
--- a/spec/support/component_helpers.rb
+++ b/spec/support/component_helpers.rb
@@ -130,10 +130,9 @@ def build_test_url_for(controller)
javascript = render_params.delete(:javascript)
code = render_params.delete(:code)
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
- page = "\n#{page}"
-
- if code
- page = "\n"+page
+ unless render_on == :server_only
+ page = "\n#{page}"
+ page = "\n"+page if code
end
#TODO figure out how to auto insert this line???? something like:
@@ -159,7 +158,7 @@ def build_test_url_for(controller)
page = "\n#{page}"
title = view_context.escape_javascript(ComponentTestHelpers.current_example.description)
title = "#{title}...continued." if ComponentTestHelpers.description_displayed
- page = "\n#{page}"
+ page = "\n#{page}"
ComponentTestHelpers.description_displayed = true
render_params[:inline] = page
render render_params