Skip to content

Instantly share code, notes, and snippets.

View dchelimsky's full-sized avatar

David Chelimsky dchelimsky

  • Retired
  • Chicago, IL, USA
View GitHub Profile
@dchelimsky
dchelimsky / output.txt
Created August 6, 2011 15:12 — forked from cjbottaro/gist:1128091
using shared_context with a block
# The following is an example of how you might use shared content to reduce the
# duplication in https://gist.github.com/1128108. I prefer to avoid examples
# that use `should respond_to`, as it specifies structure rather than behavior.
# I'd recommend specifying something about what happens when the message is
# sent, e.g. subject.some_method.should eq(some_value). That implicitly
# specifies that the object responds to some_method, and provides more useful
# direction/information about how the object should behave.
#
# That said ...
@dchelimsky
dchelimsky / temp_attribute.rb
Created July 15, 2011 16:33
assign temporary value to an attribute
with_attribute(SomeModel, :record_timestamps).temporarily(false) do
model_instance.update_attributes(:updated_at => 35.minutes.ago)
end
with_attribute(SomeModel, :record_timestamps, false) do
model_instance.update_attributes(:updated_at => 35.minutes.ago)
end
SomeModel.with(:record_timestamps, false) do # with, with_temp, with_attr???
model_instance.update_attributes(:updated_at => 35.minutes.ago)
class MacropostsController < ApplicationController
before_filter :authenticate
before_filter :authorized_user, :only => :destroy
def create
params[:macropost][:user_id] = current_user.id
params[:macropost][:project_id] = params[:project_id]
@macropost = Macropost.new(params[:macropost])
if @macropost.save
describe PostsController do
let(:post) { Factory(:post) }
describe "PUT #update" do
it "allows an author to edit a post" do
sign_in post.author
put :update, :id => post.id
response.should be_successful
end
@dchelimsky
dchelimsky / wdtm.sh
Created June 19, 2011 21:14
What does this mean?
$ which ruby
/Users/david/.rvm/rubies/ruby-1.8.6-p420/bin/ruby
$ gem install ruby-debug
Building native extensions. This could take a while...
ERROR: Error installing ruby-debug:
rbx-require-relative requires Ruby version ~> 1.8.7.
# why is anything rbx related coming into play in an mri 1.8.6 env?????
service = flexmock()
client = Client.new(service)
service.should_receive(:expensive_method).once.and_return('some data')
client.method_that_invokes_expensive_method_on_service
client.method_that_invokes_expensive_method_on_service
$ rake
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /Users/dchelimsky/.rvm/gems/ree-1.8.7-2011.03@chart/gems/rails-2.3.12/lib/rails/gem_dependency.rb:21.
NOTE: Gem::SourceIndex#spec_dirs= is deprecated, use Specification.dirs=. It will be removed on or after 2011-11-01.
Gem::SourceIndex#spec_dirs= called from /Users/dchelimsky/.rvm/gems/ree-1.8.7-2011.03@chart/gems/bundler-1.0.14/lib/bundler/rubygems_integration.rb:175.
NOTE: Gem::SourceIndex#add_specs is deprecated with no replacement. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_specs called from /Users/dchelimsky/.rvm/gems/ree-1.8.7-2011.03@chart/gems/bundler-1.0.14/lib/bundler/rubygems_integration.rb:176.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /Users/dchelimsky/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:1
shared_context 'user' do
before :all do
@user = User.create( :name => "Bob", :password => "foo", :admin => false )
end
def login
visit( url( :login ) )
fill_in :name, :with => "Bob"
fill_in :password, :with => "foo"
click_button "Login"
$ gem -v
1.8.5
$ rake -T
(in /Users/dchelimsky/work/chart)
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /Users/dchelimsky/work/chart/config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21.
NOTE: Gem::SourceIndex#refresh! is deprecated with no replacement. It will be removed on or after 2011-11-01.
Gem::SourceIndex#refresh! called from /Users/dchelimsky/work/chart/config/../vendor/rails/railties/lib/rails/vendor_gem_source_index.rb:34.
NOTE: Gem::SourceIndex#load_gems_in is deprecated with no replacement. It will be removed on or after 2011-11-01.
Gem::SourceIndex#load_gems_in called from /Users/dchelimsky/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:320.
<!DOCTYPE html>
<html>
<head>
<title>JQuery example</title>
<script src="jquery.js" type="text/javascript"></script>
<script type='text/javascript'>
//<![CDATA[
$(function() {
$('.panel').bind('showDescription', function() {
$(this).show();