Skip to content

Instantly share code, notes, and snippets.

has_and_belongs_to_many :assemblies, -> {
order(:name)
}
# ActiveRecord::StatementInvalid: SQLite3::SQLException:
# no such column: assemblies.name:
# SELECT "assemblies".*
# FROM "assemblies"
# INNER JOIN "assemblies_parts"
# ON "assemblies"."id" = "assemblies_parts"."assembly_id"
# app/models/assembly.rb
class Assembly < ActiveRecord::Base
has_and_belongs_to_many :parts
translates :name
end
# app/models/part.rb
class Part < ActiveRecord::Base
has_and_belongs_to_many :assemblies, -> {
order('assembly_translations.name asc')
@garethrees
garethrees / anonymous_controller_integration_spec.rb
Created June 19, 2017 14:17
Anonymous controller integration spec
# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe '#render_flash full stack integration' do
controller do
def escaped_string
flash.now[:escaped] = "<foo>"
render :inline => <<-EOF.strip_heredoc.html_safe
<%= render_flash(flash[:escaped]) %>
EOF
@garethrees
garethrees / translated_constants.rb
Last active April 12, 2017 10:26
Translated Constants
# A
class TrackThing
# The module can either be inline, or in its own file
module TranslatedConstants
def track_types
{ 'request_updates' => _('Individual requests'),
'all_new_requests' => _('Many requests') }
end
end
end
@garethrees
garethrees / last_event_forming_initial_request.rb
Last active March 24, 2017 10:13
Alaveteli new request where the followup is the last_event_forming_initial_request
request = FactoryGirl.create(:info_request, :user => User.last)
mail = RequestMailer.fake_response(request, request.user, 'Plz clarify', nil, nil)
request.receive(mail, mail.encoded, true)
event = request.log_event("status_update",
{ :user_id => request.user.id,
:old_described_state => request.described_state,
:described_state => 'waiting_clarification',
diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb
index 8eec4f5..0e1cf4d 100644
--- a/activerecord/lib/active_record/associations/belongs_to_association.rb
+++ b/activerecord/lib/active_record/associations/belongs_to_association.rb
@@ -10,7 +10,9 @@ module ActiveRecord
def replace(record)
raise_on_type_mismatch!(record) if record
- update_counters(record)
+ # PATCH
# Option A
# - Always send a notification if something looks like spam
# - If we have anti spam enabled, block the action unless the user is confirmed not spam
if AlaveteliSpamTermChecker.new.spam?(params[:comment][:body])
if send_exception_notifications?
e = Exception.new("Possible spam annotation from user #{@user.id}")
ExceptionNotifier.notify_exception(e, :env => request.env)
end
if AlaveteliConfiguration.enable_anti_spam && !@user.confirmed_not_spam?
@garethrees
garethrees / alaveteli-theme.yml
Last active February 15, 2017 10:12
Alaveteli tmuxinator configuration
# ~/.tmuxinator/alaveteli-theme.yml
<% theme_name = @args[0] %>
name: <%= theme_name %>
startup_window: <%= theme_name %>
root: ~
windows:
- <%= theme_name %>:
root: ~/Code/alaveteli-themes/<%= theme_name %>
@garethrees
garethrees / rsync.sh
Last active June 2, 2025 22:02
rsync & scp through jump host
# Upload
rsync -av -e "ssh -A JUMP_HOST ssh" FILE_TO_SEND DEST_HOST:/home/gareth/
# Download
rsync -av -e "ssh -A JUMP_HOST ssh" DEST_HOST:~/FILE_TO_DOWNLOAD ~/Downloads/
$ be rspec spec/models/outgoing_message_spec.rb:33
Run options: include {:locations=>{"./spec/models/outgoing_message_spec.rb"=>[33]}}
Randomized with seed 62702
From: /home/vagrant/alaveteli/app/models/outgoing_message.rb @ line 81 OutgoingMessage.fill_in_salutation:
78: def self.fill_in_salutation(text, public_body)
79: val = text.gsub(Template::BatchRequest.placeholder_salutation,
80: default_salutation(public_body))