Skip to content

Instantly share code, notes, and snippets.

@okitan
okitan / config.ru
Created October 10, 2011 06:45
api to return error status
$: << '.'
require 'test_app'
use Rack::ContentType
use Rack::ContentLength
run TestApp
@okitan
okitan / alias.rb
Created July 20, 2011 00:18
メタプログラミングRuby勉強会
class MyClass
def old_method
"my_method"
end
alias new_method old_method
# alias_method :new_method, :old_method
end
obj = MyClass.new
@okitan
okitan / gist:1077307
Created July 12, 2011 02:58
こういうのがいいかな
each_context {
'Aの場合' => { :key => 'a' },
'Bの場合' => { :key => 'b' },
} do
it { ... }
end
__EOF__
{
@okitan
okitan / $stdout
Created May 16, 2011 12:51
embedded_object_id=false bugs
FFF
Failures:
1) embedde many object making two grandsons failed childs is one
Failure/Error: Parent.where(:foo => 'foo').first.sons.should have(1).items
expected 1 items, got 2
# ./embedded_object_id_spec.rb:55:in `block (3 levels) in <top (required)>'
2) embedde many object making two grandsons failed grandsons is two
@okitan
okitan / gist:971979
Created May 14, 2011 06:18
楽になったと言えるのか怪しくはあるw
request_json 'POST /users/:user_id/articles' do # request_json is nicer than describe_jsonapi?
let(:user_id) { 1 }
let(:article_id) { 'hello' }
before(:all) { User.make!(:id => :user_id) }
after(:all) { DatabaseCleaner.clean }
context 'when user posts valid article' do
request_json do
Article.make(:user_id => id, :article_id => article_id)
@okitan
okitan / gist:971950
Created May 14, 2011 05:40
こんな感じでAPIのspecを楽に書きたいんだけど
describe_jsonapi 'GET /users/:id' do
let(:id) { 1 }
context 'when user exists' do
before(:all) do
User.make(:id => id)
Article.make(:user_id => id, :article_id => 1)
end
after(:all) { DatabaseCleaner.clean }
require 'ruby_gntp'
def your_app
#TODO:
end
def your_host
#TODO:
end
@okitan
okitan / config
Created December 8, 2010 09:31
a part of .subversion/config
[auto-props]
### The format of the entries is:
### file-name-pattern = propname[=value][;propname[=value]...]
### The file-name-pattern can contain wildcards (such as '*' and
### '?'). All entries which match (case-insensitively) will be
### applied to the file. Note that auto-props functionality
### must be enabled, which is typically done by setting the
### 'enable-auto-props' option.
# *.c = svn:eol-style=native
# *.cpp = svn:eol-style=native
if [ $rvm_ruby_home ] ; then
alias gem='gem --config-file ~/.gemrc_for_rvm'
echo `type gem`
else
[ `type gem | awk '{print $4}'` = 'alias' ] && unalias gem
fi
describe MyController, '#index' do
include PureControllerTestHelper
let(:user) { MyModel.make_unsaved }
before do
mock(MyModel).find { user }
end
it 'should assign @user'