Skip to content

Instantly share code, notes, and snippets.

View semanticart's full-sized avatar

Jeffrey Chupp semanticart

View GitHub Profile
# run the script and pass the path to your mongo/bin
# i.e.
# ruby mongodb_import_test.rb ~/Downloads/mongodb-osx-x86_64-1.0.1/bin
require 'rubygems'
require 'test/unit'
require 'mongo'
include Mongo
We couldn’t find that file to show.
~/Documents/projects/cucumber/examples/sinatra(master)$ cucumber
Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario: Add two numbers # features/add.feature:6
Given I visit the calculator page # features/step_definitions/add_steps.rb:1
wrong number of arguments (2 for 1) (ArgumentError)
(eval):2:in `visit'
$ ruby test_custom_data.rb
Loaded suite test_custom_data
Started
.F..
Finished in 0.018501 seconds.
1) Failure:
test_creating_a_thing_with_a_foo(MyTest) [test_custom_data.rb:58]:
<"--- !ruby/object:Foo \nfirst: 1st\nsecond: 2nd\n"> expected but was
<#<Foo:0x1023a5ce8 @first="1st", @second="2nd">>.
def data
data = {
:success => true,
:site => Site.find(params[:id]).site
}
render :json => data.to_json
# Returns {
# 'success': true,
# 'site': {
# 'site': {
class ActiveRecord::Base
def self.find_values opts
sql = self.send(:construct_finder_sql, opts)
self.connection.select_values(sql)
end
end
>> Tagging.find_values(:select => :taggable_id, :limit => 30, :order => 'tagged_at asc')
=> ["1", "3", "6", "6", "6", "10", "10", "10", "11", "11", "11", "10", "10", "10", "10", "10", "13", "13", "13", "13", "13", "13", "15", "15", "15", "15", "15", "15", "15", "15"]
# I'm interested in improvements or variations on doing this in rspec
# assuming we have an instance of ActiveSupport::Cache::MemCacheStore
# as the constant Mem and we want to check to see if a method changes
# the value for a particular key
# this comes into play in the first spec below...
class MemcachedValueFor
def self.method_missing name, *args
Mem.fetch(name)
>> project = Project.first
=> #<Project id: 1, name: "some project", created_at: "2009-05-16 16:37:41", updated_at: "2009-05-16 16:37:41">
>> project.tasks
=> []
>> project.tasks_attributes = [{:name => 'something'}]
=> [{:name=>"something"}]
>> project.save
=> true
>> project.tasks
=> [#<Task id: 3, name: "something", project_id: 1, deleted_at: nil, created_at: "2009-05-16 16:49:11", updated_at: "2009-05-16 16:49:11">]
diff --git a/lib/is_paranoid.rb b/lib/is_paranoid.rb
index cad76db..26624e0 100644
--- a/lib/is_paranoid.rb
+++ b/lib/is_paranoid.rb
@@ -38,13 +38,22 @@ module IsParanoid
# Use update_all with an exclusive scope to restore undo the soft-delete.
# This bypasses update-related callbacks.
#
- # By default, restores cascade through associations that are
+ # By default, restores cascade through associations that are belongs_to
diff --git a/lib/is_paranoid.rb b/lib/is_paranoid.rb
index 3c11248..c74adf1 100644
--- a/lib/is_paranoid.rb
+++ b/lib/is_paranoid.rb
@@ -30,21 +30,33 @@ module IsParanoid
# NOTE: is_paranoid declaration must follow assocation declarations.
[:has_many, :has_one].each do |macro|
self.reflect_on_all_associations(macro).each do |assoc|
- if (a = assoc.klass.reflect_on_all_associations(:belongs_to).detect{ |a| a.class_name == self.class_name })
- assoc.klass.send(