Skip to content

Commit

Permalink
new while loading specs added plus attempt to break up specs into equ…
Browse files Browse the repository at this point in the history
…al chunks
  • Loading branch information
catmando committed Jan 12, 2019
1 parent 9268e32 commit 242d7a9
Show file tree
Hide file tree
Showing 6 changed files with 327 additions and 5 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cache:
bundler: true
directories:
- node_modules # NPM packages

_test_gem: &_test_gem
stage: test
addons:
Expand Down Expand Up @@ -37,7 +37,7 @@ _test_gem: &_test_gem
- yarn install
script:
- echo running script $COMPONENT
- DRIVER=travis bundle exec rake
- DRIVER=travis bundle exec rake $TASK

_deploy_gem: &_deploy_gem
stage: release gems
Expand All @@ -63,7 +63,9 @@ jobs:
- <<: *_test_gem
env: COMPONENT=hyper-component RUBY_VERSION=2.5.1
- <<: *_test_gem
env: COMPONENT=hyper-model RUBY_VERSION=2.5.1
env: COMPONENT=hyper-model RUBY_VERSION=2.5.1 TASK=part1
- <<: *_test_gem
env: COMPONENT=hyper-model RUBY_VERSION=2.5.1 TASK=part2
- <<: *_test_gem
env: COMPONENT=hyper-operation RUBY_VERSION=2.5.1
- <<: *_test_gem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def raise_if_not_quiet=(x)
end

def quiet_test(component)
return unless component.waiting_on_resources && raise_if_not_quiet? && component.class != RescueMetaWrapper
return unless component.waiting_on_resources && raise_if_not_quiet? #&& component.class != RescueMetaWrapper <- WHY can't create a spec that this fails without this, but several fail with it.
raise NotQuiet.new("#{component} is waiting on resources")
end

Expand Down
8 changes: 8 additions & 0 deletions ruby/hyper-model/Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"

task :part1 do
(1..2).each { |batch| Rake::Task["spec:batch#{batch}"].invoke rescue nil }
end

task :part2 do
(3..7).each { |batch| Rake::Task["spec:batch#{batch}"].invoke rescue nil }
end

task :spec do
(1..7).each { |batch| Rake::Task["spec:batch#{batch}"].invoke rescue nil }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'rspec-steps'


describe "while loading", js: true do
describe "while loading (deprecated methods)", js: true do

before(:all) do
ReactiveRecord::Operations::Fetch.class_eval do
Expand Down
299 changes: 299 additions & 0 deletions ruby/hyper-model/spec/batch7/while_loading_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,299 @@
require 'spec_helper'
require 'test_components'
require 'rspec-steps'


describe "while loading", js: true do

before(:all) do
ReactiveRecord::Operations::Fetch.class_eval do
def self.semaphore
@semaphore ||= Mutex.new
end
validate { self.class.semaphore.synchronize { true } }
end
require 'pusher'
require 'pusher-fake'
Pusher.app_id = "MY_TEST_ID"
Pusher.key = "MY_TEST_KEY"
Pusher.secret = "MY_TEST_SECRET"
require "pusher-fake/support/base"

Hyperstack.configuration do |config|
config.transport = :pusher
config.channel_prefix = "synchromesh"
config.opts = {app_id: Pusher.app_id, key: Pusher.key, secret: Pusher.secret}.merge(PusherFake.configuration.web_options)
end
end

before(:each) do
client_option raise_on_js_errors: :off

# spec_helper resets the policy system after each test so we have to setup
# before each test
stub_const 'TestApplication', Class.new
stub_const 'TestApplicationPolicy', Class.new
TestApplicationPolicy.class_eval do
always_allow_connection
regulate_all_broadcasts { |policy| policy.send_all }
allow_change(to: :all, on: [:create, :update, :destroy]) { true }
end
# size_window(:small, :portrait)
FactoryBot.create(:user, first_name: 'Lily', last_name: 'DaDog')
FactoryBot.create(:user, first_name: 'Coffee', last_name: 'Boxer')
end

it "will display the while loading message for a fetch within a nested component" do
ReactiveRecord::Operations::Fetch.semaphore.synchronize do
mount "WhileLoadingTester", {}, no_wait: true do
class MyNestedGuy < HyperComponent
render(SPAN) do
"#{User.find_by_first_name('Lily').last_name} is a dog"
end
end
class WhileLoadingTester < HyperComponent
include Hyperstack::Component::WhileLoading
render do
if resources_loaded?
DIV do
MyNestedGuy {}
end
else
SPAN { 'loading...' }
end
end
end
end
expect(page).to have_content('loading...')
expect(page).not_to have_content('is a dog', wait: 0)
end
expect(page).to have_content('DaDog is a dog')
expect(page).not_to have_content('loading...', wait: 0)
end

it "will display the while loading message for a fetch within a nested component when attached to that component" do
ReactiveRecord::Operations::Fetch.semaphore.synchronize do
mount "WhileLoadingTester", {}, no_wait: true do
class MyNestedGuy < HyperComponent
render(SPAN) do
"#{User.find_by_first_name('Lily').last_name} is a dog"
end
end
class WhileLoadingTester < HyperComponent
include Hyperstack::Component::WhileLoading
render(DIV) do
if resources_loaded?
MyNestedGuy {}
else
SPAN { 'loading...' }
end
end
end
end
expect(page).to have_content('loading...')
expect(page).not_to have_content('is a dog', wait: 0)
end
expect(page).to have_content('DaDog is a dog')
expect(page).not_to have_content('loading...', wait: 0)
end

it "The inner most while_loading will display only" do
ReactiveRecord::Operations::Fetch.semaphore.synchronize do
mount "WhileLoadingTester", {}, no_wait: true do
class MyNestedGuy < HyperComponent
include Hyperstack::Component::WhileLoading
render do
if resources_loaded?
DIV { "#{User.find_by_first_name('Lily').last_name} is a dog" }
else
SPAN { 'loading...' }
end
end
end
class WhileLoadingTester < HyperComponent
include Hyperstack::Component::WhileLoading
render do
if resources_loaded?
DIV do
MyNestedGuy {}
end
else
SPAN { 'i should not display' }
end
end
end
end
expect(page).to have_content('loading...')
expect(page).not_to have_content('is a dog', wait: 0)
end
expect(page).to have_content('DaDog is a dog')
expect(page).not_to have_content('i should not display', wait: 0)
end

# it "while loading can take a string param instead of a block" do
# ReactiveRecord::Operations::Fetch.semaphore.synchronize do
# mount "WhileLoadingTester", {}, no_wait: true do
# class WhileLoadingTester < HyperComponent
# render do
# DIV do
# User.find_by_first_name('Lily').last_name
# end
# .while_loading 'loading...'
# end
# end
# end
# expect(page).to have_content('loading...')
# expect(page).not_to have_content('DaDog', wait: 0)
# end
# expect(page).to have_content('DaDog')
# expect(page).not_to have_content('loading...', wait: 0)
# end
#
# it "while loading can take an element param instead of a block" do
# ReactiveRecord::Operations::Fetch.semaphore.synchronize do
# mount "WhileLoadingTester", {}, no_wait: true do
# class WhileLoadingTester < HyperComponent
# render do
# DIV do
# User.find_by_first_name('Lily').last_name
# end
# .while_loading(DIV { 'loading...' })
# end
# end
# end
# expect(page).to have_content('loading...')
# expect(page).not_to have_content('DaDog', wait: 0)
# end
# expect(page).to have_content('DaDog')
# expect(page).not_to have_content('loading...', wait: 0)
# end
#
# it "achieving while_loading behavior with state variables" do
# ReactiveRecord::Operations::Fetch.semaphore.synchronize do
# mount "WhileLoadingTester", {}, no_wait: true do
# class MyComponent < HyperComponent
# render do
# SPAN { 'loading...' }
# end
# end
#
# class WhileLoadingTester < HyperComponent
#
# before_mount do
# ReactiveRecord.load do
# User.find_by_first_name('Lily').last_name
# end.then do |last_name|
# mutate @last_name = last_name
# end
# end
#
# render do
# if @last_name
# DIV { @last_name }
# else
# MyComponent {}
# end
# end
# end
# end
# expect(page).to have_content('loading...')
# expect(page).not_to have_content('DaDog', wait: 0)
# end
# expect(page).to have_content('DaDog')
# expect(page).not_to have_content('loading...', wait: 0)
# end
#
# it "while loading display an application defined element" do
# ReactiveRecord::Operations::Fetch.semaphore.synchronize do
# mount "WhileLoadingTester", {}, no_wait: true do
# class MyComponent < HyperComponent
# render do
# SPAN { 'loading...' }
# end
# end
# class WhileLoadingTester < HyperComponent
# render do
# DIV do
# User.find_by_first_name('Lily').last_name
# end
# .while_loading do
# MyComponent {}
# end
# end
# end
# end
# expect(page).to have_content('loading...')
# expect(page).not_to have_content('DaDog', wait: 0)
# end
# expect(page).to have_content('DaDog')
# expect(page).not_to have_content('loading...', wait: 0)
# end

it "while loading works when number of children changes (i.e. relationships)" do
ReactiveRecord::Operations::Fetch.semaphore.synchronize do
mount "WhileLoadingTester", {}, no_wait: true do
class WhileLoadingTester < HyperComponent
include Hyperstack::Component::WhileLoading
render do
if resources_loaded?
UL { User.each { |user| LI { user.last_name } } }
else
'loading...'
end
end
end
end
expect(page).to have_content('loading...')
expect(page).not_to have_content('DaDog', wait: 0)
expect(page).not_to have_content('Boxer', wait: 0)
end
expect(page).to have_content('DaDog')
expect(page).to have_content('Boxer')
expect(page).not_to have_content('loading...', wait: 0)
end


it "will display the while loading message on condition" do
isomorphic do
class FetchNow < Hyperstack::ServerOp
dispatch_to { TestApplication }
end
end
mount "WhileLoadingTester", {}, no_wait: true do
class MyNestedGuy < HyperComponent
self.class.attr_reader :fetch
receives(FetchNow) { mutate @fetch = true }
render(SPAN) do
if self.class.fetch
User.find_by_first_name('Lily').last_name
else
'no fetch yet chet'
end
end
end
class WhileLoadingTester < HyperComponent
include Hyperstack::Component::WhileLoading
render do
if resources_loaded?
DIV { MyNestedGuy {} }
else
SPAN { 'loading...' }
end
end
end
end
expect(page).to have_content('no fetch yet chet')
expect(page).not_to have_content('loading...', wait: 0)
expect(page).not_to have_content('DaDog', wait: 0)
ReactiveRecord::Operations::Fetch.semaphore.synchronize do
FetchNow.run
expect(page).to have_content('loading...')
expect(page).not_to have_content('DaDog', wait: 0)
expect(page).not_to have_content('no fetch yet chet', wait: 0)
end
expect(page).to have_content('DaDog')
expect(page).not_to have_content('loading...', wait: 0)
expect(page).not_to have_content('no fetch yet chet', wait: 0)
end

end
13 changes: 13 additions & 0 deletions ruby/hyper-model/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,19 @@ class ActiveRecord::Base
# reset this variable so if any specs are setting up models locally
# the correct has gets sent to the client.
ActiveRecord::Base.instance_variable_set('@public_columns_hash', nil)
class ActiveRecord::Base
class << self
alias original_public_columns_hash public_columns_hash
end
end
end

config.after(:all) do
class ActiveRecord::Base
class << self
alias public_columns_hash original_public_columns_hash
end
end
end

config.after(:each, :js => true) do
Expand Down

0 comments on commit 242d7a9

Please sign in to comment.