Skip to content

Instantly share code, notes, and snippets.

guard "minitest", all_on_start: false, rerun: false do
# with Minitest::Spec
watch(%r|^test/(.*)_test\.rb|)
watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
watch(%r|^test/minitest_helper\.rb|) { "test" }
watch(%r|^test/support/|) { "test" }
# Rails 3.2
watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/controllers/#{m[1]}_test.rb" }
watch(%r|^app/mailers/(.*)\.rb|) { |m| "test/mailers/#{m[1]}_test.rb" }
module Models
module Concerns
module Bannable
extend ActiveSupport::Concern
included do
default_scope -> { where(banned_at: nil) }
end
def ban(reason=nil)
(function() {
// Localize jQuery variable
var jQuery;
/******** Load jQuery if not present *********/
if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.4.2') {
var script_tag = document.createElement('script');
script_tag.setAttribute("type","text/javascript");
script_tag.setAttribute("src",
describe "unpublished reviews are fucking up listing scores" do
let(:reviewable) { create(:dispensary) }
let(:user) { create :user }
before do
25.times do
review = Review.create! user: user, reviewable: reviewable,
title: "title", body: "body"
review.create_rates atmosphere: 5, bud_quality: 5, accessibility: 5,
staff: 5, price: 5
end
module Bannable
extend ActiveSupport::Concern
included do
extend ClassMethods
default_scope where("banned_at IS NULL")
end
def ban(reason=nil)
options = ban_attributes({ban_reason: reason, banned_at: DateTime.now})
@dreamr
dreamr / gist:5052652
Created February 27, 2013 23:01
Without the self[:attr] form of referencing the attribute the tests fail because the values cant be found after being set ie: disapproved_by = user.id # or @disapproved_by = user.id # or self.disapproved_by = user.id # or
# Requires on the model that mixes this concern in:
# => approved_by integer
# => approved_at DateTime
# => disapproved_by integer
# => disapproved_at DateTime
module Moderation
extend ActiveSupport::Concern
included do
@dreamr
dreamr / gist:5000117
Created February 20, 2013 22:08
lol'd
if 5+5 == 10#topic.save!
else #Error Saving
p "#{topic.errors.full_messages}"
pp topic.attributes
20.times { p "------------------" }
errs << ["#{topic.errors.full_messages}", topic.attributes]
# output/log why no save
end
{:docs=>[{:id=>1,
:"region-tz-min-offset"=>-480,
:"dispensary-name"=>"dr. greenthumb garden supply 1",
:"dispensary-slug"=>"dr-greenthumb-garden-supply-1",
:"title-pc"=>"Dr. Greenthumb Garden Supply 1",
:"dispensary-rating-power"=>"5.0000",
:"dispensary-created"=>"1970-01-01T00:00:00.000Z", :video_url=>nil,
:"dispensary-region-slug"=>"lake-tahoe",
:"super-region-id"=>2,
:"super-region-name"=>"California",
@dreamr
dreamr / gist:4963675
Created February 15, 2013 21:26
hash 1
{:docs=>[{:id=>1, :"region-tz-min-offset"=>-480, :"dispensary-name"=>"dr. greenthumb garden supply 1", :"dispensary-slug"=>"dr-greenthumb-garden-supply-1", :"title-pc"=>"Dr. Greenthumb Garden Supply 1", :"dispensary-rating-power"=>"5.0000", :"dispensary-created"=>"1970-01-01T00:00:00.000Z", :video_url=>nil, :"dispensary-region-slug"=>"lake-tahoe", :"super-region-id"=>2, :"super-region-name"=>"California", :"super-region-slug"=>"california", :"dispensary-has-videos"=>0, :"dispensary-has-gpen"=>0, :"dispensary-hits"=>0, :hits=>0, :"reviewer-count"=>1, :intro=>"Hello body text", :"dispensary-intro"=>"Hello body text", :name=>"dr. greenthumb garden supply 1", :"name-phrase"=>"dr. greenthumb garden supply 1", :phone=>"555-555-5555", :zip=>"12345", :city=>"lake tahoe", :"city-phrase"=>"Lake Tahoe", :state=>"CA", :latitude=>32.751117, :longitude=>-117.213405, :location=>"32.751117,-117.213405", :featured=>1, :type=>"dispensary", :"within-5-mi-of"=>[], :"within-25-mi-of"=>[], :"within-50-mi-of"=>[], :"within-100-mi-o
@dreamr
dreamr / pre-commit
Created February 8, 2013 08:51
run tests with a pre-commit to keep me honest
#!/bin/sh
## .git/hooks/pre-commit
bundle exec rake db:migrate
bundle exec rake db:test:prepare
bundle exec rake test