3 日坊主日記
2008-03-05 [長年日記]
_ [Rails][NetBeans][Mercurial] NetBeans 6.1 / Rails 2.0 / Mercurial
忘れないうちにまとめ。
rails-2.0.2 projectをMercurialで管理する
ちょう簡単だった。
$ rails ror202 $ cd ror202 $ hg init $ hg add $ hg ci
いじょ。
注意:mercurialはからっぽディレクトリを保持してくれないので適当にtmp.txtを置いておこう。
$ hg revert log $ touch log/tmp.txt $ hg add log/tmp.txt
$ touch db/tmp.txt $ hg add db/tmp.txt
追記: ほかにもdb/migrate lib vendor/plugins辺り。
Mercurial reposをWeb上に公開する
とりあえずCGIなら簡単。
mercurial配布に含まれるhgweb.cgiを使う。
[moriq@dev ror202]$ cat /var/www/ror202/index.cgi
#!/usr/bin/env python
#
# An example CGI script to use hgweb, edit as necessary
# adjust python path if not a system-wide install:
#import sys
#sys.path.insert(0, "/usr/local/lib/python24/site-packages")
# enable importing on demand to reduce startup time
from mercurial import demandimport; demandimport.enable()
# send python tracebacks to the browser if an error occurs:
import cgitb
cgitb.enable()
# If you'd like to serve pages with UTF-8 instead of your default
# locale charset, you can do so by uncommenting the following lines.
# Note that this will cause your .hgrc files to be interpreted in
# UTF-8 and all your repo files to be displayed using UTF-8.
#
import os
os.environ["HGENCODING"] = "UTF-8"
from mercurial.hgweb.hgweb_mod import hgweb
from mercurial.hgweb.request import wsgiapplication
import mercurial.hgweb.wsgicgi as wsgicgi
def make_web_app():
return hgweb("/home/moriq/src/ror202", "rails-2.0.2 project")
wsgicgi.launch(wsgiapplication(make_web_app))
注意: Mercurialを何も考えずに
$ sudo make install
したら
/usr/local/lib/python24/site-packages
に置かれるのだけどPYTHONPATHを設定しないといけないとか。
よくわからないので
/usr/lib/python24/site-packages
に移動した。(よわ
追記: ApacheのCharset指定を止めている場合は
# httpd.conf: #AddDefaultCharset UTF-8
HGENCODING設定を有効にする必要がある。
# index.cgi: import os os.environ["HGENCODING"] = "UTF-8"
Apacheで公開。
# httpd.conf:
Alias /ror202 /var/www/ror202
<Directory "/var/www/ror202">
DirectoryIndex index.cgi
AddHandler cgi-script .cgi
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
できた!
やっぱりsshをつかう
httpだとhg pushできないのでsshとすべくplinkを使うよう設定。
plinkの配布元:PuTTY Download Page
1行追加するだけだった。
# Mercurial.ini: [ui] editor = d:\arc\vim\gvim.exe merge = c:\UnxUtils\usr\local\wbin\diff3.exe ssh = c:\Users\moriq\bin\plink.exe -l moriq -i C:\Users\moriq\.ssh\id_rsa.ppk
参考:*.ppkはputtygenで作ります。 詳しくはPuTTYでssh2プロトコルを使ってssh接続の後半を参照。
D:\usr\src>hg clone ssh://moriq@dev.moriq.com/src/ror202 ssh-ror202 requesting all changes adding changesets adding manifests adding file changes added 2 changesets with 45 changes to 45 files 45 files updated, 0 files merged, 0 files removed, 0 files unresolved D:\usr\src>cd ssh-ror202 D:\usr\src\ssh-ror202>hg pull ..\ror202 pulling from ..\ror202 searching for changes adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files (run 'hg update' to get a working copy) D:\usr\src\ssh-ror202>hg up 1 files updated, 0 files merged, 0 files removed, 0 files unresolved D:\usr\src\ssh-ror202>hg log changeset: 2:93bc3220fdda tag: tip user: moriq@moriq.com date: Wed Mar 05 00:10:06 2008 +0900 summary: add db/tmp.txt changeset: 1:a123037971e0 user: moriq@dev.moriq.com date: Wed Mar 05 00:00:30 2008 +0900 summary: add log/tmp.txt changeset: 0:3a81b06fdea8 user: moriq@dev.moriq.com date: Tue Mar 04 23:55:22 2008 +0900 summary: create mercurial repos for rails-2.0.2 project. D:\usr\src\ssh-ror202>hg push pushing to ssh://moriq@dev.moriq.com/src/ror202 searching for changes remote: adding changesets remote: adding manifests remote: adding file changes remote: added 1 changesets with 1 changes to 1 files
できた!
_ [NetBeans] NetBeans 6.1を野良build
Mercurial記念にNetBeans 6.1を野良buildしてみた。
最初
こっちを見たので全buildするはめになってしまった。
Ruby Packだけほしい場合は
こっちを見て進めたほうが良い。
_ [Rails] restful_authentication: RSpec option
D:\usr\src\ssh-ror202>ruby script\generate authenticated Usage: script/generate authenticated ModelName [ControllerName] Options: --rspec Force rspec mode (checks for RAILS_ROOT/spec by default)
むう。いつの間に。
D:\usr\src\ssh-ror202>ruby script\generate authenticated user sessions --rspec
? spec\controllers\sessions_controller_spec.rb ? spec\controllers\users_controller_spec.rb ? spec\fixtures\users.yml ? spec\models\user_spec.rb
# spec\models\user_spec.rb:
describe User do
fixtures :users
describe 'being created' do
before do
@user = nil
@creating_user = lambda do
@user = create_user
violated "#{@user.errors.full_messages.to_sentence}" if @user.new_record?
end
end
it 'increments User#count' do
@creating_user.should change(User, :count).by(1)
end
end
...
# spec\controllers\sessions_controller_spec.rb:
require File.dirname(__FILE__) + '/../spec_helper'
# Be sure to include AuthenticatedTestHelper in spec/spec_helper.rb instead
# Then, you can remove it from this and the units test.
include AuthenticatedTestHelper
describe SessionsController do
fixtures :users
it 'logins and redirects' do
post :create, :login => 'quentin', :password => 'test'
session[:user_id].should_not be_nil
response.should be_redirect
end
it 'fails login and does not redirect' do
post :create, :login => 'quentin', :password => 'bad password'
session[:user_id].should be_nil
response.should be_success
end
...
RSpecの教材としても有効かもしれない。
[ツッコミを入れる]
[]

