Rails(2.2.2)アプリケーション、i18n_generators、rspec-rails、Cucumber Webrat

今日現在での Railsアプリケーション作成の初期段階、或は準備

プラグイ(ギ)ンでいれる、ジェムで入れるのとどっちが良いかはよく分からない
Difference between gem and plugin - Ruby Forum

環境

[2857] uname -srvo                     ~/rails 23:07 1208
Linux 2.6.18-6-686 #1 SMP Mon Oct 13 16:13:09 UTC 2008 GNU/Linux
[2858] ruby -v                         ~/rails 23:07 1208
ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
[2859] rails -v                        ~/rails 23:07 1208
Rails 2.2.2
[2860] gem -v                          ~/rails 23:08 1208
1.3.1
[2862] git --version                   ~/rails 23:09 1208
git version 1.5.6.5

ちなみに Debian/GNU Linux 4.0(etch) に、今testingな lenny のパッケージを適宜混ぜてる。

railsコマンド

[2871] rails application -d postgresql
 <云々>
[2872] cd application                  ~/rails 23:19 1208
[2873]                     ~/rails/application 23:20 1208

config/database.yml調整、データベースユーザ等
というか、「pool: 5」だって、なってる。

[2877] rake db:create      ~/rails/application 23:25 1208
You’re riding Ruby on Rails!
About your application’s environment
Ruby version 1.8.7 (i486-linux) 
RubyGems version 1.3.1 
Rails version 2.2.2 
Active Record version 2.2.2 
Action Pack version 2.2.2 
Active Resource version 2.2.2 
Action Mailer version 2.2.2 
Active Support version 2.2.2 
Application root /home/hs9587/rails/application 
Environment development 
Database adapter postgresql 
Database schema version 0 

PostgreSQLを使ってるわけだけどこのDB接続確認は

  SQL (2.7ms)   SET client_min_messages TO 'panic'
  SQL (0.2ms)   SET client_min_messages TO 'notice'

改めて client_min_messages を見ると なってる。

application_development=> SHOW client_min_messages ;
 client_min_messages
                                        • -
notice (1 row)

クライアントが受け取るログレベル DEBUG5 | DEBUG4 | DEBUG3 | DEBUG2 | DEBUG1 | LOG | NOTICE | WARNING | ERROR

i18n_generators インストール(プラグイン)

http://blog.dio.jp/2008/11/22/japanizing-rails-2-2-by-i18n-generators
GitHub - amatsuda/i18n_generators: A pack of Rails generators gem plugin that generates Rails 3 and Rails 2 I18n locale files for almost every known locale.

[2879] script/plugin install git://github.com/amatsuda/i18n_generators.git
Ruby-GetTextインストール(ジェム)

Ruby-GetText も必要なんだよね。

[2931] sudo gem install gettext        ~/rails 21:19 1211
Successfully installed gettext-1.93.0
1 gem installed
Installing ri documentation for gettext-1.93.0...
Installing RDoc documentation for gettext-1.93.0...

Cucumberインストール(プラグイン)

Cucumberがアツい - moroの日記Webratがスゴい(続:Cucumberがアツい) - moroの日記
The world’s leading software development platform · GitHub

git submodule add git://github.com/aslakhellesoy/cucumber.git vendor/plugins/cucumber
git submodule add git://github.com/brynary/webrat.git vendor/plugins/webrat
git submodule add git://github.com/dchelimsky/rspec.git vendor/plugins/rspec
git submodule add git://github.com/dchelimsky/rspec-rails.git vendor/plugins/rspec-rails

しかし、失敗

[2897] git submodule add git://github.com/aslakhellesoy/cucumber.git vendor/plugins/cucumber
fatal: Not a git repository
[2898] git submodule add git://github.com/brynary/webrat.git vendor/plugins/webrat
fatal: Not a git repository
[2899] git submodule add git://github.com/dchelimsky/rspec.git vendor/plugins/rspec
fatal: Not a git repository
[2900] git submodule add git://github.com/dchelimsky/rspec-rails.git vendor/plugins/rspec-rails
fatal: Not a git repository

git じゃないって。
では、script/plugin で

script/plugin install git://github.com/aslakhellesoy/cucumber.git git://github.com/brynary/webrat.git git://github.com/dchelimsky/rspec.git git://github.com/dchelimsky/rspec-rails.git

今度はインストールできた。

[2909] ls vendor/plugins   ~/rails/application 20:00 1211
cucumber/  i18n_generators/  rspec/  rspec-rails/  webrat/

ちょっとやってみる

[2910] script/generate cucumber
      create  features/step_definitions
      create  features/step_definitions/webrat_steps.rb
      create  features/support
      create  features/support/env.rb
      exists  lib/tasks
      create  lib/tasks/cucumber.rake
      create  script/cucumber
[2911] rake features       ~/rails/application 20:07 1211
(in /home/hs9587/rails/application)
NOTICE:  database "application_test" does not exist, skipping
rake aborted!
no such file to load -- /home/hs9587/rails/application/db/schema.rb

(See full trace by running task with --trace)

何もないとなにもしない、DROP も出来ないと終わってる模様。
というかそれはそれとして、依存する RubyGems 無くても大丈夫なのか、まだ「gem install term-ansicolor treetop diff-lcs nokogiri」してない。
ここでスペックしてみる

[2913] script/generate rspec
[2914] rake spec           ~/rails/application 20:32 1211
(in /home/hs9587/rails/application)
rake aborted!
no such file to load -- /home/hs9587/rails/application/db/schema.rb

(See full trace by running task with --trace)
[2915] rake features       ~/rails/application 20:33 1211
(in /home/hs9587/rails/application)
rake aborted!
no such file to load -- /home/hs9587/rails/application/db/schema.rb

(See full trace by running task with --trace)

データーベース application_test は出来てる、けど何も無い。

なんかちょっと作ってみる。

何かちょっと作って試る

[2943] script/generate i18n_scaffold ja
[2977] script/generate i18n_scaffold Entry text:text timing:datetime size:integer

マイグレーションファイルちょっと

class CreateEntries < ActiveRecord::Migration
  def self.up
    create_table :entries do |t|
      t.text :text
      t.datetime :timing, :null => false
      t.integer :size, :default => 0

      t.timestamps
    end
  end

  def self.down
    drop_table :entries
  end
end

RSpec方面も

[2981] script/generate rspec_scaffold Entry text:text timing:datetime size:integer
  The name 'EntriesHelper' is either already used in your application or reserved by Ruby on Rails.
  Please choose an alternative and run this generator again.

ふうむ、一時的に 'EntriesHelper' を改名、後でマージ

overwrite app/controllers/entries_controller.rb? (enter "h" for help) [Ynaqdh] n
overwrite app/views/entries/index.html.erb? (enter "h" for help) [Ynaqdh] n
overwrite app/views/entries/show.html.erb? (enter "h" for help) [Ynaqdh] n
overwrite app/views/entries/new.html.erb? (enter "h" for help) [Ynaqdh] n
overwrite app/views/entries/edit.html.erb? (enter "h" for help) [Ynaqdh] n

まあいろいろ重複もある、app/helpers/entries_helper.rb は diff しても特に相違無かった。

Rails2.2.2 と PostgreSQL

それはそれとして、マイグレーションに失敗する。

[3012] rake db:migrate     ~/rails/application 12:33 1213
(in /home/hs9587/rails/application)
==  CreateEntries: migrating ==================================================
    • create_table(:entries)
NOTICE: CREATE TABLE will create implicit sequence "entries_id_seq" for serial column "entries.id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "entries_pkey" for table "entries" -> 0.0475s == CreateEntries: migrated (0.0485s) ========================================= rake aborted! An error has occurred, this and all later migrations canceled: undefined method `transaction_status' for # (See full trace by running task with --trace)

http://wota.jp/ac/?date=20081030#p01 より、PostgreSQLのドライバを更新。
今使ってるのは、libpgsql-ruby でしょう。

[3012] aptitude search pg G ruby
i   libdbd-pg-ruby                  - Ruby/DBI PostgreSQL driver
i A libdbd-pg-ruby1.8               - Ruby/DBI PostgreSQL driver for Ruby 1.8
p   libgpgme-ruby                   - GPGME bindings for the Ruby language
p   libgpgme-ruby1.8                - GPGME bindings for the Ruby language
p   libgpgme-ruby1.9                - GPGME bindings for the Ruby language
i   libpgsql-ruby                   - PostgreSQL interface for Ruby
p   libpgsql-ruby-doc               - Documentation for PostgreSQL interface for
i A libpgsql-ruby1.8                - PostgreSQL interface for Ruby 1.8

ruby-pgドライバをインストール

[3020] sudo gem install ruby-pg
Building native extensions.  This could take a while...
ERROR:  Error installing ruby-pg:
        ERROR: Failed to build gem native extension.
<云々>

エラー、ヘッダが無い模様 libpq-dev, postgresql-server-dev を aptitude から、ちょっと依存性警告あり。

あとまだもうちょっと。

i   postgresql-server-dev-8.3       - development files for PostgreSQL 8.3 serve
i A libpq-dev                       - header files for libpq5 (PostgreSQL librar

改めてジェムでドライバ。

[3034] sudo gem install ruby-pg
Building native extensions.  This could take a while...
Successfully installed ruby-pg-0.7.9.2008.01.28
1 gem installed
Installing ri documentation for ruby-pg-0.7.9.2008.01.28...
Installing RDoc documentation for ruby-pg-0.7.9.2008.01.28...

マイグレーション

[3042] rake db:migrate     ~/rails/application 15:27 1214
(in /home/hs9587/rails/application)
==  CreateEntries: migrating ==================================================
    • create_table(:entries)
NOTICE: CREATE TABLE will create implicit sequence "entries_id_seq" for serial column "entries.id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "entries_pkey" for table "entries" -> 0.2779s == CreateEntries: migrated (0.2814s) =========================================

最初のスペックとフィーチャ

「rake spec」はOK、generatorが作ったスペックは全部通る。「ruby stories/all.rb」も、というか何も無い。「rake features」はエラー、treetop/runtime が無いって。まあ、他にもジェムの依存性があるよね、という事で。

[3047] sudo gem install term-ansicolor treetop diff-lcs nokogiri

nokogiri がインストールエラーになる、libxslt が無いっぽい。
aptitudeから、

それで、

  • libxml-ruby1.8
  • libxslt-ruby1.8
  • libxalt1.1

まだエラー、ヘッダ必要ぽい、再び aptitudeから、

  • libxslt1-dev
[3066] sudo gem install nokogiri
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.0.7
1 gem installed
Installing ri documentation for nokogiri-1.0.7...
Installing RDoc documentation for nokogiri-1.0.7...

何とかなる、で「rake features」OK、何も無いけど。

日本語リソース

[3061] script/generate i18n ja
      exists  config/locales
      update  config/environment.rb
      create  config/locales/ja.yml
       debug  took 2.946023 secs to translate 1 models.
       debug  took 1.407494 secs to translate 9 words.
      create  config/locales/translation_ja.yml

ちょっと時間掛かる、そういえば翻訳どっか見に行ってるんだっけ。
モデルにヴァリデーション、

class Entry < ActiveRecord::Base
  validates_presence_of :text
end

「script/server」は起動し直す、なんか翻訳されてるっぽい。

index一覧

Listing エントリ
テキスト タイミング 寸法 

New エントリ 

テキストからでやってみる、何かエラーになる。

translation missing: ja, activerecord, errors, template, header
translation missing: ja, activerecord, errors, template, body

テキスト を入力してください。

エラーメッセージ自体は翻訳されてるがちょっとエラー。
config/locales/ja.yml の activerecord:節が二つに分かれちゃってるのがいけない模様、

  activerecord:
    errors:
      template:
        header:
          one:   "{{model}}にエラーが発生しました。"
          other: "{{model}}に{{count}}つのエラーが発生しました。"

        body: "次の項目を確認してください。"

  activerecord:
    errors:
      messages:
        inclusion: "は一覧にありません。"
        exclusion: "は予約されています。"
 <云々>

まとめてみる。

  activerecord:
    errors:
      template:
        header:
          one:   "{{model}}にエラーが発生しました。"
          other: "{{model}}に{{count}}つのエラーが発生しました。"

        body: "次の項目を確認してください。"

      messages:
        inclusion: "は一覧にありません。"
        exclusion: "は予約されています。"
 <云々>

これで何とかなる。

エントリにエラーが発生しました。
次の項目を確認してください。

テキスト を入力してください。

cucemberフィーチャ

[3066] script/generate feature Entry text:text timing:datetime size:integer
      exists  features/step_definitions
      create  features/manage_entries.feature
      create  features/step_definitions/entry_steps.rb

「rake features」は失敗する、大体日本語じゃないし。

2 steps passed
2 steps failed
6 steps skipped
1 steps pending (1 with no step definition)

取り敢えずこのくらい、failedを解消しフィーチャを日本語するのはまた。