簡単なサンプルを作ってみる
Chapter 8. Active Resource で提示されているサンプルを真似てみます。とりあえず以下。
$ rails new api_sample -T $ cd api_sample
で、Gemfile を以下にして
source 'http://rubygems.org' gem 'rails', '3.0.9' gem 'sqlite3', '1.3.3' group :development do gem 'rspec-rails', '2.6.1' end group :test do gem 'rspec-rails', '2.6.1' gem 'webrat', '0.7.1' end
bundle install します。
$ bundle install Fetching source index for http://rubygems.org/ Using rake (0.9.2) Using abstract (1.0.0) Using activesupport (3.0.9) Using builder (2.1.2) Using i18n (0.5.0) Using activemodel (3.0.9) Using erubis (2.6.6) Using rack (1.2.4) Using rack-mount (0.6.14) Using rack-test (0.5.7) Installing tzinfo (0.3.30) Using actionpack (3.0.9) Using mime-types (1.16) Using polyglot (0.3.2) Using treetop (1.4.10) Using mail (2.2.19) Using actionmailer (3.0.9) Using arel (2.0.10) Using activerecord (3.0.9) Using activeresource (3.0.9) Using bundler (1.0.18) Using diff-lcs (1.1.3) Using nokogiri (1.5.0) Using rdoc (3.9.4) Using thor (0.14.6) Using railties (3.0.9) Using rails (3.0.9) Using rspec-core (2.6.4) Using rspec-expectations (2.6.0) Using rspec-mocks (2.6.0) Using rspec (2.6.0) Using rspec-rails (2.6.1) Using sqlite3 (1.3.3) Using webrat (0.7.1) Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. $
最初は model を作ります。
$ rails generate model Customer name:string age:integer invoke active_record create db/migrate/20111001021050_create_customers.rb create app/models/customer.rb invoke rspec create spec/models/customer_spec.rb $
で、試験から作るのか。