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

Commit

Permalink
closes #86
Browse files Browse the repository at this point in the history
  • Loading branch information
catmando committed May 5, 2018
1 parent 57828c3 commit a97a93f
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions lib/active_record_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 0 additions & 19 deletions react_prerendering_src.js

This file was deleted.

49 changes: 40 additions & 9 deletions spec/batch3/edge_cases_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
9 changes: 4 additions & 5 deletions spec/support/component_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<script type='text/javascript'>\n#{TOP_LEVEL_COMPONENT_PATCH}\n</script>\n#{page}"

if code
page = "<script type='text/javascript'>\n#{code}\n</script>\n"+page
unless render_on == :server_only
page = "<script type='text/javascript'>\n#{TOP_LEVEL_COMPONENT_PATCH}\n</script>\n#{page}"
page = "<script type='text/javascript'>\n#{code}\n</script>\n"+page if code
end

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

0 comments on commit a97a93f

Please sign in to comment.