Consider the following spec which as intermittently failing the should update savings spec.
# spec/integration/drafts/pro/finishing_spec.rb
require 'spec_helper'
describe 'finishing', js: true do| class TodoIndex < HyperComponent | |
| def create_new_todo_item | |
| Todo.create(title: @title) | |
| @title = nil | |
| end | |
| render(DIV, class: 'ToDo') do | |
| IMG(class: 'Logo', src: 'assets/logo.png', alt: 'Hyperstack Logo') | |
| H1(class: 'ToDo-Header') { 'Hyperstack To Do' } |
| class Todo < ApplicationRecord | |
| end |
| # app/hyperstack/libs/throttle.rb | |
| class Throttle | |
| # call the provided block (using the run method) no faster than the | |
| # specified update frequency. | |
| def initialize(update_frequency = 0.5, &block) | |
| @update_frequency = update_frequency | |
| @block = block | |
| @last_start_time = Time.now - update_frequency |
| class ShowTweet < HyperComponent | |
| param :tweet | |
| render(DIV, class: "card card-body") do | |
| DIV { tweet.body } unless @editing | |
| DIV(class: "mt-2") do | |
| BUTTON { "Likes (#{tweet.likes_count})" }.on(:click) { tweet.increment!(:likes_count) } | |
| BUTTON { "Retweets (#{tweet.retweets_count})" }.on(:click) { tweet.increment!(:retweets_count) } | |
| if @editing |
| <%= turbo_frame_tag dom_id(tweet) do %> | |
| <div class="card card-body"> | |
| <div><%= tweet.body %></div> | |
| <div class="mt-2"> | |
| <%= button_to "Likes (#{tweet.likes_count})", tweet_like_path(tweet), method: :post %> | |
| <%= button_to "Retweets (#{tweet.retweets_count})", tweet_retweet_path(tweet), method: :post %> | |
| <%= link_to "Edit", edit_tweet_path(tweet) %> | |
| </div> |
| class LikesController < ApplicationController | |
| before_action :set_tweet | |
| def create | |
| @tweet.increment! :likes_count | |
| redirect_to @tweet | |
| end | |
| private |
| json.extract! tweet, :id, :body, :likes_count, :retweets_count, :created_at, :updated_at | |
| json.url tweet_url(tweet, format: :json) |
| class Tweet < ApplicationRecord | |
| after_create_commit { broadcast_prepend_to "tweets" } | |
| after_update_commit { broadcast_replace_to "tweets" } | |
| after_destroy_commit { broadcast_remove_to "tweets" } | |
| validates :body, presence: true | |
| end |
| module Hyperstack | |
| class InternalPolicy | |
| def self.log_times(model, times, messages_sent, accumlated_broadcast_time) | |
| times[:broadcast] = Time.now | |
| return if times[:broadcast]-times[:start] < 0.0100 # adjust this as needed | |
| ::Rails.logger.warn "*******************BROADCASTING MODEL CHANGES**************************" | |
| ::Rails.logger.warn "Model: #{model.inspect}" | |
| justification = 0 | |
| last_item_finished_at = times[:start] | |
| times.collect { |event, timestamp| [timestamp, event] } |