Skip to content

Instantly share code, notes, and snippets.

@timdiggins
timdiggins / request_support.rb
Created Feb 23, 2019
An equivalent to capybara save_and_open_page for request specs
View request_support.rb
# frozen_string_literal: true
RSpec.shared_context "save_and_open_page for request" do
def asset_host
"http://localhost:3000"
end
def save_and_open_page
Dir.mkdir(Rails.root.join("tmp/requests")) unless Dir.exist?(Rails.root.join("tmp/requests"))
file = Rails.root.join("tmp/requests/screenshot-#{Time.now.to_s(:number)}.html")
@timdiggins
timdiggins / traceback
Created Feb 20, 2018
traceback for oneboxing failure of https error
View traceback
2018-02-20 18:41:58 - RuntimeError - Unable to read pdf file: https://www.poettker.com/files/pdf/Produktkatalog_170912.pdf:
/Users/tim/workspaces/bws/onebox/lib/onebox/engine/pdf_onebox.rb:14:in `data'
/Users/tim/workspaces/bws/onebox/lib/onebox/engine.rb:66:in `block in record'
/Users/tim/.rvm/gems/ruby-2.3.1@rails/gems/moneta-1.0.0/lib/moneta/mixins.rb:165:in `fetch'
/Users/tim/workspaces/bws/onebox/lib/onebox/engine.rb:66:in `record'
/Users/tim/workspaces/bws/onebox/lib/onebox/layout_support.rb:9:in `layout'
/Users/tim/workspaces/bws/onebox/lib/onebox/layout_support.rb:13:in `to_html'
/Users/tim/workspaces/bws/onebox/lib/onebox/preview.rb:35:in `engine_html'
/Users/tim/workspaces/bws/onebox/lib/onebox/preview.rb:16:in `to_s'
/Users/tim/workspaces/bws/onebox/lib/onebox/web.rb:33:in `block in <class:Web>'
@timdiggins
timdiggins / gist:3eba95ba752092e3648b9a3a932df41b
Last active Feb 20, 2018
traceback for thredded demo (v0.14.2) with onebox (1.8.39) Using content with http
View gist:3eba95ba752092e3648b9a3a932df41b
RuntimeError in Thredded::Topics#show
Showing /Users/tim/workspaces/bws/thredded/app/views/thredded/posts_common/_content.html.erb where line #2 raised:
Unable to read pdf file: https://www.poettker.com/files/pdf/Produktkatalog_170912.pdf
Extracted source (around line #14):
def data
pdf_info = get_pdf_info
raise "Unable to read pdf file: #{@url}" if pdf_info.nil?
result = { link: link,
@timdiggins
timdiggins / disable_template_cache_clearing.rb
Last active Jan 29, 2018
speed up rails 5.0 feature specs by caching templates during suite
View disable_template_cache_clearing.rb
# spec/support/disable_template_cache_clearing
# may also need to configure, either here
Rails.application.config.action_view.cache_template_loading = true
# or in config/environments/test.rb:
# config.action_view.cache_template_loading = true
# ensure ActionView::Digestor is already autoloaded before patching it
ActionView::Digestor
@timdiggins
timdiggins / thredded.rb
Last active Jan 10, 2017
MainAppDelegator
View thredded.rb
# config/intitializers/thredded.rb
# to allow you to not to have to add `main_app` before every path helper
# when embedding Thredded within a main-app supplied layout (with navbar and links to the main_app)
# ... Add this to the bottom of the initializer
Rails.application.config.to_prepare do
Rails.application.reload_routes!
thredded_methods = (Thredded::Engine.routes.url_helpers.methods + Thredded::UrlsHelper.instance_methods)
@timdiggins
timdiggins / test.rb
Created May 12, 2016
Simple script to test rspec_junit_formatter against all the rspec versions
View test.rb
#!/usr/bin/env ruby
def header(version)
puts
puts "-" * 80
puts " rspec #{version}"
end
def run(version, command)
system <<-SCRIPT
@timdiggins
timdiggins / traceback.txt
Created Jan 24, 2013
traceback for stack overflow problem
View traceback.txt
ActionView::Template::Error: undefined method `action_methods' for nil:NilClass
/Users/tim/.rvm/gems/ruby-1.9.2-p320@buddy/gems/authlogic-3.2.0/lib/authlogic/controller_adapters/abstract_adapter.rb:63:in `method_missing'
/Users/tim/.rvm/gems/ruby-1.9.2-p320@buddy/gems/activeadmin-0.5.1/lib/active_admin/resource/action_items.rb:56:in `block in add_default_action_items'
/Users/tim/.rvm/gems/ruby-1.9.2-p320@buddy/gems/activeadmin-0.5.1/lib/active_admin/views/action_items.rb:9:in `instance_eval'
/Users/tim/.rvm/gems/ruby-1.9.2-p320@buddy/gems/activeadmin-0.5.1/lib/active_admin/views/action_items.rb:9:in `block (2 levels) in build'
/Users/tim/.rvm/gems/ruby-1.9.2-p320@buddy/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
/Users/tim/.rvm/gems/ruby-1.9.2-p320@buddy/gems/arbre-1.0.1/lib/arbre/context.rb:92:in `with_current_arbre_element'
/Users/tim/.rvm/gems/ruby-1.9.2-p320@buddy/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
/Users/tim/.rvm/g
@timdiggins
timdiggins / gist:2899995
Created Jun 9, 2012
method to extract parts from a rails Mail::Message
View gist:2899995
def parts(email)
splits = email.encoded.split(/(\r\n)*----==_mimepart_[a-zA-Z0-9_]+(\r\n)*/)
parts = {header: splits[0]}
splits[1..-2].each do |part|
headers, body = part.split(/\r\n\r\n/, 2)
if(m = /Content-Type: ([^; ]+);?\s/.match(headers))
type = m[1]
parts[type] = OpenStruct.new(headers:headers, body:body)
end
end
@timdiggins
timdiggins / attr_test_css.rb
Created May 26, 2012
Quick demo of problem with css attribute search with slash
View attr_test_css.rb
require 'test/unit'
require 'nokogiri'
class AttributeWithSlashCssTest < Test::Unit::TestCase
def setup
@doc = Nokogiri.parse(
<<-END
<html><body>
<a href=\"/my/path\">My link text</a>
<a href=\"/my-other-path\">